BASH 23
Guac-install.sh By facknrite on 20th April 2022 05:06:50 PM
  1. #!/bin/bash
  2. # Something isn't working? # tail -f /var/log/messages /var/log/syslog /var/log/tomcat*/*.out /var/log/mysql/*.log
  3.  
  4. # Check if user is root or sudo
  5. if ! [ $( id -u ) = 0 ]; then
  6.     echo "Please run this script as sudo or root" 1>&2
  7.     exit 1
  8. fi
  9.  
  10. # Check to see if any old files left over
  11. if [ "$( find . -maxdepth 1 \( -name 'guacamole-*' -o -name 'mysql-connector-java-*' \) )" != "" ]; then
  12.     echo "Possible temp files detected. Please review 'guacamole-*' & 'mysql-connector-java-*'" 1>&2
  13.     exit 1
  14. fi
  15.  
  16. # Version number of Guacamole to install
  17. # Homepage ~ https://guacamole.apache.org/releases/
  18. GUACVERSION="1.4.0"
  19.  
  20. # Latest Version of MySQL Connector/J if manual install is required (if libmariadb-java/libmysql-java is not available via apt)
  21. # Homepage ~ https://dev.mysql.com/downloads/connector/j/
  22. MCJVER="8.0.27"
  23.  
  24. # Colors to use for output
  25. YELLOW='\033[1;33m'
  26. BLUE='\033[0;34m'
  27. RED='\033[0;31m'
  28. GREEN='\033[0;32m'
  29. CYAN='\033[0;36m'
  30. NC='\033[0m' # No Color
  31.  
  32. # Log Location
  33. LOG="/tmp/guacamole_${GUACVERSION}_build.log"
  34.  
  35. # Initialize variable values
  36. installTOTP=""
  37. installDuo=""
  38. installMySQL=""
  39. mysqlHost=""
  40. mysqlPort=""
  41. mysqlRootPwd=""
  42. guacDb=""
  43. guacUser=""
  44. guacPwd=""
  45. PROMPT=""
  46. MYSQL=""
  47.  
  48. # Get script arguments for non-interactive mode
  49. while [ "$1" != "" ]; do
  50.     case $1 in
  51.         # Install MySQL selection
  52.         -i | --installmysql )
  53.             installMySQL=true
  54.             ;;
  55.         -n | --nomysql )
  56.             installMySQL=false
  57.             ;;
  58.  
  59.         # MySQL server/root information
  60.         -h | --mysqlhost )
  61.             shift
  62.             mysqlHost="$1"
  63.             ;;
  64.         -p | --mysqlport )
  65.             shift
  66.             mysqlPort="$1"
  67.             ;;
  68.         -r | --mysqlpwd )
  69.             shift
  70.             mysqlRootPwd="$1"
  71.             ;;
  72.  
  73.         # Guac database/user information
  74.         -db | --guacdb )
  75.             shift
  76.             guacDb="$1"
  77.             ;;
  78.         -gu | --guacuser )
  79.             shift
  80.             guacUser="$1"
  81.             ;;
  82.         -gp | --guacpwd )
  83.             shift
  84.             guacPwd="$1"
  85.             ;;
  86.  
  87.         # MFA selection
  88.         -t | --totp )
  89.             installTOTP=true
  90.             ;;
  91.         -d | --duo )
  92.             installDuo=true
  93.             ;;
  94.         -o | --nomfa )
  95.             installTOTP=false
  96.             installDuo=false
  97.             ;;
  98.     esac
  99.     shift
  100. done
  101.  
  102. if [[ -z "${installTOTP}" ]] && [[ "${installDuo}" != true ]]; then
  103.     # Prompt the user if they would like to install TOTP MFA, default of no
  104.     echo -e -n "${CYAN}MFA: Would you like to install TOTP (choose 'N' if you want Duo)? (y/N): ${NC}"
  105.     read PROMPT
  106.     if [[ ${PROMPT} =~ ^[Yy]$ ]]; then
  107.         installTOTP=true
  108.         installDuo=false
  109.     else
  110.         installTOTP=false
  111.     fi
  112. fi
  113.  
  114. if [[ -z "${installDuo}" ]] && [[ "${installTOTP}" != true ]]; then
  115.     # Prompt the user if they would like to install Duo MFA, default of no
  116.     echo -e -n "${CYAN}MFA: Would you like to install Duo (configuration values must be set after install in /etc/guacamole/guacamole.properties)? (y/N): ${NC}"
  117.     read PROMPT
  118.     if [[ ${PROMPT} =~ ^[Yy]$ ]]; then
  119.         installDuo=true
  120.         installTOTP=false
  121.     else
  122.         installDuo=false
  123.     fi
  124. fi
  125.  
  126. # We can't install TOTP and Duo at the same time...
  127. if [[ "${installTOTP}" = true ]] && [ "${installDuo}" = true ]; then
  128.     echo -e "${RED}MFA: The script does not support installing TOTP and Duo at the same time.${NC}" 1>&2
  129.     exit 1
  130. fi
  131. echo
  132.  
  133. if [[ -z ${installMySQL} ]]; then
  134.     # Prompt the user to see if they would like to install MySQL, default of yes
  135.     echo "MySQL is required for installation, if you're using a remote MySQL Server select 'n'"
  136.     echo -e -n "${CYAN}Would you like to install MySQL? (Y/n): ${NC}"
  137.     read PROMPT
  138.     if [[ ${PROMPT} =~ ^[Nn]$ ]]; then
  139.         installMySQL=false
  140.     else
  141.         installMySQL=true
  142.     fi
  143. fi
  144.  
  145. if [ "${installMySQL}" = false ]; then
  146.     # We need to get additional values
  147.     [ -z "${mysqlHost}" ] \
  148.       && read -p "Enter MySQL server hostname or IP: " mysqlHost
  149.     [ -z "${mysqlPort}" ] \
  150.       && read -p "Enter MySQL server port [3306]: " mysqlPort
  151.     [ -z "${guacDb}" ] \
  152.       && read -p "Enter Guacamole database name [guacamole_db]: " guacDb
  153.     [ -z "${guacUser}" ] \
  154.       && read -p "Enter Guacamole user [guacamole_user]: " guacUser
  155. fi
  156.  
  157. # Checking if mysql host given
  158. if [ -z "${mysqlHost}" ]; then
  159.     mysqlHost="localhost"
  160. fi
  161.  
  162. # Checking if mysql port given
  163. if [ -z "${mysqlPort}" ]; then
  164.     mysqlPort="3306"
  165. fi
  166.  
  167. # Checking if mysql user given
  168. if [ -z "${guacUser}" ]; then
  169.     guacUser="guacamole_user"
  170. fi
  171.  
  172. # Checking if database name given
  173. if [ -z "${guacDb}" ]; then
  174.     guacDb="guacamole_db"
  175. fi
  176.  
  177. if [ -z "${mysqlRootPwd}" ]; then
  178.     # Get MySQL "Root" and "Guacamole User" password
  179.     while true; do
  180.         echo
  181.         read -s -p "Enter ${mysqlHost}'s MySQL root password: " mysqlRootPwd
  182.         echo
  183.         read -s -p "Confirm ${mysqlHost}'s MySQL root password: " PROMPT2
  184.         echo
  185.         [ "${mysqlRootPwd}" = "${PROMPT2}" ] && break
  186.         echo -e "${RED}Passwords don't match. Please try again.${NC}" 1>&2
  187.     done
  188. else
  189.     echo -e "${BLUE}Read MySQL root's password from command line argument${NC}"
  190. fi
  191. echo
  192.  
  193. if [ -z "${guacPwd}" ]; then
  194.     while true; do
  195.         echo -e "${BLUE}A new MySQL user will be created (${guacUser})${NC}"
  196.         read -s -p "Enter ${mysqlHost}'s MySQL guacamole user password: " guacPwd
  197.         echo
  198.         read -s -p "Confirm ${mysqlHost}'s MySQL guacamole user password: " PROMPT2
  199.         echo
  200.         [ "${guacPwd}" = "${PROMPT2}" ] && break
  201.         echo -e "${RED}Passwords don't match. Please try again.${NC}" 1>&2
  202.         echo
  203.     done
  204. else
  205.     echo -e "${BLUE}Read MySQL ${guacUser}'s password from command line argument${NC}"
  206. fi
  207. echo
  208.  
  209. if [ "${installMySQL}" = true ]; then
  210.     # Seed MySQL install values
  211.     debconf-set-selections <<< "mysql-server mysql-server/root_password password ${mysqlRootPwd}"
  212.     debconf-set-selections <<< "mysql-server mysql-server/root_password_again password ${mysqlRootPwd}"
  213. fi
  214.  
  215. # Different version of Ubuntu/Linux Mint and Debian have different package names...
  216. source /etc/os-release
  217. if [[ "${NAME}" == "Ubuntu" ]] || [[ "${NAME}" == "Linux Mint" ]]; then
  218.     # Ubuntu > 18.04 does not include universe repo by default
  219.     # Add the "Universe" repo, don't update
  220.     add-apt-repository -y universe
  221.     # Set package names depending on version
  222.     JPEGTURBO="libjpeg-turbo8-dev"
  223.     if [[ "${VERSION_ID}" == "16.04" ]]; then
  224.         LIBPNG="libpng12-dev"
  225.     else
  226.         LIBPNG="libpng-dev"
  227.     fi
  228.     if [ "${installMySQL}" = true ]; then
  229.         MYSQL="mysql-server mysql-client mysql-common"
  230.     # Checking if (any kind of) mysql-client or compatible command installed. This is useful for existing mariadb server
  231.     elif [ -x "$( command -v mysql )" ]; then
  232.         MYSQL=""
  233.     else
  234.         MYSQL="mysql-client"
  235.     fi
  236. elif [[ "${NAME}" == *"Debian"* ]] || [[ "${NAME}" == *"Raspbian GNU/Linux"* ]] || [[ "${NAME}" == *"Kali GNU/Linux"* ]] || [[ "${NAME}" == "LMDE" ]]; then
  237.     JPEGTURBO="libjpeg62-turbo-dev"
  238.     if [[ "${PRETTY_NAME}" == *"bullseye"* ]] || [[ "${PRETTY_NAME}" == *"stretch"* ]] || [[ "${PRETTY_NAME}" == *"buster"* ]] || [[ "${PRETTY_NAME}" == *"Kali GNU/Linux Rolling"* ]] || [[ "${NAME}" == "LMDE" ]]; then
  239.         LIBPNG="libpng-dev"
  240.     else
  241.         LIBPNG="libpng12-dev"
  242.     fi
  243.     if [ "${installMySQL}" = true ]; then
  244.         MYSQL="default-mysql-server default-mysql-client mysql-common"
  245.     # Checking if (any kind of) mysql-client or compatible command installed. This is useful for existing mariadb server
  246.     elif [ -x "$( command -v mysql )" ]; then
  247.         MYSQL=""
  248.     else
  249.         MYSQL="default-mysql-client"
  250.     fi
  251. else
  252.     echo "Unsupported distribution - Debian, Kali, Raspbian, Linux Mint or Ubuntu only"
  253.     exit 1
  254. fi
  255.  
  256. # Update apt so we can search apt-cache for newest Tomcat version supported & libmariadb-java/libmysql-java
  257. echo -e "${BLUE}Updating apt...${NC}"
  258. apt-get -qq update
  259.  
  260. # Check if libmariadb-java/libmysql-java is available
  261. # Debian 10 >= ~ https://packages.debian.org/search?keywords=libmariadb-java
  262. if [[ $( apt-cache show libmariadb-java 2> /dev/null | wc -l ) -gt 0 ]]; then
  263.     # When something higher than 1.1.0 is out ~ https://issues.apache.org/jira/browse/GUACAMOLE-852
  264.     #echo -e "${BLUE}Found libmariadb-java package...${NC}"
  265.     #LIBJAVA="libmariadb-java"
  266.     # For v1.1.0 and lower
  267.     echo -e "${YELLOW}Found libmariadb-java package (known issues). Will download libmysql-java ${MCJVER} and install manually${NC}"
  268.     LIBJAVA=""
  269. # Debian 9 <= ~ https://packages.debian.org/search?keywords=libmysql-java
  270. elif [[ $( apt-cache show libmysql-java 2> /dev/null | wc -l ) -gt 0 ]]; then
  271.     echo -e "${BLUE}Found libmysql-java package...${NC}"
  272.     LIBJAVA="libmysql-java"
  273. else
  274.     echo -e "${YELLOW}lib{mariadb,mysql}-java not available. Will download mysql-connector-java-${MCJVER}.tar.gz and install manually${NC}"
  275.     LIBJAVA=""
  276. fi
  277.  
  278. # tomcat9 is the latest version
  279. # tomcat8.0 is end of life, but tomcat8.5 is current
  280. # fallback is tomcat7
  281. if [[ $( apt-cache show tomcat9 2> /dev/null | egrep "Version: 9" | wc -l ) -gt 0 ]]; then
  282.     echo -e "${BLUE}Found tomcat9 package...${NC}"
  283.     TOMCAT="tomcat9"
  284. elif [[ $( apt-cache show tomcat8 2> /dev/null | egrep "Version: 8.[5-9]" | wc -l ) -gt 0 ]]; then
  285.     echo -e "${BLUE}Found tomcat8.5+ package...${NC}"
  286.     TOMCAT="tomcat8"
  287. elif [[ $( apt-cache show tomcat7 2> /dev/null | egrep "Version: 7" | wc -l ) -gt 0 ]]; then
  288.     echo -e "${BLUE}Found tomcat7 package...${NC}"
  289.     TOMCAT="tomcat7"
  290. else
  291.     echo -e "${RED}Failed. Can't find Tomcat package${NC}" 1>&2
  292.     exit 1
  293. fi
  294.  
  295. # Uncomment to manually force a Tomcat version
  296. #TOMCAT=""
  297.  
  298. # Install features
  299. echo -e "${BLUE}Installing packages. This might take a few minutes...${NC}"
  300.  
  301. # Don't prompt during install
  302. export DEBIAN_FRONTEND=noninteractive
  303.  
  304. # Required packages
  305. apt-get -y install build-essential libcairo2-dev ${JPEGTURBO} ${LIBPNG} libossp-uuid-dev libavcodec-dev libavformat-dev libavutil-dev \
  306. libswscale-dev freerdp2-dev libpango1.0-dev libssh2-1-dev libtelnet-dev libvncserver-dev libpulse-dev libssl-dev \
  307. libvorbis-dev libwebp-dev libwebsockets-dev freerdp2-x11 libtool-bin ghostscript dpkg-dev wget crudini libc-bin \
  308. ${MYSQL} ${LIBJAVA} ${TOMCAT} &>> ${LOG}
  309.  
  310. # If apt fails to run completely the rest of this isn't going to work...
  311. if [ $? -ne 0 ]; then
  312.     echo -e "${RED}Failed. See ${LOG}${NC}" 1>&2
  313.     exit 1
  314. else
  315.     echo -e "${GREEN}OK${NC}"
  316. fi
  317. echo
  318.  
  319. # Set SERVER to be the preferred download server from the Apache CDN
  320. SERVER="http://apache.org/dyn/closer.cgi?action=download&filename=guacamole/${GUACVERSION}"
  321. echo -e "${BLUE}Downloading files...${NC}"
  322.  
  323. # Download Guacamole Server
  324. wget -q --show-progress -O guacamole-server-${GUACVERSION}.tar.gz ${SERVER}/source/guacamole-server-${GUACVERSION}.tar.gz
  325. if [ $? -ne 0 ]; then
  326.     echo -e "${RED}Failed to download guacamole-server-${GUACVERSION}.tar.gz" 1>&2
  327.     echo -e "${SERVER}/source/guacamole-server-${GUACVERSION}.tar.gz${NC}"
  328.     exit 1
  329. else
  330.     # Extract Guacamole Files
  331.     tar -xzf guacamole-server-${GUACVERSION}.tar.gz
  332. fi
  333. echo -e "${GREEN}Downloaded guacamole-server-${GUACVERSION}.tar.gz${NC}"
  334.  
  335. # Download Guacamole Client
  336. wget -q --show-progress -O guacamole-${GUACVERSION}.war ${SERVER}/binary/guacamole-${GUACVERSION}.war
  337. if [ $? -ne 0 ]; then
  338.     echo -e "${RED}Failed to download guacamole-${GUACVERSION}.war" 1>&2
  339.     echo -e "${SERVER}/binary/guacamole-${GUACVERSION}.war${NC}"
  340.     exit 1
  341. fi
  342. echo -e "${GREEN}Downloaded guacamole-${GUACVERSION}.war${NC}"
  343.  
  344. # Download Guacamole authentication extensions (Database)
  345. wget -q --show-progress -O guacamole-auth-jdbc-${GUACVERSION}.tar.gz ${SERVER}/binary/guacamole-auth-jdbc-${GUACVERSION}.tar.gz
  346. if [ $? -ne 0 ]; then
  347.     echo -e "${RED}Failed to download guacamole-auth-jdbc-${GUACVERSION}.tar.gz" 1>&2
  348.     echo -e "${SERVER}/binary/guacamole-auth-jdbc-${GUACVERSION}.tar.gz"
  349.     exit 1
  350. else
  351.     tar -xzf guacamole-auth-jdbc-${GUACVERSION}.tar.gz
  352. fi
  353. echo -e "${GREEN}Downloaded guacamole-auth-jdbc-${GUACVERSION}.tar.gz${NC}"
  354.  
  355. # Download Guacamole authentication extensions
  356.  
  357. # TOTP
  358. if [ "${installTOTP}" = true ]; then
  359.     wget -q --show-progress -O guacamole-auth-totp-${GUACVERSION}.tar.gz ${SERVER}/binary/guacamole-auth-totp-${GUACVERSION}.tar.gz
  360.     if [ $? -ne 0 ]; then
  361.         echo -e "${RED}Failed to download guacamole-auth-totp-${GUACVERSION}.tar.gz" 1>&2
  362.         echo -e "${SERVER}/binary/guacamole-auth-totp-${GUACVERSION}.tar.gz"
  363.         exit 1
  364.     else
  365.         tar -xzf guacamole-auth-totp-${GUACVERSION}.tar.gz
  366.     fi
  367.     echo -e "${GREEN}Downloaded guacamole-auth-totp-${GUACVERSION}.tar.gz${NC}"
  368. fi
  369.  
  370. # Duo
  371. if [ "${installDuo}" = true ]; then
  372.     wget -q --show-progress -O guacamole-auth-duo-${GUACVERSION}.tar.gz ${SERVER}/binary/guacamole-auth-duo-${GUACVERSION}.tar.gz
  373.     if [ $? -ne 0 ]; then
  374.         echo -e "${RED}Failed to download guacamole-auth-duo-${GUACVERSION}.tar.gz" 1>&2
  375.         echo -e "${SERVER}/binary/guacamole-auth-duo-${GUACVERSION}.tar.gz"
  376.         exit 1
  377.     else
  378.         tar -xzf guacamole-auth-duo-${GUACVERSION}.tar.gz
  379.     fi
  380.     echo -e "${GREEN}Downloaded guacamole-auth-duo-${GUACVERSION}.tar.gz${NC}"
  381. fi
  382.  
  383. # Deal with missing MySQL Connector/J
  384. if [[ -z $LIBJAVA ]]; then
  385.     # Download MySQL Connector/J
  386.     wget -q --show-progress -O mysql-connector-java-${MCJVER}.tar.gz https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-${MCJVER}.tar.gz
  387.     if [ $? -ne 0 ]; then
  388.         echo -e "${RED}Failed to download mysql-connector-java-${MCJVER}.tar.gz" 1>&2
  389.         echo -e "https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-${MCJVER}.tar.gz${NC}"
  390.         exit 1
  391.     else
  392.         tar -xzf mysql-connector-java-${MCJVER}.tar.gz
  393.     fi
  394.     echo -e "${GREEN}Downloaded mysql-connector-java-${MCJVER}.tar.gz${NC}"
  395. else
  396.     echo -e "${YELLOW}Skipping manually installing MySQL Connector/J${NC}"
  397. fi
  398. echo -e "${GREEN}Downloading complete.${NC}"
  399. echo
  400.  
  401. # Make directories
  402. rm -rf /etc/guacamole/lib/
  403. rm -rf /etc/guacamole/extensions/
  404. mkdir -p /etc/guacamole/lib/
  405. mkdir -p /etc/guacamole/extensions/
  406.  
  407. # Fix for #196
  408. mkdir -p /usr/sbin/.config/freerdp
  409. chown daemon:daemon /usr/sbin/.config/freerdp
  410.  
  411. # Fix for #197
  412. mkdir -p /var/guacamole
  413. chown daemon:daemon /var/guacamole
  414.  
  415. # Install guacd (Guacamole-server)
  416. cd guacamole-server-${GUACVERSION}/
  417.  
  418. echo -e "${BLUE}Building Guacamole-Server with GCC $( gcc --version | head -n1 | grep -oP '\)\K.*' | awk '{print $1}' ) ${NC}"
  419.  
  420. echo -e "${BLUE}Configuring Guacamole-Server. This might take a minute...${NC}"
  421. ./configure --with-systemd-dir=/etc/systemd/system  &>> ${LOG}
  422. if [ $? -ne 0 ]; then
  423.     echo "Failed to configure guacamole-server"
  424.     echo "Trying again with --enable-allow-freerdp-snapshots"
  425.     ./configure --with-systemd-dir=/etc/systemd/system --enable-allow-freerdp-snapshots
  426.     if [ $? -ne 0 ]; then
  427.         echo "Failed to configure guacamole-server - again"
  428.         exit
  429.     fi
  430. else
  431.     echo -e "${GREEN}OK${NC}"
  432. fi
  433.  
  434. echo -e "${BLUE}Running Make on Guacamole-Server. This might take a few minutes...${NC}"
  435. make &>> ${LOG}
  436. if [ $? -ne 0 ]; then
  437.     echo -e "${RED}Failed. See ${LOG}${NC}" 1>&2
  438.     exit 1
  439. else
  440.     echo -e "${GREEN}OK${NC}"
  441. fi
  442.  
  443. echo -e "${BLUE}Running Make Install on Guacamole-Server...${NC}"
  444. make install &>> ${LOG}
  445. if [ $? -ne 0 ]; then
  446.     echo -e "${RED}Failed. See ${LOG}${NC}" 1>&2
  447.     exit 1
  448. else
  449.     echo -e "${GREEN}OK${NC}"
  450. fi
  451. ldconfig
  452. echo
  453.  
  454. # Move files to correct locations (guacamole-client & Guacamole authentication extensions)
  455. cd ..
  456. mv -f guacamole-${GUACVERSION}.war /etc/guacamole/guacamole.war
  457. mv -f guacamole-auth-jdbc-${GUACVERSION}/mysql/guacamole-auth-jdbc-mysql-${GUACVERSION}.jar /etc/guacamole/extensions/
  458.  
  459. # Create Symbolic Link for Tomcat
  460. ln -sf /etc/guacamole/guacamole.war /var/lib/${TOMCAT}/webapps/
  461.  
  462. # Deal with MySQL Connector/J
  463. if [[ -z $LIBJAVA ]]; then
  464.     echo -e "${BLUE}Moving mysql-connector-java-${MCJVER}.jar (/etc/guacamole/lib/mysql-connector-java.jar)...${NC}"
  465.     mv -f mysql-connector-java-${MCJVER}/mysql-connector-java-${MCJVER}.jar /etc/guacamole/lib/mysql-connector-java.jar
  466. elif [ -e /usr/share/java/mariadb-java-client.jar ]; then
  467.     echo -e "${BLUE}Linking mariadb-java-client.jar  (/etc/guacamole/lib/mariadb-java-client.jar)...${NC}"
  468.     ln -sf /usr/share/java/mariadb-java-client.jar /etc/guacamole/lib/mariadb-java-client.jar
  469. elif [ -e /usr/share/java/mysql-connector-java.jar ]; then
  470.     echo -e "${BLUE}Linking mysql-connector-java.jar  (/etc/guacamole/lib/mysql-connector-java.jar)...${NC}"
  471.     ln -sf /usr/share/java/mysql-connector-java.jar /etc/guacamole/lib/mysql-connector-java.jar
  472. else
  473.     echo -e "${RED}Can't find *.jar file${NC}" 1>&2
  474.     exit 1
  475. fi
  476. echo
  477.  
  478. # Move TOTP Files
  479. if [ "${installTOTP}" = true ]; then
  480.     echo -e "${BLUE}Moving guacamole-auth-totp-${GUACVERSION}.jar (/etc/guacamole/extensions/)...${NC}"
  481.     mv -f guacamole-auth-totp-${GUACVERSION}/guacamole-auth-totp-${GUACVERSION}.jar /etc/guacamole/extensions/
  482.     echo
  483. fi
  484.  
  485. # Move Duo Files
  486. if [ "${installDuo}" = true ]; then
  487.     echo -e "${BLUE}Moving guacamole-auth-duo-${GUACVERSION}.jar (/etc/guacamole/extensions/)...${NC}"
  488.     mv -f guacamole-auth-duo-${GUACVERSION}/guacamole-auth-duo-${GUACVERSION}.jar /etc/guacamole/extensions/
  489.     echo
  490. fi
  491.  
  492. # Configure guacamole.properties
  493. rm -f /etc/guacamole/guacamole.properties
  494. touch /etc/guacamole/guacamole.properties
  495. echo "mysql-hostname: ${mysqlHost}" >> /etc/guacamole/guacamole.properties
  496. echo "mysql-port: ${mysqlPort}" >> /etc/guacamole/guacamole.properties
  497. echo "mysql-database: ${guacDb}" >> /etc/guacamole/guacamole.properties
  498. echo "mysql-username: ${guacUser}" >> /etc/guacamole/guacamole.properties
  499. echo "mysql-password: ${guacPwd}" >> /etc/guacamole/guacamole.properties
  500.  
  501. # Output Duo configuration settings but comment them out for now
  502. if [ "${installDuo}" = true ]; then
  503.     echo "# duo-api-hostname: " >> /etc/guacamole/guacamole.properties
  504.     echo "# duo-integration-key: " >> /etc/guacamole/guacamole.properties
  505.     echo "# duo-secret-key: " >> /etc/guacamole/guacamole.properties
  506.     echo "# duo-application-key: " >> /etc/guacamole/guacamole.properties
  507.     echo -e "${YELLOW}Duo is installed, it will need to be configured via guacamole.properties${NC}"
  508. fi
  509.  
  510. # Restart Tomcat
  511. echo -e "${BLUE}Restarting Tomcat service & enable at boot...${NC}"
  512. service ${TOMCAT} restart
  513. if [ $? -ne 0 ]; then
  514.     echo -e "${RED}Failed${NC}" 1>&2
  515.     exit 1
  516. else
  517.     echo -e "${GREEN}OK${NC}"
  518. fi
  519. # Start at boot
  520. systemctl enable ${TOMCAT}
  521. echo
  522.  
  523. # Set MySQL password
  524. export MYSQL_PWD=${mysqlRootPwd}
  525.  
  526. if [ "${installMySQL}" = true ]; then
  527.  
  528.     # Restart MySQL service
  529.     echo -e "${BLUE}Restarting MySQL service & enable at boot...${NC}"
  530.     service mysql restart
  531.     if [ $? -ne 0 ]; then
  532.         echo -e "${RED}Failed${NC}" 1>&2
  533.         exit 1
  534.     else
  535.         echo -e "${GREEN}OK${NC}"
  536.     fi
  537.     # Start at boot
  538.     systemctl enable mysql
  539.     echo
  540.  
  541.     # Default locations of MySQL config file
  542.     for x in /etc/mysql/mariadb.conf.d/50-server.cnf \
  543.              /etc/mysql/mysql.conf.d/mysqld.cnf \
  544.              /etc/mysql/my.cnf \
  545.              ; do
  546.         # Check the path exists
  547.         if [ -e "${x}" ]; then
  548.             # Does it have the necessary section
  549.             if grep -q '^\[mysqld\]$' "${x}"; then
  550.                 mysqlconfig="${x}"
  551.                 # no point keep checking!
  552.                 break
  553.             fi
  554.         fi
  555.     done
  556.  
  557.     if [ -z "${mysqlconfig}" ]; then
  558.         echo -e "${YELLOW}Couldn't detect MySQL config file - you may need to manually enter timezone settings${NC}"
  559.     else
  560.         # Is there already a value?
  561.         if grep -q "^default_time_zone[[:space:]]?=" "${mysqlconfig}"; then
  562.             echo -e "${YELLOW}Timezone already defined in ${mysqlconfig}${NC}"
  563.         else
  564.             timezone="$( cat /etc/timezone )"
  565.             if [ -z "${timezone}" ]; then
  566.                 echo -e "${YELLOW}Couldn't find timezone, using UTC${NC}"
  567.                 timezone="UTC"
  568.             fi
  569.             echo -e "${YELLOW}Setting timezone as ${timezone}${NC}"
  570.             # Fix for https://issues.apache.org/jira/browse/GUACAMOLE-760
  571.             mysql_tzinfo_to_sql /usr/share/zoneinfo 2>/dev/null | mysql -u root -D mysql -h ${mysqlHost} -P ${mysqlPort}
  572.             crudini --set ${mysqlconfig} mysqld default_time_zone "${timezone}"
  573.             # Restart to apply
  574.             service mysql restart
  575.             echo
  576.         fi
  577.     fi
  578. fi
  579.  
  580. # Create ${guacDb} and grant ${guacUser} permissions to it
  581.  
  582. # SQL code
  583. guacUserHost="localhost"
  584.  
  585. if [[ "${mysqlHost}" != "localhost" ]]; then
  586.     guacUserHost="%"
  587.     echo -e "${YELLOW}MySQL Guacamole user is set to accept login from any host, please change this for security reasons if possible.${NC}"
  588. fi
  589.  
  590. # Check for ${guacDb} already being there
  591. echo -e "${BLUE}Checking MySQL for existing database (${guacDb})${NC}"
  592. SQLCODE="
  593. SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME='${guacDb}';"
  594.  
  595. # Execute SQL code
  596. MYSQL_RESULT=$( echo ${SQLCODE} | mysql -u root -D information_schema -h ${mysqlHost} -P ${mysqlPort} )
  597. if [[ $MYSQL_RESULT != "" ]]; then
  598.     echo -e "${RED}It appears there is already a MySQL database (${guacDb}) on ${mysqlHost}${NC}" 1>&2
  599.     echo -e "${RED}Try:    mysql -e 'DROP DATABASE ${guacDb}'${NC}" 1>&2
  600.     #exit 1
  601. else
  602.     echo -e "${GREEN}OK${NC}"
  603. fi
  604.  
  605. # Check for ${guacUser} already being there
  606. echo -e "${BLUE}Checking MySQL for existing user (${guacUser})${NC}"
  607. SQLCODE="
  608. SELECT COUNT(*) FROM mysql.user WHERE user = '${guacUser}';"
  609.  
  610. # Execute SQL code
  611. MYSQL_RESULT=$( echo ${SQLCODE} | mysql -u root -D mysql -h ${mysqlHost} -P ${mysqlPort} | grep '0' )
  612. if [[ $MYSQL_RESULT == "" ]]; then
  613.     echo -e "${RED}It appears there is already a MySQL user (${guacUser}) on ${mysqlHost}${NC}" 1>&2
  614.     echo -e "${RED}Try:    mysql -e \"DROP USER '${guacUser}'@'${guacUserHost}'; FLUSH PRIVILEGES;\"${NC}" 1>&2
  615.     #exit 1
  616. else
  617.     echo -e "${GREEN}OK${NC}"
  618. fi
  619.  
  620. # Create database & user, then set permissions
  621. SQLCODE="
  622. DROP DATABASE IF EXISTS ${guacDb};
  623. CREATE DATABASE IF NOT EXISTS ${guacDb};
  624. CREATE USER IF NOT EXISTS '${guacUser}'@'${guacUserHost}' IDENTIFIED BY \"${guacPwd}\";
  625. GRANT SELECT,INSERT,UPDATE,DELETE ON ${guacDb}.* TO '${guacUser}'@'${guacUserHost}';
  626. FLUSH PRIVILEGES;"
  627.  
  628. # Execute SQL code
  629. echo ${SQLCODE} | mysql -u root -D mysql -h ${mysqlHost} -P ${mysqlPort}
  630.  
  631. # Add Guacamole schema to newly created database
  632. echo -e "${BLUE}Adding database tables...${NC}"
  633. cat guacamole-auth-jdbc-${GUACVERSION}/mysql/schema/*.sql | mysql -u root -D ${guacDb} -h ${mysqlHost} -P ${mysqlPort}
  634. if [ $? -ne 0 ]; then
  635.     echo -e "${RED}Failed${NC}" 1>&2
  636.     exit 1
  637. else
  638.     echo -e "${GREEN}OK${NC}"
  639. fi
  640. echo
  641.  
  642. # Create guacd.conf file required for 1.4.0
  643. echo -e "${BLUE}Create guacd.conf file...${NC}"
  644. cat >> /etc/guacamole/guacd.conf <<- "EOF"
  645. [server]
  646. bind_host = 0.0.0.0
  647. bind_port = 4822
  648. EOF
  649.  
  650. # Ensure guacd is started
  651. echo -e "${BLUE}Starting guacd service & enable at boot...${NC}"
  652. service guacd stop 2>/dev/null
  653. service guacd start
  654. systemctl enable guacd
  655. echo
  656.  
  657. # Deal with ufw and/or iptables
  658.  
  659. # Check if ufw is a valid command
  660. if [ -x "$( command -v ufw )" ]; then
  661.     # Check if ufw is active (active|inactive)
  662.     if [[ $(ufw status | grep inactive | wc -l) -eq 0 ]]; then
  663.         # Check if 8080 is not already allowed
  664.         if [[ $(ufw status | grep "8080/tcp" | grep "ALLOW" | grep "Anywhere" | wc -l) -eq 0 ]]; then
  665.             # ufw is running, but 8080 is not allowed, add it
  666.             ufw allow 8080/tcp comment 'allow tomcat'
  667.         fi
  668.     fi
  669. fi    
  670.  
  671. # It's possible that someone is just running pure iptables...
  672.  
  673. # Check if iptables is a valid running service
  674. systemctl is-active --quiet iptables
  675. if [ $? -eq 0 ]; then
  676.     # Check if 8080 is not already allowed
  677.     # FYI: This same command matches the rule added with ufw (-A ufw-user-input -p tcp -m tcp --dport 22 -j ACCEPT)
  678.     if [[ $(iptables --list-rules | grep -- "-p tcp" | grep -- "--dport 8080" | grep -- "-j ACCEPT" | wc -l) -eq 0 ]]; then
  679.         # ALlow it
  680.         iptables -A INPUT -p tcp --dport 8080 --jump ACCEPT
  681.     fi
  682. fi
  683.  
  684. # I think there is another service called firewalld that some people could be running instead
  685. # Unless someone opens an issue about it or submits a pull request, I'm going to ignore it for now
  686.  
  687. # Cleanup
  688. echo -e "${BLUE}Cleanup install files...${NC}"
  689. rm -rf guacamole-*
  690. rm -rf mysql-connector-java-*
  691. unset MYSQL_PWD
  692. echo
  693.  
  694. # Done
  695. echo -e "${BLUE}Installation Complete\n- Visit: http://localhost:8080/guacamole/\n- Default login (username/password): guacadmin/guacadmin\n***Be sure to change the password***.${NC}"
  696.  
  697. if [ "${installDuo}" = true ]; then
  698.     echo -e "${YELLOW}\nDon't forget to configure Duo in guacamole.properties. You will not be able to login otherwise.\nhttps://guacamole.apache.org/doc/${GUACVERSION}/gug/duo-auth.html${NC}"
  699. fi

PasteBin is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.