Update OneClickDesktop_zh-CN.sh

Add CentOS 7/8 support.
This commit is contained in:
Har-Kuun 2020-09-29 01:58:07 -05:00 committed by GitHub
parent 901cb651fa
commit 4a65134b14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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"
#此脚本仅支持Ubuntu 18/20或Debian 10.
#此脚本仅支持Ubuntu 18/20, Debian 10, 以及CentOS 7/8.
#如果您试图再其他版本的操作系统中安装可以在下面禁用OS检查开关。
#请注意,在其他操作系统上安装此脚本可能会导致不可预料的错误。请在安装前做好备份。
#请注意,在其他操作系统上安装此脚本可能会导致不可预料的错误。 请在安装前做好备份。
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 "很抱歉此脚本仅支持Ubuntu 18/20与Debian 10操作系统。" red
say "很抱歉此脚本仅支持Ubuntu 18/20, Debian 10, 以及CentOS 7/8操作系统。" red
echo
exit 1
fi
@ -63,12 +60,32 @@ function check_OS
if [ $? = 0 ] ; then
OS=DEBIAN10
else
say "很抱歉此脚本仅支持Ubuntu 18/20与Debian 10操作系统。" red
say "很抱歉此脚本仅支持Ubuntu 18/20, Debian 10, 以及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"CentOS 8的支持目前还处于测试阶段如果有bug欢迎提出。" yellow
say @B"如果安装好后无法访问您的服务器桌面请考虑禁用firewalld或者selinux." yellow
echo
else
cat /etc/redhat-release | grep " 7." >/dev/null
if [ $? = 0 ] ; then
OS=CENTOS7
say @B"CentOS 7的支持目前还处于测试阶段如果有bug欢迎提出。" yellow
say @B"如果安装好后无法访问您的服务器桌面请考虑禁用firewalld或者selinux." yellow
echo
else
say "很抱歉此脚本仅支持Ubuntu 18/20, Debian 10, 以及CentOS 7/8操作系统。" red
echo
exit 1
fi
fi
else
say "很抱歉此脚本仅支持Ubuntu 18/20与Debian 10操作系统。" red
say "很抱歉此脚本仅支持Ubuntu 18/20, Debian 10, 以及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"您想让Guacamole通过RDP还是VNC连接Linux桌面" yellow
say @B"RDP请输入1, VNC请输入2. 如果您不清楚这是什么请输入1." yellow
read choice_rdpvnc
if [ "x$OS" != "xCENTOS8" ] && [ "x$OS" != "xCENTOS7" ] ; then
say @B"您想让Guacamole通过RDP还是VNC连接Linux桌面" yellow
say @B"RDP请输入1, VNC请输入2. 如果您不清楚这是什么请输入1." yellow
read choice_rdpvnc
else
say @B"Guacamole将通过RDP与桌面环境通信。" yellow
choice_rdpvnc=1
fi
echo
if [ $choice_rdpvnc = 1 ] ; then
say @B"请选择屏幕分辨率。" yellow
@ -174,9 +196,9 @@ function get_user_options
echo
say @B"请问您是否想要设置Nginx反代" yellow
say @B"请注意如果您想在本地电脑和服务器之间复制粘贴文本您必须启用反代并设置SSL. 不过,您也可以暂时先不设置反代,以后再手动设置。" yellow
echo "Please type [Y/n]:"
echo "请输入 [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"请输入您的域名比如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"安装依赖环境..." yellow
@ -253,20 +275,124 @@ function install_guacamole
fi
}
function install_guacamole_centos
{
echo
say @B"安装依赖环境..." 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 "开始安装Guacamole服务器..."
./configure --with-init-dir=/etc/init.d
if [ -f $CurrentDir/guacamole-server-$GUACAMOLE_VERSION/config.status ] ; then
say @B"编译条件已满足!" green
say @B"开始编译源码..." green
echo
else
echo
say "依赖环境缺失。" red
echo "请核查日志,安装必要的依赖环境,并再次运行此脚本。"
echo "欢迎您在https://github.com/Har-Kuun/OneClickDesktop/issues这里提交错误报告以便我修复脚本。"
echo "谢谢!"
echo
exit 1
fi
sleep 2
make
make install
ldconfig
echo "第一次启动Guacamole服务器可能需要较长时间..."
echo "请耐心等待..."
echo
service guacd start
chkconfig guacd on
ss -lnpt | grep guacd >/dev/null
if [ $? = 0 ] ; then
say @B"Guacamole服务器安装成功" green
echo
else
say "Guacamole服务器安装失败。" red
say @B"请检查上面的日志。" yellow
echo "欢迎您在https://github.com/Har-Kuun/OneClickDesktop/issues这里提交错误报告以便我修复脚本。"
echo "谢谢!"
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 <<END
[Unit]
Description=Apache Tomcat Server
After=syslog.target network.target
[Service]
Type=forking
User=tomcat
Group=tomcat
Environment=CATALINA_PID=/etc/tomcat9/temp/tomcat.pid
Environment=CATALINA_HOME=/etc/tomcat9
Environment=CATALINA_BASE=/etc/tomcat9
ExecStart=/etc/tomcat9/bin/catalina.sh start
ExecStop=/etc/tomcat9/bin/catalina.sh stop
RestartSec=10
Restart=always
[Install]
WantedBy=multi-user.target
END
systemctl daemon-reload
systemctl start tomcat9
systemctl enable tomcat9
}
function install_guacamole_web
{
echo
echo "开始安装Guacamole Web应用..."
cd $CurrentDir
wget https://downloads.apache.org/guacamole/$GUACAMOLE_VERSION/binary/guacamole-$GUACAMOLE_VERSION.war
mv guacamole-$GUACAMOLE_VERSION.war /var/lib/tomcat9/webapps/guacamole.war
if [ "$OS" = "CENTOS7" ] || [ "$OS" = "CENTOS8" ] ; then
mv guacamole-$GUACAMOLE_VERSION.war /etc/tomcat9/webapps/guacamole.war
else
mv guacamole-$GUACAMOLE_VERSION.war /var/lib/tomcat9/webapps/guacamole.war
fi
systemctl restart tomcat9 guacd
echo
say @B"Guacamole Web应用成功安装" green
echo
}
function configure_guacamole
function configure_guacamole_ubuntu_debian
{
echo
mkdir /etc/guacamole/
@ -332,6 +458,56 @@ END
echo
}
function configure_guacamole_centos
{
echo
mkdir /etc/guacamole/
cat > /etc/guacamole/guacamole.properties <<END
guacd-hostname: localhost
guacd-port: 4822
auth-provider: net.sourceforge.guacamole.net.basic.BasicFileAuthenticationProvider
basic-user-mapping: /etc/guacamole/user-mapping.xml
END
if [ $set_rdp_resolution = 0 ] ; then
cat > /etc/guacamole/user-mapping.xml <<END
<user-mapping>
<authorize
username="$guacamole_username"
password="$guacamole_password_md5"
encoding="md5">
<connection name="default">
<protocol>rdp</protocol>
<param name="hostname">localhost</param>
<param name="port">3389</param>
<param name="security">rdp</param>
</connection>
</authorize>
</user-mapping>
END
else
cat > /etc/guacamole/user-mapping.xml <<END
<user-mapping>
<authorize
username="$guacamole_username"
password="$guacamole_password_md5"
encoding="md5">
<connection name="default">
<protocol>rdp</protocol>
<param name="hostname">localhost</param>
<param name="port">3389</param>
<param name="width">$rdp_screen_width</param>
<param name="height">$rdp_screen_height</param>
<param name="security">rdp</param>
</connection>
</authorize>
</user-mapping>
END
fi
systemctl restart tomcat9 guacd
say @B"Guacamole配置成功" green
echo
}
function install_vnc
{
echo
@ -416,22 +592,31 @@ function install_rdp
{
echo
echo "开始安装桌面环境Firefox浏览器以及XRDP服务器..."
say @B"如果系统提示您配置LightDM您可以直接按回车键。" yellow
echo
echo "请按回车键继续。"
read catch_all
echo
if [ "$OS" = "UBUNTU18" ] || [ "$OS" = "UBUNTU20" ] ; then
say @B"如果系统提示您配置LightDM您可以直接按回车键。" yellow
echo
echo "请按回车键继续。"
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"桌面环境浏览器以及XRDP服务器安装成功。" green
echo "开始配置XRDP服务器..."
sleep 2
echo
mv /etc/xrdp/startwm.sh /etc/xrdp/startwm.sh.backup
cat > /etc/xrdp/startwm.sh <<END
if [ "$OS" != "CENTOS7" ] && [ "$OS" != "CENTOS8" ] ; then
mv /etc/xrdp/startwm.sh /etc/xrdp/startwm.sh.backup
cat > /etc/xrdp/startwm.sh <<END
#!/bin/sh
# xrdp X session start script (c) 2015, 2017 mirabilos
# published under The MirOS Licence
@ -470,7 +655,8 @@ test -x /etc/X11/Xsession && exec /etc/X11/Xsession
exec /bin/sh /etc/X11/Xsession
END
chmod +x /etc/xrdp/startwm.sh
chmod +x /etc/xrdp/startwm.sh
fi
systemctl enable xrdp
systemctl restart xrdp
sleep 5
@ -511,12 +697,58 @@ END
fi
}
function compile_xrdp_centos
{
if [ "$OS" = "CENTOS7" ] ; then
yum -y install firefox finger cmake patch gcc make autoconf libtool automake pkgconfig openssl-devel gettext file pam-devel libX11-devel libXfixes-devel libjpeg-devel libXrandr-devel nasm flex bison gcc-c++ libxslt perl-libxml-perl xorg-x11-font-utils xmlto-tex
else
dnf -y --enablerepo=PowerTools install firefox cmake patch gcc make autoconf libtool automake pkgconfig openssl-devel gettext file pam-devel libX11-devel libXfixes-devel libjpeg-devel libXrandr-devel nasm flex bison gcc-c++ libxslt perl-libxml-perl xorg-x11-font-utils
fi
echo
say @B"开始编译安装xrdp..." yellow
sleep 2
cd $CurrentDir
git clone --recursive https://github.com/neutrinolabs/xrdp.git
cd xrdp
./bootstrap
./configure
if [ -f $CurrentDir/xrdp/config.status ] ; then
say @B"编译条件已满足!" green
say @B"开始编译源码..." green
echo
else
echo
say "依赖环境缺失。" red
echo "请核查日志,安装必要的依赖环境,并再次运行此脚本。"
echo "欢迎您在https://github.com/Har-Kuun/OneClickDesktop/issues这里提交错误报告以便我修复脚本。"
echo "谢谢!"
echo
exit 1
fi
sleep 2
make
make install
systemctl start xrdp
echo
ss -lnpt | grep xrdp >/dev/null
if [ $? = 0 ] ; then
say @B"XRDP安装成功" green
echo
else
say "XRDP安装失败!" red
say @B"请检查上面的日志。" yellow
echo "欢迎您在https://github.com/Har-Kuun/OneClickDesktop/issues这里提交错误报告以便我修复脚本。"
echo "谢谢!"
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"安装Nginx反代..." yellow
sleep 2
apt-get install nginx certbot python3-certbot-nginx -y
say @B"Nginx安装成功" 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安装成功" green
cat > /etc/nginx/conf.d/guacamole.conf <<END
server {
listen 80;
@ -568,7 +810,7 @@ END
say @B"Let's Encrypt证书未安装如果您之后需要安装Let's Encrypt证书请手动执行 \"certbot --nginx --agree-tos --redirect --hsts --staple-ocsp -d $guacamole_hostname\"." yellow
say @B"开始使用您的远程桌面,请在浏览器中访问 http://${guacamole_hostname}!" green
fi
say @B"您的Guacamole用户名是$guacamole_username密码是 $guacamole_password_prehash" green
say @B"您的Guacamole用户名是$guacamole_username您的Guacamole密码是$guacamole_password_prehash." green
}
function main
@ -579,22 +821,34 @@ function main
fi
echo "此脚本将在本服务器上安装一个桌面环境。您可以随时随地在浏览器上使用这个桌面环境。"
echo
say @B"此桌面环境需要至少1 GB内存。" yellow
if [ "$OS" = "CENTOS7" ] || [ "$OS" = "CENTOS8" ] ; then
say @B"此桌面环境需要至少1.5 GB内存。" yellow
else
say @B"此桌面环境需要至少1 GB内存。" yellow
fi
echo
echo "请问是否继续? [Y/N]"
read confirm_installation
if [ "x$confirm_installation" = "xY" ] || [ "x$confirm_installation" = "xy" ] ; then
determine_system_variables
get_user_options
install_guacamole
if [ "$OS" = "CENTOS7" ] || [ "$OS" = "CENTOS8" ] ; then
install_guacamole_centos
else
install_guacamole_ubuntu_debian
fi
install_guacamole_web
configure_guacamole
if [ "$OS" = "CENTOS7" ] || [ "$OS" = "CENTOS8" ] ; then
configure_guacamole_centos
else
configure_guacamole_ubuntu_debian
fi
if [ $choice_rdpvnc = 1 ] ; then
install_rdp
else
install_vnc
fi
if [ "x$install_nginx" = "xY" ] || [ "x$install_nginx" = "xy" ] ; then
if [ "x$install_nginx" != "xn" ] && [ "x$install_nginx" != "xN" ] ; then
install_reverse_proxy
else
say @B"开始使用您的远程桌面,请在浏览器中访问 http://$(curl -s icanhazip.com):8080/guacamole!" green
@ -602,7 +856,7 @@ function main
fi
if [ $choice_rdpvnc = 1 ] ; then
echo
say @B"请注意使用上述用户名与密码登录Guacamole后您还会需要在XRDP登录界面输入Linux系统用户名与密码(比如root用户或者自行新建一个用户)。Session选项请保持默认Xorg即可。" yellow
say @B"请注意使用上述用户名与密码登录Guacamole后您还会需要在XRDP登录界面输入Linux系统用户名与密码(比如root用户或者自行新建一个用户)。Session Type请选择默认的Xorg." yellow
fi
fi
echo