From f89fa0bf68ea51fc1829a93b46029fe9a0a23e0f Mon Sep 17 00:00:00 2001 From: viennet Date: Sat, 19 Dec 2020 19:22:22 +0100 Subject: [PATCH] WIP - shellchek config scripts --- config/config.sh | 18 ++--- config/configure_systemd.sh | 4 +- config/create_database.sh | 4 +- config/create_dept.sh | 12 +-- config/create_user_db.sh | 12 +-- config/delete_dept.sh | 16 ++-- config/diagnostic.sh | 128 +++++++++++++++---------------- config/distrib.sh | 18 ++--- config/initialize_database.sh | 9 ++- config/install_debian10.sh | 43 +++++------ config/psql_restore_databases.sh | 6 +- config/restore_scodoc_data.sh | 10 +-- config/save_scodoc_data.sh | 9 +-- config/set_passwd.sh | 6 +- config/upgrade.sh | 24 +++--- config/utils.sh | 20 ++--- 16 files changed, 169 insertions(+), 170 deletions(-) diff --git a/config/config.sh b/config/config.sh index 423cd166cb..124d494b4d 100644 --- a/config/config.sh +++ b/config/config.sh @@ -1,4 +1,4 @@ - +#!/bin/bash # Version majeure de Debian (..., 9, 10) debian_version=$(cat /etc/debian_version) debian_version=${debian_version%%.*} @@ -24,28 +24,28 @@ export POSTGRES_SUPERUSER=postgres export POSTGRES_USER=www-data # psql command: if various versions installed, force the one we want: -if [ ${debian_version} = "10" ] +if [ "${debian_version}" = "10" ] then PSQL=/usr/lib/postgresql/11/bin/psql -elif [ ${debian_version} = "9" ] +elif [ "${debian_version}" = "9" ] then PSQL=/usr/lib/postgresql/9.6/bin/psql -elif [ ${debian_version} = "8" ] +elif [ "${debian_version}" = "8" ] then PSQL=/usr/lib/postgresql/9.4/bin/psql -elif [ ${debian_version} = "7" ] +elif [ "${debian_version}" = "7" ] then PSQL=/usr/lib/postgresql/9.1/bin/psql -elif [ ${debian_version} = "5" ] +elif [ "${debian_version}" = "5" ] then PSQL=/usr/lib/postgresql/8.3/bin/psql - elif [ ${debian_version} = "6" ] + elif [ "${debian_version}" = "6" ] then PSQL=/usr/lib/postgresql/8.4/bin/psql else PSQL=/usr/lib/postgresql/8.1/bin/psql fi - +export PSQL # tcp port for SQL server (under Debian 4, 5432 or 5433 for 8.1 if 7.4 also installed !) # Important note: if changed, you should probably also change it in @@ -53,7 +53,7 @@ fi export POSTGRES_PORT=5432 # Utilise par le script de reset du mot de passe: -if [ ${debian_version} -ge "7" ] +if [ "${debian_version}" -ge "7" ] then export ZOPE_VERSION=2.13 else diff --git a/config/configure_systemd.sh b/config/configure_systemd.sh index ed0b0d4f4c..8ad275add5 100755 --- a/config/configure_systemd.sh +++ b/config/configure_systemd.sh @@ -5,10 +5,10 @@ source config.sh source utils.sh -check_uid_root $0 +check_uid_root "$0" echo 'Installation du demarrage automatique de ScoDoc (systemd)' -cp $SCODOC_DIR/config/etc/scodoc.service /etc/systemd/system +cp "$SCODOC_DIR"/config/etc/scodoc.service /etc/systemd/system systemctl enable scodoc.service echo "A partir de maintenant, utiliser" diff --git a/config/create_database.sh b/config/create_database.sh index 3485b2164b..e684f1b4f2 100755 --- a/config/create_database.sh +++ b/config/create_database.sh @@ -11,6 +11,6 @@ source utils.sh echo 'Creating postgresql database' # --- -echo 'Creating postgresql database ' $db_name -createdb -E UTF-8 -p $POSTGRES_PORT -O $POSTGRES_USER $db_name +echo 'Creating postgresql database ' "$db_name" +createdb -E UTF-8 -p "$POSTGRES_PORT" -O "$POSTGRES_USER" "$db_name" diff --git a/config/create_dept.sh b/config/create_dept.sh index 4b39b6283f..4486d0c15f 100755 --- a/config/create_dept.sh +++ b/config/create_dept.sh @@ -13,11 +13,11 @@ source config.sh source utils.sh -check_uid_root $0 +check_uid_root "$0" echo -n "Nom du departement (un mot sans ponctuation, exemple \"Info\"): " -read DEPT +read -r DEPT if [[ ! "$DEPT" =~ ^[A-Za-z0-9]+$ ]] then @@ -31,9 +31,9 @@ export db_name=SCO$(to_upper "$DEPT") cfg_pathname="${SCODOC_VAR_DIR}/config/depts/$DEPT".cfg -if [ -e $cfg_pathname ] +if [ -e "$cfg_pathname" ] then - echo 'Erreur: Il existe deja une configuration pour "'$DEPT'"' + echo 'Erreur: Il existe deja une configuration pour "'"$DEPT"'"' exit 1 fi @@ -48,11 +48,11 @@ su -c ./create_database.sh $POSTGRES_SUPERUSER su -c ./initialize_database.sh $POSTGRES_USER # ----------------------- Enregistre fichier config -echo "dbname="$db_name > $cfg_pathname +echo "dbname=$db_name" > "$cfg_pathname" # ----------------------- Force mise à jour echo -n "Voulez vous mettre a jour ScoDoc (tres recommande) ? (y/n) [y] " -read ans +read -r ans if [ "$(norm_ans "$ans")" != 'N' ] then (cd "$SCODOC_DIR/config"; ./upgrade.sh) diff --git a/config/create_user_db.sh b/config/create_user_db.sh index 8790cd5d6c..1fd84dc10e 100755 --- a/config/create_user_db.sh +++ b/config/create_user_db.sh @@ -4,7 +4,7 @@ # ScoDoc: creation de la base de donnees d'utilisateurs # # Ce script prend en charge la creation de la base de donnees -# et doit être lancé par l'utilisateur unix root dans le repertoire .../config +# et doit �tre lanc� par l'utilisateur unix root dans le repertoire .../config # ^^^^^^^^^^^^^^^^^^^^^ # E. Viennet, Juin 2008 # @@ -12,7 +12,7 @@ source config.sh source utils.sh -check_uid_root $0 +check_uid_root "$0" # --- Ensure postgres user www-data exists init_postgres_user @@ -21,8 +21,8 @@ db_name=SCOUSERS echo 'Creating postgresql database ' $db_name -su -c "createdb -E UTF-8 -O $POSTGRES_USER -p $POSTGRES_PORT $db_name" $POSTGRES_SUPERUSER +su -c "createdb -E UTF-8 -O $POSTGRES_USER -p $POSTGRES_PORT $db_name" "$POSTGRES_SUPERUSER" -echo 'Initializing tables in database ' $db_name -echo su -c "$PSQL -U $POSTGRES_USER -p $POSTGRES_PORT $db_name < $SCODOC_DIR/misc/create_user_table.sql" $POSTGRES_USER -su -c "$PSQL -U $POSTGRES_USER -p $POSTGRES_PORT $db_name < $SCODOC_DIR/misc/create_user_table.sql" $POSTGRES_USER +echo 'Initializing tables in database ' "$db_name" +echo su -c "$PSQL -U $POSTGRES_USER -p $POSTGRES_PORT $db_name < $SCODOC_DIR/misc/create_user_table.sql" "$POSTGRES_USER" +su -c "$PSQL -U $POSTGRES_USER -p $POSTGRES_PORT $db_name < $SCODOC_DIR/misc/create_user_table.sql" "$POSTGRES_USER" diff --git a/config/delete_dept.sh b/config/delete_dept.sh index b0e9919a42..b80b2ddb70 100755 --- a/config/delete_dept.sh +++ b/config/delete_dept.sh @@ -17,7 +17,7 @@ source config.sh source utils.sh -check_uid_root $0 +check_uid_root "$0" echo echo "Ce script supprime la base de donnees ScoDoc d'un departement" @@ -26,7 +26,7 @@ echo "Attention: le departement doit au prealable avoir ete supprime via l'inter echo "faites le AVANT d'executer ce script !!!" echo echo -n "Nom du departement a supprimer (un mot sans ponctuation, exemple \"Info\"): " -read DEPT +read -r DEPT if [[ ! "$DEPT" =~ ^[A-Za-z0-9]+$ ]] then @@ -38,26 +38,26 @@ export DEPT cfg_pathname="${SCODOC_VAR_DIR}/config/depts/$DEPT".cfg -if [ -e $cfg_pathname ] +if [ -e "$cfg_pathname" ] then # arret de ScoDoc scodocctl stop # suppression de la base postgres - db_name=$(cat $cfg_pathname | sed '/^dbname=*/!d; s///;q') + db_name=$(sed '/^dbname=*/!d; s///;q' < "$cfg_pathname") echo "suppression de la base postgres $db_name" - su -c "dropdb $db_name" $POSTGRES_SUPERUSER || terminate "ne peux supprimer base de donnees $db_name" + su -c "dropdb $db_name" "$POSTGRES_SUPERUSER" || terminate "ne peux supprimer base de donnees $db_name" # suppression du fichier de config - /bin/rm -f $cfg_pathname || terminate "ne peux supprimer $cfg_pathname" + /bin/rm -f "$cfg_pathname" || terminate "ne peux supprimer $cfg_pathname" # relance ScoDoc echo -n "Demarrer le serveur ScoDoc ? (y/n) [n]" - read ans + read -r ans if [ "$(norm_ans "$ans")" = 'Y' ] then scodocctl start fi exit 0 else - echo 'Erreur: pas de configuration trouvee pour "'$DEPT'"' + echo 'Erreur: pas de configuration trouvee pour "'"$DEPT"'"' exit 1 fi diff --git a/config/diagnostic.sh b/config/diagnostic.sh index fc0fb959dd..2e4b28ae93 100755 --- a/config/diagnostic.sh +++ b/config/diagnostic.sh @@ -6,7 +6,7 @@ # Avec option: # -a : sauve aussi les bases de données # -DEST_ADDRESS=emmanuel.viennet@univ-paris13.fr +DEST_ADDRESS=emmanuel.viennet@gmail.com INSTANCE_DIR=/opt/scodoc @@ -36,7 +36,7 @@ while getopts ":d:aunh" opt; do SEND_BY_MAIL=0 ;; d) - DEPTS_TO_SAVE=$( join_by ' ' $DEPTS_TO_SAVE $OPTARG ) + DEPTS_TO_SAVE=$( join_by ' ' "$DEPTS_TO_SAVE" "$OPTARG" ) ;; h) echo "Diagnostic installation ScoDoc" @@ -71,7 +71,7 @@ then apt-get install sharutils fi -mkdir $TMP +mkdir "$TMP" # Files to copy: FILES="/etc/hosts /etc/debian_version /etc/apt /etc/apache2" @@ -91,33 +91,33 @@ echo "left in ${TMP}" # ------------------------------------- copy_log() { - if [ -e $1 ] + if [ -e "$1" ] then - cp $1 $TMP/scodoc_logs/ + cp "$1" "$TMP"/scodoc_logs/ fi } -mkdir $TMP/scodoc_logs/ -copy_log /opt/scodoc/instance/log/event.log -copy_log /opt/scodoc/instance/log/event.log.1 -copy_log /opt/scodoc/instance/log/notes.log -copy_log /opt/scodoc/instance/log/notes.log.1 +mkdir "$TMP"/scodoc_logs/ +copy_log /opt/scodoc/log/event.log +copy_log /opt/scodoc/log/event.log.1 +copy_log /opt/scodoc/log/notes.log +copy_log /opt/scodoc/log/notes.log.1 # ------------------------------------- # Linux System Configuration # ------------------------------------- -iptables -L > $TMP/iptables.out -ip a > $TMP/ifconfig.out -ps auxww > $TMP/ps.out -df -h > $TMP/df.out -dpkg -l > $TMP/dpkg.lst +iptables -L > "$TMP"/iptables.out +ip a > "$TMP"/ifconfig.out +ps auxww > "$TMP"/ps.out +df -h > "$TMP"/df.out +dpkg -l > "$TMP"/dpkg.lst -(cd /opt/scodoc/instance/Products/ScoDoc; svn status > $TMP/svn.status) -(cd /opt/scodoc/instance/Products/ScoDoc; svn diff > $TMP/svn.diff) +(cd /opt/scodoc/Products/ScoDoc; svn status > "$TMP"/svn.status) +(cd /opt/scodoc/Products/ScoDoc; svn diff > "$TMP"/svn.diff) -(cd /opt/scodoc/instance/Products/ScoDoc; svnversion > $TMP/svn.version) -ls -laR /opt/scodoc/instance/Products/ScoDoc > $TMP/ls-laR +(cd /opt/scodoc/Products/ScoDoc; svnversion > "$TMP"/svn.version) +ls -laR /opt/scodoc/Products/ScoDoc > "$TMP"/ls-laR # ------------------------------------- @@ -126,7 +126,7 @@ ls -laR /opt/scodoc/instance/Products/ScoDoc > $TMP/ls-laR (su postgres -c "psql -l") > "${TMP}/psql-l.out" for dept in "${INSTANCE_DIR}"/var/scodoc/config/depts/*.cfg do - cnx=$(cat $dept) + cnx=$(cat "$dept") (su postgres -c "echo '\dt' | psql -d $cnx") > "${TMP}/psql-$(basename ${dept%%.*}).out" done @@ -137,14 +137,14 @@ done # copy files: for f in $FILES do - cp -R $f $TMP + cp -R "$f" "$TMP" done # ------------------------------------- # Optionally save dept(s) database(s) # ------------------------------------- -DEPTS_TO_SAVE=$(echo ${DEPTS_TO_SAVE} | tr ' ' '\n' | sort | uniq) +DEPTS_TO_SAVE=$(echo "${DEPTS_TO_SAVE}" | tr ' ' '\n' | sort | uniq) # Dump database of a dept (eg "RT") function dump_dept_db { @@ -176,10 +176,10 @@ fi # Archive all stuff to /tmp # ------------------------------------- -tar cfz $TMP.tgz $TMP +tar cfz "$TMP".tgz "$TMP" echo -echo "Fichier de diagnostic: $TMP.tgz" +echo "Fichier de diagnostic: "$TMP".tgz" echo # If no mail, stop here @@ -197,9 +197,9 @@ fi #requires: basename,date,md5sum,sed,sendmail,uuencode function fappend { - echo "$2">>$1; + echo "$2">>"$1"; } -YYYYMMDD=`date +%Y%m%d` +YYYYMMDD=$(date +%Y%m%d) # CHANGE THESE TOEMAIL=$DEST_ADDRESS @@ -212,45 +212,45 @@ MIMETYPE="application/gnutar" #if not sure, use http://www.webmaster-toolkit.com # DON'T CHANGE ANYTHING BELOW TMP="/tmp/tmpfil_123"$RANDOM; -BOUNDARY=`date +%s|md5sum` +BOUNDARY=$(date +%s|md5sum) BOUNDARY=${BOUNDARY:0:32} -FILENAME=`basename $ATTACHMENT` +FILENAME=$(basename "$ATTACHMENT") -rm -rf $TMP; -cat $ATTACHMENT|uuencode --base64 $FILENAME>$TMP; -sed -i -e '1,1d' -e '$d' $TMP;#removes first & last lines from $TMP -DATA=`cat $TMP` +rm -rf "$TMP" +uuencode --base64 "$FILENAME" < "$ATTACHMENT" >"$TMP" +sed -i -e '1,1d' -e '$d' "$TMP"; #removes first & last lines from "$TMP" +DATA=$(cat "$TMP") -rm -rf $TMP; -fappend $TMP "From: $FREMAIL"; -fappend $TMP "To: $TOEMAIL"; -fappend $TMP "Reply-To: $FREMAIL"; -fappend $TMP "Subject: $SUBJECT"; -fappend $TMP "Content-Type: multipart/mixed; boundary=\""$BOUNDARY"\""; -fappend $TMP ""; -fappend $TMP "This is a MIME formatted message. If you see this text it means that your"; -fappend $TMP "email software does not support MIME formatted messages."; -fappend $TMP ""; -fappend $TMP "--$BOUNDARY"; -fappend $TMP "Content-Type: text/plain; charset=ISO-8859-1; format=flowed"; -fappend $TMP "Content-Transfer-Encoding: 7bit"; -fappend $TMP "Content-Disposition: inline"; -fappend $TMP ""; -fappend $TMP "$MSGBODY"; -fappend $TMP ""; -fappend $TMP ""; -fappend $TMP "--$BOUNDARY"; -fappend $TMP "Content-Type: $MIMETYPE; name=\"$FILENAME\""; -fappend $TMP "Content-Transfer-Encoding: base64"; -fappend $TMP "Content-Disposition: attachment; filename=\"$FILENAME\";"; -fappend $TMP ""; -fappend $TMP "$DATA"; -fappend $TMP ""; -fappend $TMP ""; -fappend $TMP "--$BOUNDARY--"; -fappend $TMP ""; -fappend $TMP ""; -#cat $TMP>out.txt -cat $TMP|sendmail -t -f none@example.com; -rm $TMP; +rm -rf "$TMP"; +fappend "$TMP" "From: $FREMAIL"; +fappend "$TMP" "To: $TOEMAIL"; +fappend "$TMP" "Reply-To: $FREMAIL"; +fappend "$TMP" "Subject: $SUBJECT"; +fappend "$TMP" "Content-Type: multipart/mixed; boundary=\""$BOUNDARY"\""; +fappend "$TMP" ""; +fappend "$TMP" "This is a MIME formatted message. If you see this text it means that your"; +fappend "$TMP" "email software does not support MIME formatted messages."; +fappend "$TMP" ""; +fappend "$TMP" "--$BOUNDARY"; +fappend "$TMP" "Content-Type: text/plain; charset=ISO-8859-1; format=flowed"; +fappend "$TMP" "Content-Transfer-Encoding: 7bit"; +fappend "$TMP" "Content-Disposition: inline"; +fappend "$TMP" ""; +fappend "$TMP" "$MSGBODY"; +fappend "$TMP" ""; +fappend "$TMP" ""; +fappend "$TMP" "--$BOUNDARY"; +fappend "$TMP" "Content-Type: $MIMETYPE; name=\"$FILENAME\""; +fappend "$TMP" "Content-Transfer-Encoding: base64"; +fappend "$TMP" "Content-Disposition: attachment; filename=\"$FILENAME\";"; +fappend "$TMP" ""; +fappend "$TMP" "$DATA"; +fappend "$TMP" ""; +fappend "$TMP" ""; +fappend "$TMP" "--$BOUNDARY--"; +fappend "$TMP" ""; +fappend "$TMP" ""; +#cat "$TMP">out.txt +cat "$TMP"|sendmail -t -f none@example.com; +rm "$TMP"; diff --git a/config/distrib.sh b/config/distrib.sh index 9ffead11c1..7a29157a25 100644 --- a/config/distrib.sh +++ b/config/distrib.sh @@ -15,15 +15,15 @@ then fi -echo "Changing to directory " $SCODOC_DIR/config -cd $SCODOC_DIR/config +echo "Changing to directory " "$SCODOC_DIR"/config +cd "$SCODOC_DIR"/config || { echo "directory does not exist"; exit 1; } echo "Stopping ScoDoc..." scodocctl stop # DROITS echo -n "Verification des droits: proprietaire www-data ? (y/n) [y] " -read ans +read -r ans if [ "$(norm_ans "$ans")" != 'N' ] then echo 'changing owner to www-data' @@ -31,7 +31,7 @@ then fi echo -n 'Suppression des backups des sources (*~) ? (y/n) [y] ' -read ans +read -r ans if [ "$(norm_ans "$ans")" != 'N' ] then /bin/rm -f ../*~ ../*/*~ @@ -40,7 +40,7 @@ fi # SVN echo -n "svn update ? (y/n) [y] " -read ans +read -r ans if [ "$(norm_ans "$ans")" != 'N' ] then echo 'Updating from SVN...' @@ -50,7 +50,7 @@ fi # DEPARTEMENTS (maintenant inutile car dans /var) echo -n "Supprimer les (anciennes) configs de departements ? (y/n) [y] " -read ans +read -r ans if [ "$(norm_ans "$ans")" != 'N' ] then echo "moving " depts/*.cfg "to /tmp" @@ -59,7 +59,7 @@ fi # .../var/ echo -n "Supprimer et recréer .../var (archives, photos, configs, ...) ? (y/n) [y] " -read ans +read -r ans if [ "$(norm_ans "$ans")" != 'N' ] then echo "moving ../../../var/scodoc to /tmp" @@ -73,7 +73,7 @@ fi # LOGS ZOPE echo -n "Effacer les logs de Zope et ScoDoc ? (y/n) [y] " -read ans +read -r ans if [ "$(norm_ans "$ans")" != 'N' ] then (cd ../../../log/; ./purge) @@ -81,7 +81,7 @@ fi # IMAGE Data.fs echo -n "Recopier le Data.fs original ? (y/n) [y] " -read ans +read -r ans if [ "$(norm_ans "$ans")" != 'N' ] then echo "moving Data.fs to /tmp" diff --git a/config/initialize_database.sh b/config/initialize_database.sh index d57849a01b..9b81c7cdd0 100755 --- a/config/initialize_database.sh +++ b/config/initialize_database.sh @@ -8,15 +8,16 @@ source config.sh source utils.sh -if [ $(id -nu) != $POSTGRES_USER ] +if [ "$(id -nu)" != "$POSTGRES_USER" ] then echo "$0: script must be runned as user $POSTGRES_USER" exit 1 fi -echo 'Initializing tables in database ' $db_name -$PSQL -U $POSTGRES_USER -p $POSTGRES_PORT $db_name -f $SCODOC_DIR/misc/createtables.sql +# shellcheck disable=SC2154 +echo 'Initializing tables in database ' "$db_name" +$PSQL -U "$POSTGRES_USER" -p "$POSTGRES_PORT" "$db_name" -f "$SCODOC_DIR"/misc/createtables.sql # Set DeptName in preferences: -echo "insert into sco_prefs (name, value) values ('DeptName', '"${DEPT}\'\) | $PSQL -U $POSTGRES_USER -p $POSTGRES_PORT $db_name \ No newline at end of file +echo "insert into sco_prefs (name, value) values ('DeptName', '"${DEPT}\'\) | $PSQL -U "$POSTGRES_USER" -p "$POSTGRES_PORT" "$db_name" \ No newline at end of file diff --git a/config/install_debian10.sh b/config/install_debian10.sh index 9195c4f648..6ef8406cce 100755 --- a/config/install_debian10.sh +++ b/config/install_debian10.sh @@ -13,16 +13,14 @@ source utils.sh check_uid_root $0 -PYTHON=/opt/zope213/bin/python - # ------------ Safety checks -if [ ${debian_version} != "10" ] +if [ "${debian_version}" != "10" ] then echo "Version du systeme Linux Debian incompatible" exit 1 fi -if [ $(arch) != "x86_64" ] +if [ "$(arch)" != "x86_64" ] then echo "Version du systeme Linux Debian incompatible (pas X86 64 bits)" exit 1 @@ -30,8 +28,8 @@ fi # ------------ Permissions & directories # source dir should be writable by scodoc to write bytecode files -chgrp www-data $SCODOC_DIR $SCODOC_DIR/ZopeProducts/* -chmod g+w $SCODOC_DIR $SCODOC_DIR/ZopeProducts/* +chgrp www-data "$SCODOC_DIR" "$SCODOC_DIR"/ZopeProducts/* +chmod g+w "$SCODOC_DIR" "$SCODOC_DIR"/ZopeProducts/* chgrp -R www-data "${SCODOC_VAR_DIR}"/photos chmod -R g+w "${SCODOC_VAR_DIR}"/photos @@ -54,8 +52,8 @@ fi for locname in en_US.UTF-8 en_US.ISO-8859-15 en_US.ISO-8859-1 do - outname=$(echo ${locname//-/} | tr '[A-Z]' '[a-z]') - if [ $(locale -a | egrep -i ^${outname}$ | wc -l) -lt 1 ] + outname=$(echo ${locname//-/} | tr 'A-Z' 'a-z') + if [ "$(locale -a | grep -E -i ^${outname}$ | wc -l)" -lt 1 ] then echo adding $locname echo "$locname ${locname##*.}" >> /etc/locale.gen @@ -87,7 +85,7 @@ apt-get -y install postgresql apt-get -y install graphviz # ------------ INSTALL DES EXTENSIONS PYTHON (2.7) - +# XXX to fix: pip in our env apt-get -y install python-docutils apt-get -y install python-jaxml apt-get -y install python-psycopg2 @@ -97,20 +95,21 @@ apt-get -y install python-cracklib # was python-crack apt-get -y install python-icalendar apt-get -y install python-requests +# XXX to fix: mx not needed anymore ! apt-get -y install python-egenix-mxtools python-egenix-mxdatetime # ------------ SVNVERSION=$(cd ..; svnversion) -SVERSION=$(curl --silent http://scodoc.iutv.univ-paris13.fr/scodoc-installmgr/version?mode=install\&svn=$SVNVERSION) -echo $SVERSION > "${SCODOC_VERSION_DIR}/scodoc.sn" +SVERSION=$(curl --silent http://scodoc.iutv.univ-paris13.fr/scodoc-installmgr/version?mode=install\&svn="$SVNVERSION") +echo "$SVERSION" > "${SCODOC_VERSION_DIR}/scodoc.sn" # ------------ POSTFIX echo echo "ScoDoc a besoin de pouvoir envoyer des messages par mail." echo -n "Voulez vous configurer la messagerie (tres recommande) ? (y/n) [y] " -read ans +read -r ans if [ "$(norm_ans "$ans")" != 'N' ] then apt-get -y install postfix @@ -120,7 +119,7 @@ fi echo echo "Le firewall aide a proteger votre serveur d'intrusions indesirables." echo -n "Voulez vous configurer un firewall minimal (ufw) ? (y/n) [n] " -read ans +read -r ans if [ "$(norm_ans "$ans")" = 'Y' ] then echo 'Installation du firewall IP ufw (voir documentation Debian)' @@ -145,16 +144,16 @@ a2enmod rewrite echo echo "La configuration du serveur web va modifier votre installation Apache pour supporter ScoDoc." echo -n "Voulez vous configurer le serveur web Apache maintenant (tres conseille) ? (y/n) [y] " -read ans +read -r ans if [ "$(norm_ans "$ans")" != 'N' ] then echo "Configuration d'Apache" server_name="" - while [ -z $server_name ] + while [ -z "$server_name" ] do echo "Le nom de votre serveur doit normalement etre connu dans le DNS." echo -n "Nom complet de votre serveur (exemple: notes.univ.fr): " - read server_name + read -r server_name done # --- CERTIFICATS AUTO-SIGNES echo @@ -162,7 +161,7 @@ then echo "auto-signes, qui ne seront pas reconnus comme de confiance" echo "par les navigateurs, mais offrent une certaine securite." echo -n 'Voulez vous generer des certificats ssl auto-signes ? (y/n) [y] ' - read ans + read -r ans if [ "$(norm_ans "$ans")" != 'N' ] then # attention: utilise dans scodoc-site-ssl.orig @@ -178,7 +177,7 @@ then fi # --- echo 'generation de /etc/apache2/sites-available/scodoc-site-ssl' - cat $SCODOC_DIR/config/etc/scodoc-site-ssl-apache2.4.orig | sed -e "s:YOUR\.FULL\.HOST\.NAME:$server_name:g" > /etc/apache2/sites-available/scodoc-site-ssl.conf + cat "$SCODOC_DIR"/config/etc/scodoc-site-ssl-apache2.4.orig | sed -e "s:YOUR\.FULL\.HOST\.NAME:$server_name:g" > /etc/apache2/sites-available/scodoc-site-ssl.conf echo 'activation du site...' a2ensite scodoc-site-ssl @@ -188,7 +187,7 @@ then then mv $fn $fn.bak fi - cp $SCODOC_DIR/config/etc/scodoc-site.orig $fn + cp "$SCODOC_DIR"/config/etc/scodoc-site.orig $fn if [ -z "$(grep Listen /etc/apache2/ports.conf | grep 443)" ] then @@ -222,7 +221,7 @@ if [ "$(norm_ans "$ans")" != 'N' ] then # ScoDoc 7.19+ uses systemd echo 'Installation du demarrage automatique de ScoDoc (systemd)' - cp $SCODOC_DIR/config/etc/scodoc.service /etc/systemd/system + cp "$SCODOC_DIR"/config/etc/scodoc.service /etc/systemd/system systemctl enable scodoc.service fi @@ -233,8 +232,8 @@ echo -n "Mises a jour hebdomadaires (tres recommande) ? (y/n) [y] " read ans if [ "$(norm_ans "$ans")" != 'N' ] then - cp $SCODOC_DIR/config/etc/scodoc-updater.service /etc/systemd/system - cp $SCODOC_DIR/config/etc/scodoc-updater.timer /etc/systemd/system + cp "$SCODOC_DIR"/config/etc/scodoc-updater.service /etc/systemd/system + cp "$SCODOC_DIR"/config/etc/scodoc-updater.timer /etc/systemd/system systemctl enable scodoc-updater.timer systemctl start scodoc-updater.timer fi diff --git a/config/psql_restore_databases.sh b/config/psql_restore_databases.sh index 9eb260a539..e18f595017 100755 --- a/config/psql_restore_databases.sh +++ b/config/psql_restore_databases.sh @@ -8,7 +8,7 @@ PG_DUMPFILE=$1 # Check locale of installation. If invalid, reinitialize all system is_latin1=$(psql -l | grep postgres | grep iso88591 | wc -l) -if [ $is_latin1 -gt 1 ] +if [ "$is_latin1" -gt 1 ] then echo "Recreating postgres cluster using UTF-8" @@ -20,8 +20,8 @@ fi # Drop all current ScoDoc databases, if any: for f in $(psql -l --no-align --field-separator . | grep SCO | cut -f 1 -d.); do - echo dropping $f - dropdb $f + echo dropping "$f" + dropdb "$f" done echo "Restoring postgres data..." psql -f "$PG_DUMPFILE" postgres diff --git a/config/restore_scodoc_data.sh b/config/restore_scodoc_data.sh index f2bd87858d..9cd2df28b2 100755 --- a/config/restore_scodoc_data.sh +++ b/config/restore_scodoc_data.sh @@ -15,7 +15,7 @@ SCODOC_DIR="${INSTANCE_DIR}/Products/ScoDoc" SCODOC_VAR_DIR="${INSTANCE_DIR}/var/scodoc" source utils.sh -check_uid_root $0 +check_uid_root "$0" # Safety check echo "Ce script va remplacer les donnees de votre installation ScoDoc par celles" @@ -28,7 +28,7 @@ echo echo "TOUTES LES BASES POSTGRESQL SERONT EFFACEES !!!" echo echo -n "Voulez vous poursuivre cette operation ? (y/n) [n]" -read ans +read -r ans if [ ! "$(norm_ans "$ans")" = 'Y' ] then echo "Annulation" @@ -57,7 +57,7 @@ then echo "Opening tgz archive..." tmp=$(mktemp -d) chmod a+rx "$tmp" - cd "$tmp" + cd "$tmp" || { echo "Fatal error: directory not available"; exit 1; } tar xfz "$SRC" SRC=$(ls -1d "$tmp"/*) IS_TMP=1 @@ -132,11 +132,11 @@ chmod -R 775 "$SCODOC_DIR" # Remove tmp directory if [ $IS_TMP = "1" ] then - rm -rf $tmp + rm -rf "$tmp" fi # Mise a jour BD ScoDoc -cd $SCODOC_DIR/config +cd "$SCODOC_DIR"/config || { echo "Fatal error: invalid directory"; exit 2; } ./upgrade.sh # diff --git a/config/save_scodoc_data.sh b/config/save_scodoc_data.sh index a53c764034..65985afd65 100755 --- a/config/save_scodoc_data.sh +++ b/config/save_scodoc_data.sh @@ -10,6 +10,8 @@ # source utils.sh +check_uid_root "$0" + # Destination directory if [ ! $# -eq 1 ] then @@ -34,9 +36,6 @@ fi INSTANCE_DIR=/opt/scodoc SCODOC_DIR="$INSTANCE_DIR/Products/ScoDoc" -source utils.sh -check_uid_root $0 - echo "Stopping ScoDoc..." scodocctl stop @@ -46,7 +45,7 @@ chown postgres "$DEST" su -c "pg_dumpall > \"$DEST\"/scodoc.dump.txt" postgres if [ ! $? -eq 0 ] then - echo "Error dumping postgresql database\nPlease check that SQL server is running\nAborting." + printf "Error dumping postgresql database\nPlease check that SQL server is running\nAborting.\n" exit 1 fi chown root "$DEST" @@ -57,7 +56,7 @@ cp -rp "$INSTANCE_DIR/var" "$DEST" # Depts db config (now in .../var) shopt -s nullglob -if [ ! -z "$(echo ${SCODOC_DIR}/config/depts/*.cfg)" ] +if [ -n "$(echo ${SCODOC_DIR}/config/depts/*.cfg)" ] then echo "Copying legacy depts configs..." cp -rp "$SCODOC_DIR/config/depts" "$DEST" diff --git a/config/set_passwd.sh b/config/set_passwd.sh index 2d024c3a8e..68a63db6ff 100755 --- a/config/set_passwd.sh +++ b/config/set_passwd.sh @@ -4,7 +4,7 @@ # ScoDoc: reglage du mot de passe admin Zope # (in Zope terminology, an emergency user) # -# Doit être lancé par l'utilisateur unix root dans le repertoire .../config +# Doit �tre lanc� par l'utilisateur unix root dans le repertoire .../config # ^^^^^^^^^^^^^^^^^^^^^ # E. Viennet, Juin 2008, Jul 2019 # @@ -22,14 +22,14 @@ fi echo "Creation d'un utilisateur d'urgence pour ScoDoc" echo "(utile en cas de perte de votre mot de passe admin)" -if [ ${debian_version} != "10" ] +if [ "${debian_version}" != "10" ] then mdir=/opt/zope213/lib/python2.7/site-packages/Zope2-2.13.21-py2.7.egg/Zope2/utilities else mdir=/opt/zope213/lib/python2.7/site-packages/Zope2/utilities fi -python $mdir/zpasswd.py $SCODOC_DIR/../../access +python $mdir/zpasswd.py "$SCODOC_DIR"/../../access echo echo "redemarrer scodoc pour prendre en compte le mot de passe" diff --git a/config/upgrade.sh b/config/upgrade.sh index 3bec0947ae..578f9d2112 100755 --- a/config/upgrade.sh +++ b/config/upgrade.sh @@ -1,20 +1,20 @@ #!/bin/bash -# Upgrade ScoDoc installation using SVN -# SVN must be properly configured and have read access to ScoDoc repository +# Upgrade ScoDoc installation using GIT +# GIT must be properly configured and have read access to ScoDoc repository # This script STOP and RESTART ScoDoc and should be runned as root # # Upgrade also the Linux system using apt. # -# Script for ScoDoc 7 (Debian 7, 8, 9, 10) +# Script for ScoDoc 8 (10) # -# E. Viennet, sep 2013, mar 2017, jun 2019, aug 2020 +# E. Viennet, sep 2013, mar 2017, jun 2019, aug 2020, dec 2020 -cd /opt/scodoc/Products/ScoDoc/config +cd /opt/scodoc/Products/ScoDoc/config || { echo "Invalid directory"; exit 1; } source config.sh source utils.sh -check_uid_root $0 +check_uid_root "$0" if [ -z "$SCODOC_UPGRADE_RUNNING" ] then @@ -31,8 +31,8 @@ fi scodocctl stop echo -echo "Using SVN to update $SCODOC_DIR..." -(cd "$SCODOC_DIR"; svn update) +echo "Using git to update $SCODOC_DIR..." +(cd "$SCODOC_DIR"; git checkout ScoDoc8; git pull origin master) SVNVERSION=$(cd ..; svnversion) @@ -72,13 +72,13 @@ fi # Check that no Zope "access" file has been forgotten in the way: -if [ -e $SCODOC_DIR/../../access ] +if [ -e "$SCODOC_DIR"/../../access ] then - mv $SCODOC_DIR/../../access $SCODOC_DIR/../../access.bak + mv "$SCODOC_DIR"/../../access "$SCODOC_DIR"/../../access.bak fi # Fix some permissions which may have been altered in the way: -chsh -s /bin/sh $POSTGRES_USER # www-data, nologin in Debian 9 +chsh -s /bin/sh "$POSTGRES_USER" # www-data, nologin in Debian 9 chown root.www-data "$SCODOC_DIR" # important to create .pyc chmod 775 "${SCODOC_DIR}" chmod a+r "$SCODOC_DIR"/*.py @@ -141,7 +141,7 @@ echo "Executing post-upgrade script..." "$SCODOC_DIR"/config/postupgrade.py echo "Executing post-upgrade database script..." -su -c "$SCODOC_DIR/config/postupgrade-db.py" $POSTGRES_USER +su -c "$SCODOC_DIR/config/postupgrade-db.py" "$POSTGRES_USER" # echo diff --git a/config/utils.sh b/config/utils.sh index 4508303b61..d8be48d446 100644 --- a/config/utils.sh +++ b/config/utils.sh @@ -1,17 +1,17 @@ - +#!/bin/bash # Misc utilities for ScoDoc install shell scripts to_lower() { - echo $1 | tr "[:upper:]" "[:lower:]" + echo "$1" | tr "[:upper:]" "[:lower:]" } to_upper() { - echo $1 | tr "[:lower:]" "[:upper:]" + echo "$1" | tr "[:lower:]" "[:upper:]" } norm_ans() { - x=$(to_upper $1 | tr O Y) - echo ${x:0:1} + x=$(to_upper "$1" | tr O Y) + echo "${x:0:1}" } check_uid_root() { @@ -44,7 +44,7 @@ scodocctl() { systemctl $1 scodoc else echo "(using legacy SystemV)" - /etc/init.d/scodoc $1 + /etc/init.d/scodoc "$1" fi } @@ -54,7 +54,7 @@ init_postgres_user() { # run as root then # add database user echo "Creating postgresql user $POSTGRES_USER" - su -c "createuser -p $POSTGRES_PORT --no-superuser --no-createdb --no-adduser --no-createrole ${POSTGRES_USER}" $POSTGRES_SUPERUSER + su -c "createuser -p $POSTGRES_PORT --no-superuser --no-createdb --no-adduser --no-createrole ${POSTGRES_USER}" "$POSTGRES_SUPERUSER" fi } @@ -69,8 +69,8 @@ gen_passwd() { password="" while [ "$n" -le "$PASSWORD_LENGTH" ] do - password="$password${ALLOWABLE_ASCII:$(($RANDOM%${#ALLOWABLE_ASCII})):1}" - n=$((n+1)) + password="$password${ALLOWABLE_ASCII:$((RANDOM%${#ALLOWABLE_ASCII})):1}" + n=$((n+1)) done - echo $password + echo "$password" }