From 3d99b8c0870b012e0609f3827134c046d48558d4 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Mon, 9 Aug 2021 08:25:33 +0200 Subject: [PATCH] =?UTF-8?q?Ajout/suppression=20de=20d=C3=A9partement=20en?= =?UTF-8?q?=20tant=20qu'utilisateur=20scodoc=20(non=20root)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- scodoc.py | 10 ++-------- tools/create_dept.sh | 21 ++++++--------------- tools/install_debian10.sh | 5 +++++ 4 files changed, 15 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 8ae84c1f..10bf02c1 100644 --- a/README.md +++ b/README.md @@ -168,7 +168,7 @@ de votre installation ScoDoc 7 pour passer à ScoDoc 8 (*ne pas utiliser en prod ## Création d'un département - sudo su + su scodoc # si besoin cd /opt/scodoc source venv/bin/activate flask sco-create-dept DEPT @@ -177,7 +177,7 @@ où `DEPT` est le nom du département (un acronyme en majuscule, comme "RT", "GE ### Suppression d'un département - sudo su + su scodoc # si besoin cd /opt/scodoc source venv/bin/activate flask sco-delete-dept DEPT diff --git a/scodoc.py b/scodoc.py index 9f6a6102..a921f2a2 100755 --- a/scodoc.py +++ b/scodoc.py @@ -152,10 +152,7 @@ def user_password(username, password=None): # user-password @click.argument("dept") def sco_delete_dept(dept): # sco-delete-dept "Delete existing departement" - if os.getuid() != 0: - sys.stderr.write("sco_delete_dept: must be run by root\n") - return 1 - if os.system('cd tools && ./delete_dept.sh -n "{}"'.format(dept)): + if os.system('tools/delete_dept.sh -n "{}"'.format(dept)): sys.stderr.write("error deleting dept " + dept) return 1 return 0 @@ -165,10 +162,7 @@ def sco_delete_dept(dept): # sco-delete-dept @click.argument("dept") def sco_create_dept(dept): # sco-create-dept "Create new departement" - if os.getuid() != 0: - sys.stderr.write("sco_create_dept: must be run by root\n") - return 1 - if os.system(f'cd tools && ./create_dept.sh -n "{dept}"'): + if os.system(f'tools/create_dept.sh -n "{dept}"'): sys.stderr.write(f"error creating dept {dept}\n") return 1 return 0 diff --git a/tools/create_dept.sh b/tools/create_dept.sh index 8eb86036..4d81ce44 100755 --- a/tools/create_dept.sh +++ b/tools/create_dept.sh @@ -17,7 +17,7 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" source "$SCRIPT_DIR/config.sh" source "$SCRIPT_DIR/utils.sh" -check_uid_root "$0" +[ "$USER" = "$SCODOC_USER" ] || die "$0 must run as user $SCODOC_USER" cd "$SCRIPT_DIR" @@ -61,19 +61,17 @@ then exit 1 fi -# --- Ensure postgres user "scodoc" ($POSTGRES_USER) exists -init_postgres_user - # ----------------------- Create Dept database -su -c ./create_database.sh "$POSTGRES_SUPERUSER" +# (créée en tant qu'utilisateur scodoc) +./create_database.sh # ----------------------- Initialize table database # POSTGRES_USER == regular unix user (scodoc) if [ "$interactive" = 1 ] then - su -c ./initialize_database.sh "$POSTGRES_USER" + ./initialize_database.sh else - su -c ./initialize_database.sh "$POSTGRES_USER" > /dev/null 2>&1 + ./initialize_database.sh > /dev/null 2>&1 fi @@ -84,17 +82,10 @@ echo "dbname=${db_name}" > "$cfg_pathname" if [ "$interactive" = 1 ] then - # ----------------------- Force mise à jour - echo -n "Voulez vous mettre a jour ScoDoc (tres recommande) ? (y/n) [y] " - read -r ans - if [ "$(norm_ans "$ans")" != 'N' ] - then - (cd "$SCODOC_DIR/tools" || terminate "no config directory"; ./upgrade.sh) - fi # ----------------------- echo echo " Departement $DEPT cree" echo echo " Attention: la base de donnees n'a pas de copies de sauvegarde" - echo + echo "(XXX section à revoir en ScoDoc 8.1)" # #sco8 fi diff --git a/tools/install_debian10.sh b/tools/install_debian10.sh index df2b9272..cc50925a 100755 --- a/tools/install_debian10.sh +++ b/tools/install_debian10.sh @@ -105,6 +105,11 @@ then yes | ufw enable fi +# --- POSTGRESQL +# --- Ensure postgres user "scodoc" ($POSTGRES_USER) exists +init_postgres_user + + # --- XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX --- echo echo "WARNING: version ScoDoc8 expérimentale"