2021-07-23 08:35:20 +02:00
#!/bin/bash
2021-08-18 18:53:45 +02:00
# Migre une install ScoDoc 7 vers ScoDoc 9
# Les données ScoDoc7 sauvegardées par save_scodoc7_data.sh
# sont copiés au bon endroit
# puis les bases SQL ScoDoc 7 sont traduites dans la base ScoDoc 9
2021-07-23 08:35:20 +02:00
#
2021-08-18 18:53:45 +02:00
# Fichiers de données et config locale:
2021-07-25 09:51:09 +02:00
# archives, photos: /opt/scodoc/var/ => /opt/scodoc-data
2021-07-23 08:35:20 +02:00
#
#
2021-08-15 16:43:53 +02:00
set -euo pipefail
2021-07-27 16:07:03 +02:00
# Le répertoire de ce script:
SCRIPT_DIR = " $( cd " $( dirname " ${ BASH_SOURCE [0] } " ) " & > /dev/null && pwd ) "
source " $SCRIPT_DIR /config.sh "
source " $SCRIPT_DIR /utils.sh "
2021-08-18 18:53:45 +02:00
cd " $SCODOC_DIR " || die "ScoDoc 9 non installe"
source "venv/bin/activate"
2021-07-23 08:35:20 +02:00
2021-08-18 18:53:45 +02:00
# Ce script doit tourner comme "root"
check_uid_root " $0 "
# En principe, l'utilisateur "scodoc" existe déjà, mais au cas où on vérifie:
check_create_scodoc_user
# Usage
if [ ! $# -eq 1 ]
then
echo " Usage: $0 directory "
exit 1
fi
2021-07-23 08:35:20 +02:00
2021-08-18 18:53:45 +02:00
SCODOC7_HOME = " $1 " # racine de l'archive importée
#SCODOC7_HOME="/opt/scodoc7"
#SCODOC7_DIR="${SCODOC7_HOME}/Products/ScoDoc"
# if [ "${SRC##*.}" == "tgz" ]
# then
# if [ -e ${SRC%%.*} ]
# then
# echo "Error: ${SRC} is an archive but ${SRC%%.*} already exists"
# exit 2
# fi
# echo "extracting archive ${SRC}..."
# tar xvfz ...
2021-07-23 08:35:20 +02:00
# --- 2. Propriétaire des bases de données
# Bases appartenant à www-data:
2021-08-18 18:53:45 +02:00
# inutile si on importe via pg_restore (voir restore-scodoc7_data.sh)
2021-07-23 09:32:20 +02:00
migrate_database_ownership( ) {
2021-07-23 08:35:20 +02:00
SCO7_BASES = $( su -c "psql -l -t | grep www-data" " $POSTGRES_SUPERUSER " | awk -F '|' '{print $1}' )
for base in $SCO7_BASES
do
su -c " psql -c 'REASSIGN OWNED BY \"www-data\" TO scodoc;' $base " " $POSTGRES_SUPERUSER "
done
su -c "psql -c 'REASSIGN OWNED BY \"www-data\" TO scodoc;'" " $POSTGRES_SUPERUSER "
}
2021-07-25 09:51:09 +02:00
# --- 3. Fichiers locaux: /opt/scodoc/var => /opt/scodoc-data
2021-07-23 08:35:20 +02:00
migrate_local_files( ) {
2021-08-18 18:53:45 +02:00
echo "Déplacement des fichiers de configuration et des archives"
2021-07-23 08:35:20 +02:00
SCODOC_VAR_DIR_BACKUP = " $SCODOC_VAR_DIR " .bak
if [ -e " $SCODOC_VAR_DIR_BACKUP " ]
then
die " supprimer ou déplacer $SCODOC_VAR_DIR_BACKUP avant de continuer "
fi
if [ -e " $SCODOC_VAR_DIR " ]
then
echo " renomme $SCODOC_VAR_DIR en $SCODOC_VAR_DIR_BACKUP "
mv " $SCODOC_VAR_DIR " " $SCODOC_VAR_DIR_BACKUP "
fi
2021-08-18 18:53:45 +02:00
mkdir " $SCODOC_VAR_DIR " || die "erreur creation repertoire"
2021-07-25 09:51:09 +02:00
mv " ${ SCODOC7_HOME } " /var/scodoc/* " $SCODOC_VAR_DIR " || die "migrate_local_files failed"
2021-08-18 18:53:45 +02:00
# Anciens logs ScoDoc7
old_logs_dest = " $SCODOC_VAR_DIR /log/scodoc7 "
echo " Copie des anciens logs ScoDoc 7 dans $old_logs_dest "
mkdir -p " $old_logs_dest " || die " erreur creation $old_logs_dest "
mv " ${ SCODOC7_HOME } " /log/* " $old_logs_dest " || die "erreur mv"
2021-07-25 09:51:09 +02:00
# Templates locaux poursuites etudes
2021-08-18 18:53:45 +02:00
if [ -e " ${ SCODOC7_HOME } " /config/doc_poursuites_etudes/local ]
2021-07-25 09:51:09 +02:00
then
2021-08-18 18:53:45 +02:00
mv " ${ SCODOC7_HOME } " /config/doc_poursuites_etudes/local " $SCODOC_VAR_DIR " /config/doc_poursuites_etudes || die "migrate_local_files failed to migrate doc_poursuites_etudes/local"
2021-07-25 09:51:09 +02:00
fi
# S'assure que le propriétaire est "scodoc":
chown -R " ${ SCODOC_USER } : ${ SCODOC_GROUP } " " ${ SCODOC_VAR_DIR } " || die " change_scodoc_file_ownership failed on ${ SCODOC_VAR_DIR } "
2021-07-23 08:35:20 +02:00
}
# ------ MAIN
2021-08-18 18:53:45 +02:00
change_scodoc_file_ownership
2021-07-23 08:35:20 +02:00
2021-08-18 18:53:45 +02:00
migrate_local_files
set_scodoc_var_dir
2021-07-23 08:35:20 +02:00
2021-07-23 09:32:20 +02:00
echo
2021-08-18 18:53:45 +02:00
echo "Les fichiers locaux de ScoDoc: configuration, photos, procès-verbaux..."
2021-07-23 08:35:20 +02:00
echo " sont maintenant stockées dans $SCODOC_VAR_DIR "
2021-08-18 18:53:45 +02:00
echo
2021-07-23 08:35:20 +02:00
2021-08-14 18:54:32 +02:00
# ----- Migration base utilisateurs
2021-07-27 16:07:03 +02:00
echo
2021-08-14 18:54:32 +02:00
echo "-------------------------------------------------------------"
2021-08-18 18:53:45 +02:00
echo "Importation des utilisateurs de ScoDoc7 dans ScoDoc 9 "
2021-07-27 16:07:03 +02:00
echo "(la base SCOUSERS de ScoDoc7 sera laissée inchangée)"
2021-08-18 18:53:45 +02:00
echo "(les utilisateurs ScoDoc 9 existants seront laissés inchangés)"
2021-08-14 18:54:32 +02:00
echo "-------------------------------------------------------------"
echo
2021-08-15 16:43:53 +02:00
su -c " (cd $SCODOC_DIR && flask import-scodoc7-users) " " $SCODOC_USER "
2021-08-14 18:54:32 +02:00
2021-08-18 18:53:45 +02:00
2021-08-14 18:54:32 +02:00
# ----- Migration bases départements
# les départements ScoDoc7 ont été déplacés dans /opt/scodoc-data/config/dept
for f in " $SCODOC_VAR_DIR " /config/depts/*.cfg
do
dept = $( basename " ${ f %.* } " )
2021-08-15 16:43:53 +02:00
echo
echo "----------------------------------------------"
echo " | MIGRATION DU DEPARTEMENT $dept "
echo "----------------------------------------------"
2021-08-18 18:53:45 +02:00
su -c " (cd $SCODOC_DIR && flask import-scodoc7-dept $dept ) " " $SCODOC_USER "
2021-08-15 16:43:53 +02:00
echo "restarting postgresql server..."
systemctl restart postgresql
done
# Précaution a priori inutile (import-scodoc7-dept efface les caches)
systemctl restart redis
# Commande listant les nom des departement en DB:
# Liste des bases de données de département:
# dept_db=$(psql -l | awk '{print $1;}' | grep ^SCO | grep -v SCOUSERS | grep -v SCO8USERS | awk '{print substr($1,4);}')