1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/my_webapp_ynh.git synced 2024-09-03 19:46:26 +02:00

configpanel update with_sftp

This commit is contained in:
Tagadda 2022-01-31 12:48:53 +00:00
parent 0617fcaab7
commit 3c2b4bc2a7
3 changed files with 67 additions and 3 deletions

View file

@ -7,7 +7,7 @@ name = "My webapp configuration"
[main.sftp] [main.sftp]
name = "SFTP access" name = "SFTP access"
[main.sftp.sftp] [main.sftp.with_sftp]
ask = "Do you need a SFTP access?" ask = "Do you need a SFTP access?"
type = "boolean" type = "boolean"
default = true default = true
@ -16,7 +16,8 @@ name = "My webapp configuration"
ask = "Set a password for the SFTP access" ask = "Set a password for the SFTP access"
type = "password" type = "password"
optional = true optional = true
help = "If a password already exist, it will not be replaced." visible = "stfp"
help = "If a password already exist, leave blank and it will not be replaced."
[main.php_fpm_config] [main.php_fpm_config]
name = "PHP-FPM configuration" name = "PHP-FPM configuration"

View file

@ -365,3 +365,38 @@ ynh_app_changelog () {
echo "No significative changes from the changelog..." > "${final_changelog}_lite" echo "No significative changes from the changelog..." > "${final_changelog}_lite"
fi fi
} }
ynh_system_user_add_group() {
# Declare an array to define the options of this helper.
local legacy_args=uhs
local -A args_array=([u]=username= [g]=groups=)
local username
local groups
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
groups="${groups:-}"
local group
for group in $groups; do
usermod -a -G "$group" "$username"
done
}
ynh_system_user_del_group() {
# Declare an array to define the options of this helper.
local legacy_args=uhs
local -A args_array=([u]=username= [g]=groups=)
local username
local groups
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
groups="${groups:-}"
local group
for group in $groups; do
gpasswd -d "$username" "$group"
done
}

View file

@ -20,6 +20,13 @@ final_path=$(ynh_app_setting_get $app final_path)
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
current_fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint) current_fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint)
is_password_exist=0
current_password=$(ynh_app_setting_get --app=$app --key=password)
if [ -n "$current_password" ]
then
is_password_exist=1
fi
#================================================= #=================================================
# SPECIFIC GETTERS FOR TOML SHORT KEY # SPECIFIC GETTERS FOR TOML SHORT KEY
#================================================= #=================================================
@ -47,7 +54,6 @@ get__free_footprint() {
fi fi
} }
#================================================= #=================================================
# SPECIFIC VALIDATORS FOR TOML SHORT KEYS # SPECIFIC VALIDATORS FOR TOML SHORT KEYS
#================================================= #=================================================
@ -70,6 +76,13 @@ set__free_footprint() {
fi fi
} }
set__password() {
if [ ! $is_password_exist -eq 1 ]
then
ynh_app_setting_set --app=$app --key=password --value="$password"
fi
}
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
#================================================= #=================================================
@ -97,6 +110,21 @@ ynh_app_config_apply() {
_ynh_app_config_apply _ynh_app_config_apply
ynh_add_fpm_config --phpversion=$phpversion --usage=$fpm_usage --footprint=$fpm_footprint ynh_add_fpm_config --phpversion=$phpversion --usage=$fpm_usage --footprint=$fpm_footprint
if [ $with_sftp -eq 1 ]
then
ynh_system_user_add_group --username=$app --groups="sftp.app"
if [ $is_password_exist -eq 1 ]
then
ynh_print_warn --message="A password already exist, it will not be replaced."
else
# Add the password to the user
chpasswd <<< "${app}:${password}"
fi
else
ynh_system_user_del_group --username=$app --groups="sftp.app"
fi
} }
ynh_app_config_run $1 ynh_app_config_run $1