Advertisement
chocolatkey

Untitled

Apr 17th, 2017
631
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 33.22 KB | None | 0 0
  1. #!/bin/bash
  2. ##############################################################
  3. # This script was created by Hernan Dario Nacimiento based on:
  4. #  http://guacamole.incubator.apache.org/releases/0.9.10-incubating/
  5. #  http://guacamole.incubator.apache.org/doc/0.9.10-incubating/gug/
  6. #  http://guacamole.incubator.apache.org/doc/0.9.10-incubating/gug/administration.html
  7. #  http://nginx.org/en/docs/http/configuring_https_servers.html
  8. #  http://nginx.org/en/docs/http/ngx_http_spdy_module.html
  9. #  https://wiki.centos.org/AdditionalResources/Repositories
  10. # Task of this script:
  11. #  Install Packages Dependencies
  12. #  Download Guacamole and MySQL Connector packages
  13. #  Install Guacamole Server
  14. #  Install Guacamole Client
  15. #  Install MySQL Connector
  16. #  Configure MariaDB or MySQL
  17. #  Setting Tomcat Server
  18. #  Generates a Java KeyStore for SSL Support
  19. #  Install and Setting Nginx Proxy (SPDY enabled)
  20. #  Generates a Self-Signed Certificate for SSL Support
  21. #  Cofigure SELinux for Nginx Proxy
  22. #  Configure FirewallD or iptables
  23. ##############################################################
  24. #####    VARIABLES    ####
  25. ##########################
  26. SCRIPT=`basename ${BASH_SOURCE[0]}` #Script File Name
  27. GUACA_VER="0.9.12-incubating"
  28. MYSQL_CONNECTOR_VER="5.1.40"
  29. LIBJPEG_VER="1.5.1"
  30. SCRIPT_BUILD="1"
  31. SCRIPT_VERSION="${GUACA_VER} Build ${SCRIPT_BUILD}"
  32. SERVER_HOSTNAME="localhost"
  33. INSTALL_DIR="/usr/local/src/guacamole/${GUACA_VER}/"
  34. LIB_DIR="/var/lib/guacamole/"
  35. PWD=`pwd`
  36. filename="${PWD}/guacamole-${GUACA_VER}."$(date +"%d-%y-%b")""
  37. logfile="${filename}.log"
  38. fwbkpfile="${filename}.firewall.bkp"
  39. MYSQ_CONNECTOR_URL="http://dev.mysql.com/get/Downloads/Connector-J/"
  40. MYSQL_CONNECTOR="mysql-connector-java-${MYSQL_CONNECTOR_VER}"
  41. MYSQL_PORT="3306"
  42. GUACA_PORT="4822"
  43. GUACA_CONF="guacamole.properties"
  44. GUACA_URL="http://sourceforge.net/projects/guacamole/files/current/"
  45. GUACA_SERVER="guacamole-server-${GUACA_VER}" #Source
  46. #GUACA_CLIENT="guacamole-client-${GUACA_VER}" #Source
  47. GUACA_CLIENT="guacamole-${GUACA_VER}" #Binary
  48. GUACA_JDBC="guacamole-auth-jdbc-${GUACA_VER}" #Extension
  49. LIBJPEG_URL="http://sourceforge.net/projects/libjpeg-turbo/files/${LIBJPEG_VER}/"
  50. #LIBJPEG_TURBO="libjpeg-turbo-${LIBJPEG_VER}" #Dependency source
  51. LIBJPEG_TURBO="libjpeg-turbo-official-${LIBJPEG_VER}" #Dependency rpm
  52. CENTOS_VER=`rpm -qi --whatprovides /etc/redhat-release | awk '/Version/ {print $3}'`
  53. if [ $CENTOS_VER -ge 7 ]; then MySQL_Packages="mariadb mariadb-server"; Menu_SQL="MariaDB"; else MySQL_Packages="mysql mysql-server"; Menu_SQL="MySQL"; fi #set rpm packages name
  54. MACHINE_ARCH=`uname -m`
  55. if [ $MACHINE_ARCH = "x86_64" ]; then ARCH="64"; elif [ $MACHINE_ARCH = "i686" ]; then MACHINE_ARCH="i386"; else ARCH=""; fi #set arch
  56. Black=`tput setaf 0`   #${Black}
  57. Red=`tput setaf 1`     #${Red}
  58. Green=`tput setaf 2`   #${Green}
  59. Yellow=`tput setaf 3`  #${Yellow}
  60. Blue=`tput setaf 4`    #${Blue}
  61. Magenta=`tput setaf 5` #${Magenta}
  62. Cyan=`tput setaf 6`    #${Cyan}
  63. White=`tput setaf 7`   #${White}
  64. Bold=`tput bold`       #${Bold}
  65. Rev=`tput smso`        #${Rev}
  66. Reset=`tput sgr0`      #${Reset}
  67.  
  68. #Initialize variables to default values.
  69. MYSQL_PASSWD="guacamole"
  70. DB_NAME="guacamole"
  71. DB_USER="guacamole"
  72. DB_PASSWD="guacamole"
  73. JKSTORE_PASSWD="guacamole"
  74. INSTALL_MODE="interactive"
  75. INSTALL_NGINX="no"
  76. GUACASERVER_HOSTNAME="localhost"
  77. GUACAMOLE_URIPATH="guacamole"
  78.  
  79. HELP () { #Help function
  80.   echo -e \\n"${Bold}Guacamole Install Script Help.${Reset}"\\n
  81.   echo "${Bold}Usage:${Reset}"
  82.   echo "  $SCRIPT [options] -s      install Guacamole Silently"
  83.   echo -e "  $SCRIPT [options] -p [yes|no]  install Proxy feature"\\n
  84.   echo "${Bold}Options:${Reset}"
  85.   echo " -${Rev}a${Reset}, <string> --Sets the root password for ${Menu_SQL}. Default is ${Bold}guacamole${Reset}."
  86.   echo " -${Rev}b${Reset}, <string> --Sets the Guacamole DB name. Default is ${Bold}guacamole${Reset}."
  87.   echo " -${Rev}c${Reset}, <string> --Sets the Guacamole DB username. Default is ${Bold}guacamole${Reset}."
  88.   echo " -${Rev}d${Reset}, <string> --Sets the Guacamole DB password. Default is ${Bold}guacamole${Reset}."
  89.   echo " -${Rev}e${Reset}, <string> --Sets the Java KeyStore password (least 6 characters). Default is ${Bold}guacamole${Reset}."
  90.   echo " -${Rev}s${Reset},      --Install Guacamole Silently. Default names and password are: ${Bold}guacamole${Reset}."
  91.   echo " -${Rev}p${Reset}, [yes|no] --Install the Proxy feature (Nginx)?."
  92.   echo " -${Rev}i${Reset},      --This option launch the interactive menu. Default is ${Bold}yes${Reset}."
  93.   echo " -${Rev}h${Reset},      --Displays this help message and exit."
  94.   echo -e " -${Rev}v${Reset},       --Displays the script version information and exit."\\n
  95.   echo "${Bold}Examples:${Reset}"
  96.   echo "  * Full and no interactive install: ${Bold}$SCRIPT -a sqlpasswd -b guacadb -c guacadbuser -d guacadbpasswd -e guacakey -s -p yes${Reset}"
  97.   echo "  * Same as above but with defult names and passwords: ${Bold}$SCRIPT -s -p yes${Reset}"
  98.   echo "  * Same as above but not install Nginx: ${Bold}$SCRIPT -s -p no${Reset}"
  99.   echo -e "  * Only install Nginx: ${Bold}$SCRIPT -p yes${Reset}"\\n
  100.   exit 1
  101. }
  102.  
  103. showscriptversion () {
  104. echo -e " Guacamole Install Script Version ${SCRIPT_VERSION}"\\n
  105. exit 2
  106. }
  107.  
  108. while getopts a:b:c:d:e:p:sihv FLAG; do
  109.   case $FLAG in
  110.     a)  #set option "a"
  111.       MYSQL_PASSWD=$OPTARG
  112.       ;;
  113.     b)  #set option "b"
  114.       DB_NAME=$OPTARG
  115.       ;;
  116.     c)  #set option "c"
  117.       DB_USER=$OPTARG
  118.       ;;
  119.     d)  #set option "d"
  120.       DB_PASSWD=$OPTARG
  121.       ;;
  122.     e)  #set option "e"
  123.       JKSTORE_PASSWD=$OPTARG
  124.       ;;
  125.     p)  #set option "p"
  126.       INSTALL_NGINX=$OPTARG
  127.       if [ $INSTALL_MODE != "silent" ]; then INSTALL_MODE="proxy"; fi
  128.       ;;
  129.     s)  #set option "s"
  130.       INSTALL_MODE="silent"
  131.       ;;
  132.     i)  #set option "i"
  133.       if [ $INSTALL_MODE != "silent" ]; then INSTALL_MODE="interactive"; fi
  134.       ;;
  135.     h)  #show help
  136.       HELP
  137.       ;;
  138.     v)  #set option "v"
  139.       showscriptversion
  140.       ;;
  141.     \?) #unrecognized option - show help
  142.       echo -e \\n"Option -${BOLD}$OPTARG${NORM} not allowed."
  143.       HELP
  144.       ;;
  145.   esac
  146. done
  147.  
  148. ##########################
  149. #####      MENU      #####
  150. ##########################
  151.  
  152. clear
  153. echo -e "
  154.                                                                
  155.                                                                
  156.                                                ${Yellow}'.'              
  157.                            ${Green}'.:///:-.....'     ${Yellow}-yyys/-          
  158.                     ${Green}.://///++++++++++++++/-  ${Yellow}.yhhhhhys/'        
  159.                  ${Green}'.:++++++++++++++++++++++: ${Yellow}'yhhhhhhhhy-        
  160.          ${White}.+y' ${Green}'://++++++++++++++++++++++++' ${Yellow}':yhhhhyo:'        
  161.        ${White}-yNd. ${Green}'/+++++++++++++++++++++++++++//' ${Yellow}.+yo:' ${White}'::        
  162.       ${White}oNMh' ${Green}./++++++++++++++++++++++++++++++/:' '''' ${White}'mMh.      
  163.      ${White}-MMM:  ${Green}/+++++++++++++++++++++++++++++++++-.:/+:  ${White}yMMs      
  164.      ${White}-MMMs  ${Green}./++++++++++++++++++++++++++++++++++++/' ${White}.mMMy      
  165.      ${White}'NMMMy. ${Green}'-/+++++++++++++++++++++++++++++++/:.  ${White}:dMMMo      
  166.       ${White}+MMMMNy:' ${Green}'.:///++++++++++++++++++++//:-.' ${White}./hMMMMN'      
  167.       ${White}-MMMMMMMmy+-.${Green}''''.---::::::::::--..''''${White}.:ohNMMMMMMy      
  168.        ${White}sNMMMMMMMMMmdhs+/:${Green}--..........--${White}:/oyhmNMMMMMMMMMd-      
  169.         ${White}.+dNMMMMMMMMMMMMMMNNmmmmmmmNNNMMMMMMMMMMMMMMmy:'        
  170.            ${White}./sdNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNmho:'          
  171.          ${White}'     .:+shmmNNMMMMMMMMMMMMMMMMNNmdyo/-'              
  172.          ${White}.o:.       '.-::/+ossssssso++/:-.'       '-/'          
  173.           ${White}.ymh+-.'                           ''./ydy.          
  174.             ${White}/dMMNdyo/-.''''         ''''.-:+shmMNh:            
  175.               ${White}:yNMMMMMMNmdhhyyyyyyyhhdmNNMMMMMNy:              
  176.                 ${White}':sdNNMMMMMMMMMMMMMMMMMMMNNds:'                
  177.                     ${White}'-/+syhdmNNNNNNmdhyo/-'                    
  178. "
  179. menu () {                                                                      
  180. echo -e "                         Installation Menu\n                ${Bold}Guacamole Remote Desktop Gateway ${GUACA_VER}\n" && tput sgr0
  181. echo -n "${Blue} Enter the root password for ${Menu_SQL}: ${Yellow}"
  182.   read MYSQL_PASSWD
  183.   MYSQL_PASSWD=${MYSQL_PASSWD:-guacamole}
  184. echo -n "${Blue} Enter the Guacamole DB name: ${Yellow}"
  185.   read DB_NAME
  186.   DB_NAME=${DB_NAME:-guacamole}
  187. echo -n "${Blue} Enter the Guacamole DB username: ${Yellow}"
  188.   read DB_USER
  189.   DB_USER=${DB_USER:-guacamole}
  190. echo -n "${Blue} Enter the Guacamole DB password: ${Yellow}"
  191.   read DB_PASSWD
  192.   DB_PASSWD=${DB_PASSWD:-guacamole}
  193. echo -n "${Blue} Enter the Java KeyStore password (least 6 characters): ${Yellow}"
  194.   read JKSTORE_PASSWD
  195.   JKSTORE_PASSWD=${JKSTORE_PASSWD:-guacamole}
  196. while true; do
  197.     read -p "${Blue} Do you wish to Install the Proxy feature (Nginx)?: ${Yellow}" yn
  198.     case $yn in
  199.         [Yy]* ) INSTALL_NGINX="yes"; nginxmenu; break;;
  200.         [Nn]* ) INSTALL_NGINX="no"; break;;
  201.         * ) echo "${Blue} Please enter yes or no. ${Yellow}";;
  202.     esac
  203. done
  204. tput sgr0
  205. }
  206.  
  207. nginxmenu ()
  208. {
  209. echo -n "${Blue} Enter the Guacamole Server IP addres or hostame (default localhost): ${Yellow}"
  210.   read GUACASERVER_HOSTNAME
  211.   GUACASERVER_HOSTNAME=${GUACASERVER_HOSTNAME:-localhost}
  212. echo -n "${Blue} Enter the URI path (default guacamole): ${Yellow}"
  213.   read GUACAMOLE_URIPATH
  214.   GUACAMOLE_URIPATH=${GUACAMOLE_URIPATH:-guacamole}
  215. }
  216.  
  217.  
  218. progressfilt () {
  219.     local flag=false c count cr=$'\r' nl=$'\n'
  220.     while IFS='' read -d '' -rn 1 c
  221.     do
  222.         if $flag
  223.         then
  224.             printf '%c' "$c"
  225.         else
  226.             if [[ $c != $cr && $c != $nl ]]
  227.             then
  228.                 count=0
  229.             else
  230.                 ((count++))
  231.                 if ((count > 1))
  232.                 then
  233.                     flag=true
  234.                 fi
  235.             fi
  236.         fi
  237.     done
  238. }
  239.  
  240.  
  241.  
  242.  
  243. reposinstall () {
  244. echo -e "\nChecking CentOS version...\n...CentOS $CENTOS_VER found\n"; echo -e "\nChecking CentOS version...\n...CentOS $CENTOS_VER found\n" >> $logfile  2>&1
  245. echo -e "\nStarting...\n...Preparing ingredients\n"; echo -e "\nStarting...\n...Preparing ingredients\n" >> $logfile  2>&1
  246. sleep 1 | echo -e "\nSearching for EPEL Repository...";echo -e "\nSearching for EPEL Repository..." >> $logfile  2>&1
  247. rpm -qa | grep epel-release
  248. RETVAL=$?
  249. if [ $RETVAL -eq 0 ]; then
  250.     sleep 1 | echo -e "No need to install EPEL repository!"; echo -e "No need to install EPEL repository!" >> $logfile  2>&1
  251. else
  252.     sleep 1 | echo -e "\nIs necessary to install the EPEL repositories\nInstalling..."; echo -e "\nIs necessary to install the EPEL repositories\nInstalling..." >> $logfile  2>&1
  253.     rpm -Uvh http://dl.fedoraproject.org/pub/epel/epel-release-latest-${CENTOS_VER}.noarch.rpm
  254. fi
  255.  
  256. sleep 1 | echo -e "\nSearching for nux-dextop Repository...";echo -e "\nSearching for nut-dextop Repository..." >> $logfile  2>&1
  257. rpm -qa | grep nux-dextop-release
  258. RETVAL=$?
  259. if [ $RETVAL -eq 0 ]; then
  260.     sleep 1 | echo -e "No need to install nut-dextop repository!"; echo -e "No need to install nux-dextop repository!" >> $logfile  2>&1
  261. else
  262.     sleep 1 | echo -e "\nIs necessary to install the nux-dextop repositories\nInstalling..."; echo -e "\nIs necessary to install the nux-dextop repositories\nInstalling..." >> $logfile  2>&1
  263.     rpm -Uvh http://li.nux.ro/download/nux/dextop/el${CENTOS_VER}/${MACHINE_ARCH}/nux-dextop-release-0-2.el${CENTOS_VER}.nux.noarch.rpm
  264.     sed -i "s/enabled=1/enabled=0/g" /etc/yum.repos.d/nux-dextop.repo
  265. fi
  266. }
  267.  
  268.  
  269. yumupdate () {
  270. sleep 1 | echo -e "\nUpdating CentOS...\n"; echo -e "\nUpdating CentOS...\n" >> $logfile  2>&1
  271. yum update -y
  272. }
  273.  
  274. guacamoleinstall () {
  275. sleep 1 | echo -e "\nInstalling Dependencies..."; echo -e "\nInstalling Dependencies..." >> $logfile  2>&1
  276.  
  277. rpm -qa | grep libjpeg-turbo-official-${LIBJPEG_VER}
  278. RETVAL=$? ; echo -e "rpm -qa | grep libjpeg-turbo-official-${LIBJPEG_VER} RC is: $RETVAL" >> $logfile  2>&1
  279.  
  280. if [ $RETVAL -eq 0 ]; then
  281.     sleep 1 | echo -e "...libjpeg-turbo-official-${LIBJPEG_VER} is installed on the system\n"; echo -e "...libjpeg-turbo-official-${LIBJPEG_VER} is installed on the system\n" >> $logfile  2>&1
  282. else
  283.     sleep 1 | echo -e "...libjpeg-turbo-official-${LIBJPEG_VER} is not installed on the system\n"; echo -e "...libjpeg-turbo-official-${LIBJPEG_VER} is not installed on the system\n" >> $logfile  2>&1
  284.     yum localinstall -y ${LIBJPEG_URL}${LIBJPEG_TURBO}.${MACHINE_ARCH}.rpm
  285.     RETVAL=$? ; echo -e "yum localinstall -y ${LIBJPEG_URL}${LIBJPEG_TURBO}.${MACHINE_ARCH}.rpm RC is: $RETVAL" >> $logfile  2>&1
  286.     ln -vfs /opt/libjpeg-turbo/include/* /usr/include/ || exit 1
  287.     ln -vfs /opt/libjpeg-turbo/lib??/* /usr/lib${ARCH}/ || exit 1
  288. fi
  289.  
  290. rpm -qa | grep ffmpeg-devel
  291. RETVAL=$? ; echo -e "rpm -qa | grep ffmpeg-devel RC is: $RETVAL" >> $logfile  2>&1
  292. if [ $RETVAL -eq 0 ]; then
  293.     sleep 1 | echo -e "...ffmpeg-devel is installed on the system\n"; echo -e "...ffmpeg-devel is installed on the system\n" >> $logfile  2>&1
  294. else
  295.     sleep 1 | echo -e "...ffmpeg-devel is not installed on the system\n"; echo -e "...ffmpeg-devel is not installed on the system\n" >> $logfile  2>&1
  296.     yum --enablerepo=nux-dextop install -y ffmpeg-devel
  297.     RETVAL=$? ; echo -e "yum --enablerepo=nux-dextop install -y ffmpeg-devel RC is: $RETVAL" >> $logfile  2>&1
  298. fi
  299.  
  300. yum install -y wget pv dialog gcc cairo-devel libpng-devel uuid-devel ffmpeg-devel freerdp-devel freerdp-plugins pango-devel libssh2-devel libtelnet-devel libvncserver-devel pulseaudio-libs-devel openssl-devel libvorbis-devel libwebp-devel tomcat gnu-free-mono-fonts ${MySQL_Packages}
  301. RETVAL=$? ; echo -e "yum install RC is: $RETVAL" >> $logfile  2>&1
  302.  
  303. sleep 1 | echo -e "\nCreating Directories...\n" | pv -qL 25; echo -e "\nCreating Directories...\n" >> $logfile  2>&1
  304. rm -fr ${INSTALL_DIR}
  305. mkdir -v /etc/guacamole >> $logfile  2>&1
  306. mkdir -vp ${INSTALL_DIR}{client,selinux} >> $logfile 2>&1 && cd ${INSTALL_DIR}
  307. mkdir -vp ${LIB_DIR}{extensions,lib} >> $logfile  2>&1
  308. mkdir -v /usr/share/tomcat/.guacamole/ >> $logfile  2>&1
  309.  
  310. sleep 1 | echo -e "\nDownloading Guacamole packages for installation...\n" | pv -qL 25; echo -e "\nDownloading Guacamole packages for installation...\n" >> $logfile  2>&1
  311. wget --progress=bar:force ${GUACA_URL}source/${GUACA_SERVER}.tar.gz 2>&1 | progressfilt
  312. #wget --progress=bar:force ${GUACA_URL}source/${GUACA_CLIENT}.tar.gz 2>&1 | progressfilt
  313. wget --progress=bar:force ${GUACA_URL}binary/${GUACA_CLIENT}.war -O ${INSTALL_DIR}client/guacamole.war 2>&1 | progressfilt
  314. wget --progress=bar:force ${GUACA_URL}extensions/${GUACA_JDBC}.tar.gz 2>&1 | progressfilt
  315. wget --progress=bar:force ${MYSQ_CONNECTOR_URL}${MYSQL_CONNECTOR}.tar.gz 2>&1 | progressfilt
  316.  
  317. sleep 1 | echo -e "\nDerompessing Guacamole Server Source...\n" | pv -qL 25; echo -e "\nDerompessing Guacamole Server Source...\n" >> $logfile  2>&1
  318. pv ${GUACA_SERVER}.tar.gz | tar xzf - && rm -f ${GUACA_SERVER}.tar.gz
  319. mv ${GUACA_SERVER} server
  320.  
  321. #sleep 1 | echo -e "\nDerompessing Guacamole Client...\n" | pv -qL 25
  322. #pv ${GUACA_CLIENT}.tar.gz | tar xzf - && rm -f ${GUACA_CLIENT}.tar.gz
  323. #mv ${GUACA_CLIENT} client
  324.  
  325. sleep 1 | echo -e "\nDecrompressing Guacamole JDBC Extension...\n" | pv -qL 25; echo -e "\nDecrompressing Guacamole JDBC Extension...\n" >> $logfile  2>&1
  326. pv ${GUACA_JDBC}.tar.gz | tar xzf - && rm -f ${GUACA_JDBC}.tar.gz
  327. mv ${GUACA_JDBC} extension
  328.  
  329. sleep 1 | echo -e "\nDecompressing MySQL Connector...\n" | pv -qL 25; echo -e "\nDecompressing MySQL Connector...\n" >> $logfile  2>&1
  330. pv ${MYSQL_CONNECTOR}.tar.gz | tar xzf - && rm -f ${MYSQL_CONNECTOR}.tar.gz
  331.  
  332. sleep 1 | echo -e "\nCompiling Gucamole Server...\n" | pv -qL 25; echo -e "\nCompiling Gucamole Server...\n" >> $logfile  2>&1
  333. cd server
  334. ./configure --with-init-dir=/etc/init.d
  335. make
  336. sleep 1 && make install
  337. sleep 1 && ldconfig
  338. cd ..
  339.  
  340. # sleep 1 | echo -e "\nCompiling Gucamole Client...\n" | pv -qL 25
  341. # cd client
  342. # mvn package
  343. # cp guacamole/doc/example/guacamole.properties /etc/guacamole/
  344. # cp guacamole/doc/example/user-mapping.xml /etc/guacamole/
  345.  
  346. sleep 1 | echo -e "\nCopying Gucamole Client...\n" | pv -qL 25; echo -e "\nCopying Gucamole Client...\n" >> $logfile  2>&1
  347. cp -v client/guacamole.war ${LIB_DIR}guacamole.war
  348. #cp -v client/guacamole.war /var/lib/tomcat/webapps/guacamole.war
  349.  
  350. sleep 1 | echo -e "\nMaking Guacamole configurtion files...\n" | pv -qL 25; echo -e "\nMaking Guacamole configurtion files...\n" >> $logfile  2>&1
  351. echo "# Hostname and port of guacamole proxy
  352. guacd-hostname: ${SERVER_HOSTNAME}
  353. guacd-port:     ${GUACA_PORT}
  354.  
  355. # MySQL properties
  356. mysql-hostname: ${SERVER_HOSTNAME}
  357. mysql-port: ${MYSQL_PORT}
  358. mysql-database: ${DB_NAME}
  359. mysql-username: ${DB_USER}
  360. mysql-password: ${DB_PASSWD}
  361. mysql-default-max-connections-per-user: 0
  362. mysql-default-max-group-connections-per-user: 0" > /etc/guacamole/${GUACA_CONF}
  363.  
  364. sleep 1 | echo -e "\nMaking Guacamole simbolic links...\n" | pv -qL 25; echo -e "\nMaking Guacamole simbolic links...\n" >> $logfile  2>&1
  365. ln -vfs ${LIB_DIR}guacamole.war /var/lib/tomcat/webapps || exit 1
  366. ln -vfs /etc/guacamole/${GUACA_CONF} /usr/share/tomcat/.guacamole/ || exit 1
  367. ln -vfs ${LIB_DIR}lib/ /usr/share/tomcat/.guacamole/ || exit 1
  368. ln -vfs ${LIB_DIR}extensions/ /usr/share/tomcat/.guacamole/ || exit 1
  369. ln -vfs /usr/local/lib/freerdp/guac* /usr/lib${ARCH}/freerdp || exit 1
  370.  
  371. sleep 1 | echo -e "\nCopying Guacamole JDBC Extension to Extensions Dir...\n" | pv -qL 25; echo -e "\nCopying Guacamole JDBC Extension to Extensions Dir...\n" >> $logfile  2>&1
  372. cp -v extension/mysql/guacamole-auth-jdbc-mysql-${GUACA_VER}.jar ${LIB_DIR}extensions/ || exit 1
  373.  
  374. sleep 1 | echo -e "\nCopying MySQL Connector to Lib Dir...\n" | pv -qL 25; echo -e "\nCopying MySQL Connector to Lib Dir...\n" >> $logfile  2>&1
  375. cp -v mysql-connector-java-${MYSQL_CONNECTOR_VER}/mysql-connector-java-${MYSQL_CONNECTOR_VER}-bin.jar ${LIB_DIR}/lib/ || exit 1
  376.  
  377. if [ $CENTOS_VER -ge 7 ]; then
  378.     sleep 1 | echo -e "\nSetting MariaDB Service...\n" | pv -qL 25; echo -e "\nSetting MariaDB Service...\n" >> $logfile  2>&1
  379.     systemctl enable mariadb.service
  380.     systemctl restart mariadb.service
  381.     sleep 1 | echo -e "\nSetting Root Password for MariaDB...\n" | pv -qL 25; echo -e "\nSetting Root Password for MariaDB...\n" >> $logfile  2>&1
  382. else
  383.     sleep 1 | echo -e "\nSetting MySQL Service...\n" | pv -qL 25; echo -e "\nSetting MySQL Service...\n" >> $logfile  2>&1
  384.     chkconfig mysqld on
  385.     service mysqld start
  386.     sleep 1 | echo -e "\nSetting Root Password for MySQL...\n" | pv -qL 25; echo -e "\nSetting Root Password for MySQL...\n" >> $logfile  2>&1
  387. fi
  388.  
  389. mysqladmin -u root password ${MYSQL_PASSWD} || exit 1
  390.  
  391. sleep 1 | echo -e "\nCreating BD & User for Guacamole...\n" | pv -qL 25; echo -e "\nCreating BD & User for Guacamole...\n" >> $logfile  2>&1
  392. mysql -u root -p${MYSQL_PASSWD} -e "CREATE DATABASE ${DB_NAME};" || exit 1
  393. mysql -u root -p${MYSQL_PASSWD} -e "GRANT SELECT,INSERT,UPDATE,DELETE ON ${DB_NAME}.* TO '${DB_USER}'@'localhost' IDENTIFIED BY '${DB_PASSWD}';" || exit 1
  394. mysql -u root -p${MYSQL_PASSWD} -e "FLUSH PRIVILEGES;" || exit 1
  395.  
  396. sleep 1 | echo -e "\nCreating Guacamole Tables...\n" | pv -qL 25; echo -e "\nCreating Guacamole Tables...\n" >> $logfile  2>&1
  397. cat extension/mysql/schema/*.sql | mysql -u root -p${MYSQL_PASSWD} -D ${DB_NAME}
  398.  
  399. sleep 1 | echo -e "\nSetting Tomcat Server...\n" | pv -qL 25; echo -e "\nSetting Tomcat Server...\n" >> $logfile  2>&1
  400. sed -i '72i URIEncoding="UTF-8"' /etc/tomcat/server.xml
  401. sed -i '92i <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" \
  402.               maxThreads="150" scheme="https" secure="true" \
  403.               clientAuth="false" sslProtocol="TLS" \
  404.               keystoreFile="/var/lib/tomcat/webapps/.keystore" \
  405.               keystorePass="JKSTORE_PASSWD" \
  406.               URIEncoding="UTF-8" />' /etc/tomcat/server.xml
  407. sed -i "s/JKSTORE_PASSWD/${JKSTORE_PASSWD}/g" /etc/tomcat/server.xml
  408.  
  409. if [ $INSTALL_MODE = "silent" ]; then
  410.     sleep 1 | echo -e "\nGenerating the Java KeyStore\n" | pv -qL 25; echo -e "\nGenerating the Java KeyStore\n" >> $logfile  2>&1
  411.     noprompt="-noprompt -dname CN=,OU=,O=,L=,S=,C="
  412. else
  413.     sleep 1 | echo -e "\nPlease complete the Wizard for the Java KeyStore\n" | pv -qL 25; echo -e "\nPlease complete the Wizard for the Java KeyStore\n" >> $logfile  2>&1
  414. fi
  415. keytool -genkey -alias Guacamole -keyalg RSA -keystore /var/lib/tomcat/webapps/.keystore -storepass ${JKSTORE_PASSWD} -keypass ${JKSTORE_PASSWD} ${noprompt}
  416.  
  417. sleep 1 | echo -e "\nSetting Tomcat and Guacamole Service...\n" | pv -qL 25; echo -e "\nSetting Tomcat and Guacamole Service...\n" >> $logfile  2>&1
  418.  
  419. if [ $CENTOS_VER -ge 7 ]; then
  420.     systemctl enable tomcat.service >> $logfile  2>&1
  421.     systemctl start tomcat.service >> $logfile  2>&1
  422.     chkconfig guacd on >> $logfile  2>&1
  423.     systemctl start guacd.service >> $logfile  2>&1
  424. else
  425.     chkconfig tomcat on
  426.     service tomcat start >> $logfile  2>&1
  427.     chkconfig guacd on >> $logfile  2>&1
  428.     service guacd start >> $logfile  2>&1
  429. fi
  430. }
  431.  
  432. selinuxchanges () {
  433. sleep 1 | echo -e "\nInstalling SELinux Tools...\n" | pv -qL 25; echo -e "\nInstalling SELinux Tools...\n" >> $logfile  2>&1
  434. yum install -y policycoreutils-{python,devel}
  435. sleep 1 | echo -e "\nSetting SELinux...\n" | pv -qL 25; echo -e "\nSetting SELinux...\n" >> $logfile  2>&1
  436.  
  437. if [ -d ${INSTALL_DIR}selinux ]; then
  438.     sleep 1 | echo -e "\nThe directory ${INSTALL_DIR}selinux already exist...\n" | pv -qL 25; echo -e "\nThe directory ${INSTALL_DIR}selinux already exist...\n" >> $logfile  2>&1
  439. else
  440.     sleep 1 | echo -e "\nCreating the directory... ${INSTALL_DIR}selinux\n" | pv -qL 25; echo -e "\nCreating the directory... ${INSTALL_DIR}selinux ...\n" >> $logfile  2>&1
  441.     mkdir -vp ${INSTALL_DIR}selinux >> $logfile 2>&1 && cd ${INSTALL_DIR}selinux
  442. fi
  443.  
  444. echo '
  445. module nginx 1.0;
  446.  
  447. require {
  448.     type httpd_t;
  449.     type http_cache_port_t;
  450.     class tcp_socket name_connect;
  451. }
  452.  
  453. #============= httpd_t ==============
  454.  
  455. #!!!! This avc can be allowed using one of the these booleans:
  456. #     httpd_can_network_relay, httpd_can_network_connect
  457. allow httpd_t http_cache_port_t:tcp_socket name_connect;' > nginx.te
  458. checkmodule -M -m -o nginx.mod nginx.te >> $logfile  2>&1
  459. semodule_package -o nginx.pp -m nginx.mod >> $logfile  2>&1
  460. semodule -i nginx.pp >> $logfile  2>&1
  461. }
  462.  
  463. nginxinstall ()
  464. {
  465. sleep 1 | echo -e "\nInstalling Nginx repository..."; echo -e "\nInstalling Nginx repository..." >> $logfile  2>&1
  466. echo '[nginx]
  467. name=nginx repo
  468. baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
  469. gpgcheck=0
  470. enabled=1' > /etc/yum.repos.d/nginx.repo
  471.  
  472. sleep 1 | echo -e "\nInstalling Nginx..."; echo -e "\nInstalling Nginx..." >> $logfile  2>&1
  473. yum install -y nginx pv
  474. RETVAL=$? ; echo -e "yum install RC is: $RETVAL" >> $logfile  2>&1
  475.  
  476. sleep 1 | echo -e "\nMaking Nginx Backup\nmv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.ori.bkp" | pv -qL 25; echo -e "\nMaking Nginx Backup\nmv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.ori.bkp" >> $logfile  2>&1
  477. mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.ori.bkp
  478. sleep 1 | echo -e "\nMaking Nginx configurations..." | pv -qL 25; echo -e "\nMaking Nginx configurations..." >> $logfile  2>&1
  479. echo 'server {
  480.    listen 80;
  481.    server_name localhost;
  482.  
  483.     location /_new-path_/ {
  484.         proxy_pass http://_SERVER_HOSTNAME_:8080/guacamole/;
  485.         proxy_buffering off;
  486.         proxy_http_version 1.1;
  487.         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  488.         proxy_set_header Upgrade $http_upgrade;
  489.         proxy_set_header Connection $http_connection;
  490.         proxy_cookie_path /guacamole/ /_new-path_/;
  491.         access_log off;
  492.     }
  493. }' > /etc/nginx/conf.d/guacamole.conf
  494. sed -i "s/_SERVER_HOSTNAME_/${GUACASERVER_HOSTNAME}/g" /etc/nginx/conf.d/guacamole.conf
  495. sed -i "s/_new-path_/${GUACAMOLE_URIPATH}/g" /etc/nginx/conf.d/guacamole.conf
  496.  
  497. echo 'server {
  498.     listen              443 ssl http2;
  499.     server_name         localhost;
  500.     ssl_certificate     guacamole.crt;
  501.     ssl_certificate_key guacamole.key;
  502.     ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
  503.     ssl_ciphers         HIGH:!aNULL:!MD5;
  504.  
  505.     location /_new-path_/ {
  506.         proxy_pass http://_SERVER_HOSTNAME_:8080/guacamole/;
  507.         proxy_buffering off;
  508.         proxy_http_version 1.1;
  509.         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  510.         proxy_set_header Upgrade $http_upgrade;
  511.         proxy_set_header Connection $http_connection;
  512.         proxy_cookie_path /guacamole/ /_new-path_/;
  513.         access_log off;
  514.    }
  515. }' > /etc/nginx/conf.d/guacamole_ssl.conf
  516. sed -i "s/_SERVER_HOSTNAME_/${GUACASERVER_HOSTNAME}/g" /etc/nginx/conf.d/guacamole_ssl.conf
  517. sed -i "s/_new-path_/${GUACAMOLE_URIPATH}/g" /etc/nginx/conf.d/guacamole_ssl.conf
  518.  
  519. if [ $INSTALL_MODE = "silent" ]; then
  520.     sleep 1 | echo -e "\nGenerating a Self-Signed SSL Certificate...\n" | pv -qL 25; echo -e "\nGenerating a Self-Signed SSL Certificate...\n" >> $logfile  2>&1
  521.     subj="-subj /C=XX/ST=/L=City/O=Company/CN=/"
  522. else
  523.     sleep 1 | echo -e "\nPlease complete the Wizard for the Self-Signed SSL Certificate...\n" | pv -qL 25; echo -e "\nPlease complete the Wizard for the Self-Signed SSL Certificate...\n" >> $logfile  2>&1
  524. fi
  525. openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/guacamole.key -out /etc/nginx/guacamole.crt ${subj}
  526.  
  527. sleep 1 | echo -e "\nStarting Nginx Service...\n" | pv -qL 25; echo -e "\nStarting Nginx Service...\n" >> $logfile  2>&1
  528. if [ $CENTOS_VER -ge 7 ]; then
  529.     systemctl enable nginx.service || exit 1
  530.     systemctl start nginx.service || exit 1
  531. else
  532.     chkconfig nginx on
  533.     service nginx start
  534. fi
  535.  
  536. sleep 1 | echo -e "${Bold}\nIf you need understand the Nginx configurations please go to:\n ${Green} http://nginx.org/en/docs/ ${Reset} ${Bold} \nIf you need replace the certificate file plese read first:\n ${Green} http://nginx.org/en/docs/http/configuring_https_servers.html ${Reset} \n"  | pv -qL 25; echo -e "${Bold}\nIf you need understand the Nginx configurations please go to:\n ${Green} http://nginx.org/en/docs/ ${Reset} ${Bold} \nIf you need replace the certificate file plese read first:\n ${Green} http://nginx.org/en/docs/http/configuring_https_servers.html ${Reset} \n" >> $logfile  2>&1
  537.  
  538. selinuxchanges
  539. }
  540.  
  541.  
  542. firewallD () {
  543.     echo -e "\nMaking Firewall Backup...\ncp /etc/firewalld/zones/public.xml $fwbkpfile" >> $logfile  2>&1
  544.     cp /etc/firewalld/zones/public.xml $fwbkpfile
  545.     if [ $INSTALL_NGINX = "yes" ]; then
  546.         sleep 1 | echo -e "...Opening ports 80 and 443\n" | pv -qL 25; echo -e "...Opening ports 80 and 443\n" >> $logfile  2>&1
  547.         echo -e "Add new rule...\nfirewall-cmd --permanent --zone=public --add-service=http" >> $logfile  2>&1
  548.         firewall-cmd --permanent --zone=public --add-service=http >> $logfile  2>&1
  549.         echo -e "Add new rule...\nfirewall-cmd --permanent --zone=public --add-service=https" >> $logfile  2>&1
  550.         firewall-cmd --permanent --zone=public --add-service=https >> $logfile  2>&1
  551.     fi
  552.     if [ $INSTALL_MODE = "interactive" ] || [ $INSTALL_MODE = "silent" ]; then
  553.     sleep 1 | echo -e "...Opening ports 8080 and 8443\n" | pv -qL 25; echo -e "...Opening ports 8080 and 8443\n" >> $logfile  2>&1
  554.         echo -e "Add new rule...\nfirewall-cmd --permanent --zone=public --add-port=8080/tcp" >> $logfile  2>&1
  555.         firewall-cmd --permanent --zone=public --add-port=8080/tcp >> $logfile  2>&1
  556.         echo -e "Add new rule...\nfirewall-cmd --permanent --zone=public --add-port=8443/tcp" >> $logfile  2>&1
  557.         firewall-cmd --permanent --zone=public --add-port=8443/tcp >> $logfile  2>&1
  558.         echo -e "Reload firewall...\nfirewall-cmd --reload\n" >> $logfile  2>&1
  559.     fi
  560.     firewall-cmd --reload >> $logfile  2>&1
  561. }
  562.  
  563. Iptables () {
  564.     echo -e "Making Firewall Backup...\niptables-save >> $fwbkpfile" >> $logfile  2>&1
  565.     iptables-save >> $fwbkpfile  2>&1
  566.     if [ $INSTALL_NGINX = "yes" ]; then
  567.         sleep 1 | echo -e "...Opening ports 80 and 443\n" | pv -qL 25; echo -e "...Opening ports 80 and 443\n" >> $logfile  2>&1
  568.         echo -e "Add new rule...\niptables -I INPUT -m tcp -p tcp --dport 80 -m state --state NEW -j ACCEPT" >> $logfile  2>&1
  569.         iptables -I INPUT -m tcp -p tcp --dport 80 -m state --state NEW -j ACCEPT >> $logfile  2>&1
  570.         echo -e "Add new rule...\niptables -I INPUT -m tcp -p tcp --dport 443 -m state --state NEW -j ACCEPT" >> $logfile  2>&1
  571.         iptables -I INPUT -m tcp -p tcp --dport 443 -m state --state NEW -j ACCEPT >> $logfile  2>&1
  572.     fi
  573.     if [ $INSTALL_MODE = "interactive" ] || [ $INSTALL_MODE = "silent" ]; then
  574.         sleep 1 | echo -e "...Opening ports 8080 and 8443\n" | pv -qL 25; echo -e "...Opening ports 8080 and 8443\n" >> $logfile  2>&1
  575.         echo -e "Add new rule...\niptables -I INPUT -m tcp -p tcp --dport 8080 -m state --state NEW -j ACCEPT" >> $logfile  2>&1
  576.         iptables -I INPUT -m tcp -p tcp --dport 8080 -m state --state NEW -j ACCEPT >> $logfile  2>&1
  577.         echo -e "Add new rule...\niptables -I INPUT -m tcp -p tcp --dport 8443 -m state --state NEW -j ACCEPT" >> $logfile  2>&1
  578.         iptables -I INPUT -m tcp -p tcp --dport 8443 -m state --state NEW -j ACCEPT >> $logfile  2>&1
  579.     fi
  580.     echo -e "Save new rules\nservice iptables save\n" >> $logfile  2>&1
  581.     service iptables save >> $logfile  2>&1
  582. }
  583.  
  584. firewallsetting () {
  585. sleep 1 | echo -e "\nSetting Firewall...\n" | pv -qL 25; echo -e "\nSetting Firewall..." >> $logfile  2>&1
  586. echo -e "Take Firewall RC...\n" >> $logfile  2>&1
  587. echo -e "rpm -qa | grep firewalld" >> $logfile  2>&1
  588. rpm -qa | grep firewalld >> $logfile  2>&1
  589. RETVALqaf=$?
  590. echo -e "\nservice firewalld status" >> $logfile  2>&1
  591. service firewalld status >> $logfile  2>&1
  592. RETVALsf=$?
  593.  
  594. if [ $RETVALsf -eq 0 ]; then
  595.     sleep 1 | echo -e "...firewalld is installed and started on the system\n" | pv -qL 25; echo -e "...firewalld is installed and started on the system\n" >> $logfile  2>&1
  596.     firewallD
  597. elif [ $RETVALqaf -eq 0 ]; then
  598.     sleep 1 | echo -e "...firewalld is installed but not enabled or started on the system\n" | pv -qL 25; echo -e "...firewalld is installed but not enabled or started on the system\n" >> $logfile  2>&1
  599.     firewallD
  600. else
  601.     sleep 1 | echo -e "...firewalld is not installed on the system\n" | pv -qL 25; echo -e "...firewalld is not installed on the system\n" >> $logfile  2>&1
  602.     echo -e "Checking Firewall RC..." >> $logfile  2>&1
  603.     rpm -qa | grep iptables-services >> $logfile  2>&1
  604.     RETVALqai=$?
  605.     service iptables status >> $logfile  2>&1
  606.     RETVALsi=$?
  607.  
  608.     if [ $RETVALsi -eq 0 ]; then
  609.         sleep 1 | echo -e "...iptables service is installed and started on the system\n" | pv -qL 25; echo -e "...iptables service is installed and started on the system\n" >> $logfile  2>&1
  610.         Iptables
  611.     elif [ $RETVALqaf -eq 0 ]; then
  612.         sleep 1 | echo -e "...iptables is installed but not enabled or started on the system\n" | pv -qL 25; echo -e "...iptables is installed but not enabled or started on the system\n" >> $logfile  2>&1
  613.         Iptables
  614.     else
  615.             sleep 1 | echo -e "...iptables service is not installed on the system\n" | pv -qL 25; echo -e "...iptables service is not installed on the system\n" >> $logfile  2>&1
  616.             sleep 1 | echo -e "Please check and configure you firewall...\nIn order to Guacamole work properly open the ports tcp 8080 and 8443." | pv -qL 25; echo -e "Please check and configure you firewall...\nIn order to Guacamole work properly open the ports tcp 80, 443, 8080 and 8443." >> $logfile  2>&1
  617.     fi
  618. fi
  619. }
  620.  
  621.  
  622. showmessages () {
  623. sleep 1 | echo -e "\nFinished Successfully\n" | pv -qL 25; echo -e "\nFinished Successfully\n" >> $logfile  2>&1
  624. sleep 1 | echo -e "\nYou can check the log file ${logfile}\n" | pv -qL 25; echo -e "\nYou can check the log file ${logfile}\n" >> $logfile  2>&1
  625. sleep 1 | echo -e "\nYour firewall backup file ${fwbkpfile}\n" | pv -qL 25; echo -e "\nYour firewall backup file ${fwbkpfile}\n" >> $logfile  2>&1
  626. if [ $INSTALL_NGINX = "yes" ]; then
  627.     sleep 1 | echo -e "\nTo manage the Guacamole GW via proxy go to http://<IP>/${GUACAMOLE_URIPATH}/ or https://<IP>/${GUACAMOLE_URIPATH}/\n" | pv -qL 25; echo -e "\nTo manage the Guacamole GW via proxy go to http://<IP>/${GUACAMOLE_URIPATH}/ or https://<IP>/${GUACAMOLE_URIPATH}/\n" >> $logfile  2>&1
  628. fi
  629. if [ $INSTALL_MODE = "interactive" ] || [ $INSTALL_MODE = "silent" ]; then
  630.     sleep 1 | echo -e "\nTo manage the Guacamole GW go to http://<IP>:8080/${GUACAMOLE_URIPATH}/ or https://<IP>:8443/${GUACAMOLE_URIPATH}/\n" | pv -qL 25; echo -e "\nTo manage the Guacamole GW go to http://<IP>:8080/${GUACAMOLE_URIPATH}/ or https://<IP>:8443/${GUACAMOLE_URIPATH}/\n" >> $logfile  2>&1
  631. sleep 1 | echo -e "\nThe username and password is: guacadmin\n" | pv -qL 25; echo -e "\nThe username and password is: guacadmin\n" >> $logfile  2>&1
  632. fi
  633. sleep 1 | echo -e "\nIf you have any suggestions please write to: correo@nacimientohernan.com.ar\n" | pv -qL 25; echo -e "\nIf you have any suggestions please write to: correo@nacimientohernan.com.ar\n" >> $logfile  2>&1
  634. }
  635.  
  636.  
  637. # Start
  638. if [[ $INSTALL_MODE = "interactive"  &&  $INSTALL_MODE != "silent" && $INSTALL_MODE != "proxy" ]] ; then menu; fi
  639. if [ $INSTALL_MODE = "interactive" ] || [ $INSTALL_MODE = "silent" ] || [ $INSTALL_NGINX = "yes" ]; then reposinstall; fi
  640. if [ $INSTALL_MODE = "interactive" ] || [ $INSTALL_MODE = "silent" ]; then yumupdate; fi
  641. if [ $INSTALL_MODE = "interactive" ] || [ $INSTALL_MODE = "silent" ]; then guacamoleinstall; fi
  642. if [ $INSTALL_NGINX = "yes" ]; then nginxinstall; fi
  643. if [ $INSTALL_MODE = "interactive" ] || [ $INSTALL_MODE = "silent" ] || [ $INSTALL_NGINX = "yes" ]; then firewallsetting; fi
  644. if [ $INSTALL_MODE = "interactive" ] || [ $INSTALL_MODE = "silent" ] || [ $INSTALL_NGINX = "yes" ]; then showmessages; fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement