mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Improve ynh_load_environment helper
This commit is contained in:
parent
d27e9a9eea
commit
68a4f2b4bc
1 changed files with 13 additions and 6 deletions
19
helpers/apps
19
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
|
||||
|
|
Loading…
Add table
Reference in a new issue