From dc25ad7ca22aab15e97d85e5946af1c66ec8e2fa Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sat, 24 Aug 2024 14:39:02 +0200 Subject: [PATCH] =?UTF-8?q?Install/Upgrade:=20am=C3=A9liore=20script,=20ma?= =?UTF-8?q?il=20si=20=C3=A9chec=20(WIP)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/config.sh | 8 ++++---- tools/debian/postinst | 23 ++++++++++++++++------- tools/debian/prerm | 19 +++++++++++++++++++ tools/upgrade.sh | 7 ++++--- tools/utils.sh | 28 ++++++++++++++++++++-------- 5 files changed, 63 insertions(+), 22 deletions(-) create mode 100644 tools/debian/prerm diff --git a/tools/config.sh b/tools/config.sh index 25d95316..038c61b2 100644 --- a/tools/config.sh +++ b/tools/config.sh @@ -4,7 +4,7 @@ debian_version=$(cat /etc/debian_version) debian_version=${debian_version%%.*} die() { - echo + echo echo "Erreur: $1" echo exit 1 @@ -17,8 +17,8 @@ export PATH="${PATH}":/usr/sbin:/sbin umask 0022 export SCODOC_DIR=/opt/scodoc -export SCODOC_VAR_DIR=/opt/scodoc-data - +export SCODOC_VAR_DIR=/opt/scodoc-data +export SCODOC_INSTALL_STATUS_FILE="${SCODOC_VAR_DIR}/.install_status" export SCODOC_VERSION_DIR="${SCODOC_VAR_DIR}/config/version" export SCODOC_LOGOS_DIR="${SCODOC_VAR_DIR}/config/logos" @@ -49,7 +49,7 @@ else fi export PSQL -# tcp port for SQL server +# tcp port for SQL server # Important note: if changed, you should probably also change it in # sco_utils.py (SCO_DEFAULT_SQL_PORT). export POSTGRES_PORT=5432 diff --git a/tools/debian/postinst b/tools/debian/postinst index 9cae57ff..26a550d5 100755 --- a/tools/debian/postinst +++ b/tools/debian/postinst @@ -3,11 +3,17 @@ # Post-installation de scodoc # ici, le répertoire /opt/scodoc vient d'être installé +set -euo pipefail + cd /opt/scodoc || (echo "Error chdir to /opt/scodoc"; exit 1) # On peut donc charger la config: -source /opt/scodoc/tools/config.sh -source /opt/scodoc/tools/utils.sh +source /opt/scodoc/tools/config.sh || (echo "Error loading /opt/scodoc/tools/config.sh"; exit 1) +source /opt/scodoc/tools/utils.sh || (echo "Error loading /opt/scodoc/tools/utils.sh"; exit 1) + +# Enleve fichier de statut d'installation s'il existe +# (la présence de ce fichier indique que l'install s'est bien passée) +remove_install_status # -- Création au besoin de notre utilisateur # adduser --system "${SCODOC_USER}" @@ -26,7 +32,7 @@ do then echo adding $locname echo "$locname ${locname##*.}" >> /etc/locale.gen - /usr/sbin/locale-gen --keep-existing + /usr/sbin/locale-gen --keep-existing fi done echo "debian postinst: scodoc9 systemd service is $(systemctl is-active scodoc9)" @@ -44,7 +50,7 @@ then if [[ ! "${SN}" =~ ^[0-9].* ]] then SN='' # fix for invalid previous replies - fi + fi else # first install echo "mode: install" @@ -56,10 +62,10 @@ CMD="curl --fail --connect-timeout 5 --silent https://scodoc.org/scodoc-installm SVERSION="$(${CMD})" if [ "$?" == 0 ]; then - #echo "answer=${SVERSION}" + #echo "answer=${SVERSION}" echo "${SVERSION}" > "${SCODOC_VERSION_DIR}"/scodoc.sn else - echo 'Warning: cannot connect to scodoc release server' + echo 'Warning: cannot connect to scodoc release server' fi # ------------ LIEN VERS .env @@ -117,7 +123,7 @@ cp "$SCODOC_DIR"/tools/etc/scodoc-logrotate /etc/logrotate.d/scodoc chmod 644 /etc/logrotate.d/scodoc # ------------ CONFIG SERVICE SCODOC -echo +echo echo "Installation du service systemd scodoc9..." cp "$SCODOC_DIR"/tools/etc/scodoc9.service /etc/systemd/system/ systemctl daemon-reload @@ -134,3 +140,6 @@ systemctl enable scodoc9 # --- RESTART SCODOC systemctl restart scodoc9 + +# On est arrivé au bout du post-install ! +create_install_status diff --git a/tools/debian/prerm b/tools/debian/prerm new file mode 100644 index 00000000..eb5957e0 --- /dev/null +++ b/tools/debian/prerm @@ -0,0 +1,19 @@ +#!/bin/bash + +set -euo pipefail + +# Pre-removal script for scodoc +# This script is called by dpkg before removing the package + +cd /opt/scodoc || (echo "Error chdir to /opt/scodoc"; exit 1) + +# On peut donc charger la config: +source /opt/scodoc/tools/config.sh || (echo "Error loading /opt/scodoc/tools/config.sh"; exit 1) +source /opt/scodoc/tools/utils.sh || (echo "Error loading /opt/scodoc/tools/utils.sh"; exit 1) + +check_uid_root + +remove_install_status + + + diff --git a/tools/upgrade.sh b/tools/upgrade.sh index 551ca1a8..93a5de31 100755 --- a/tools/upgrade.sh +++ b/tools/upgrade.sh @@ -1,15 +1,16 @@ #!/bin/bash # Upgrade ScoDoc installation using APT -# +# # This script STOP and RESTART ScoDoc and should be runned as root # # Upgrade also the Linux system using apt. # -# Script for ScoDoc 9 +# Script for ScoDoc 9. Lancé automatiquement par scodoc-updater. # # E. Viennet, sep 2013, mar 2017, jun 2019, aug 2020, dec 2020, aug 21 +set -euo pipefail # Le répertoire de ce script: SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" @@ -29,7 +30,7 @@ if [ -z "$SCODOC_UPGRADE_RUNNING" ] # install spécifiquement scodoc9, utile si les dépendances Debian de scodoc9 # ont été changées, ce qui peut provoquer un # "packages have been kept back" - apt install scodoc9 + apt install scodoc9 || alarm_admin "apt install scodoc9 failed" fi systemctl restart redis systemctl restart nginx diff --git a/tools/utils.sh b/tools/utils.sh index e751501a..a9ca54a4 100644 --- a/tools/utils.sh +++ b/tools/utils.sh @@ -2,12 +2,12 @@ # 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) @@ -15,7 +15,7 @@ norm_ans() { } check_uid_root() { - if [ "$UID" != "0" ] + if [ "$UID" != "0" ] then echo "Erreur: le script $1 doit etre lance par root" exit 1 @@ -24,7 +24,7 @@ check_uid_root() { terminate() { status=${2:-1} # default: exit 1 - echo + echo echo "Erreur: $1" echo exit $status @@ -95,8 +95,8 @@ set_scodoc_var_dir() { } -# XXX inutilise -gen_passwd() { +# XXX inutilise +gen_passwd() { PASSWORD_LENGTH="8" ALLOWABLE_ASCII="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@#$%^&*()_+=-?><" SEED=$(head -c4 /dev/urandom | od -t u4 | awk '{ print $2 }') @@ -110,3 +110,15 @@ gen_passwd() { done echo "$password" } + + +# Status file: indique si l'install s'est complètement déroulée +create_install_status() { + touch "${SCODOC_INSTALL_STATUS_FILE}" || die "can't create ${SCODOC_INSTALL_STATUS_FILE}" +} +remove_install_status() { + if [ -e "${SCODOC_INSTALL_STATUS_FILE}" ] + then + rm -f "${SCODOC_INSTALL_STATUS_FILE}" + fi +}