From 383fdb0e53e6e7091073d8755dd8f11ddaf150e6 Mon Sep 17 00:00:00 2001 From: IDK Date: Mon, 2 Aug 2021 11:34:28 +0300 Subject: [PATCH] modified to run as tools/script.sh --- tools/create_dept.sh | 9 +++- tools/create_users_database.sh | 8 +++- tools/delete_dept.sh | 6 ++- tools/diagnostic.sh | 8 ++-- tools/initialize_database.sh | 7 ++- tools/install_debian10.sh | 7 ++- tools/make-release.sh | 1 + tools/postupgrade-db.py | 80 +++++++++++++++++----------------- tools/restore_scodoc_data.sh | 8 +++- tools/save_scodoc_data.sh | 8 +++- tools/scodocutils.py | 9 ++-- tools/upgrade.sh | 11 +++-- 12 files changed, 97 insertions(+), 65 deletions(-) diff --git a/tools/create_dept.sh b/tools/create_dept.sh index 8386b04d2..8eb86036a 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 cc8b501cd..afcd8292e 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 7956a995e..6ebaff947 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 5d7ba2bb8..abd8657f5 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 7d126b7ed..ac7ba3440 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 aaa1aa5f1..df2b92725 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 a045d799c..4e7457c31 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 e4a4f50bb..613d5482d 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 bba6c1043..90a88f4f6 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 8e98f2781..9dc7e6c1f 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 9c378992a..21c1536f3 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 940637b89..34d628182 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"