Skip to content

Instantly share code, notes, and snippets.

@PradyumnaKrishna
Last active November 28, 2023 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 10 You must be signed in to fork a gist
  • Save PradyumnaKrishna/affb0d4478d74305441046cfcd748a6e to your computer and use it in GitHub Desktop.
Save PradyumnaKrishna/affb0d4478d74305441046cfcd748a6e to your computer and use it in GitHub Desktop.
Make any Instance Ready for Remote Desktop or RDP (Chrome Remote Desktop)
#!/bin/bash -x
#
# Startup script to install Chrome remote desktop and a desktop environment.
#
# See environmental variables at then end of the script for configuration
#
# Run this script by root
# a user will get created with name: user and password: root
# Make Instance Ready for Remote Desktop or RDP
# Branding
printf """
Remote Desktop Setup
By Pradyumna Krishna © 2020
Github : https://github.com/PradyumnaKrishna
""";
# User Creation
user=user
# Creation of user
useradd -m user
# Add user to sudo group
adduser user sudo
# Set password of user to 'root'
echo 'user:root' | sudo chpasswd
# Change default shell from sh to bash
sed -i 's/\/bin\/sh/\/bin\/bash/g' /etc/passwd
function install_desktop_env {
PACKAGES="desktop-base xscreensaver"
if [[ "$INSTALL_XFCE" != "yes" && "$INSTALL_CINNAMON" != "yes" ]] ; then
# neither XFCE nor cinnamon specified; install both
INSTALL_XFCE=yes
INSTALL_CINNAMON=yes
fi
if [[ "$INSTALL_XFCE" = "yes" ]] ; then
PACKAGES="$PACKAGES xfce4"
echo "exec xfce4-session" > /etc/chrome-remote-desktop-session
[[ "$INSTALL_FULL_DESKTOP" = "yes" ]] && \
PACKAGES="$PACKAGES task-xfce-desktop"
fi
if [[ "$INSTALL_CINNAMON" = "yes" ]] ; then
PACKAGES="$PACKAGES cinnamon-core"
echo "exec cinnamon-session-cinnamon2d" > /etc/chrome-remote-desktop-session
[[ "$INSTALL_FULL_DESKTOP" = "yes" ]] && \
PACKAGES="$PACKAGES task-cinnamon-desktop"
fi
DEBIAN_FRONTEND=noninteractive \
apt-get install --assume-yes $PACKAGES $EXTRA_PACKAGES
systemctl disable lightdm.service
}
function download_and_install { # args URL FILENAME
curl -L -o "$2" "$1"
dpkg --install "$2"
apt-get install --assume-yes --fix-broken
}
function is_installed { # args PACKAGE_NAME
dpkg-query --list "$1" | grep -q "^ii" 2>/dev/null
return $?
}
# Configure the following environmental variables as required:
INSTALL_XFCE=yes
INSTALL_CINNAMON=no
INSTALL_CHROME=yes
INSTALL_FULL_DESKTOP=no
# Any additional packages that should be installed on startup can be added here
EXTRA_PACKAGES="less bzip2 zip unzip"
apt-get update
! is_installed chrome-remote-desktop && \
download_and_install \
https://dl.google.com/linux/direct/chrome-remote-desktop_current_amd64.deb \
/tmp/chrome-remote-desktop_current_amd64.deb
install_desktop_env
[[ "$INSTALL_CHROME" = "yes" ]] && \
! is_installed google-chrome-stable && \
download_and_install \
https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \
/tmp/google-chrome-stable_current_amd64.deb
echo "Chrome remote desktop installation completed"
# Adding user to CRP group
adduser $user chrome-remote-desktop
# Finishing Work
printf '\nVisit http://remotedesktop.google.com/headless and Copy the command after authentication\n'
read -p "Give Command: " CRP
su - $user -c """$CRP"""
service chrome-remote-desktop start
printf "\nFinished Succesfully"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment