mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
removal simplification
This commit is contained in:
parent
85ddb4a8a0
commit
a07328c99d
1 changed files with 72 additions and 54 deletions
124
helpers/app
124
helpers/app
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Install other YunoHost apps
|
# Install other YunoHost apps when they are not multi-instance
|
||||||
#
|
#
|
||||||
# usage: ynh_install_apps --apps="appfoo appbar?domain=DOMAIN&path=PATH&admin=USER&language=fr&is_public=1&password=pass&port=666"
|
# usage: ynh_install_apps --apps="appfoo appbar?domain=DOMAIN&path=PATH&admin=USER&language=fr&is_public=1&password=pass&port=666"
|
||||||
# | arg: -a, --apps= - apps to install
|
# | arg: -a, --apps= - apps to install
|
||||||
|
@ -16,78 +16,96 @@ ynh_install_apps() {
|
||||||
|
|
||||||
# Split the list of apps in an array
|
# Split the list of apps in an array
|
||||||
local apps_list=($(echo $apps | tr " " "\n"))
|
local apps_list=($(echo $apps | tr " " "\n"))
|
||||||
|
local apps_dependencies=""
|
||||||
|
|
||||||
# For each app
|
# For each app
|
||||||
for oneapp_and_its_args in "${apps_list[@]}"
|
for one_app_and_its_args in "${apps_list[@]}"
|
||||||
do
|
do
|
||||||
# Retrieve the name of the app (part before _ynh)
|
# Retrieve the name of the app (part before ?)
|
||||||
local oneapp=$(echo "$oneapp_and_its_args" | awk -F'?' '{print $1}')
|
local one_app=$(echo "$one_app_and_its_args" | awk -F'?' '{print $1}')
|
||||||
[ -z "$oneapp" ] && ynh_die --message="You didn't provided a YunoHost app to install"
|
[ -z "$one_app" ] && ynh_die --message="You didn't provided a YunoHost app to install"
|
||||||
|
|
||||||
# Retrieve the arguments of the app (part after ?)
|
|
||||||
local oneargument=$(echo "$oneapp_and_its_args" | awk -F'?' '{print $2}')
|
|
||||||
[ ! -z "$oneargument" ] && oneargument="--args \"$oneargument\""
|
|
||||||
|
|
||||||
# Installing or upgrading the app
|
|
||||||
yunohost tools update apps
|
yunohost tools update apps
|
||||||
if ! yunohost app list --output-as json --quiet | jq -e --arg id $oneapp '.apps[] | select(.id == $id)' >/dev/null
|
|
||||||
|
# Installing or upgrading the app depending if it's installed or not
|
||||||
|
if ! yunohost app list --output-as json --quiet | jq -e --arg id $one_app '.apps[] | select(.id == $id)' >/dev/null
|
||||||
then
|
then
|
||||||
yunohost app install $oneapp $oneargument
|
# Retrieve the arguments of the app (part after ?)
|
||||||
|
local one_argument=$(echo "$one_app_and_its_args" | awk -F'?' '{print $2}')
|
||||||
|
[ ! -z "$one_argument" ] && one_argument="--args \"$one_argument\""
|
||||||
|
|
||||||
|
# Install the app with its arguments
|
||||||
|
yunohost app install $one_app $one_argument
|
||||||
else
|
else
|
||||||
yunohost app upgrade $oneapp $oneargument
|
# Upgrade the app
|
||||||
|
yunohost app upgrade $one_app
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -z "$apps_dependencies" ]
|
||||||
|
then
|
||||||
|
apps_dependencies="$apps_dependencies, $one_app"
|
||||||
|
else
|
||||||
|
apps_dependencies="$one_app"
|
||||||
fi
|
fi
|
||||||
ynh_app_setting_set --app=$app --key=require_$oneapp --value="1"
|
|
||||||
done
|
done
|
||||||
|
|
||||||
|
ynh_app_setting_set --app=$app --key=apps_dependencies --value="$apps_dependencies"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Remove other YunoHost apps
|
# Remove other YunoHost apps
|
||||||
#
|
#
|
||||||
# apps will be removed only if no other apps need them.
|
# Other YunoHost apps will be removed only if no other apps need them.
|
||||||
#
|
#
|
||||||
# usage: ynh_remove_apps --apps="appfoo appbar?domain=DOMAIN&path=PATH&admin=USER&language=fr&is_public=1&password=pass&port=666"
|
# usage: ynh_remove_apps
|
||||||
# | arg: -a, --apps= - apps to install
|
|
||||||
#
|
#
|
||||||
# Requires YunoHost version *.*.* or higher.
|
# Requires YunoHost version *.*.* or higher.
|
||||||
ynh_remove_apps() {
|
ynh_remove_apps() {
|
||||||
# Declare an array to define the options of this helper.
|
|
||||||
local legacy_args=a
|
|
||||||
local -A args_array=([a]=app=)
|
|
||||||
local app
|
|
||||||
# Manage arguments with getopts
|
|
||||||
ynh_handle_getopts_args "$@"
|
|
||||||
|
|
||||||
# Split the list of apps in an array
|
# Retrieve the apps dependencies of the app
|
||||||
local apps_list=($(echo $apps | tr " " "\n"))
|
local apps_dependencies=$(ynh_app_setting_get --app=$app --key=apps_dependencies) || true
|
||||||
|
ynh_app_setting_delete --app=$app --key=apps_dependencies || true
|
||||||
|
|
||||||
# For each app
|
if [ ! -z "$apps_dependencies" ]
|
||||||
for i in "${apps_list[@]}"
|
then
|
||||||
do
|
# Split the list of apps dependencies in an array
|
||||||
# Retrieve the name of the app (part before _ynh)
|
local apps_dependencies_list=($(echo $apps_dependencies | tr ", " "\n"))
|
||||||
local oneapp=$(echo "$i" | awk -F'?' '{print $1}')
|
|
||||||
[ -z "$oneapp" ] && ynh_die --message="You didn't provided a YunoHost app to remove"
|
|
||||||
|
|
||||||
ynh_app_setting_delete --app=$app --key=require_$oneapp
|
# For each apps dependencies
|
||||||
|
for one_app in "${apps_dependencies_list[@]}"
|
||||||
# List apps requiring $oneapp
|
|
||||||
local installed_apps=$(yunohost app list --output-as json --quiet | jq -r .apps[].id)
|
|
||||||
local required_by=""
|
|
||||||
local installed_app_required_by=""
|
|
||||||
for installed_app in $installed_apps
|
|
||||||
do
|
do
|
||||||
local installed_app_required_by=$(ynh_app_setting_get --app=$installed_app --key="require_$oneapp")
|
# Retrieve the list of installed apps
|
||||||
if [[ -n "$installed_app_required_by" ]]
|
local installed_apps_list=$(yunohost app list --output-as json --quiet | jq -r .apps[].id)
|
||||||
then
|
local required_by=""
|
||||||
required_by="${installed_app_required_by}"
|
local installed_app_required_by=""
|
||||||
fi
|
|
||||||
installed_app_required_by=""
|
|
||||||
done
|
|
||||||
|
|
||||||
# If $oneapp is no more required
|
# For each other installed app
|
||||||
if [[ -z "$required_by" ]]
|
for one_installed_app in $installed_apps_list
|
||||||
then
|
do
|
||||||
# Remove $oneapp
|
# Retrieve the other apps dependencies
|
||||||
ynh_print_info --message="Removing of $oneapp"
|
one_installed_apps_dependencies=$(ynh_app_setting_get --app=$one_installed_app --key=apps_dependencies)
|
||||||
yunohost app remove $oneapp --purge
|
if [ ! -z "$one_installed_apps_dependencies" ]
|
||||||
fi
|
then
|
||||||
done
|
one_installed_apps_dependencies_list=($(echo $one_installed_apps_dependencies | tr ", " "\n"))
|
||||||
|
|
||||||
|
# For each dependency of the other apps
|
||||||
|
for one_installed_app_dependency in "${one_installed_apps_dependencies_list[@]}"
|
||||||
|
do
|
||||||
|
if [[ $one_installed_app_dependency == $one_app ]]; then
|
||||||
|
required_by="$required_by $one_installed_app"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# If $one_app is no more required
|
||||||
|
if [[ -z "$required_by" ]]
|
||||||
|
then
|
||||||
|
# Remove $one_app
|
||||||
|
ynh_print_info --message="Removing of $one_app"
|
||||||
|
yunohost app remove $one_app --purge
|
||||||
|
else
|
||||||
|
ynh_print_info --message="$one_app was not removed because it's still required by${required_by}"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue