From c2d89799f04e5a5f4ab5bc31bb582ca4f37badd3 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sun, 25 Jul 2021 10:51:09 +0300 Subject: [PATCH] Reorganisation des fichiers, scripts d'install et doc installation --- README.md | 69 +++++++++++++++++++++++--------- app/scodoc/pe_avislatex.py | 10 ++--- app/scodoc/pe_tools.py | 16 ++++---- app/scodoc/sco_archives.py | 6 +-- app/scodoc/sco_cache.py | 9 +++-- app/scodoc/sco_config.py | 4 +- app/scodoc/sco_emails.py | 1 - app/scodoc/sco_etud.py | 4 +- app/scodoc/sco_import_etuds.py | 10 ++--- app/scodoc/sco_photos.py | 4 +- app/scodoc/sco_utils.py | 29 ++++++++------ app/views/scolar.py | 2 +- config.py | 7 +--- scotests/sco_fake_gen.py | 3 +- tests/unit/test_caches.py | 9 +++++ tools/config.sh | 6 +-- tools/diagnostic.sh | 28 +++++-------- tools/etc/scodoc-updater.service | 2 +- tools/install_debian10.sh | 17 +++++++- tools/make-release.sh | 13 +++--- tools/migrate_from_scodoc7.sh | 29 ++++++++++---- tools/scodoc_config.py | 4 +- tools/scodoc_config_tmpl.py | 5 +-- tools/scodocutils.py | 6 --- tools/upgrade.sh | 5 ++- tools/utils.sh | 15 ++++++- 26 files changed, 190 insertions(+), 123 deletions(-) diff --git a/README.md b/README.md index 5ca2d730a..567bec881 100644 --- a/README.md +++ b/README.md @@ -42,18 +42,41 @@ On peut installer à partir de zéro, ou sur une machine ayant déjà un ScoDoc ### Installation +#### Arrêter et renommer ScoDoc7 +**Important**: si vous avez un ScoDoc7 installé sur ce serveur, le mettre à jour, l'arrêter et renommer son répertoire avant de commencer l'installation de ScoDoc 8: + + 1. S'assurer que l'installation ScoDoc 7 est à jour + + sudo su + cd /opt/scodoc/Products/ScoDoc/config + ./upgrade.sh + + 2. Arrêter le service ScoDoc 7 + + systemctl stop scodoc7 + + S'assurer qu'il est bien stoppé (`ps auxw`, ...), sans qui la migration va échouer. + + 3. Renommer le répertoire de ScoDoc 7: + + sudo su + mv /opt/scodoc /opt/scodoc7 + +Les données pourront être migrées après installation la nouvelle evrsion, voir plus loin. + +#### Installer ScoDoc Sur un système Linux Debian 10, en tant que `root`: - Charger la dernière release depuis https://scodoc.org/git/viennet/ScoDoc/releases - - Déplacer ou copier le fichier `scodoc-v8.x.y.tgz` dans `/opt` et le décomprimer: + - Déplacer ou copier le fichier `scodoc-x.y.z.tgz` dans `/opt` et le décomprimer: sudo su - cd /opt; tar xf - scodoc-v8.x.y.tgz # remplacer x et y par votre version + cd /opt; tar xf - scodoc-x.y.z.tgz # remplacer x.y.z par votre version - Lancer le script d'installation: - cd /opt/scodoc8/tools + cd /opt/scodoc/tools ./install_debian10.sh ce script crée un compte utilisateur "scodoc". @@ -71,7 +94,7 @@ via `sqlalchemy`. Lancer le script: su postgres - cd /opt/scodoc8/tools + cd /opt/scodoc/tools ./create_database.sh Ce script crée une base nommée `SCO8USERS`, appartenant à l'utilisateur (role) postgres `scodoc`. @@ -115,23 +138,11 @@ Le script `migrate_from_scodoc7.sh` va déplacer les donneés et reconfigurer le de votre installation ScoDoc 7 pour passer à ScoDoc 8 (*ne pas utiliser en production !*). **Les modifications effectuées sont sans retour: ScoDoc 7 ne fonctionnera plus !** - 1. S'assurer que l'installation ScoDoc 7 est à jour - - sudo su - cd /opt/scodoc/Products/ScoDoc/config - ./upgrade.sh - - 2. Arrêter le service ScoDoc 7 - - systemctl stop scodoc7 - - S'assurer qu'il est bien stoppé (`ps auxw`, ...), sans qui la migration va échouer. - - 3. Lancer le script de migration + 1. Lancer le script de migration ScoDoc 8 doit avoir été installé comme expliqué plus haut. sudo su - cd /opt/scodoc8/tools + cd /opt/scodoc/tools ./migrate_from_scodoc7.sh @@ -149,6 +160,28 @@ En tant qu'utilisateur `scodoc` (pour avoir accès aux bases départements de Sc export FLASK_ENV=development flask run --host=0.0.0.0 +## Organisation des fichiers + +L'installation comporte les fichiers de l'application, sous `/opt/scodoc/`, et les fichiers locaux (archives, photos, configurations, logs) sous `/opt/scodoc-data`. Par ailleurs, il y a évidemment les bases de données postgresql et la configuration du système. + +### Fichiers locaux +Sous `/opt/scodoc-data`, fichiers et répertoires appartienant à l'utilisateur `scodoc`. +Ils ne doivent pas être modifiés à la main, sauf certains fichiers de configuration sous +`/opt/scodoc-data/config`. + +Le répertoire `/opt/scodoc-data` doit être régulièrement sauvegardé. + +Principaux contenus: + + /opt/scodoc-data + /opt/scodoc-data/log # Fichiers de log ScoDoc + /opt/scodoc-data/config # Fichiers de configuration + .../config/logos # Logos de l'établissement + .../config/depts # un fichier par département + /opt/scodoc-data/photos # Photos des étudiants + /opt/scodoc-data/archives # Archives: PV de jury, maquettes Apogée, fichiers étudiants + + ## Tests unitaires pytest tests/unit diff --git a/app/scodoc/pe_avislatex.py b/app/scodoc/pe_avislatex.py index 87ce7aa81..01e1a65c5 100644 --- a/app/scodoc/pe_avislatex.py +++ b/app/scodoc/pe_avislatex.py @@ -445,13 +445,11 @@ def get_templates_from_distrib(template="avis"): if template in ["avis", "footer"]: # pas de preference pour le template: utilise fichier du serveur - p = os.path.join(scu.SCO_SRC_DIR, pe_local_tmpl) - if os.path.exists(p): - template_latex = get_code_latex_from_modele(p) + if os.path.exists(pe_local_tmpl): + template_latex = get_code_latex_from_modele(pe_local_tmpl) else: - p = os.path.join(scu.SCO_SRC_DIR, pe_default_tmpl) - if os.path.exists(p): - template_latex = get_code_latex_from_modele(p) + if os.path.exists(pe_default_tmpl): + template_latex = get_code_latex_from_modele(pe_default_tmpl) else: template_latex = "" # fallback: avis vides return template_latex diff --git a/app/scodoc/pe_tools.py b/app/scodoc/pe_tools.py index 966799c89..fd1587d8a 100644 --- a/app/scodoc/pe_tools.py +++ b/app/scodoc/pe_tools.py @@ -62,11 +62,14 @@ else: # Generated LaTeX files are encoded as: PE_LATEX_ENCODING = "utf-8" -REP_DEFAULT_AVIS = "config/doc_poursuites_etudes/" +# /opt/scodoc/tools/doc_poursuites_etudes +REP_DEFAULT_AVIS = os.path.join(scu.SCO_TOOLS_DIR, "doc_poursuites_etudes/") +REP_LOCAL_AVIS = os.path.join(scu.SCODOC_CFG_DIR, "doc_poursuites_etudes/") + PE_DEFAULT_AVIS_LATEX_TMPL = REP_DEFAULT_AVIS + "distrib/modeles/un_avis.tex" -PE_LOCAL_AVIS_LATEX_TMPL = REP_DEFAULT_AVIS + "local/modeles/un_avis.tex" +PE_LOCAL_AVIS_LATEX_TMPL = REP_LOCAL_AVIS + "local/modeles/un_avis.tex" PE_DEFAULT_FOOTER_TMPL = REP_DEFAULT_AVIS + "distrib/modeles/un_footer.tex" -PE_LOCAL_FOOTER_TMPL = REP_DEFAULT_AVIS + "local/modeles/un_footer.tex" +PE_LOCAL_FOOTER_TMPL = REP_LOCAL_AVIS + "local/modeles/un_footer.tex" # ---------------------------------------------------------------------------------------- @@ -176,15 +179,14 @@ def add_pe_stuff_to_zip(context, zipfile, ziproot): Also copy logos """ - PE_AUX_DIR = os.path.join(scu.SCO_SRC_DIR, "config/doc_poursuites_etudes") - distrib_dir = os.path.join(PE_AUX_DIR, "distrib") + distrib_dir = os.path.join(REP_DEFAULT_AVIS, "distrib") distrib_pathnames = list_directory_filenames( distrib_dir - ) # eg /opt/scodoc/Products/ScoDoc/config/doc_poursuites_etudes/distrib/modeles/toto.tex + ) # eg /opt/scodoc/tools/doc_poursuites_etudes/distrib/modeles/toto.tex l = len(distrib_dir) distrib_filenames = {x[l + 1 :] for x in distrib_pathnames} # eg modeles/toto.tex - local_dir = os.path.join(PE_AUX_DIR, "local") + local_dir = os.path.join(REP_LOCAL_AVIS, "local") local_pathnames = list_directory_filenames(local_dir) l = len(local_dir) local_filenames = {x[l + 1 :] for x in local_pathnames} diff --git a/app/scodoc/sco_archives.py b/app/scodoc/sco_archives.py index 0fad17f91..5ab5c548a 100644 --- a/app/scodoc/sco_archives.py +++ b/app/scodoc/sco_archives.py @@ -29,8 +29,8 @@ Archives are plain files, stored in - /var/scodoc/archives/ - (where is usually /opt/scodoc/instance, and a departement id) + /archives/ + (where is usually /opt/scodoc-data, and a departement id) Les PV de jurys et documents associés sont stockées dans un sous-repertoire de la forme /// @@ -72,7 +72,7 @@ from app.scodoc import sco_pvpdf class BaseArchiver(object): def __init__(self, archive_type=""): - dirs = [Config.INSTANCE_HOME, "var", "scodoc", "archives"] + dirs = [Config.SCODOC_VAR_DIR, "archives"] if archive_type: dirs.append(archive_type) self.root = os.path.join(*dirs) diff --git a/app/scodoc/sco_cache.py b/app/scodoc/sco_cache.py index 579aff129..35f8e05f8 100644 --- a/app/scodoc/sco_cache.py +++ b/app/scodoc/sco_cache.py @@ -87,7 +87,10 @@ class ScoDocCache: """Store value""" key = cls._get_key(oid) log(f"CACHE key={key}, timeout={cls.timeout}") - return CACHE.set(key, value, timeout=cls.timeout) + status = CACHE.set(key, value, timeout=cls.timeout) + if not status: + log("Error: cache set failed") + return status @classmethod def delete(cls, oid): @@ -205,9 +208,7 @@ class NotesTableCache(ScoDocCache): nt = notes_table.NotesTable(None, formsemestre_id) dt = time.time() - t0 log("caching formsemestre_id=%s (%gs)" % (formsemestre_id, dt)) - s = cls.set(formsemestre_id, nt) - if not s: - log("Warning: cache.set failed") + _ = cls.set(formsemestre_id, nt) return nt diff --git a/app/scodoc/sco_config.py b/app/scodoc/sco_config.py index c16865daf..dc74f4fa5 100644 --- a/app/scodoc/sco_config.py +++ b/app/scodoc/sco_config.py @@ -89,8 +89,8 @@ CONFIG.CUSTOM_HTML_FOOTER_CNX = CONFIG.CUSTOM_HTML_FOOTER # ----------------------------------------------------- # Fichier de correspondance codelycee -> noms -# (chemin relatif au repertoire d'install des sources) -CONFIG.ETABL_FILENAME = "config/etablissements.csv" +# (dans tools/) +CONFIG.ETABL_FILENAME = "etablissements.csv" # ---------------------------------------------------- # -------------- Divers: diff --git a/app/scodoc/sco_emails.py b/app/scodoc/sco_emails.py index 6aa9ba273..9ebdf5977 100644 --- a/app/scodoc/sco_emails.py +++ b/app/scodoc/sco_emails.py @@ -124,7 +124,6 @@ def _report_request(context, REQUEST, fmt="txt"): HTTP_USER_AGENT=HTTP_USER_AGENT, form=REQUEST.form, HTTP_X_FORWARDED_FOR="?", - svn_version=scu.get_svn_version(scu.SCO_SRC_DIR), SCOVERSION=VERSION.SCOVERSION, ) txt = ( diff --git a/app/scodoc/sco_etud.py b/app/scodoc/sco_etud.py index 61c72b1ab..cc17bb77a 100644 --- a/app/scodoc/sco_etud.py +++ b/app/scodoc/sco_etud.py @@ -29,7 +29,7 @@ """ # Ancien module "scolars" - +import os import time from flask import url_for, g @@ -811,7 +811,7 @@ appreciations_edit = _appreciationsEditor.edit # -------- Noms des Lycées à partir du code def read_etablissements(): - filename = scu.SCO_SRC_DIR + "/" + scu.CONFIG.ETABL_FILENAME + filename = os.path.join(scu.SCO_TOOLS_DIR, scu.CONFIG.ETABL_FILENAME) log("reading %s" % filename) f = open(filename) L = [x[:-1].split(";") for x in f] diff --git a/app/scodoc/sco_import_etuds.py b/app/scodoc/sco_import_etuds.py index 191166ced..026bf691a 100644 --- a/app/scodoc/sco_import_etuds.py +++ b/app/scodoc/sco_import_etuds.py @@ -28,10 +28,10 @@ """ Importation des etudiants à partir de fichiers CSV """ - -import time import collections +import os import re +import time import app.scodoc.sco_utils as scu import app.scodoc.notesdb as ndb @@ -59,8 +59,8 @@ from app.scodoc import sco_groups_view from app.scodoc import sco_news from app.scodoc import sco_preferences -# format description (relative to Product directory)) -FORMAT_FILE = "misc/format_import_etudiants.txt" +# format description (in tools/) +FORMAT_FILE = "format_import_etudiants.txt" # Champs modifiables via "Import données admission" ADMISSION_MODIFIABLE_FIELDS = ( @@ -109,7 +109,7 @@ ADMISSION_MODIFIABLE_FIELDS = ( def sco_import_format(with_codesemestre=True): "returns tuples (Attribut, Type, Table, AllowNulls, Description)" r = [] - for l in open(scu.SCO_SRC_DIR + "/" + FORMAT_FILE): + for l in open(os.path.join(scu.SCO_TOOLS_DIR, FORMAT_FILE)): l = l.strip() if l and l[0] != "#": fs = l.split(";") diff --git a/app/scodoc/sco_photos.py b/app/scodoc/sco_photos.py index ac9373c21..807486be3 100644 --- a/app/scodoc/sco_photos.py +++ b/app/scodoc/sco_photos.py @@ -70,8 +70,8 @@ import app.scodoc.notesdb as ndb import app.scodoc.sco_utils as scu # Full paths on server's filesystem. Something like "/opt/scodoc/var/scodoc/photos" -PHOTO_DIR = os.path.join(Config.INSTANCE_HOME, "var", "scodoc", "photos") -ICONS_DIR = os.path.join(scu.SCO_SRC_DIR, "app", "static", "icons") +PHOTO_DIR = os.path.join(Config.SCODOC_VAR_DIR, "photos") +ICONS_DIR = os.path.join(Config.SCODOC_DIR, "app", "static", "icons") UNKNOWN_IMAGE_PATH = os.path.join(ICONS_DIR, "unknown.jpg") UNKNOWN_IMAGE_URL = "get_photo_image?etudid=" # with empty etudid => unknown face image IMAGE_EXT = ".jpg" diff --git a/app/scodoc/sco_utils.py b/app/scodoc/sco_utils.py index 700ce8d55..038cc4821 100644 --- a/app/scodoc/sco_utils.py +++ b/app/scodoc/sco_utils.py @@ -220,24 +220,22 @@ def group_by_key(d, key): # ----- Global lock for critical sections (except notes_tables caches) GSL = six.moves._thread.allocate_lock() # Global ScoDoc Lock -# ----- Repertoire "var" (local) -SCODOC_VAR_DIR = os.path.join(Config.INSTANCE_HOME, "var", "scodoc") +SCODOC_DIR = Config.SCODOC_DIR + # ----- Repertoire "config" modifiable -# /opt/scodoc/var/scodoc/config -SCODOC_CFG_DIR = os.path.join(SCODOC_VAR_DIR, "config") +# /opt/scodoc-data/config +SCODOC_CFG_DIR = os.path.join(Config.SCODOC_VAR_DIR, "config") # ----- Version information SCODOC_VERSION_DIR = os.path.join(SCODOC_CFG_DIR, "version") -# ----- Repertoire tmp -SCO_TMP_DIR = os.path.join(SCODOC_VAR_DIR, "tmp") +# ----- Repertoire tmp : /opt/scodoc-data/tmp +SCO_TMP_DIR = os.path.join(Config.SCODOC_VAR_DIR, "tmp") if not os.path.exists(SCO_TMP_DIR): os.mkdir(SCO_TMP_DIR, 0o755) -# ----- Les logos: /opt/scodoc/var/scodoc/config/logos +# ----- Les logos: /opt/scodoc-data/config/logos SCODOC_LOGOS_DIR = os.path.join(SCODOC_CFG_DIR, "logos") -# Racine projet: /.../ScoDoc/ -SCO_SRC_DIR = os.path.join(Config.INSTANCE_HOME, "Products", "ScoDoc") -# - Les outils distribués -SCO_TOOLS_DIR = os.path.join(SCO_SRC_DIR, "config") +# ----- Les outils distribués +SCO_TOOLS_DIR = os.path.join(Config.SCODOC_DIR, "tools") # ----- Lecture du fichier de configuration @@ -720,7 +718,14 @@ def icontag(name, file_format="png", **attrs): """ if ("width" not in attrs) or ("height" not in attrs): if name not in ICONSIZES: - img_file = SCO_SRC_DIR + "/app/static/icons/%s.%s" % (name, file_format) + img_file = os.path.join( + Config.SCODOC_DIR, + "app/static/icons/%s.%s" + % ( + name, + file_format, + ), + ) im = PILImage.open(img_file) width, height = im.size[0], im.size[1] ICONSIZES[name] = (width, height) # cache diff --git a/app/views/scolar.py b/app/views/scolar.py index 03f2f3d1a..94acf0d11 100644 --- a/app/views/scolar.py +++ b/app/views/scolar.py @@ -125,7 +125,7 @@ def sco_publish(route, function, permission, methods=("GET",)): ) -log.set_log_directory(Config.INSTANCE_HOME + "/log") +log.set_log_directory(Config.SCODOC_VAR_DIR + "/log") log("ScoDoc8 restarting...") # -------------------------------------------------------------------- diff --git a/config.py b/config.py index 1d0983834..096adcd28 100755 --- a/config.py +++ b/config.py @@ -28,11 +28,8 @@ class Config: ADMINS = [SCODOC_ADMIN_MAIL] SCODOC_ERR_MAIL = os.environ.get("SCODOC_ERR_MAIL") BOOTSTRAP_SERVE_LOCAL = os.environ.get("BOOTSTRAP_SERVE_LOCAL") - # for ScoDoc 7 compat (à changer) - INSTANCE_HOME = os.environ.get("INSTANCE_HOME", "/opt/scodoc") - SCODOC_VAR_DIR = os.path.join( - os.environ.get("INSTANCE_HOME", "/opt/scodoc"), "var", "scodoc" - ) + SCODOC_DIR = os.environ.get("SCODOC_DIR", "/opt/scodoc") + SCODOC_VAR_DIR = os.environ.get("SCODOC_VAR_DIR", "/opt/scodoc-data") # For legacy ScoDoc7 installs: postgresql user SCODOC7_SQL_USER = os.environ.get("SCODOC7_SQL_USER", "www-data") diff --git a/scotests/sco_fake_gen.py b/scotests/sco_fake_gen.py index b1bf273f8..9bd12cab8 100644 --- a/scotests/sco_fake_gen.py +++ b/scotests/sco_fake_gen.py @@ -17,6 +17,7 @@ import pprint import random import scodoc_manager +from config import Config from app.scodoc import notesdb as ndb from app.scodoc import sco_codes_parcours from app.scodoc import sco_edit_formation @@ -40,7 +41,7 @@ from app.scodoc.sco_exceptions import ScoValueError random.seed(12345) # tests reproductibles -DEMO_DIR = scu.SCO_SRC_DIR + "/scotests/demo/" +DEMO_DIR = Config.SCODOC_DIR + "/scotests/demo/" NOMS = [x.strip() for x in open(DEMO_DIR + "/noms.txt").readlines()] PRENOMS_H = [x.strip() for x in open(DEMO_DIR + "/prenoms-h.txt").readlines()] PRENOMS_F = [x.strip() for x in open(DEMO_DIR + "/prenoms-f.txt").readlines()] diff --git a/tests/unit/test_caches.py b/tests/unit/test_caches.py index 43db1f1e5..2139ba0d4 100644 --- a/tests/unit/test_caches.py +++ b/tests/unit/test_caches.py @@ -30,6 +30,15 @@ def test_notes_table(test_client): assert sco_cache.NotesTableCache.get(formsemestre_id, compute=False) sco_cache.invalidate_formsemestre(formsemestre_id) assert not sco_cache.NotesTableCache.get(formsemestre_id, compute=False) + # cache les 5 premiers + for sem in sems[:5]: + formsemestre_id = sem["formsemestre_id"] + nt = sco_cache.NotesTableCache.get(formsemestre_id) + assert sco_cache.NotesTableCache.get(formsemestre_id, compute=False) + # assert "SEM38882" in {s["formsemestre_id"] for s in sems} + # formsemestre_id = "SEM38882" + # nt = sco_cache.NotesTableCache.get(formsemestre_id) + # assert sco_cache.NotesTableCache.get(formsemestre_id, compute=False) def test_cache_evaluations(test_client): diff --git a/tools/config.sh b/tools/config.sh index 44043da07..a77f00df3 100644 --- a/tools/config.sh +++ b/tools/config.sh @@ -16,11 +16,9 @@ export PATH="${PATH}":/usr/sbin:/sbin # ScoDoc: environment variables umask 0022 -export SCODOC_DIR=/opt/scodoc8 +export SCODOC_DIR=/opt/scodoc +export SCODOC_VAR_DIR=/opt/scodoc-data -SCODOC_VAR_DIR=$(realpath -L "$SCODOC_DIR/var") || die "can't set SCODOC_VAR_DIR" -export SCODOC_VAR_DIR -# = /opt/scodoc/var/scodoc export SCODOC_VERSION_DIR="${SCODOC_VAR_DIR}/config/version" export SCODOC_LOGOS_DIR="${SCODOC_VAR_DIR}/config/logos" diff --git a/tools/diagnostic.sh b/tools/diagnostic.sh index afec5906b..5d7ba2bb8 100755 --- a/tools/diagnostic.sh +++ b/tools/diagnostic.sh @@ -8,15 +8,14 @@ # DEST_ADDRESS=emmanuel.viennet@gmail.com -INSTANCE_DIR=/opt/scodoc - TMP=/tmp/scodoc-$(date +%F-%s) DEPTS_TO_SAVE="" SAVE_USERS=0 SEND_BY_MAIL=1 -SCODOC_HOME="/opt/scodoc8" +SCODOC_DIR="/opt/scodoc" +SCODOC_VAR_DIR="/opt/scodoc-data" # ------------------------------------- # Arguments @@ -76,7 +75,7 @@ fi mkdir "$TMP" # Files to copy: -FILES="/etc/hosts /etc/debian_version /etc/apt /etc/apache2" +FILES="/etc/hosts /etc/debian_version /etc/apt /etc/apache2 $SCODOC_DIR/VERSION" echo "ScoDoc diagnostic: informations about your system will be " @@ -92,18 +91,8 @@ echo "left in ${TMP}" # Logs # ------------------------------------- -copy_log() { - if [ -e "$1" ] - then - cp "$1" "$TMP"/scodoc_logs/ - fi -} mkdir "$TMP"/scodoc_logs/ -copy_log "$SCODOC_HOME/log/event.log" -copy_log "$SCODOC_HOME/log/event.log.1" -copy_log "$SCODOC_HOME/log/notes.log" -copy_log "$SCODOC_HOME/log/notes.log.1" - +cp "$SCODOC_VAR_DIR"/log/*.log "$TMP"/scodoc_logs/ # ------------------------------------- # Linux System Configuration @@ -126,7 +115,7 @@ ls -laR "$SCODOC_HOME" > "$TMP"/ls-laR # Databases configurations # ------------------------------------- (su postgres -c "psql -l") > "${TMP}/psql-l.out" -for dept in "${INSTANCE_DIR}"/var/scodoc/config/depts/*.cfg +for dept in "${SCODOC_VAR_DIR}"/config/depts/*.cfg do cnx=$(cat "$dept") (su postgres -c "echo '\dt' | psql -d $cnx") > "${TMP}/psql-$(basename ${dept%%.*}).out" @@ -138,8 +127,11 @@ done # ------------------------------------- # copy files: for f in $FILES -do - cp -R "$f" "$TMP" +do + if [ -e "$f" ] + then + cp -R "$f" "$TMP" + fi done diff --git a/tools/etc/scodoc-updater.service b/tools/etc/scodoc-updater.service index 7717cd3be..f7a11466f 100644 --- a/tools/etc/scodoc-updater.service +++ b/tools/etc/scodoc-updater.service @@ -14,5 +14,5 @@ Description=Update ScoDoc Software [Service] Type=oneshot -ExecStart=/opt/scodoc8/tools/upgrade.sh +ExecStart=/opt/scodoc/tools/upgrade.sh diff --git a/tools/install_debian10.sh b/tools/install_debian10.sh index bda1aeac4..04446f912 100755 --- a/tools/install_debian10.sh +++ b/tools/install_debian10.sh @@ -11,7 +11,9 @@ source config.sh source utils.sh -check_uid_root $0 +check_uid_root "$0" + +cd "$SCODOC_DIR" || die "can't cd $SCODOC_DIR" # ------------ Safety checks if [ "${debian_version}" != "10" ] @@ -29,13 +31,24 @@ fi # ------------ Unix user check_create_scodoc_user +# --- Create empty .../var/ subdir +echo "Creating empty local directories..." +for d in var var/scodoc var/scodoc/archives var/scodoc/photos var/scodoc/tmp var/scodoc/config var/scodoc/config/version var/scodoc/config/depts var/scodoc/config/logos +do + [ -d "$d" ] || mkdir "$d" || die "can't create $d subdirectory" +done + # ------------ Permissions & directories change_scodoc_file_ownership +set_scodoc_var_dir # ------------ AJOUT DES PAQUETS DEBIAN NECESSAIRES apt-get update +apt-get -y install gcc apt-get -y install python3-dev apt-get -y install python3-venv +apt-get -y install python3-pip +apt-get install -y python3-wheel apt-get -y install libpq-dev apt-get -y install libcrack2-dev apt-get -y install postgresql @@ -44,12 +57,12 @@ apt-get -y install graphviz # ------------ CREATION DU VIRTUALENV echo "Creating python3 virtualenv..." -cd "$SCODOC_DIR" || die "can't cd $SCODOC_DIR" python3 -m venv venv || die "can't create Python 3 virtualenv" # ------------ INSTALL DES PAQUETS PYTHON (3.7) # ScoDoc8 uses pip in our env source venv/bin/activate +pip install --upgrade pip pip install wheel pip install -r requirements-3.7.txt diff --git a/tools/make-release.sh b/tools/make-release.sh index fa75077e7..a045d799c 100755 --- a/tools/make-release.sh +++ b/tools/make-release.sh @@ -1,5 +1,7 @@ #!/bin/bash +# INUTILE + # Préparation d'une release ScoDoc # Download last git source config.sh @@ -61,18 +63,13 @@ git clone "$SOURCE_URL" || die "git error cloning $SOURCE_URL" cd ScoDoc || die "no ScoDoc directory !" git checkout "$SOURCE_BRANCH" || die "git ckecking out branch $SOURCE_BRANCH" -# --- Create empty .../var/ subdir -echo "Creating empty local directories..." -mkdir -p var/scodoc || die "can't create var subdirectory" -mkdir var/scodoc/archives var/scodoc/photos var/scodoc/tmp var/scodoc/config -mkdir var/scodoc/config/version var/scodoc/config/depts var/scodoc/config/logos cd .. # --- Archive echo "Preparing archive..." -mv ScoDoc scodoc8 -chown -R scodoc scodoc8 -tar cfz "$RESULTFILE" scodoc8 +mv ScoDoc scodoc +chown -R scodoc scodoc +tar cfz "$RESULTFILE" scodoc echo echo "Release: $(pwd)/$RESULTFILE" diff --git a/tools/migrate_from_scodoc7.sh b/tools/migrate_from_scodoc7.sh index b8d9be8be..3e433eceb 100755 --- a/tools/migrate_from_scodoc7.sh +++ b/tools/migrate_from_scodoc7.sh @@ -1,14 +1,14 @@ #!/bin/bash # Migre une install ScoDoc 7 vers ScoDoc 8 -# Le ScoDoc7 est supposé être dans /opt/scodoc/Products/ScoDoc -# Le nouveau est /opt/scodoc8/ +# Le ScoDoc7 est supposé être dans /opt/scodoc7/Products/ScoDoc +# Le nouveau est /opt/scodoc/ # # L'install ScoDoc7 de départ doit impérativement être à jour (upgrade.sh). # # 1- Utilisateur Unix: # scodoc7 tournait comme www-data -# scodoc8 tourne sous l'utilisateur unix scodoc +# scodoc >= 8 tourne sous l'utilisateur unix scodoc # # 2- Utilisateur postgresql (bases de données) # scodoc7 les bases appartenaient à "www-data" @@ -17,7 +17,7 @@ # idem pour la base SCOUSERS (avant sa migration vers SCO8USERS) # # 3- Fichiers de données et config locale: -# archives, photos: /opt/scodoc/var/ => /opt/scodoc8/var +# archives, photos: /opt/scodoc/var/ => /opt/scodoc-data # # 4- TODO migrer de Apache à nginx, installer memcached, scripts service systemd # @@ -26,7 +26,7 @@ source config.sh source utils.sh check_uid_root -SCODOC7_HOME="/opt/scodoc" +SCODOC7_HOME="/opt/scodoc7" SCODOC7_DIR="${SCODOC7_HOME}/Products/ScoDoc" @@ -41,7 +41,7 @@ migrate_database_ownership() { su -c "psql -c 'REASSIGN OWNED BY \"www-data\" TO scodoc;'" "$POSTGRES_SUPERUSER" } -# --- 3. Fichiers locaux: /opt/scodoc/var => /opt/scodoc8/var +# --- 3. Fichiers locaux: /opt/scodoc/var => /opt/scodoc-data migrate_local_files() { SCODOC_VAR_DIR_BACKUP="$SCODOC_VAR_DIR".bak if [ -e "$SCODOC_VAR_DIR_BACKUP" ] @@ -53,7 +53,15 @@ migrate_local_files() { echo "renomme $SCODOC_VAR_DIR en $SCODOC_VAR_DIR_BACKUP" mv "$SCODOC_VAR_DIR" "$SCODOC_VAR_DIR_BACKUP" fi - mv "${SCODOC7_HOME}"/var/* "$SCODOC_VAR_DIR" || die "migrate_local_files failed" + mv "${SCODOC7_HOME}"/var/scodoc/* "$SCODOC_VAR_DIR" || die "migrate_local_files failed" + + # Templates locaux poursuites etudes + if [ -e "${SCODOC7_DIR}"/config/doc_poursuites_etudes/local ] + then + mv "${SCODOC7_DIR}"/config/doc_poursuites_etudes/local "$SCODOC_VAR_DIR"/config/doc_poursuites_etudes || die "migrate_local_files failed to migrate doc_poursuites_etudes/local" + 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}" } @@ -85,5 +93,12 @@ read -r ans if [ "$(norm_ans "$ans")" != 'N' ] then migrate_local_files +else + echo -n "Vérifier et créer si besoin le répertoire local /opt/scodoc-data ?" + read -r ans + if [ "$(norm_ans "$ans")" != 'N' ] + then + set_scodoc_var_dir + fi fi diff --git a/tools/scodoc_config.py b/tools/scodoc_config.py index 7173559aa..6cada0107 100644 --- a/tools/scodoc_config.py +++ b/tools/scodoc_config.py @@ -117,8 +117,8 @@ CONFIG.CUSTOM_HTML_FOOTER_CNX = CONFIG.CUSTOM_HTML_FOOTER # ----------------------------------------------------- # Fichier de correspondance codelycee -> noms -# (chemin relatif au repertoire d'install des sources) -CONFIG.ETABL_FILENAME = "tools/etablissements.csv" +# (dans tools/) +CONFIG.ETABL_FILENAME = "etablissements.csv" # ---------------------------------------------------- diff --git a/tools/scodoc_config_tmpl.py b/tools/scodoc_config_tmpl.py index b13b27dc3..ee757bd70 100644 --- a/tools/scodoc_config_tmpl.py +++ b/tools/scodoc_config_tmpl.py @@ -3,7 +3,7 @@ # # Configuration globale de ScoDoc (version juin 2009) -# Ce fichier est copié dans /opt/scodoc8/var/scodoc/config +# Ce fichier est copié dans /opt/scodoc-data/config # par les scripts d'installation/mise à jour. # La plupart des réglages sont stoqués en base de donnée et accessibles via le web @@ -100,8 +100,7 @@ CONFIG = CFG() # -------------- Noms de Lycées # ----------------------------------------------------- # Fichier de correspondance codelycee -> noms -# (chemin relatif au repertoire d'install des sources) -# CONFIG.ETABL_FILENAME = "tools/etablissements.csv" +# CONFIG.ETABL_FILENAME = "etablissements.csv" # ---------------------------------------------------- diff --git a/tools/scodocutils.py b/tools/scodocutils.py index 5b893dcfe..f5cb036d6 100755 --- a/tools/scodocutils.py +++ b/tools/scodocutils.py @@ -12,12 +12,6 @@ import traceback sys.path.append("..") -# INSTANCE_HOME est nécessaire pour sco_utils.py -# note: avec le python 2.7 de Zope2, l'import de pyscopg2 change -# INSTANCE_HOME dans l'environnement ! -# Ici on le fixe à la "bonne" valeur pour ScoDoc7. -os.environ["INSTANCE_HOME"] = "/opt/scodoc" - def log(msg): "write msg on stderr, add newline and flush" diff --git a/tools/upgrade.sh b/tools/upgrade.sh index 0a451fd1a..940637b89 100644 --- a/tools/upgrade.sh +++ b/tools/upgrade.sh @@ -10,7 +10,10 @@ # # E. Viennet, sep 2013, mar 2017, jun 2019, aug 2020, dec 2020 -cd /opt/scodoc8 || { echo "Invalid directory"; exit 1; } + +A REVOIR : utiliser releases + +cd /opt/scodoc || { echo "Invalid directory"; exit 1; } source config.sh source utils.sh diff --git a/tools/utils.sh b/tools/utils.sh index a13e51953..93f45c5cf 100644 --- a/tools/utils.sh +++ b/tools/utils.sh @@ -72,10 +72,21 @@ check_create_scodoc_user() { # --- Give all ScoDoc files to user "scodoc": change_scodoc_file_ownership() { - echo "Changing owner of $SCODOC_DIR to ${SCODOC_USER}" - chown -R "${SCODOC_USER}:${SCODOC_GROUP}" "$SCODOC_DIR" + echo "Changing owner of ${SCODOC_DIR} to ${SCODOC_USER}" + chown -R "${SCODOC_USER}:${SCODOC_GROUP}" "${SCODOC_DIR}" || die "change_scodoc_file_ownership failed on ${SCODOC_DIR}" } +# Création du répertoire local (scodoc-data) et vérification du propriétaire +set_scodoc_var_dir() { + echo "Checking $SCODOC_VAR_DIR..." + for d in archives photos tmp log config config/version config/depts config/logos + do + [ -d "$SCODOC_VAR_DIR/$d" ] || mkdir "$SCODOC_VAR_DIR/$d" || die "can't create $SCODOC_VAR_DIR/$d subdirectory" + done + chown -R "${SCODOC_USER}:${SCODOC_GROUP}" "${SCODOC_VAR_DIR}" || die "change_scodoc_file_ownership failed on ${SCODOC_VAR_DIR}" +} + + # XXX inutilise gen_passwd() { PASSWORD_LENGTH="8"