From 061386e23a772c32a823db7d75e0d5968fec9da8 Mon Sep 17 00:00:00 2001 From: polytan02 Date: Fri, 24 Feb 2017 17:12:32 +0000 Subject: [PATCH] Simpler test to check if user cops-ynh exists or not --- scripts/install | 10 +++++----- scripts/restore | 10 +++++----- scripts/upgrade | 10 +++++----- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/scripts/install b/scripts/install index 09c5fde..54b07db 100755 --- a/scripts/install +++ b/scripts/install @@ -151,14 +151,14 @@ 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 -getent passwd $runninguser > /dev/null 2&>1 -if [ $? -eq 0 ]; then - echo "The user $runninguser exists, no need to create it" -else - echo "No, the user $runninguser does not exist, we can create it" +test="$(grep ^${tuser}: /etc/passwd)" +if [ -n "${test}" ]; 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 \ || ynh_die "Unable to create $runninguser system account" +else + echo "The user $runninguser exists, no need to create it" fi ynh_app_setting_set "$app" runninguser "$runninguser" diff --git a/scripts/restore b/scripts/restore index 8915ba7..3baac84 100755 --- a/scripts/restore +++ b/scripts/restore @@ -45,14 +45,14 @@ 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 -getent passwd $runninguser > /dev/null 2&>1 -if [ $? -eq 0 ]; then - echo "The user $runninguser exists, no need to create it" -else - echo "No, the user $runninguser does not exist, we can create it" +test="$(grep ^${tuser}: /etc/passwd)" +if [ -n "${test}" ]; 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 \ || ynh_die "Unable to create $runninguser system account" +else + echo "The user $runninguser exists, no need to create it" fi ynh_app_setting_set "$app" runninguser "$runninguser" diff --git a/scripts/upgrade b/scripts/upgrade index c7ca64a..aa2eeec 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -83,14 +83,14 @@ 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 -getent passwd $runninguser > /dev/null 2&>1 -if [ $? -eq 0 ]; then - echo "The user $runninguser exists, no need to create it" -else - echo "No, the user $runninguser does not exist, we can create it" +test="$(grep ^${tuser}: /etc/passwd)" +if [ -n "${test}" ]; 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 \ || ynh_die "Unable to create $runninguser system account" +else + echo "The user $runninguser exists, no need to create it" fi ynh_app_setting_set "$app" runninguser "$runninguser"