From 9a6da8841876c9251a8c2235d91cf6cdf2477795 Mon Sep 17 00:00:00 2001 From: Chase Wright Date: Fri, 9 Mar 2018 15:51:48 -0600 Subject: [PATCH] Add Non-Interactive Option (#37) Thanks to @bigredthelogger for providing the initial code * Add Non-Interactive Option to Installer * Update README for Non-Interactive Options * Add Non-Interactive Option to Upgrade --- README.md | 32 ++++++++++++++++++------- guac-install.sh | 62 ++++++++++++++++++++++++++++++++----------------- guac-upgrade.sh | 41 ++++++++++++++++++++++---------- 3 files changed, 94 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 3724adf..8971f93 100644 --- a/README.md +++ b/README.md @@ -5,20 +5,30 @@ Run script, enter MySQL Root Password and Guacamole User password. Guacamole Use The script attempts to install tomcat8 if the available version is 8.5.x or newer, if tomcat8 is only 8.0.x it will fall back to tomcat7. If you want to manually specify a tomcat version there's a commented out line you can modify at line #73. Have at it. -How to Run: +## How to Run: -Download file directly from here: +### Download file directly from here: wget https://raw.githubusercontent.com/MysticRyuujin/guac-install/master/guac-install.sh -Make it executable: +### Make it executable: chmod +x guac-install.sh -Run it as root: +### Run it as root: + +Interactive (asks for passwords): ./guac-install.sh +Non-Interactive (passwords provided via cli): + +./guac-install.sh --mysqlpwd password --guacpwd password + +OR + +./guac-install.sh -m password -g password + Once installation is done you can access guacamole by browsing to: http://:8080/guacamole/ The default credentials are guacadmin as both username and password. Please change them or disable guacadmin after install! @@ -27,16 +37,22 @@ Script for upgrading currently installed Guacamole instance (previously installe If looks for the tomcat folder in /etc/ (E.G. `/etc/tomcat7` or `/etc/tomcat8`) hopefully that works to identify the correct tomcat version/path :smile: I'm open to suggestions/pull requests for a cleaner method. -How to Run: +## How to Run: -Download file directly from here: +### Download file directly from here: wget https://raw.githubusercontent.com/MysticRyuujin/guac-install/master/guac-upgrade.sh -Make it executable: +### Make it executable: chmod +x guac-upgrade.sh -Run it as root: +### Run it as root: + +Interactive (asks for passwords): ./guac-upgrade.sh + +Non-Interactive (password provided via cli): + +./guac-upgrade.sh --mysqlpwd password diff --git a/guac-install.sh b/guac-install.sh index b90b161..12c8a02 100644 --- a/guac-install.sh +++ b/guac-install.sh @@ -6,30 +6,50 @@ GUACVERSION="0.9.14" # Update apt so we can search apt-cache for newest tomcat version supported apt update +# Get script arguments for non-interactive mode +while [ "$1" != "" ]; do + case $1 in + -m | --mysqlpwd ) + shift + mysqlpwd="$1" + ;; + -g | --guacpwd ) + shift + guacpwd="$1" + ;; + esac + shift +done + # Get MySQL root password and Guacamole User password -echo -while true -do - read -s -p "Enter a MySQL ROOT Password: " mysqlrootpassword +if [ -n "$mysqlpwd" ] && [ -n "$guacpwd" ]; then + mysqlrootpassword=$mysqlpwd + guacdbuserpassword=$guacpwd +else + echo + while true + do + read -s -p "Enter a MySQL ROOT Password: " mysqlrootpassword + echo + read -s -p "Confirm MySQL ROOT Password: " password2 + echo + [ "$mysqlrootpassword" = "$password2" ] && break + echo "Passwords don't match. Please try again." + echo + done echo - read -s -p "Confirm MySQL ROOT Password: " password2 + while true + do + read -s -p "Enter a Guacamole User Database Password: " guacdbuserpassword + echo + read -s -p "Confirm Guacamole User Database Password: " password2 + echo + [ "$guacdbuserpassword" = "$password2" ] && break + echo "Passwords don't match. Please try again." + echo + done echo - [ "$mysqlrootpassword" = "$password2" ] && break - echo "Passwords don't match. Please try again." - echo -done -echo -while true -do - read -s -p "Enter a Guacamole User Database Password: " guacdbuserpassword - echo - read -s -p "Confirm Guacamole User Database Password: " password2 - echo - [ "$guacdbuserpassword" = "$password2" ] && break - echo "Passwords don't match. Please try again." - echo -done -echo +fi debconf-set-selections <<< "mysql-server mysql-server/root_password password $mysqlrootpassword" debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $mysqlrootpassword" diff --git a/guac-upgrade.sh b/guac-upgrade.sh index c29f3a0..d838707 100644 --- a/guac-upgrade.sh +++ b/guac-upgrade.sh @@ -1,23 +1,40 @@ #!/bin/bash +# Version Numbers of Guacamole to download +GUACVERSION="0.9.14" + # Try to get database from /etc/guacamole/guacamole.properties DATABASE=$(grep -oP 'mysql-database:\K.*' /etc/guacamole/guacamole.properties | awk '{print $1}') MYSQL_SERVER=$(grep -oP 'mysql-hostname:\K.*' /etc/guacamole/guacamole.properties | awk '{print $1}') -# Get MySQL root password -echo -while true -do - read -s -p "Enter MySQL ROOT Password: " mysqlrootpassword - export MYSQL_PWD=${mysqlrootpassword} - echo - mysql -u root -h ${MYSQL_SERVER} ${DATABASE} -e"quit" && break - echo +# Get script arguments for non-interactive mode +while [ "$1" != "" ]; do + case $1 in + -m | --mysqlpwd ) + shift + mysqlpwd="$1" + ;; + esac + shift done -echo -# Version Numbers of Guacamole to download -GUACVERSION="0.9.14" +# Get MySQL root password +if [ -n "$mysqlpwd" ]; then + mysqlrootpassword=$mysqlpwd + export MYSQL_PWD=${mysqlrootpassword} + mysql -u root -h ${MYSQL_SERVER} ${DATABASE} -e"quit" || exit +else + echo + while true + do + read -s -p "Enter MySQL ROOT Password: " mysqlrootpassword + export MYSQL_PWD=${mysqlrootpassword} + echo + mysql -u root -h ${MYSQL_SERVER} ${DATABASE} -e"quit" && break + echo + done + echo +fi # Get Tomcat Version TOMCAT=$(ls /etc/ | grep tomcat)