mirror of
https://github.com/YunoHost-Apps/lutim_ynh.git
synced 2024-09-03 19:36:24 +02:00
New reset actions
This commit is contained in:
parent
e481e03e05
commit
e1c90a7c1b
5 changed files with 266 additions and 1 deletions
29
actions.toml
29
actions.toml
|
@ -21,3 +21,32 @@ name = "Reset the config file and restore a default one."
|
|||
command = "/bin/bash scripts/actions/reset_default_config \"lutim.conf\""
|
||||
accepted_return_codes = [0]
|
||||
description = "Reset the config file lutim.conf."
|
||||
|
||||
|
||||
[reset_default_nginx]
|
||||
name = "Reset the nginx config for this app."
|
||||
command = "/bin/bash scripts/actions/reset_default_system nginx"
|
||||
# user = "root" # optional
|
||||
# cwd = "/" # optional
|
||||
# accepted_return_codes = [0, 1, 2, 3] # optional
|
||||
accepted_return_codes = [0]
|
||||
description = "Reset the nginx config for this app."
|
||||
|
||||
[reset_default_systemd]
|
||||
name = "Reset the systemd config for this app."
|
||||
command = "/bin/bash scripts/actions/reset_default_system systemd"
|
||||
# user = "root" # optional
|
||||
# cwd = "/" # optional
|
||||
# accepted_return_codes = [0, 1, 2, 3] # optional
|
||||
accepted_return_codes = [0]
|
||||
description = "Reset the systemd config for this app."
|
||||
|
||||
|
||||
[reset_default_app]
|
||||
name = "Reset the app with a default configuration."
|
||||
command = "/bin/bash scripts/actions/reset_default_app"
|
||||
# user = "root" # optional
|
||||
# cwd = "/" # optional
|
||||
# accepted_return_codes = [0, 1, 2, 3] # optional
|
||||
accepted_return_codes = [0]
|
||||
description = "Reset the app to its default configuration to try to fix potential issues.<br>This action won't remove any data added to the app.<br>However, if you have modified any configuration, it will be overwritten."
|
||||
|
|
|
@ -4,6 +4,15 @@
|
|||
path="/path" (PATH)
|
||||
is_public=1 (PUBLIC|public=1|private=0)
|
||||
always_encrypt=1
|
||||
; Actions
|
||||
; Config_panel
|
||||
main.configuration.always_encrypt=0|1
|
||||
main.configuration.antiflood=10
|
||||
main.configuration.delay=None|Day|Week|Month|Year
|
||||
main.overwrite_files.overwrite_settings=0|1
|
||||
main.overwrite_files.overwrite_nginx=0|1
|
||||
main.overwrite_files.overwrite_systemd=0|1
|
||||
main.global_config.email_type=0|1
|
||||
; Checks
|
||||
pkg_linter=1
|
||||
setup_sub_dir=1
|
||||
|
@ -17,6 +26,8 @@
|
|||
multi_instance=0
|
||||
port_already_use=1 (8095)
|
||||
change_url=1
|
||||
actions=1
|
||||
config_panel=1
|
||||
;;; Levels
|
||||
Level 5=auto
|
||||
;;; Options
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
"en": "Self hosting images and sharing anonymous application",
|
||||
"fr": "Application d'hébergement et de partage d'images anonyme"
|
||||
},
|
||||
"version": "0.11.6~ynh3",
|
||||
"version": "0.11.6~ynh4",
|
||||
"url": "https://lut.im",
|
||||
"license": "AGPL-3.0",
|
||||
"maintainer": {
|
||||
|
|
158
scripts/actions/reset_default_app
Executable file
158
scripts/actions/reset_default_app
Executable file
|
@ -0,0 +1,158 @@
|
|||
#!/bin/bash
|
||||
|
||||
#=================================================
|
||||
# GENERIC STARTING
|
||||
#=================================================
|
||||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
# Load common variables for all scripts.
|
||||
source scripts/_variables
|
||||
|
||||
source scripts/_common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# MANAGE SCRIPT FAILURE
|
||||
#=================================================
|
||||
|
||||
ynh_clean_setup () {
|
||||
# Clean installation remaining that are not handle by the remove script.
|
||||
ynh_clean_check_starting
|
||||
}
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
#=================================================
|
||||
# RETRIEVE ARGUMENTS
|
||||
#=================================================
|
||||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
||||
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
|
||||
port=$(ynh_app_setting_get --app=$app --key=port)
|
||||
always_encrypt=$(ynh_app_setting_get --app=$app --key=always_encrypt)
|
||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||
secret=$(ynh_app_setting_get --app=$app --key=secret)
|
||||
|
||||
#=================================================
|
||||
# STORE SETTINGS FROM MANIFEST
|
||||
#=================================================
|
||||
|
||||
ynh_app_setting_set --app=$app --key=overwrite_settings --value=1
|
||||
ynh_app_setting_set --app=$app --key=overwrite_nginx --value=1
|
||||
ynh_app_setting_set --app=$app --key=overwrite_systemd --value=1
|
||||
ynh_app_setting_set --app=$app --key=admin_mail_html --value=1
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC ACTION
|
||||
#=================================================
|
||||
# ACTIVATE MAINTENANCE MODE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Activating maintenance mode..."
|
||||
|
||||
ynh_maintenance_mode_ON
|
||||
|
||||
#=================================================
|
||||
# STOP LUTIM
|
||||
#=================================================
|
||||
|
||||
ynh_systemd_action --action=stop
|
||||
|
||||
#=================================================
|
||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Resetting source files..." --weight=2
|
||||
|
||||
# Download, check integrity, uncompress and patch the source from app.src
|
||||
(cd scripts; YNH_CWD=$PWD ynh_setup_source --dest_dir="$final_path")
|
||||
|
||||
#=================================================
|
||||
# NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Resetting nginx web server configuration..." --weight=4
|
||||
|
||||
# Create a dedicated nginx config
|
||||
yunohost app action run $app reset_default_nginx
|
||||
|
||||
#=================================================
|
||||
# CREATE DEDICATED USER
|
||||
#=================================================
|
||||
ynh_script_progression --message="Making sure dedicated system user exists..."
|
||||
|
||||
# Create a dedicated user (if not existing)
|
||||
ynh_system_user_create --username=$app
|
||||
|
||||
#=================================================
|
||||
# RECONFIGURE APP
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Reconfiguring Lutim..." --weight=2
|
||||
|
||||
# Configure Lutim
|
||||
# Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script.
|
||||
ynh_backup_if_checksum_is_different --file="$final_path/lutim.conf"
|
||||
(cd scripts; cp ../conf/lutim.conf.template "$final_path/lutim.conf")
|
||||
ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/lutim.conf"
|
||||
ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$final_path/lutim.conf"
|
||||
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$final_path/lutim.conf"
|
||||
ynh_replace_string --match_string="__ENCRYPT__" --replace_string="$always_encrypt" --target_file="$final_path/lutim.conf"
|
||||
ynh_replace_string --match_string="__SECRET__" --replace_string="$secret" --target_file="$final_path/lutim.conf"
|
||||
# Set the number of process for Lutim to twice the number of CPU core.
|
||||
ynh_replace_string --match_string="__WORKERS__" --replace_string="$(( $(nproc) * 2 ))" --target_file="$final_path/lutim.conf"
|
||||
# Recalculate and store the checksum of the file for the next upgrade.
|
||||
ynh_store_file_checksum --file="$final_path/lutim.conf"
|
||||
|
||||
#=================================================
|
||||
# SETUP CRON
|
||||
#=================================================
|
||||
|
||||
(cd scripts; cp ../conf/cron_lutim /etc/cron.d/$app)
|
||||
ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path/" --target_file=/etc/cron.d/$app
|
||||
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file=/etc/cron.d/$app
|
||||
|
||||
#=================================================
|
||||
# SECURING FILES AND DIRECTORIES
|
||||
#=================================================
|
||||
|
||||
# Set permissions on app files
|
||||
chown -R $app: $final_path
|
||||
|
||||
#=================================================
|
||||
# SETUP SYSTEMD
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Resetting systemd configuration..."
|
||||
yunohost app action run $app reset_default_systemd
|
||||
|
||||
#=================================================
|
||||
# SETUP LOGROTATE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Resetting logrotate configuration..."
|
||||
|
||||
ynh_use_logrotate --non-append
|
||||
chown $app -R /var/log/$app
|
||||
|
||||
#=================================================
|
||||
# RELOAD NGINX
|
||||
#=================================================
|
||||
ynh_script_progression --message="Reloading nginx web server..."
|
||||
|
||||
ynh_systemd_action --service_name=nginx --action=reload
|
||||
|
||||
#=================================================
|
||||
# DEACTIVE MAINTENANCE MODE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Disabling maintenance mode..."
|
||||
|
||||
ynh_maintenance_mode_OFF
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Execution completed" --last
|
67
scripts/actions/reset_default_system
Executable file
67
scripts/actions/reset_default_system
Executable file
|
@ -0,0 +1,67 @@
|
|||
#!/bin/bash
|
||||
|
||||
#=================================================
|
||||
# GENERIC STARTING
|
||||
#=================================================
|
||||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
source scripts/_common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# MANAGE SCRIPT FAILURE
|
||||
#=================================================
|
||||
|
||||
ynh_clean_setup () {
|
||||
# Clean installation remaining that are not handle by the remove script.
|
||||
ynh_clean_check_starting
|
||||
}
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
#=================================================
|
||||
# RETRIEVE ARGUMENTS
|
||||
#=================================================
|
||||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
type=$1
|
||||
|
||||
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||
port=$(ynh_app_setting_get --app=$app --key=port)
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC ACTION
|
||||
#=================================================
|
||||
# RESET THE CONFIG FILE
|
||||
#=================================================
|
||||
|
||||
if [ $type == nginx ]; then
|
||||
name=Nginx
|
||||
elif [ $type == systemd ]; then
|
||||
name=systemd
|
||||
else
|
||||
ynh_die --message="The type $type is not recognized"
|
||||
fi
|
||||
|
||||
ynh_script_progression --message="Resetting the specific configuration of $name for the app $app..." --weight=3
|
||||
|
||||
if [ $type == nginx ]
|
||||
then
|
||||
(cd scripts; ynh_add_nginx_config)
|
||||
|
||||
elif [ $type == systemd ]
|
||||
then
|
||||
ynh_systemd_action --action=stop
|
||||
(cd scripts; ynh_add_systemd_config)
|
||||
ynh_systemd_action --action=restart --line_match="Manager.*started" --log_path="/var/log/$app/production.log" --timeout="300"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Execution completed" --last
|
Loading…
Reference in a new issue