From ab10ef650441cccb1afab2c063d47738db43d0ca Mon Sep 17 00:00:00 2001 From: Martin Winkler Date: Fri, 17 May 2019 11:59:51 +0100 Subject: [PATCH] Bump to revision 3 addConf with mandatory paramter; suppots appending --- seqTemplate.sh | 2 +- seqs/gitea.sh | 2 +- seqs/kodi.sh | 6 ++--- seqs/librenms.sh | 2 +- seqs/mayan-edms.sh | 50 +++++++++++++++++++++++++------------ seqs/paperless.sh | 3 +++ seqs/pixelfed.sh | 6 ++--- seqs/tvheadend.sh | 5 ++-- seqs/webserver.sh | 12 ++++----- seqs/webserverUbuntu.sh | 13 +++++----- sequencer/sequencer.sh | 55 ++++++++++++++++++++++++++++++----------- 11 files changed, 103 insertions(+), 53 deletions(-) diff --git a/seqTemplate.sh b/seqTemplate.sh index 2bbe7d9..bdc2654 100755 --- a/seqTemplate.sh +++ b/seqTemplate.sh @@ -41,7 +41,7 @@ step_11() { } # Sequence Revision -VERSION_SEQREV=2 +VERSION_SEQREV=3 # Workaround when called from different directory # Not needed when path to sequencer is absolut diff --git a/seqs/gitea.sh b/seqs/gitea.sh index 31aa2e1..307864e 100755 --- a/seqs/gitea.sh +++ b/seqs/gitea.sh @@ -139,7 +139,7 @@ step_20() { } # Sequence Revision -VERSION_SEQREV=2 +VERSION_SEQREV=3 # Workaround when called from different directory # Not needed when path to sequencer is absolut diff --git a/seqs/kodi.sh b/seqs/kodi.sh index 8179533..6907708 100755 --- a/seqs/kodi.sh +++ b/seqs/kodi.sh @@ -46,7 +46,7 @@ step_3() { step_4_info() { echo "Create systemd service"; } step_4() { - addConf "$toolServiceContent" "$toolServiceFile" + addConf -c "$toolServiceContent" "$toolServiceFile" if [ $? -eq 0 ] ; then exe systemctl daemon reload @@ -85,7 +85,7 @@ step_5() { local udevFile="/etc/udev/rules.d/99-kodi.rules" local inputRule="KERNEL==\"tty[0-9]*\", GROUP=\"tty\", MODE=\"0660\"" - addConf "$inputRule" "$udevFile" + addConf -c "$inputRule" "$udevFile" } step_6_info() { echo "Increase raspberry pi GPU memory to 320"; } @@ -127,5 +127,5 @@ step_7() { esac } -VERSION_SEQREV=2 +VERSION_SEQREV=3 . sequencer.sh diff --git a/seqs/librenms.sh b/seqs/librenms.sh index b9ef16d..86a50d4 100755 --- a/seqs/librenms.sh +++ b/seqs/librenms.sh @@ -135,7 +135,7 @@ step_42() { } # Sequence Revision -VERSION_SEQREV=2 +VERSION_SEQREV=3 # Workaround when called from different directory # Not needed when path to sequencer is absolut diff --git a/seqs/mayan-edms.sh b/seqs/mayan-edms.sh index 8fb074c..dcbe4aa 100755 --- a/seqs/mayan-edms.sh +++ b/seqs/mayan-edms.sh @@ -4,6 +4,11 @@ toolName="Mayan EDMS" toolRoot="/opt/mayan-edms" toolMediaFolder="/opt/mayan-edms/media" +# Needed for different steps +postgresDb="" +postgresUser="" +postgresPass="" + step_1_info() { echo "Install libreoffice without gui"; } step_1() { exe apt update @@ -28,19 +33,11 @@ step_3() { exe chown -R mayan:mayan ${toolRoot} } -postgresDb="" -postgresUser="" -postgresPass="" step_4_info() { echo "Create postgres database for $toolName"; } step_4_alias() { ALIAS="createdb"; } step_4() { - exe read -p "Enter postgres database name: " postgresDb - endCheckEmpty postgresDb "database" - exe read -p "Enter postgres user name: " postgresUser - endCheckEmpty postgresUser "user name" - exe read -p "Enter postgres password: " postgresPass - endCheckEmpty postgresPass "password" - + readDatabaseInfos + exe sudo -u postgres psql -c "CREATE USER ${postgresUser} WITH password '${postgresPass}';" # -O owner : Specifies the database user who will own the new database. exe sudo -u postgres createdb -O ${postgresUser} ${postgresDb} @@ -55,6 +52,8 @@ step_5() { saveReturn $? endReturn + readDatabaseInfos + exe sudo -u mayan MAYAN_DATABASE_ENGINE=django.db.backends.postgresql MAYAN_DATABASE_NAME=${postgresDb} \ MAYAN_DATABASE_PASSWORD="${postgresPass}" MAYAN_DATABASE_USER=${postgresUser} \ MAYAN_DATABASE_HOST=127.0.0.1 MAYAN_MEDIA_ROOT=${toolMediaFolder} \ @@ -66,11 +65,10 @@ step_5() { step_6_info() { echo "$toolName configuration file"; } step_6() { - addConf "$supervisorFile" "$supervisorFileLoc" - - exe echo "maxmemory-policy allkeys-lru" >> "$redisConfLoc" - exe echo "save \"\"" >> "$redisConfLoc" - exe echo "databases 1" >> "$redisConfLoc" + readDatabaseInfos + addConf -c "$supervisorFile" "$supervisorFileLoc" + addConf -a "$redisConf" "$redisConfLoc" + exe systemctl restart redis exe systemctl enable supervisor @@ -78,6 +76,10 @@ step_6() { } redisConfLoc="/etc/redis/redis.conf" +redisConf="\ +maxmemory-policy allkeys-lru +save \"\" +databases 1" supervisorFileLoc="/etc/supervisor/conf.d/mayan.conf" supervisorFile="\ [supervisord] @@ -159,5 +161,21 @@ step_22() { echo " e.g. psql -h 127.0.0.1 -U mayan -d mayan -W -f 2018-06-07_18-10-56.sql" } -VERSION_SEQREV=2 +# Read postgres database information dbname/user/pass if empty +readDatabaseInfos() { + if [ "$postgresDb" == "" ] ; then + read -p "Enter postgres database name: " postgresDb + endCheckEmpty postgresDb "database" + fi + if [ "$postgresUser" == "" ] ; then + read -p "Enter postgres user name: " postgresUser + endCheckEmpty postgresUser "user name" + fi + if [ "$postgresPass" == "" ] ; then + read -p "Enter postgres password: " postgresPass + endCheckEmpty postgresPass "password" + fi +} + +VERSION_SEQREV=3 . sequencer.sh diff --git a/seqs/paperless.sh b/seqs/paperless.sh index cb513fa..9d4f60e 100755 --- a/seqs/paperless.sh +++ b/seqs/paperless.sh @@ -26,4 +26,7 @@ step_4() { echo "[ WARN ] Configuration already exists. Doing nothing" fi } + +VERSION_SEQREV=3 + . sequencer.sh diff --git a/seqs/pixelfed.sh b/seqs/pixelfed.sh index ba442f5..cfbf39a 100755 --- a/seqs/pixelfed.sh +++ b/seqs/pixelfed.sh @@ -93,7 +93,7 @@ step_6() { step_7_info() { echo "Create pixelfed (horzion) service"; } step_7() { - addConf "${horizonService}" "${horizonServiceLoc}" + addConf -c "${horizonService}" "${horizonServiceLoc}" exe systemctl daemon-reload exe systemctl enable pixelfed.service exe service pixelfed start @@ -132,7 +132,7 @@ WantedBy=multi-user.target" step_8_info() { echo "Nginx configuration"; } step_8() { - addConf "$nginxConfig" "$nginxConfigLoc" + addConf -c "$nginxConfig" "$nginxConfigLoc" exe ln -s "$nginxConfigLoc" "$nginxConfigEnable" exe nginx -t saveReturn $? @@ -202,7 +202,7 @@ step_22() { } # Sequence Revision -VERSION_SEQREV=2 +VERSION_SEQREV=3 # Workaround when called from different directory # Not needed when path to sequencer is absolut diff --git a/seqs/tvheadend.sh b/seqs/tvheadend.sh index 7c1f321..8df0a36 100755 --- a/seqs/tvheadend.sh +++ b/seqs/tvheadend.sh @@ -19,7 +19,7 @@ step_1() { saveReturn $? endReturn - addConf "$sourceEntry" "$sourceList" + addConf -c "$sourceEntry" "$sourceList" } step_2_info() { echo "Install/Upate $toolName"; } @@ -51,5 +51,6 @@ step_99() { endReturn } -VERSION_SEQREV=2 +VERSION_SEQREV=3 + . sequencer.sh diff --git a/seqs/webserver.sh b/seqs/webserver.sh index 7589eb7..353a2a2 100755 --- a/seqs/webserver.sh +++ b/seqs/webserver.sh @@ -21,10 +21,10 @@ step_1() { step_2_info() { echo "Basic nginx configuration for initial letsencrypt certificate creation"; } step_2() { # Writing acme-challenge code snipped for certbot web root authentication - addConf "$snippetLetsencrypt" "$snippetLetsencryptLoc" + addConf -c "$snippetLetsencrypt" "$snippetLetsencryptLoc" # Writing minimal default (see below) - addConf "$siteDefaultIp4" "$siteDefaultLoc" + addConf -c "$siteDefaultIp4" "$siteDefaultLoc" # try fix errors on first install attempt # (possible missing ipv6 support on system) @@ -62,7 +62,7 @@ step_3() { step_4_info() { echo "Mariadb configuration"; } step_4() { - addConf "$mariadbConfig" "$mariadbConfigLoc" + addConf -c "$mariadbConfig" "$mariadbConfigLoc" echo -n "Restarting mysql ... " exe service mysql restart && echo "ok" @@ -107,8 +107,8 @@ date.timezone = Europe/Berlin" step_6_info() { echo -e "Configuration of ${phpName} fpm and cli\n"; } step_6() { - addConf "$phpFpmConfig" "$phpFpmConfigLocation" - addConf "$phpCliConfig" "$phpCliConfigLocation" + addConf -c "$phpFpmConfig" "$phpFpmConfigLocation" + addConf -c "$phpCliConfig" "$phpCliConfigLocation" echo -n "Restarting ${phpName} ... " exe service ${phpName}-fpm restart && echo "ok" @@ -183,5 +183,5 @@ step_12() { exe mysql -u root -e 'FLUSH PRIVILEGES;' } -VERSION_SEQREV=2 +VERSION_SEQREV=3 . sequencer.sh diff --git a/seqs/webserverUbuntu.sh b/seqs/webserverUbuntu.sh index cbff1cc..35b046b 100755 --- a/seqs/webserverUbuntu.sh +++ b/seqs/webserverUbuntu.sh @@ -22,10 +22,10 @@ step_1() { step_2_info() { echo "Basic nginx configuration for initial letsencrypt certificate creation"; } step_2() { # Writing acme-challenge code snipped for certbot web root authentication - addConf "$snippetLetsencrypt" "$snippetLetsencryptLoc" + addConf -c "$snippetLetsencrypt" "$snippetLetsencryptLoc" # Writing minimal default (see below) - addConf "$siteDefaultIp4" "$siteDefaultLoc" + addConf -c "$siteDefaultIp4" "$siteDefaultLoc" # try fix errors on first install attempt # (possible missing ipv6 support on system) @@ -63,7 +63,7 @@ step_3() { step_4_info() { echo "Mariadb configuration"; } step_4() { - addConf "$mariadbConfig" "$mariadbConfigLoc" + addConf -c "$mariadbConfig" "$mariadbConfigLoc" echo -n "Restarting mysql ... " exe service mysql restart && echo "ok" @@ -108,8 +108,8 @@ date.timezone = Europe/Berlin" step_6_info() { echo -e "Configuration of ${phpName} fpm and cli\n"; } step_6() { - addConf "$phpFpmConfig" "$phpFpmConfigLocation" - addConf "$phpCliConfig" "$phpCliConfigLocation" + addConf -c "$phpFpmConfig" "$phpFpmConfigLocation" + addConf -c "$phpCliConfig" "$phpCliConfigLocation" echo -n "Restarting ${phpName} ... " exe service ${phpName}-fpm restart && echo "ok" @@ -184,5 +184,6 @@ step_12() { exe mysql -u root -e 'FLUSH PRIVILEGES;' } -VERSION_SEQREV=2 +VERSION_SEQREV=3 + . sequencer.sh diff --git a/sequencer/sequencer.sh b/sequencer/sequencer.sh index 66c5cc7..85018c5 100755 --- a/sequencer/sequencer.sh +++ b/sequencer/sequencer.sh @@ -6,7 +6,7 @@ ## Version information -VERSION_REV=2 +VERSION_REV=3 VERSION_MAJOR=0 VERSION_MINOR=0 @@ -95,29 +95,51 @@ endReturn() { fi } -# addConf +# addConf # trying to write a file # if exists, one attempt is made to create bck file of it # if all fails, a log file is created with the conflicts to be resolved by the user addConf() { - echo -n "Writing $2 ... " + local confMode="" + case "$1" in + -c) # create a new file + confMode="-c" + ;; + -a) # append to existing file + confMode="-a" + ;; + *) # default + echo "Parameter 1 (-a|-c) missing for addConf()" + exit 0; + ;; + esac + + echo -n "Writing $3 ... " if [ "$DRY" -ne 0 ] ; then echo "dry-run" return 0; fi # try writing config directly - if [ ! -f "$2" ] ; then - echo "$1" > "$2" + if [ ! -f "$3" ] ; then + if [ $confMode == "-c" ] ; then + echo "$2" > "$3" + else + echo "$2" >> "$3" + fi echo "ok" return 0 fi # try backup existing config - if [ ! -f "$2".bck ] ; then - cp -ar "$2" "$2".bck - echo "$1" > "$2" - echo "[WARN] Existing config saved to ${2}.bck" + if [ ! -f "$3".bck ] ; then + cp -ar "$3" "$3".bck + if [ $confMode == "-c" ] ; then + echo "$2" > "$3" + else + echo "$2" >> "$3" + fi + echo "[WARN] Existing config saved to ${3}.bck" return 0 fi @@ -127,11 +149,11 @@ addConf() { echo -n "### " >> "$MISSING_CONF" date >> "$MISSING_CONF" fi - echo "#--- $2 ---" >> "$MISSING_CONF" - echo "$1" >> "$MISSING_CONF" + echo "#--- $3 ---" >> "$MISSING_CONF" + echo "$2" >> "$MISSING_CONF" echo >> "$MISSING_CONF" - echo "[WARN] Check $(realpath "$missingConf") for configuration conflicts ($2)" + echo "[WARN] Check $(realpath "$missingConf") for configuration conflicts ($3)" return 1 } @@ -249,7 +271,7 @@ createTemplate() { echo " echo \"Doing something...\"" >> $TEMPLATE_NAME echo "}" >> $TEMPLATE_NAME echo >> $TEMPLATE_NAME - echo "VERSION_SEQREV=2" >> $TEMPLATE_NAME + echo "VERSION_SEQREV=${VERSION_REV}" >> $TEMPLATE_NAME echo ". $0" >> $TEMPLATE_NAME chmod +x $TEMPLATE_NAME @@ -396,7 +418,12 @@ main() { showVersion exit 1 fi - # TODO exclude older versions if needed + # exclude older versions if needed + if [ ! -z $VERSION_SEQREV ] && [ $VERSION_SEQREV -lt 3 ] ; then + echo "[ERROR] Unsupported sequence revision (addConf)" + showVersion + exit 1 + fi if [ -z $VERSION_SEQREV ] ; then echo -e "[WARNING] No sequence revision found. Trying anyway...\n"; fi