2021-08-24 16:18:00 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Post-installation de scodoc
|
|
|
|
# ici, le répertoire /opt/scodoc vient d'être installé
|
|
|
|
|
2024-09-05 00:24:18 +02:00
|
|
|
# set -euo pipefail commenté pour tolérer qq erruers, comme le timeout sur le curl
|
2024-08-24 14:39:02 +02:00
|
|
|
|
2021-08-25 16:55:30 +02:00
|
|
|
cd /opt/scodoc || (echo "Error chdir to /opt/scodoc"; exit 1)
|
|
|
|
|
2021-08-24 16:18:00 +02:00
|
|
|
# On peut donc charger la config:
|
2024-08-24 14:39:02 +02:00
|
|
|
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
|
2021-08-24 16:18:00 +02:00
|
|
|
|
|
|
|
# -- Création au besoin de notre utilisateur
|
2021-08-24 18:55:58 +02:00
|
|
|
# adduser --system "${SCODOC_USER}"
|
|
|
|
check_create_scodoc_user
|
2021-08-24 16:18:00 +02:00
|
|
|
|
|
|
|
# -- Répertoires /opt/scodoc donné à scodoc
|
|
|
|
change_scodoc_file_ownership
|
2021-08-27 17:03:47 +02:00
|
|
|
# --- Création au besoin de /opt/scodoc-data
|
2021-08-24 16:18:00 +02:00
|
|
|
set_scodoc_var_dir
|
|
|
|
|
2021-08-26 15:35:08 +02:00
|
|
|
# ------------ LOCALES (pour compat bases ScoDoc 7 et plus anciennes)
|
|
|
|
for locname in "en_US.UTF-8"
|
|
|
|
do
|
2024-08-26 01:51:12 +02:00
|
|
|
outname=$(echo ${locname//-/} | tr '[:upper:]' '[:lower:]')
|
|
|
|
if [ "$(locale -a | grep -c -E -i ^${outname}$ )" -lt 1 ]
|
2021-08-26 15:35:08 +02:00
|
|
|
then
|
|
|
|
echo adding $locname
|
|
|
|
echo "$locname ${locname##*.}" >> /etc/locale.gen
|
2024-08-24 14:39:02 +02:00
|
|
|
/usr/sbin/locale-gen --keep-existing
|
2021-08-26 15:35:08 +02:00
|
|
|
fi
|
|
|
|
done
|
2021-09-06 21:35:17 +02:00
|
|
|
echo "debian postinst: scodoc9 systemd service is $(systemctl is-active scodoc9)"
|
2021-08-30 11:03:24 +02:00
|
|
|
# On a besoin d'un postgresql lancé pour la mise à jour
|
|
|
|
systemctl restart postgresql
|
2021-08-24 16:18:00 +02:00
|
|
|
|
2021-08-25 21:55:27 +02:00
|
|
|
# Le numero de version complet, genre 9.0.0
|
2024-08-26 01:51:12 +02:00
|
|
|
SCODOC_RELEASE=$(grep SCOVERSION "$SCODOC_DIR/sco_version.py" | awk '{ print substr($3, 2, length($3)-2) }')
|
2021-08-25 21:55:27 +02:00
|
|
|
if [ -e "${SCODOC_VERSION_DIR}/scodoc.sn" ]
|
|
|
|
then
|
|
|
|
# upgrading
|
|
|
|
echo "mode: upgrade"
|
|
|
|
mode=upgrade
|
|
|
|
SN=$(cat "${SCODOC_VERSION_DIR}"/scodoc.sn)
|
|
|
|
if [[ ! "${SN}" =~ ^[0-9].* ]]
|
|
|
|
then
|
|
|
|
SN='' # fix for invalid previous replies
|
2024-08-24 14:39:02 +02:00
|
|
|
fi
|
2021-08-25 21:55:27 +02:00
|
|
|
else
|
|
|
|
# first install
|
|
|
|
echo "mode: install"
|
|
|
|
mode=install
|
|
|
|
SN=""
|
|
|
|
fi
|
2021-08-24 16:18:00 +02:00
|
|
|
|
2021-10-14 11:01:29 +02:00
|
|
|
CMD="curl --fail --connect-timeout 5 --silent https://scodoc.org/scodoc-installmgr/version?mode=$mode\&release=${SCODOC_RELEASE}\&sn=${SN}"
|
2021-08-25 21:55:27 +02:00
|
|
|
|
|
|
|
SVERSION="$(${CMD})"
|
|
|
|
if [ "$?" == 0 ]; then
|
2024-08-24 14:39:02 +02:00
|
|
|
#echo "answer=${SVERSION}"
|
2021-08-25 21:55:27 +02:00
|
|
|
echo "${SVERSION}" > "${SCODOC_VERSION_DIR}"/scodoc.sn
|
|
|
|
else
|
2024-08-24 14:39:02 +02:00
|
|
|
echo 'Warning: cannot connect to scodoc release server'
|
2021-08-25 21:55:27 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# ------------ LIEN VERS .env
|
|
|
|
# Pour conserver le .env entre les mises à jour, on le génère dans
|
2022-01-03 12:31:20 +01:00
|
|
|
# /opt/scodoc-data/.env et on le lie:
|
2021-08-25 21:55:27 +02:00
|
|
|
if [ ! -e "$SCODOC_DIR/.env" ] && [ ! -L "$SCODOC_DIR/.env" ]
|
|
|
|
then
|
|
|
|
ln -s "$SCODOC_VAR_DIR/.env" "$SCODOC_DIR"
|
|
|
|
fi
|
2021-08-24 23:36:58 +02:00
|
|
|
|
|
|
|
# ------------ CREATION DU VIRTUALENV
|
2021-08-25 21:55:27 +02:00
|
|
|
# donc re-créé sur le client à chaque install ou upgrade
|
2021-08-24 23:36:58 +02:00
|
|
|
#echo "Creating python3 virtualenv..."
|
2021-08-27 17:03:47 +02:00
|
|
|
su -c "(cd $SCODOC_DIR && python3 -m venv venv)" "$SCODOC_USER" || die "Error creating Python 3 virtualenv"
|
2021-08-24 23:36:58 +02:00
|
|
|
|
2023-07-19 15:37:43 +02:00
|
|
|
# ------------ INSTALL DES PAQUETS PYTHON (3.11)
|
2021-08-24 23:36:58 +02:00
|
|
|
# pip in our env, as user "scodoc"
|
2023-07-19 15:37:43 +02:00
|
|
|
su -c "(cd $SCODOC_DIR && source venv/bin/activate && pip install wheel && pip install -r requirements-3.11.txt)" "$SCODOC_USER" || die "Error installing python packages"
|
2021-08-24 23:36:58 +02:00
|
|
|
|
2021-08-25 16:55:30 +02:00
|
|
|
# --- NGINX
|
2021-09-13 10:00:07 +02:00
|
|
|
# Evite d'écraser: il faudrait ici présenter un dialogue "fichier local modifié, ..."
|
|
|
|
if [ ! -e /etc/nginx/sites-available/scodoc9.nginx ]
|
|
|
|
then
|
|
|
|
cp -p /etc/nginx/sites-available/scodoc9.nginx.distrib /etc/nginx/sites-available/scodoc9.nginx || die "can't copy nginx config"
|
|
|
|
fi
|
2021-08-25 21:55:27 +02:00
|
|
|
if [ ! -L /etc/nginx/sites-enabled/scodoc9.nginx ]
|
|
|
|
then
|
2021-08-27 10:41:22 +02:00
|
|
|
echo "Enabling scodoc9 in nginx"
|
2021-08-25 21:55:27 +02:00
|
|
|
ln -s /etc/nginx/sites-available/scodoc9.nginx /etc/nginx/sites-enabled/
|
|
|
|
fi
|
2021-08-25 16:55:30 +02:00
|
|
|
/bin/rm -f /etc/nginx/sites-enabled/default
|
2021-08-24 23:36:58 +02:00
|
|
|
|
2021-08-27 10:41:22 +02:00
|
|
|
# ------------ POSTGRESQL
|
2021-08-24 16:18:00 +02:00
|
|
|
# --- Ensure postgres user "scodoc" ($POSTGRES_USER) exists
|
|
|
|
init_postgres_user
|
|
|
|
|
2021-08-27 17:03:47 +02:00
|
|
|
# ------------ BASE DE DONNEES
|
|
|
|
# Si la base SCODOC existe, tente de la mettre à jour
|
|
|
|
# (Ne gère pas les bases DEV et TEST)
|
|
|
|
n=$(su -c "psql -l | grep -c -E '^[[:blank:]]*SCODOC[[:blank:]]*\|'" "$SCODOC_USER")
|
|
|
|
if [ "$n" == 1 ]
|
|
|
|
then
|
|
|
|
echo "Upgrading existing SCODOC database..."
|
2023-06-16 07:54:28 +02:00
|
|
|
# Ajout extension unaccent (postgres superuser, ajout sur base SCODOC)
|
2023-06-20 07:51:40 +02:00
|
|
|
(cd /tmp; echo 'CREATE EXTENSION IF NOT EXISTS "unaccent";' | su -c "psql SCODOC" postgres)
|
2023-06-16 07:54:28 +02:00
|
|
|
# Migrations gérées avec Flask-Migrate (Alembic/SQLAlchemy)
|
2021-08-27 17:03:47 +02:00
|
|
|
# utilise les scripts dans migrations/version/
|
|
|
|
# pour mettre à jour notre base (en tant qu'utilisateur scodoc)
|
2021-08-27 17:25:18 +02:00
|
|
|
export FLASK_ENV="production"
|
2022-01-08 17:38:38 +01:00
|
|
|
su -c "(cd $SCODOC_DIR && source venv/bin/activate && flask db upgrade && flask clear-cache --sanitize)" "$SCODOC_USER"
|
2021-08-27 17:03:47 +02:00
|
|
|
fi
|
2021-08-27 10:41:22 +02:00
|
|
|
|
2021-08-29 19:57:32 +02:00
|
|
|
# ------------ LOGROTATE
|
|
|
|
cp "$SCODOC_DIR"/tools/etc/scodoc-logrotate /etc/logrotate.d/scodoc
|
|
|
|
chmod 644 /etc/logrotate.d/scodoc
|
|
|
|
|
2021-08-27 10:41:22 +02:00
|
|
|
# ------------ CONFIG SERVICE SCODOC
|
2024-08-24 14:39:02 +02:00
|
|
|
echo
|
2021-08-27 10:41:22 +02:00
|
|
|
echo "Installation du service systemd scodoc9..."
|
|
|
|
cp "$SCODOC_DIR"/tools/etc/scodoc9.service /etc/systemd/system/
|
|
|
|
systemctl daemon-reload
|
|
|
|
|
|
|
|
# ------------ MISES A JOUR
|
2021-08-25 23:51:07 +02:00
|
|
|
cp "$SCODOC_DIR"/tools/etc/scodoc-updater.service /etc/systemd/system
|
|
|
|
cp "$SCODOC_DIR"/tools/etc/scodoc-updater.timer /etc/systemd/system
|
|
|
|
systemctl enable scodoc-updater.timer
|
|
|
|
systemctl start scodoc-updater.timer
|
|
|
|
|
2021-08-25 21:55:27 +02:00
|
|
|
# --- SYSTEMD: on a (peut-être) installé un fichier de service
|
2021-08-24 16:18:00 +02:00
|
|
|
systemctl daemon-reload
|
2021-08-25 23:05:41 +02:00
|
|
|
systemctl enable scodoc9
|
|
|
|
|
2021-08-30 11:03:24 +02:00
|
|
|
# --- RESTART SCODOC
|
|
|
|
systemctl restart scodoc9
|
2024-08-24 14:39:02 +02:00
|
|
|
|
|
|
|
# On est arrivé au bout du post-install !
|
|
|
|
create_install_status
|