From d2811d9103d251f9f5a80dc39956fbb33f9c046f Mon Sep 17 00:00:00 2001 From: polytan02 Date: Fri, 24 Feb 2017 17:24:17 +0000 Subject: [PATCH] Test if the user exists with ERR code if not --- scripts/install | 5 +++-- scripts/restore | 6 ++++-- scripts/upgrade | 6 ++++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/scripts/install b/scripts/install index 0ca5d72..b23e164 100755 --- a/scripts/install +++ b/scripts/install @@ -151,8 +151,9 @@ sudo cp ../conf/robots.txt $final_path runninguser="${app}-ynh" # 1. Create the user # Create a system account for COPS if it doesn't already exists -test="$(sudo grep ^${runninguser}: /etc/passwd)" -if [ -n "${test}" ]; then +check_user="$(sudo grep ^${runninguser}: /etc/passwd)" +if [ -z "${check_user}" ]; +then echo "The user $runninguser does not exist, we can create it" sudo useradd -c "$runninguser system account" \ -d $final_path --system --user-group $runninguser \ diff --git a/scripts/restore b/scripts/restore index a7009be..8c3de9b 100755 --- a/scripts/restore +++ b/scripts/restore @@ -45,8 +45,9 @@ sudo cp -a ./sources/* $final_path/ runninguser="${app}-ynh" # 1. Create the user # Create a system account for COPS if it doesn't already exists -test="$(sudo grep ^${runninguser}: /etc/passwd)" -if [ -n "${test}" ]; then +check_user="$(sudo grep ^${runninguser}: /etc/passwd)" +if [ -z "${check_user}" ]; +then echo "The user $runninguser does not exist, we can create it" sudo useradd -c "$runninguser system account" \ -d $final_path --system --user-group $runninguser \ @@ -54,6 +55,7 @@ if [ -n "${test}" ]; then else echo "The user $runninguser exists, no need to create it" fi + ynh_app_setting_set "$app" runninguser "$runninguser" # 2. Add cops-ynh to groups www-data and nextcloud/owncloud if they exist diff --git a/scripts/upgrade b/scripts/upgrade index a9ed45b..cd0e5c7 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -83,8 +83,9 @@ sudo cp ../conf/robots.txt $final_path runninguser="${app}-ynh" # 1. Create the user # Create a system account for COPS if it doesn't already exists -test="$(sudo grep ^${runninguser}: /etc/passwd)" -if [ -n "${test}" ]; then +check_user="$(sudo grep ^${runninguser}: /etc/passwd)" +if [ -z "${check_user}" ]; +then echo "The user $runninguser does not exist, we can create it" sudo useradd -c "$runninguser system account" \ -d $final_path --system --user-group $runninguser \ @@ -92,6 +93,7 @@ if [ -n "${test}" ]; then else echo "The user $runninguser exists, no need to create it" fi + ynh_app_setting_set "$app" runninguser "$runninguser" # 2. Add cops-ynh to groups www-data and nextcloud/owncloud if they exist