1
0
forked from ScoDoc/ScoDoc

Install/Upgrade: améliore script, mail si échec (WIP)

This commit is contained in:
Emmanuel Viennet 2024-08-24 14:39:02 +02:00
parent f059073bfc
commit dc25ad7ca2
5 changed files with 63 additions and 22 deletions

View File

@ -4,7 +4,7 @@ debian_version=$(cat /etc/debian_version)
debian_version=${debian_version%%.*} debian_version=${debian_version%%.*}
die() { die() {
echo echo
echo "Erreur: $1" echo "Erreur: $1"
echo echo
exit 1 exit 1
@ -17,8 +17,8 @@ export PATH="${PATH}":/usr/sbin:/sbin
umask 0022 umask 0022
export SCODOC_DIR=/opt/scodoc 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_VERSION_DIR="${SCODOC_VAR_DIR}/config/version"
export SCODOC_LOGOS_DIR="${SCODOC_VAR_DIR}/config/logos" export SCODOC_LOGOS_DIR="${SCODOC_VAR_DIR}/config/logos"
@ -49,7 +49,7 @@ else
fi fi
export PSQL export PSQL
# tcp port for SQL server # tcp port for SQL server
# Important note: if changed, you should probably also change it in # Important note: if changed, you should probably also change it in
# sco_utils.py (SCO_DEFAULT_SQL_PORT). # sco_utils.py (SCO_DEFAULT_SQL_PORT).
export POSTGRES_PORT=5432 export POSTGRES_PORT=5432

View File

@ -3,11 +3,17 @@
# Post-installation de scodoc # Post-installation de scodoc
# ici, le répertoire /opt/scodoc vient d'être installé # ici, le répertoire /opt/scodoc vient d'être installé
set -euo pipefail
cd /opt/scodoc || (echo "Error chdir to /opt/scodoc"; exit 1) cd /opt/scodoc || (echo "Error chdir to /opt/scodoc"; exit 1)
# On peut donc charger la config: # On peut donc charger la config:
source /opt/scodoc/tools/config.sh source /opt/scodoc/tools/config.sh || (echo "Error loading /opt/scodoc/tools/config.sh"; exit 1)
source /opt/scodoc/tools/utils.sh 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 # -- Création au besoin de notre utilisateur
# adduser --system "${SCODOC_USER}" # adduser --system "${SCODOC_USER}"
@ -26,7 +32,7 @@ do
then then
echo adding $locname echo adding $locname
echo "$locname ${locname##*.}" >> /etc/locale.gen echo "$locname ${locname##*.}" >> /etc/locale.gen
/usr/sbin/locale-gen --keep-existing /usr/sbin/locale-gen --keep-existing
fi fi
done done
echo "debian postinst: scodoc9 systemd service is $(systemctl is-active scodoc9)" echo "debian postinst: scodoc9 systemd service is $(systemctl is-active scodoc9)"
@ -44,7 +50,7 @@ then
if [[ ! "${SN}" =~ ^[0-9].* ]] if [[ ! "${SN}" =~ ^[0-9].* ]]
then then
SN='' # fix for invalid previous replies SN='' # fix for invalid previous replies
fi fi
else else
# first install # first install
echo "mode: install" echo "mode: install"
@ -56,10 +62,10 @@ CMD="curl --fail --connect-timeout 5 --silent https://scodoc.org/scodoc-installm
SVERSION="$(${CMD})" SVERSION="$(${CMD})"
if [ "$?" == 0 ]; then if [ "$?" == 0 ]; then
#echo "answer=${SVERSION}" #echo "answer=${SVERSION}"
echo "${SVERSION}" > "${SCODOC_VERSION_DIR}"/scodoc.sn echo "${SVERSION}" > "${SCODOC_VERSION_DIR}"/scodoc.sn
else else
echo 'Warning: cannot connect to scodoc release server' echo 'Warning: cannot connect to scodoc release server'
fi fi
# ------------ LIEN VERS .env # ------------ LIEN VERS .env
@ -117,7 +123,7 @@ cp "$SCODOC_DIR"/tools/etc/scodoc-logrotate /etc/logrotate.d/scodoc
chmod 644 /etc/logrotate.d/scodoc chmod 644 /etc/logrotate.d/scodoc
# ------------ CONFIG SERVICE SCODOC # ------------ CONFIG SERVICE SCODOC
echo echo
echo "Installation du service systemd scodoc9..." echo "Installation du service systemd scodoc9..."
cp "$SCODOC_DIR"/tools/etc/scodoc9.service /etc/systemd/system/ cp "$SCODOC_DIR"/tools/etc/scodoc9.service /etc/systemd/system/
systemctl daemon-reload systemctl daemon-reload
@ -134,3 +140,6 @@ systemctl enable scodoc9
# --- RESTART SCODOC # --- RESTART SCODOC
systemctl restart scodoc9 systemctl restart scodoc9
# On est arrivé au bout du post-install !
create_install_status

19
tools/debian/prerm Normal file
View File

@ -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

View File

@ -1,15 +1,16 @@
#!/bin/bash #!/bin/bash
# Upgrade ScoDoc installation using APT # Upgrade ScoDoc installation using APT
# #
# This script STOP and RESTART ScoDoc and should be runned as root # This script STOP and RESTART ScoDoc and should be runned as root
# #
# Upgrade also the Linux system using apt. # 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 # E. Viennet, sep 2013, mar 2017, jun 2019, aug 2020, dec 2020, aug 21
set -euo pipefail
# Le répertoire de ce script: # Le répertoire de ce script:
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" 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 # install spécifiquement scodoc9, utile si les dépendances Debian de scodoc9
# ont été changées, ce qui peut provoquer un # ont été changées, ce qui peut provoquer un
# "packages have been kept back" # "packages have been kept back"
apt install scodoc9 apt install scodoc9 || alarm_admin "apt install scodoc9 failed"
fi fi
systemctl restart redis systemctl restart redis
systemctl restart nginx systemctl restart nginx

View File

@ -2,12 +2,12 @@
# Misc utilities for ScoDoc install shell scripts # Misc utilities for ScoDoc install shell scripts
to_lower() { to_lower() {
echo "$1" | tr "[:upper:]" "[:lower:]" echo "$1" | tr "[:upper:]" "[:lower:]"
} }
to_upper() { to_upper() {
echo "$1" | tr "[:lower:]" "[:upper:]" echo "$1" | tr "[:lower:]" "[:upper:]"
} }
norm_ans() { norm_ans() {
x=$(to_upper "$1" | tr O Y) x=$(to_upper "$1" | tr O Y)
@ -15,7 +15,7 @@ norm_ans() {
} }
check_uid_root() { check_uid_root() {
if [ "$UID" != "0" ] if [ "$UID" != "0" ]
then then
echo "Erreur: le script $1 doit etre lance par root" echo "Erreur: le script $1 doit etre lance par root"
exit 1 exit 1
@ -24,7 +24,7 @@ check_uid_root() {
terminate() { terminate() {
status=${2:-1} # default: exit 1 status=${2:-1} # default: exit 1
echo echo
echo "Erreur: $1" echo "Erreur: $1"
echo echo
exit $status exit $status
@ -95,8 +95,8 @@ set_scodoc_var_dir() {
} }
# XXX inutilise # XXX inutilise
gen_passwd() { gen_passwd() {
PASSWORD_LENGTH="8" PASSWORD_LENGTH="8"
ALLOWABLE_ASCII="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@#$%^&*()_+=-?><" ALLOWABLE_ASCII="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@#$%^&*()_+=-?><"
SEED=$(head -c4 /dev/urandom | od -t u4 | awk '{ print $2 }') SEED=$(head -c4 /dev/urandom | od -t u4 | awk '{ print $2 }')
@ -110,3 +110,15 @@ gen_passwd() {
done done
echo "$password" 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
}