diff --git a/tools/create_dept.sh b/tools/create_dept.sh index 8386b04d21..8eb86036a2 100755 --- a/tools/create_dept.sh +++ b/tools/create_dept.sh @@ -11,11 +11,16 @@ set -eo pipefail -source config.sh -source utils.sh +# 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" check_uid_root "$0" +cd "$SCRIPT_DIR" + usage() { echo "$0 [-n DEPT]" echo "(default to interactive mode)" diff --git a/tools/create_users_database.sh b/tools/create_users_database.sh index cc8b501cdb..afcd8292e5 100755 --- a/tools/create_users_database.sh +++ b/tools/create_users_database.sh @@ -5,8 +5,12 @@ # # $db_name is passed as an environment variable -source config.sh -source utils.sh +# 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" + check_uid_root "$0" diff --git a/tools/delete_dept.sh b/tools/delete_dept.sh index 7956a995ef..6ebaff9477 100755 --- a/tools/delete_dept.sh +++ b/tools/delete_dept.sh @@ -13,9 +13,11 @@ # E. Viennet, Sept 2008 # +# Le répertoire de ce script: +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" -source config.sh -source utils.sh +source "$SCRIPT_DIR/config.sh" +source "$SCRIPT_DIR/utils.sh" check_uid_root "$0" usage() { diff --git a/tools/diagnostic.sh b/tools/diagnostic.sh index 5d7ba2bb89..abd8657f58 100755 --- a/tools/diagnostic.sh +++ b/tools/diagnostic.sh @@ -104,11 +104,11 @@ ps auxww > "$TMP"/ps.out df -h > "$TMP"/df.out dpkg -l > "$TMP"/dpkg.lst -(cd "$SCODOC_HOME"; git status > "$TMP"/git.status) -(cd "$SCODOC_HOME"; git diff > "$TMP"/git.diff) +(cd "$SCODOC_DIR"; git status > "$TMP"/git.status) +(cd "$SCODOC_DIR"; git diff > "$TMP"/git.diff) -(cd "$SCODOC_HOME"; git log -n 5 > "$TMP"/git.log) -ls -laR "$SCODOC_HOME" > "$TMP"/ls-laR +(cd "$SCODOC_DIR"; git log -n 5 > "$TMP"/git.log) +ls -laR "$SCODOC_DIR" > "$TMP"/ls-laR # ------------------------------------- diff --git a/tools/initialize_database.sh b/tools/initialize_database.sh index 7d126b7edb..ac7ba3440e 100755 --- a/tools/initialize_database.sh +++ b/tools/initialize_database.sh @@ -5,8 +5,11 @@ # # $db_name and $DEPT passed as environment variables -source config.sh -source utils.sh +# 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" if [ "$(id -nu)" != "$SCODOC_USER" ] then diff --git a/tools/install_debian10.sh b/tools/install_debian10.sh index aaa1aa5f15..df2b92725f 100755 --- a/tools/install_debian10.sh +++ b/tools/install_debian10.sh @@ -8,8 +8,11 @@ # Jun 2019, Oct 2019, Dec 2020, Jul 2021 # -source config.sh -source utils.sh +# 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" check_uid_root "$0" diff --git a/tools/make-release.sh b/tools/make-release.sh index a045d799cc..4e7457c310 100755 --- a/tools/make-release.sh +++ b/tools/make-release.sh @@ -1,6 +1,7 @@ #!/bin/bash # INUTILE +XXX # Préparation d'une release ScoDoc # Download last git diff --git a/tools/postupgrade-db.py b/tools/postupgrade-db.py index e4a4f50bbb..613d5482d6 100755 --- a/tools/postupgrade-db.py +++ b/tools/postupgrade-db.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python # -*- coding: utf-8 -*- """ @@ -15,7 +15,7 @@ existing scodoc instances). E. Viennet, june 2008, sept 2013 """ -from tools.scodocutils import * +from scodocutils import * for dept in get_depts(): log("\nChecking database for dept %s" % dept) @@ -30,8 +30,6 @@ for dept in get_depts(): continue cnx.set_session(autocommit=False) cursor = cnx.cursor() - print "passing !" - continue # Apply upgrades: # SVN 564 -> 565 @@ -1072,43 +1070,43 @@ for dept in get_depts(): # Base utilisateurs: -log("\nChecking users database") -cnx = psycopg2.connect(get_users_cnx_str()) -cursor = cnx.cursor() -check_field( - cnx, - "sco_users", - "passwd_temp", - [ - "alter table sco_users add column passwd_temp int default 0", - "update sco_users set passwd_temp=0", - ], -) -check_field( - cnx, - "sco_users", - "status", - ["alter table sco_users add column status text default NULL"], -) -check_field( - cnx, - "sco_users", - "date_expiration", - [ - "alter table sco_users add column date_expiration date", - "update sco_users set status=NULL where status=''", # fix a bug in previous update... - ], -) -check_field( - cnx, - "sco_users", - "login_edt", - [ - "alter table sco_users add column login_edt text default NULL", - ], -) -cnx.commit() -cnx.close() +log("\nNOT Checking users database") +# cnx = psycopg2.connect(get_users_cnx_str()) +# cursor = cnx.cursor() +# check_field( +# cnx, +# "sco_users", +# "passwd_temp", +# [ +# "alter table sco_users add column passwd_temp int default 0", +# "update sco_users set passwd_temp=0", +# ], +# ) +# check_field( +# cnx, +# "sco_users", +# "status", +# ["alter table sco_users add column status text default NULL"], +# ) +# check_field( +# cnx, +# "sco_users", +# "date_expiration", +# [ +# "alter table sco_users add column date_expiration date", +# "update sco_users set status=NULL where status=''", # fix a bug in previous update... +# ], +# ) +# check_field( +# cnx, +# "sco_users", +# "login_edt", +# [ +# "alter table sco_users add column login_edt text default NULL", +# ], +# ) +# cnx.commit() +# cnx.close() # The end. sys.exit(0) diff --git a/tools/restore_scodoc_data.sh b/tools/restore_scodoc_data.sh index bba6c10438..90a88f4f6e 100755 --- a/tools/restore_scodoc_data.sh +++ b/tools/restore_scodoc_data.sh @@ -9,8 +9,12 @@ # E. Viennet, Sept 2011, Nov 2013, Mar 2017, Aug 2020, Jul 2021 # -source config.sh -source utils.sh +# 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" + check_uid_root "$0" # Safety check diff --git a/tools/save_scodoc_data.sh b/tools/save_scodoc_data.sh index 8e98f2781e..9dc7e6c1fc 100755 --- a/tools/save_scodoc_data.sh +++ b/tools/save_scodoc_data.sh @@ -8,8 +8,12 @@ # # E. Viennet, Sept 2011, Aug 2020, Jul 2021 # -source config.sh -source utils.sh +# 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" + check_uid_root "$0" diff --git a/tools/scodocutils.py b/tools/scodocutils.py index 9c378992a0..21c1536f34 100755 --- a/tools/scodocutils.py +++ b/tools/scodocutils.py @@ -2,15 +2,18 @@ """ Some utilities used by upgrade scripts + XXX python2 XXX """ import glob import os +import psycopg2 import sys import traceback -from config import Config +SCODOC_DIR = os.environ.get("SCODOC_DIR", "/opt/scodoc") +SCODOC_VAR_DIR = os.environ.get("SCODOC_VAR_DIR", "/opt/scodoc-data") def log(msg): @@ -22,7 +25,7 @@ def log(msg): def get_dept_cnx_str(dept): "db cnx string for dept" - f = os.path.join(Config.SCODOC_VAR_DIR, "config", "depts", dept + ".cfg") + f = os.path.join(SCODOC_VAR_DIR, "config", "depts", dept + ".cfg") try: return open(f).readline().strip() except: @@ -33,7 +36,7 @@ def get_dept_cnx_str(dept): def get_depts(): "list of defined depts" - files = glob.glob(Config.SCODOC_VAR_DIR + "/config/depts/*.cfg") + files = glob.glob(SCODOC_VAR_DIR + "/config/depts/*.cfg") return [os.path.splitext(os.path.split(f)[1])[0] for f in files] diff --git a/tools/upgrade.sh b/tools/upgrade.sh index 940637b898..34d628182b 100644 --- a/tools/upgrade.sh +++ b/tools/upgrade.sh @@ -13,9 +13,14 @@ A REVOIR : utiliser releases -cd /opt/scodoc || { echo "Invalid directory"; exit 1; } -source config.sh -source utils.sh +# 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" + +cd "$SCODOC_DIR" || { echo "Invalid directory"; exit 1; } + check_uid_root "$0"