helpers 2.1: fix indent

This commit is contained in:
Alexandre Aubin 2024-05-27 20:20:12 +02:00
parent 365d0b25af
commit 422e02244d

View file

@ -125,89 +125,89 @@ ynh_remove_apps() {
# from the app's service configuration file (defaults to $app.service, overridable by the packager with `service` setting). # from the app's service configuration file (defaults to $app.service, overridable by the packager with `service` setting).
# If the app relies on a specific PHP version, then `php` will be aliased that version. The PHP command will also be appended with the `phpflags` settings. # If the app relies on a specific PHP version, then `php` will be aliased that version. The PHP command will also be appended with the `phpflags` settings.
ynh_spawn_app_shell() { ynh_spawn_app_shell() {
# ============ Argument parsing ============= # ============ Argument parsing =============
local -A args_array=([a]=app=) local -A args_array=([a]=app=)
local app local app
ynh_handle_getopts_args "$@" ynh_handle_getopts_args "$@"
# =========================================== # ===========================================
# Force Bash to be used to run this helper # Force Bash to be used to run this helper
if [[ ! $0 =~ \/?bash$ ]] if [[ ! $0 =~ \/?bash$ ]]
then then
ynh_print_err --message="Please use Bash as shell" ynh_print_err --message="Please use Bash as shell"
exit 1 exit 1
fi fi
# Make sure the app is installed # Make sure the app is installed
local installed_apps_list=($(yunohost app list --output-as json --quiet | jq -r .apps[].id)) local installed_apps_list=($(yunohost app list --output-as json --quiet | jq -r .apps[].id))
if [[ " ${installed_apps_list[*]} " != *" ${app} "* ]] if [[ " ${installed_apps_list[*]} " != *" ${app} "* ]]
then then
ynh_print_err --message="$app is not in the apps list" ynh_print_err --message="$app is not in the apps list"
exit 1 exit 1
fi fi
# Make sure the app has its own user # Make sure the app has its own user
if ! id -u "$app" &>/dev/null; then if ! id -u "$app" &>/dev/null; then
ynh_print_err --message="There is no \"$app\" system user" ynh_print_err --message="There is no \"$app\" system user"
exit 1 exit 1
fi fi
# Make sure the app has an install_dir setting # Make sure the app has an install_dir setting
local install_dir=$(ynh_app_setting_get --key=install_dir) local install_dir=$(ynh_app_setting_get --key=install_dir)
if [ -z "$install_dir" ] if [ -z "$install_dir" ]
then then
ynh_print_err --message="$app has no install_dir setting (does it use packaging format >=2?)" ynh_print_err --message="$app has no install_dir setting (does it use packaging format >=2?)"
exit 1 exit 1
fi fi
# Load the app's service name, or default to $app # Load the app's service name, or default to $app
local service=$(ynh_app_setting_get --key=service) local service=$(ynh_app_setting_get --key=service)
[ -z "$service" ] && service=$app; [ -z "$service" ] && service=$app;
# Export HOME variable # Export HOME variable
export HOME=$install_dir; export HOME=$install_dir;
# Load the Environment variables from the app's service # Load the Environment variables from the app's service
local env_var=$(systemctl show $service.service -p "Environment" --value) local env_var=$(systemctl show $service.service -p "Environment" --value)
[ -n "$env_var" ] && export $env_var; [ -n "$env_var" ] && export $env_var;
# Force `php` to its intended version # Force `php` to its intended version
# We use `eval`+`export` since `alias` is not propagated to subshells, even with `export` # We use `eval`+`export` since `alias` is not propagated to subshells, even with `export`
local phpversion=$(ynh_app_setting_get --key=phpversion) local phpversion=$(ynh_app_setting_get --key=phpversion)
local phpflags=$(ynh_app_setting_get --key=phpflags) local phpflags=$(ynh_app_setting_get --key=phpflags)
if [ -n "$phpversion" ] if [ -n "$phpversion" ]
then then
eval "php() { php${phpversion} ${phpflags} \"\$@\"; }" eval "php() { php${phpversion} ${phpflags} \"\$@\"; }"
export -f php export -f php
fi fi
# Source the EnvironmentFiles from the app's service # Source the EnvironmentFiles from the app's service
local env_files=($(systemctl show $service.service -p "EnvironmentFiles" --value)) local env_files=($(systemctl show $service.service -p "EnvironmentFiles" --value))
if [ ${#env_files[*]} -gt 0 ] if [ ${#env_files[*]} -gt 0 ]
then then
# set -/+a enables and disables new variables being automatically exported. Needed when using `source`. # set -/+a enables and disables new variables being automatically exported. Needed when using `source`.
set -a set -a
for file in ${env_files[*]} for file in ${env_files[*]}
do do
[[ $file = /* ]] && source $file [[ $file = /* ]] && source $file
done done
set +a set +a
fi fi
# Activate the Python environment, if it exists # Activate the Python environment, if it exists
if [ -f $install_dir/venv/bin/activate ] if [ -f $install_dir/venv/bin/activate ]
then then
# set -/+a enables and disables new variables being automatically exported. Needed when using `source`. # set -/+a enables and disables new variables being automatically exported. Needed when using `source`.
set -a set -a
source $install_dir/venv/bin/activate source $install_dir/venv/bin/activate
set +a set +a
fi fi
# cd into the WorkingDirectory set in the service, or default to the install_dir # cd into the WorkingDirectory set in the service, or default to the install_dir
local env_dir=$(systemctl show $service.service -p "WorkingDirectory" --value) local env_dir=$(systemctl show $service.service -p "WorkingDirectory" --value)
[ -z $env_dir ] && env_dir=$install_dir; [ -z $env_dir ] && env_dir=$install_dir;
cd $env_dir cd $env_dir
# Spawn the app shell # Spawn the app shell
su -s /bin/bash $app su -s /bin/bash $app
} }