1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/uptime-kuma_ynh.git synced 2024-10-01 13:34:58 +02:00

add backup, restore and upgrade scripts + notes on post-install

This commit is contained in:
Hadrien 2021-11-02 08:19:30 +03:00
parent 8539138446
commit 8b7e64c3d8
8 changed files with 193 additions and 203 deletions

View file

@ -42,10 +42,8 @@ It is a self-hosted monitoring tool like "Uptime Robot".
- Requires a full dedicated domain
- ARM architecture not supported
- This app needs a manual post-install
- No upgrade script in this package
- No restore script in this package
- Backup script is untested in this package
- Uses N to install specific nodejs version
- We could pre-configure mail notifications with YunoHost mail server as an improvement.
<!-- * Any known limitations, constrains or stuff not working, such as (but not limited to):
* requiring a full dedicated domain ?
* architectures not supported ?

View file

@ -38,10 +38,8 @@ It is a self-hosted monitoring tool like "Uptime Robot".
- Requires a full dedicated domain
- ARM architecture not supported
- This app needs a manual post-install
- No upgrade script in this package
- No restore script in this package
- Backup script is untested in this package
- Uses N to install specific nodejs version
- We could pre-configure mail notifications with YunoHost mail server as an improvement.
<!-- * Any known limitations, constrains or stuff not working, such as (but not limited to):
* requiring a full dedicated domain ?
* architectures not supported ?

View file

@ -1,10 +1,8 @@
- Requires a full dedicated domain
- ARM architecture not supported
- This app needs a manual post-install
- No upgrade script in this package
- No restore script in this package
- Backup script is untested in this package
- Uses N to install specific nodejs version
- We could pre-configure mail notifications with YunoHost mail server as an improvement.
<!-- * Any known limitations, constrains or stuff not working, such as (but not limited to):
* requiring a full dedicated domain ?
* architectures not supported ?

View file

@ -48,13 +48,13 @@ ynh_print_info --message="Declaring files to be backed up..."
# BACKUP THE APP MAIN DIR
#=================================================
ynh_backup --src_path="$final_path"
ynh_backup --src_path="$final_path" --is_big
#=================================================
# BACKUP THE DATA DIR
#=================================================
ynh_backup --src_path="$datadir" --is_big
ynh_backup --src_path="$datadir"
#=================================================
# BACKUP THE NGINX CONFIGURATION
@ -95,7 +95,7 @@ ynh_backup --src_path="/etc/systemd/system/$app.service"
# ynh_backup --src_path="/etc/cron.d/$app"
ynh_backup --src_path="/etc/$app/"
# ynh_backup --src_path="/etc/$app/"
#=================================================
# BACKUP THE MYSQL DATABASE

View file

@ -295,22 +295,20 @@ ynh_script_progression --message="Configuring a systemd service..." --time --wei
ynh_add_systemd_config
#=================================================
# SETUP APPLICATION WITH CURL
# SETUP APPLICATION
#=================================================
### We cannot use it since this app uses websocket exclusively.
### It could be tricky to use CURL since this app uses websocket exclusively.
# curl --data-binary '{"jsonrpc": "2.0", "method": "VideoLibrary.Scan", "id": "1"}' -H "Upgrade:websocket" -H 'content-type: application/json;' http://localhost:9090/jsonrpc
# # Set the app as temporarily public for curl call
# ynh_script_progression --message="Configuring SSOwat..." --time --weight=1
# # Making the app public for curl
# ynh_permission_update --permission="main" --add="visitors"
### We could write to its SQLite. Didn't find where the language preferences are though.
# # Installation with curl
# ynh_script_progression --message="Finalizing installation..." --time --weight=1
# ynh_local_curl "/" "key1=value1" "key2=value2" "key3=value3"
# password_hashed = $(htpasswd -bnBC 10 "" $password | tr -d ':\n')
# sqlite3 $final_path/db/kuma.db <<EOF
# INSERT INTO "main"."user" ("id", "username", "password", "active", "timezone", "twofa_secret", "twofa_status", "twofa_last_token") VALUES ('1', '$admin', '$password_hashed', '1', '', '', '0', '');
# EOF
# # Remove the public access
# ynh_permission_update --permission="main" --remove="visitors"
### We could pre-configure mail notifications.
#=================================================
# GENERIC FINALIZATION

View file

@ -78,7 +78,7 @@ ynh_remove_nodejs
#=================================================
# REMOVE APP MAIN DIR
#=================================================
ynh_script_progression --message="Removing app main directory..." --time --weight=1
ynh_script_progression --message="Removing app main directory and dependencies..." --time --weight=2
# Remove the app directory securely
ynh_secure_remove --file="$final_path"
@ -139,7 +139,7 @@ ynh_script_progression --message="Removing various files..." --time --weight=1
# ynh_secure_remove --file="/etc/cron.d/$app"
# Remove a directory securely
ynh_secure_remove --file="/etc/$app"
# ynh_secure_remove --file="/etc/$app"
# Remove the log files
ynh_secure_remove --file="/var/log/$app"

View file

@ -31,9 +31,9 @@ app=$YNH_APP_INSTANCE_NAME
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)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
# db_name=$(ynh_app_setting_get --app=$app --key=db_name)
# db_user=$db_name
# phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
#=================================================
@ -97,13 +97,6 @@ chmod 750 "$datadir"
chmod -R o-rwx "$datadir"
chown -R $app:www-data "$datadir"
#=================================================
# RESTORE THE PHP-FPM CONFIGURATION
#=================================================
# ynh_script_progression --message="Restoring the PHP-FPM configuration..." --time --weight=1
# ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"
#=================================================
# RESTORE FAIL2BAN CONFIGURATION
#=================================================
@ -115,10 +108,29 @@ chown -R $app:www-data "$datadir"
#=================================================
# SPECIFIC RESTORATION
#=================================================
#=================================================
# INSTALL NODEJS
#=================================================
ynh_script_progression --message="Reinstalling NodeJS..." --time --weight=2
ynh_install_nodejs --nodejs_version=$nodejs_version
#=================================================
# NODEJS Version
#=================================================
ynh_use_nodejs
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Reinstalling dependencies..." --time --weight=1
ynh_script_progression --message="Reinstalling dependencies..." --time --weight=7
cd $final_path && ynh_exec_warn_less $ynh_npm install
ynh_script_progression --message="Downloading Uptime Kuma frontend..." --time --weight=1
ynh_exec_warn_less wget https://github.com/louislam/uptime-kuma/releases/download/1.10.0/dist.tar.gz
ynh_exec_as $app tar -xvf dist.tar.gz --directory=$final_path
# Define and install dependencies
# ynh_install_app_dependencies $pkg_dependencies
@ -135,11 +147,11 @@ ynh_script_progression --message="Reinstalling dependencies..." --time --weight=
#=================================================
# RESTORE VARIOUS FILES
#=================================================
ynh_script_progression --message="Restoring various files..." --time --weight=1
# ynh_script_progression --message="Restoring various files..." --time --weight=1
# ynh_restore_file --origin_path="/etc/cron.d/$app"
ynh_restore_file --origin_path="/etc/$app/"
# ynh_restore_file --origin_path="/etc/$app/"
#=================================================
# RESTORE SYSTEMD
@ -175,9 +187,9 @@ ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$ap
#=================================================
# RELOAD NGINX AND PHP-FPM
#=================================================
ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..." --time --weight=1
ynh_script_progression --message="Reloading NGINX web server..." --time --weight=1
ynh_systemd_action --service_name=php$phpversion-fpm --action=reload
# ynh_systemd_action --service_name=php$phpversion-fpm --action=reload
ynh_systemd_action --service_name=nginx --action=reload
#=================================================

View file

@ -1,167 +1,153 @@
# #!/bin/bash
#!/bin/bash
# See
# https://github.com/louislam/uptime-kuma/wiki/%F0%9F%86%99-How-to-Update
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# #=================================================
# # GENERIC START
# #=================================================
# # IMPORT GENERIC HELPERS
# #=================================================
source _common.sh
source /usr/share/yunohost/helpers
# source _common.sh
# source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --time --weight=1
# #=================================================
# # LOAD SETTINGS
# #=================================================
# ynh_script_progression --message="Loading installation settings..." --time --weight=1
app=$YNH_APP_INSTANCE_NAME
# app=$YNH_APP_INSTANCE_NAME
# domain=$(ynh_app_setting_get --app=$app --key=domain)
# path_url=$(ynh_app_setting_get --app=$app --key=path)
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
# admin=$(ynh_app_setting_get --app=$app --key=admin)
# final_path=$(ynh_app_setting_get --app=$app --key=final_path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
# language=$(ynh_app_setting_get --app=$app --key=language)
# db_name=$(ynh_app_setting_get --app=$app --key=db_name)
# #=================================================
# # CHECK VERSION
# #=================================================
#=================================================
# CHECK VERSION
#=================================================
# ### This helper will compare the version of the currently installed app and the version of the upstream package.
# ### $upgrade_type can have 2 different values
# ### - UPGRADE_APP if the upstream app version has changed
# ### - UPGRADE_PACKAGE if only the YunoHost package has changed
# ### ynh_check_app_version_changed will stop the upgrade if the app is up to date.
# ### UPGRADE_APP should be used to upgrade the core app only if there's an upgrade to do.
# upgrade_type=$(ynh_check_app_version_changed)
### This helper will compare the version of the currently installed app and the version of the upstream package.
### $upgrade_type can have 2 different values
### - UPGRADE_APP if the upstream app version has changed
### - UPGRADE_PACKAGE if only the YunoHost package has changed
### ynh_check_app_version_changed will stop the upgrade if the app is up to date.
### UPGRADE_APP should be used to upgrade the core app only if there's an upgrade to do.
upgrade_type=$(ynh_check_app_version_changed)
# #=================================================
# # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
# #=================================================
# ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --time --weight=1
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --time --weight=1
# # Backup the current version of the app
# ynh_backup_before_upgrade
# ynh_clean_setup () {
# # Restore it if the upgrade fails
# ynh_restore_upgradebackup
# }
# # Exit if an error occurs during the execution of the script
# ynh_abort_if_errors
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# Restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
# #=================================================
# # STANDARD UPGRADE STEPS
# #=================================================
# # STOP SYSTEMD SERVICE
# #=================================================
# ynh_script_progression --message="Stopping a systemd service..." --time --weight=1
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --time --weight=1
# ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
# #=================================================
# # ENSURE DOWNWARD COMPATIBILITY
# #=================================================
# ynh_script_progression --message="Ensuring downward compatibility..." --time --weight=1
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --time --weight=1
# #
# # N.B. : the followings setting migrations snippets are provided as *EXAMPLES*
# # of what you may want to do in some cases (e.g. a setting was not defined on
# # some legacy installs and you therefore want to initiaze stuff during upgrade)
# #
#
# N.B. : the followings setting migrations snippets are provided as *EXAMPLES*
# of what you may want to do in some cases (e.g. a setting was not defined on
# some legacy installs and you therefore want to initiaze stuff during upgrade)
#
# # If db_name doesn't exist, create it
# #if [ -z "$db_name" ]; then
# # db_name=$(ynh_sanitize_dbid --db_name=$app)
# # ynh_app_setting_set --app=$app --key=db_name --value=$db_name
# #fi
# If db_name doesn't exist, create it
#if [ -z "$db_name" ]; then
# db_name=$(ynh_sanitize_dbid --db_name=$app)
# ynh_app_setting_set --app=$app --key=db_name --value=$db_name
#fi
# # If final_path doesn't exist, create it
# #if [ -z "$final_path" ]; then
# # final_path=/var/www/$app
# # ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# #fi
# ### If nobody installed your app before 4.1,
# ### then you may safely remove these lines
# # Cleaning legacy permissions
# if ynh_legacy_permissions_exists; then
# ynh_legacy_permissions_delete_all
# ynh_app_setting_delete --app=$app --key=is_public
# If final_path doesn't exist, create it
# if [ -z "$final_path" ]; then
# final_path=/var/www/$app
# ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# fi
# if ! ynh_permission_exists --permission="admin"; then
# # Create the required permissions
# ynh_permission_create --permission="admin" --url="/admin" --allowed=$admin
# fi
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..." --time --weight=1
# # Create a permission if needed
# if ! ynh_permission_exists --permission="api"; then
# ynh_permission_create --permission="api" --url="/api" --allowed="visitors" --show_tile="false" --protected="true"
# fi
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path"
# #=================================================
# # CREATE DEDICATED USER
# #=================================================
# ynh_script_progression --message="Making sure dedicated system user exists..." --time --weight=1
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
# # Create a dedicated user (if not existing)
# ynh_system_user_create --username=$app --home_dir="$final_path"
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading source files..." --time --weight=1
# #=================================================
# # DOWNLOAD, CHECK AND UNPACK SOURCE
# #=================================================
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path" --keep=data/
# Download, check integrity, uncompress and patch the source from dist.src
ynh_setup_source --source_id="dist" --dest_dir="$final_path/dist"
# if [ "$upgrade_type" == "UPGRADE_APP" ]
# then
# ynh_script_progression --message="Upgrading source files..." --time --weight=1
fi
# # Download, check integrity, uncompress and patch the source from app.src
# ynh_setup_source --dest_dir="$final_path"
# fi
# FIXME: this should be managed by the core in the future
# Here, as a packager, you may have to tweak the ownerhsip/permissions
# such that the appropriate users (e.g. maybe www-data) can access
# files in some cases.
# But FOR THE LOVE OF GOD, do not allow r/x for "others" on the entire folder -
# this will be treated as a security issue.
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
# # FIXME: this should be managed by the core in the future
# # Here, as a packager, you may have to tweak the ownerhsip/permissions
# # such that the appropriate users (e.g. maybe www-data) can access
# # files in some cases.
# # But FOR THE LOVE OF GOD, do not allow r/x for "others" on the entire folder -
# # this will be treated as a security issue.
# chmod 750 "$final_path"
# chmod -R o-rwx "$final_path"
# chown -R $app:www-data "$final_path"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..." --time --weight=1
# #=================================================
# # NGINX CONFIGURATION
# #=================================================
# ynh_script_progression --message="Upgrading NGINX web server configuration..." --time --weight=1
# Create a dedicated NGINX config
ynh_add_nginx_config
# # Create a dedicated NGINX config
# ynh_add_nginx_config
#=================================================
# INSTALL NODEJS
#=================================================
ynh_script_progression --message="Upgrading NodeJS..." --time --weight=2
# #=================================================
# # UPGRADE DEPENDENCIES
# #=================================================
# ynh_script_progression --message="Upgrading dependencies..." --time --weight=1
ynh_install_nodejs --nodejs_version=$nodejs_version
#=================================================
# NODEJS Version
#=================================================
ynh_use_nodejs
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..." --time --weight=1
# ynh_install_app_dependencies $pkg_dependencies
# #=================================================
# # PHP-FPM CONFIGURATION
# #=================================================
# ynh_script_progression --message="Upgrading PHP-FPM configuration..." --time --weight=1
#=================================================
# SPECIFIC UPGRADE
#=================================================
# # Create a dedicated PHP-FPM config
# ynh_add_fpm_config
# #=================================================
# # SPECIFIC UPGRADE
# #=================================================
# # ...
# #=================================================
ynh_script_progression --message="Upgrading Uptime Kuma dependencies..." --time --weight=7
cd $final_path && ynh_exec_warn_less $ynh_npm install
# #=================================================
# # UPDATE A CONFIG FILE
@ -188,37 +174,37 @@
# ### ynh_replace_string --match_string="match_string" --replace_string="replace_string" --target_file="$final_path/some_config_file"
# ### ynh_store_file_checksum --file="$final_path/some_config_file"
# #=================================================
# # SETUP SYSTEMD
# #=================================================
# ynh_script_progression --message="Upgrading systemd configuration..." --time --weight=1
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Upgrading systemd configuration..." --time --weight=1
# # Create a dedicated systemd config
# ynh_add_systemd_config
# Create a dedicated systemd config
ynh_add_systemd_config
# #=================================================
# # GENERIC FINALIZATION
# #=================================================
# # SETUP LOGROTATE
# #=================================================
# ynh_script_progression --message="Upgrading logrotate configuration..." --time --weight=1
#=================================================
# GENERIC FINALIZATION
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Upgrading logrotate configuration..." --time --weight=1
# # Use logrotate to manage app-specific logfile(s)
# ynh_use_logrotate --non-append
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
# #=================================================
# # INTEGRATE SERVICE IN YUNOHOST
# #=================================================
# ynh_script_progression --message="Integrating service in YunoHost..." --time --weight=1
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --time --weight=1
# yunohost service add $app --description="A short description of the app" --log="/var/log/$app/$app.log"
yunohost service add $app --description="A short description of the app" --log="/var/log/$app/$app.log"
# #=================================================
# # START SYSTEMD SERVICE
# #=================================================
# ynh_script_progression --message="Starting a systemd service..." --time --weight=1
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --time --weight=1
# ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
# #=================================================
# # UPGRADE FAIL2BAN
@ -228,15 +214,15 @@
# # Create a dedicated Fail2Ban config
# ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login"
# #=================================================
# # RELOAD NGINX
# #=================================================
# ynh_script_progression --message="Reloading NGINX web server..." --time --weight=1
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --time --weight=1
# ynh_systemd_action --service_name=nginx --action=reload
ynh_systemd_action --service_name=nginx --action=reload
# #=================================================
# # END OF SCRIPT
# #=================================================
#=================================================
# END OF SCRIPT
#=================================================
# ynh_script_progression --message="Upgrade of $app completed" --time --last
ynh_script_progression --message="Upgrade of $app completed" --time --last