diff --git a/helpers/apps b/helpers/apps index c5fe6cdad..bb60fea59 100644 --- a/helpers/apps +++ b/helpers/apps @@ -126,9 +126,6 @@ ynh_load_app_environment() { # Manage arguments with getopts ynh_handle_getopts_args "$@" - # Retrieve the list of installed apps - local installed_apps_list=($(yunohost app list --output-as json --quiet | jq -r .apps[].id)) - # Force Bash to be used to run this helper if [ $0 != "bash" ] then @@ -137,14 +134,21 @@ ynh_load_app_environment() { fi # Make sure the app is installed + local installed_apps_list=($(yunohost app list --output-as json --quiet | jq -r .apps[].id)) if [[ " ${installed_apps_list[*]} " != *" ${app} "* ]] then ynh_print_err --message="$app is not in the apps list" exit 1 fi + # Make sure the app is installed + if ! id -u "$app" &>/dev/null; then + ynh_print_err --message="There is no \"$app\" system user" + exit 1 + fi + # Make sure the app has an install_dir setting - install_dir="$(yunohost app setting $app install_dir)" + local install_dir="$(yunohost app setting $app install_dir)" if [ -z "$install_dir" ] then ynh_print_err --message="$app has no install_dir setting (does it use packaging format >=2?)" @@ -152,18 +156,21 @@ ynh_load_app_environment() { fi # Load the Environment variables from the app's service - env_var=`systemctl show $app.service -p "Environment" --value` + local env_var=`systemctl show $app.service -p "Environment" --value` [ -n "$env_var" ] && export $env_var; export HOME=$install_dir; # Source the EnvironmentFiles from the app's service - env_files=(`systemctl show $app.service -p "EnvironmentFiles" --value`) + local env_files=(`systemctl show $app.service -p "EnvironmentFiles" --value`) if [ ${#env_files[*]} -gt 0 ] then + # set -/+a enables and disables new variables being automatically exported. Needed when using `source`. + set -a for file in ${env_files[*]} do [[ $file = /* ]] && source $file done + set +a fi # Open the app shell