1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/my_webapp_ynh.git synced 2024-09-03 19:46:26 +02:00
my_webapp_ynh/scripts/actions/sftp
2020-03-25 20:46:16 +01:00

73 lines
2.4 KiB
Bash
Executable file

#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID}
with_sftp=${YNH_ACTION_WITH_SFTP}
user=$(ynh_app_setting_get --app=$app --key=user)
#=================================================
# CHECK IF ARGUMENTS ARE CORRECT
#=================================================
#=================================================
# CHECK IF AN ACTION HAS TO BE DONE
#=================================================
with_sftp_old=$(ynh_app_setting_get --app=$app --key=with_sftp)
if [ $with_sftp -eq $with_sftp_old ]
then
ynh_die --message="with_sftp is already set as $with_sftp." --ret_code=0
fi
#=================================================
# SPECIFIC ACTION
#=================================================
# MOVE TO PUBLIC OR PRIVATE
#=================================================
if [ $with_sftp -eq 1 ]
then
ynh_script_progression --message="Configuring ssh to add a SFTP access..." --weight=3
cp -R conf/ssh_regenconf_hook /usr/share/yunohost/hooks/conf_regen/90-ssh_$app
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file=/usr/share/yunohost/hooks/conf_regen/90-ssh_$app
ynh_replace_string --match_string="__USER__" --replace_string="$user" --target_file=/usr/share/yunohost/hooks/conf_regen/90-ssh_$app
yunohost tools regen-conf ssh
else
ynh_script_progression --message="Removing the custom ssh config for the SFTP access..." --weight=3
sed -i "/##-> ${app}/,/##<- ${app}/d" /etc/ssh/sshd_config
# Remove regen-conf hook
ynh_secure_remove --file="/usr/share/yunohost/hooks/conf_regen/90-ssh_$app"
fi
# Update the config of the app
ynh_app_setting_set --app=$app --key=with_sftp --value=$with_sftp
#=================================================
# RELOAD SSH
#=================================================
ynh_script_progression --message="Reloading SSH..."
ynh_systemd_action --service_name=ssh --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Execution completed" --last