Advertisement
xosski

Chrome Remote Desktop Cadilac

Jan 22nd, 2025
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.84 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Set up logging
  4. LOGFILE="/var/log/setup-chrome-rdp.log"
  5. exec > >(tee -i "$LOGFILE") 2>&1
  6. exec 2>&1
  7.  
  8. # Require script to be run as root
  9. function super_user_check() {
  10. if [ "${EUID}" -ne 0 ]; then
  11. echo "You need to run this script as a superuser."
  12. exit 1
  13. fi
  14. }
  15.  
  16. # Check for root
  17. super_user_check
  18.  
  19. # Detect Operating System
  20. function dist_check() {
  21. if [ -f /etc/os-release ]; then
  22. # shellcheck disable=SC1091
  23. source /etc/os-release
  24. DISTRO=${ID}
  25. else
  26. echo "Error: Unable to detect operating system."
  27. exit 1
  28. fi
  29. }
  30.  
  31. # Check Operating System
  32. dist_check
  33.  
  34. # Install system requirements
  35. function install_system_requirements() {
  36. if [[ "${DISTRO}" == "ubuntu" || "${DISTRO}" == "debian" ]]; then
  37. echo "Updating package lists..."
  38. apt-get update || { echo "Error: Failed to update package lists."; exit 1; }
  39. echo "Installing necessary packages..."
  40. apt-get install -y curl haveged || { echo "Error: Failed to install required packages."; exit 1; }
  41. else
  42. echo "Error: ${DISTRO} is not supported."
  43. exit 1
  44. fi
  45. }
  46.  
  47. install_system_requirements
  48.  
  49. # Install Chrome Remote Desktop and Google Chrome
  50. function install_chrome_headless() {
  51. local chrome_remote_desktop_url="https://dl.google.com/linux/direct/chrome-remote-desktop_current_amd64.deb"
  52. local chrome_browser_url="https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb"
  53. local chrome_remote_desktop_local_path="/tmp/chrome-remote-desktop_current_amd64.deb"
  54. local chrome_browser_local_path="/tmp/google-chrome-stable_current_amd64.deb"
  55.  
  56. if dpkg -l | grep -q chrome-remote-desktop; then
  57. echo "Chrome Remote Desktop is already installed. Skipping installation."
  58. else
  59. echo "Installing Chrome Remote Desktop..."
  60. curl -o "${chrome_remote_desktop_local_path}" "${chrome_remote_desktop_url}" || { echo "Error: Failed to download Chrome Remote Desktop."; exit 1; }
  61. dpkg --install "${chrome_remote_desktop_local_path}" || { echo "Error: Failed to install Chrome Remote Desktop."; exit 1; }
  62. rm -f "${chrome_remote_desktop_local_path}"
  63. fi
  64.  
  65. if dpkg -l | grep -q google-chrome-stable; then
  66. echo "Google Chrome is already installed. Skipping installation."
  67. else
  68. echo "Installing Google Chrome..."
  69. curl -o "${chrome_browser_local_path}" "${chrome_browser_url}" || { echo "Error: Failed to download Google Chrome."; exit 1; }
  70. dpkg --install "${chrome_browser_local_path}" || { echo "Error: Failed to install Google Chrome."; exit 1; }
  71. rm -f "${chrome_browser_local_path}"
  72. fi
  73.  
  74. echo "Installing XFCE desktop environment..."
  75. apt-get install -y xfce4 desktop-base task-xfce-desktop xscreensaver || { echo "Error: Failed to install XFCE."; exit 1; }
  76.  
  77. echo "Configuring Chrome Remote Desktop session..."
  78. echo "exec /etc/X11/Xsession /usr/bin/xfce4-session" >> /etc/chrome-remote-desktop-session || { echo "Error: Failed to configure Chrome Remote Desktop session."; exit 1; }
  79.  
  80. echo "Resolving dependencies..."
  81. apt-get install -f -y || { echo "Error: Failed to resolve dependencies."; exit 1; }
  82. }
  83.  
  84. install_chrome_headless
  85.  
  86. # Handle LightDM service
  87. function handle_services() {
  88. echo "Stopping LightDM service to avoid conflicts..."
  89. if command -v systemctl &>/dev/null; then
  90. systemctl stop lightdm || echo "Warning: Failed to stop LightDM with systemctl."
  91. elif command -v service &>/dev/null; then
  92. service lightdm stop || echo "Warning: Failed to stop LightDM with service."
  93. else
  94. echo "Error: No service management tool found to stop LightDM."
  95. exit 1
  96. fi
  97. }
  98.  
  99. handle_services
  100.  
  101. # Cleanup and exit
  102. echo "Setup completed successfully. Logs can be found at $LOGFILE."
  103. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement