diff --git a/OneClickDesktop.sh b/OneClickDesktop.sh index 5f8705e..d40cfc1 100644 --- a/OneClickDesktop.sh +++ b/OneClickDesktop.sh @@ -1,6 +1,6 @@ #!/bin/bash ########################################################################################### -# One-click Desktop & Browser Access Setup Script v0.1.0 # +# One-click Desktop & Browser Access Setup Script v0.2.0 # # Written by shc (https://qing.su) # # Github link: https://github.com/Har-Kuun/OneClickDesktop # # Contact me: https://t.me/hsun94 E-mail: hi@qing.su # @@ -22,9 +22,9 @@ GUACAMOLE_DOWNLOAD_LINK="https://mirrors.ocf.berkeley.edu/apache/guacamole/1.2.0/source/guacamole-server-1.2.0.tar.gz" GUACAMOLE_VERSION="1.2.0" -#By default, this script only works on Ubuntu 18/20 and Debian 10. +#By default, this script only works on Ubuntu 18/20, Debian 10, and CentOS 7/8. #You can disable the OS check switch below and tweak the code yourself to try to install it in other OS versions. -#Please do note that if you choose to use this script on OS other than Ubuntu 18/20 or Debian 10, you might mess up your OS. Please keep a backup of your server before installation. +#Please do note that if you choose to use this script on OS other than Ubuntu 18/20, Debian 10, or CentOS 7/8, you might mess up your OS. Please keep a backup of your server before installation. OS_CHECK_ENABLED=ON @@ -41,19 +41,16 @@ exec 2>&1 function check_OS { - if [ -f /etc/lsb-release ] - then + if [ -f /etc/lsb-release ] ; then cat /etc/lsb-release | grep "DISTRIB_RELEASE=18." >/dev/null - if [ $? = 0 ] - then + if [ $? = 0 ] ; then OS=UBUNTU18 else cat /etc/lsb-release | grep "DISTRIB_RELEASE=20." >/dev/null - if [ $? = 0 ] - then + if [ $? = 0 ] ; then OS=UBUNTU20 else - say "Sorry, this script only supports Ubuntu 18, 20 and Debian 10." red + say "Sorry, this script only supports Ubuntu 20, Debian 10, and CentOS 7/8." red echo exit 1 fi @@ -63,12 +60,32 @@ function check_OS if [ $? = 0 ] ; then OS=DEBIAN10 else - say "Sorry, this script only supports Ubuntu 18, 20 and Debian 10." red + say "Sorry, this script only supports Ubuntu 20, Debian 10, and CentOS 7/8." red echo exit 1 fi + elif [ -f /etc/redhat-release ] ; then + cat /etc/redhat-release | grep " 8." >/dev/null + if [ $? = 0 ] ; then + OS=CENTOS8 + say @B"Support of CentOS 8 is experimental. Please report bugs." yellow + say @B"Please try disabling selinux or firewalld if you cannot visit your desktop." yellow + echo + else + cat /etc/redhat-release | grep " 7." >/dev/null + if [ $? = 0 ] ; then + OS=CENTOS7 + say @B"Support of CentOS 7 is experimental. Please report bugs." yellow + say @B"Please try disabling selinux or firewalld if you cannot visit your desktop." yellow + echo + else + say "Sorry, this script only supports Ubuntu 20, Debian 10, and CentOS 7/8." red + echo + exit 1 + fi + fi else - say "Sorry, this script only supports Ubuntu 18, 20 and Debian 10." red + say "Sorry, this script only supports Ubuntu 20, Debian 10, and CentOS 7/8." red echo exit 1 fi @@ -129,9 +146,14 @@ function get_user_options read guacamole_password_prehash read guacamole_password_md5 <<< $(echo -n $guacamole_password_prehash | md5sum | awk '{print $1}') echo - say @B"Would you like Guacamole to connect to the server desktop through RDP or VNC?" yellow - say @B"Input 1 for RDP, or 2 for VNC. If you have no idea what's this, please choose 1." yellow - read choice_rdpvnc + if [ "x$OS" != "xCENTOS8" ] && [ "x$OS" != "xCENTOS7" ] ; then + say @B"Would you like Guacamole to connect to the server desktop through RDP or VNC?" yellow + say @B"Input 1 for RDP, or 2 for VNC. If you have no idea what's this, please choose 1." yellow + read choice_rdpvnc + else + say @B"Guacamole will use RDP to communicate with server desktop." yellow + choice_rdpvnc=1 + fi echo if [ $choice_rdpvnc = 1 ] ; then say @B"Please choose a screen resolution." yellow @@ -176,7 +198,7 @@ function get_user_options say @B"Please note that if you want to copy or paste text between the server and your computer, you MUST set up an Nginx Reverse Proxy AND an SSL certificate. You can set it up later manually though." yellow echo "Please type [Y/n]:" read install_nginx - if [ "x$install_nginx" = "xY" ] || [ "x$install_nginx" = "xy" ] ; then + if [ "x$install_nginx" != "xn" ] && [ "x$install_nginx" != "xN" ] ; then echo say @B"Please tell me your domain name (e.g., desktop.qing.su):" yellow read guacamole_hostname @@ -199,7 +221,7 @@ function get_user_options sleep 3 } -function install_guacamole +function install_guacamole_ubuntu_debian { echo say @B"Setting up dependencies..." yellow @@ -253,20 +275,124 @@ function install_guacamole fi } +function install_guacamole_centos +{ + echo + say @B"Setting up dependencies..." yellow + echo + if [ "$OS" = "CENTOS8" ] ; then + dnf -y update + dnf -y group install "Development Tools" + dnf -y install --nogpgcheck https://download1.rpmfusion.org/free/el/rpmfusion-free-release-8.noarch.rpm + dnf -y install http://rpmfind.net/linux/epel/7/x86_64/Packages/s/SDL2-2.0.10-1.el7.x86_64.rpm + dnf -y install http://mirror.centos.org/centos/8/Devel/x86_64/os/Packages/libuv-devel-1.23.1-1.el8.x86_64.rpm + dnf -y --enablerepo=PowerTools install perl expect cairo cairo-devel libpng-devel libtool uuid libjpeg-devel libjpeg-turbo-devel freerdp freerdp-devel pango-devel libssh2-devel libvncserver-devel pulseaudio-libs-devel openssl-devel libwebp-devel libwebsockets-devel libvorbis-devel ffmpeg-devel uuid-devel ffmpeg ffmpeg-devel mingw64-filesystem + yum -y groupinstall Fonts + dnf -y install java-11-openjdk-devel + else + yum update -y + yum -y install epel-release + yum -y install wget curl vim tar sudo zip unzip perl git cairo-devel freerdp-devel freerdp-plugins gcc gnu-free-mono-fonts libjpeg-turbo-devel libjpeg-turbo-official libpng-devel libssh2-devel libtelnet-devel libvncserver-devel libvorbis-devel libwebp-devel libwebsockets-devel openssl-devel pango-devel policycoreutils-python pulseaudio-libs-devel setroubleshoot uuid-devel + yum -y localinstall --nogpgcheck https://download1.rpmfusion.org/free/el/rpmfusion-free-release-7.noarch.rpm + yum -y install ffmpeg ffmpeg-devel + yum -y groupinstall Fonts + yum -y install java-11-openjdk-devel + fi + install_tomcat9_centos + wget $GUACAMOLE_DOWNLOAD_LINK + tar zxf guacamole-server-${GUACAMOLE_VERSION}.tar.gz + rm -f guacamole-server-${GUACAMOLE_VERSION}.tar.gz + cd $CurrentDir/guacamole-server-$GUACAMOLE_VERSION + echo "Start building Guacamole Server from source..." + ./configure --with-init-dir=/etc/init.d + if [ -f $CurrentDir/guacamole-server-$GUACAMOLE_VERSION/config.status ] ; then + say @B"Dependencies met!" green + say @B"Compiling now..." green + echo + else + echo + say "Missing dependencies." red + echo "Please check log, install required dependencies, and run this script again." + echo "Please also consider to report your log here https://github.com/Har-Kuun/OneClickDesktop/issues so that I can fix this issue." + echo "Thank you!" + echo + exit 1 + fi + sleep 2 + make + make install + ldconfig + echo "Trying to start Guacamole Server for the first time..." + echo "This can take a while..." + echo + service guacd start + chkconfig guacd on + ss -lnpt | grep guacd >/dev/null + if [ $? = 0 ] ; then + say @B"Guacamole Server successfully installed!" green + echo + else + say "Guacamole Server installation failed." red + say @B"Please check the above log for reasons." yellow + echo "Please also consider to report your log here https://github.com/Har-Kuun/OneClickDesktop/issues so that I can fix this issue." + echo "Thank you!" + exit 1 + fi +} + +function install_tomcat9_centos +{ + curl -s https://mirrors.ocf.berkeley.edu/apache/tomcat/tomcat-9/v9.0.38/bin/apache-tomcat-9.0.38.tar.gz | tar -xz + mv apache-tomcat-9.0.38 /etc/tomcat9 + echo "export CATALINA_HOME="/etc/tomcat9"" >> ~/.bashrc + source ~/.bashrc + useradd -r tomcat + chown -R tomcat:tomcat /etc/tomcat9 + cat > /etc/systemd/system/tomcat9.service < /etc/guacamole/guacamole.properties < /etc/guacamole/user-mapping.xml < + + + rdp + localhost + 3389 + rdp + + + +END + else + cat > /etc/guacamole/user-mapping.xml < + + + rdp + localhost + 3389 + $rdp_screen_width + $rdp_screen_height + rdp + + + +END + fi + systemctl restart tomcat9 guacd + say @B"Guacamole successfully configured!" green + echo +} + function install_vnc { echo @@ -416,22 +592,31 @@ function install_rdp { echo echo "Starting to install desktop, browser, and XRDP server..." - say @B"Please note that if you are asked to configure LightDM during this step, simply press Enter." yellow - echo - echo "Press Enter to continue." - read catch_all - echo + if [ "$OS" = "UBUNTU18" ] || [ "$OS" = "UBUNTU20" ] ; then + say @B"Please note that if you are asked to configure LightDM during this step, simply press Enter." yellow + echo + echo "Press Enter to continue." + read catch_all + echo + fi if [ "$OS" = "DEBIAN10" ] ; then apt-get install xfce4 xfce4-goodies firefox-esr xrdp -y - else + elif [ "$OS" = "CENTOS8" ] || [ "$OS" = "CENTOS7" ] ; then + yum -y groupinstall "Server with GUI" + yum -y install firefox + compile_xrdp_centos + yum -y install xorgxrdp + echo "allowed_users=anybody" > /etc/X11/Xwrapper.config + else apt-get install xfce4 xfce4-goodies firefox xrdp -y fi say @B"Desktop, browser, and XRDP server successfully installed." green echo "Starting to configure XRDP server..." sleep 2 echo - mv /etc/xrdp/startwm.sh /etc/xrdp/startwm.sh.backup - cat > /etc/xrdp/startwm.sh < /etc/xrdp/startwm.sh </dev/null + if [ $? = 0 ] ; then + say @B"Xrdp successfully installed!" green + echo + else + say "XRDP installation failed!" red + say @B"Please check the above log for reasons." yellow + echo "Please also consider to report your log here https://github.com/Har-Kuun/OneClickDesktop/issues so that I can fix this issue." + echo "Thank you!" + exit 1 + fi +} + function display_license { echo echo '*******************************************************************' echo '* One-click Desktop & Browser Access Setup Script *' - echo '* Version 0.0.2 *' + echo '* Version 0.2.0 *' echo '* Author: shc (Har-Kuun) https://qing.su *' echo '* https://github.com/Har-Kuun/OneClickDesktop *' echo '* Thank you for using this script. E-mail: hi@qing.su *' @@ -529,8 +761,18 @@ function install_reverse_proxy echo say @B"Setting up Nginx reverse proxy..." yellow sleep 2 - apt-get install nginx certbot python3-certbot-nginx -y - say @B"Nginx successfully installed!" green + if [ "$OS" = "CENTOS8" ] ; then + dnf -y install nginx certbot python3-certbot-nginx + systemctl enable nginx + systemctl start nginx + elif [ "$OS" = "CENTOS7" ] ; then + yum -y install nginx certbot python-certbot-nginx + systemctl enable nginx + systemctl start nginx + else + apt-get install nginx certbot python3-certbot-nginx -y + fi + say @B"Nginx successfully installed!" green cat > /etc/nginx/conf.d/guacamole.conf <