From efbd54e536d74bfc91233b7798431b2bfeee55be Mon Sep 17 00:00:00 2001 From: Chase Wright Date: Thu, 4 Apr 2019 12:06:13 -0500 Subject: [PATCH] Support DB Name and DB User Name Also doesn't try to install MySQL if it's already installed Closes #80 --- guac-install.sh | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/guac-install.sh b/guac-install.sh index 68cdc1b..a9970b9 100644 --- a/guac-install.sh +++ b/guac-install.sh @@ -16,9 +16,6 @@ NC='\033[0m' # No Color # Log Location LOG="/tmp/guacamole_${GUACVERSION}_build.log" -# Database Name -DB="guacamole_db" - # Get script arguments for non-interactive mode while [ "$1" != "" ]; do case $1 in @@ -30,10 +27,28 @@ while [ "$1" != "" ]; do shift guacpwd="$1" ;; + -u | --mysqluser ) + shift + mysqluser="$1" + ;; + -d | --database ) + shift + DB="$1" + ;; esac shift done +# Checking if mysql user given +if [ -z "$mysqluser" ]; then + mysqluser="guacamole_user" +fi + +# Checking if database name given +if [ -z "$DB" ]; then + DB="guacamole_db" +fi + # Get MySQL root password and Guacamole User password if [ -n "$mysqlpwd" ] && [ -n "$guacpwd" ]; then mysqlrootpassword=$mysqlpwd @@ -111,6 +126,13 @@ else TOMCAT="tomcat7" fi +if [ -z $(command -v mysql)] +then + MYSQL="mysql-server mysql-client mysql-common mysql-utilities" +else + MYSQL="" +fi + # Uncomment to manually force a tomcat version #TOMCAT="" @@ -119,7 +141,7 @@ echo -e "${BLUE}Installing dependencies. This might take a few minutes...${NC}" apt-get -y install build-essential libcairo2-dev ${JPEGTURBO} ${LIBPNG} libossp-uuid-dev libavcodec-dev libavutil-dev \ libswscale-dev libfreerdp-dev libpango1.0-dev libssh2-1-dev libtelnet-dev libvncserver-dev libpulse-dev libssl-dev \ -libvorbis-dev libwebp-dev mysql-server mysql-client mysql-common mysql-utilities libmysql-java ${TOMCAT} freerdp-x11 \ +libvorbis-dev libwebp-dev ${MYSQL} libmysql-java ${TOMCAT} freerdp-x11 \ ghostscript wget dpkg-dev &>> ${LOG} if [ $? -ne 0 ]; then @@ -220,7 +242,7 @@ cp guacamole-auth-jdbc-${GUACVERSION}/mysql/guacamole-auth-jdbc-mysql-${GUACVERS echo "mysql-hostname: localhost" >> /etc/guacamole/guacamole.properties echo "mysql-port: 3306" >> /etc/guacamole/guacamole.properties echo "mysql-database: ${DB}" >> /etc/guacamole/guacamole.properties -echo "mysql-username: guacamole_user" >> /etc/guacamole/guacamole.properties +echo "mysql-username: ${mysqluser}" >> /etc/guacamole/guacamole.properties echo "mysql-password: ${guacdbuserpassword}" >> /etc/guacamole/guacamole.properties # restart tomcat @@ -234,13 +256,13 @@ else echo -e "${GREEN}OK${NC}" fi -# Create guacamole_db and grant guacamole_user permissions to it +# Create guacamole_db and grant $mysqluser permissions to it # SQL code SQLCODE=" create database ${DB}; -create user 'guacamole_user'@'localhost' identified by \"${guacdbuserpassword}\"; -GRANT SELECT,INSERT,UPDATE,DELETE ON guacamole_db.* TO 'guacamole_user'@'localhost'; +create user if not exists '${mysqluser}'@'localhost' identified by \"${guacdbuserpassword}\"; +GRANT SELECT,INSERT,UPDATE,DELETE ON guacamole_db.* TO '${mysqluser}'@'localhost'; flush privileges;" # Execute SQL code