forked from ScoDoc/ScoDoc
Ajout/suppression de département en tant qu'utilisateur scodoc (non root)
This commit is contained in:
parent
76a6270740
commit
3d99b8c087
@ -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
|
||||
|
10
scodoc.py
10
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
|
||||
|
@ -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
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user