1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/hedgedoc_ynh.git synced 2024-09-03 19:25:52 +02:00
hedgedoc_ynh/scripts/change_url

148 lines
4.7 KiB
Text
Raw Normal View History

2020-11-19 21:41:03 +01:00
#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
old_domain=$YNH_APP_OLD_DOMAIN
old_path=$YNH_APP_OLD_PATH
new_domain=$YNH_APP_NEW_DOMAIN
new_path=$YNH_APP_NEW_PATH
app=$YNH_APP_INSTANCE_NAME
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
# Needed for helper "ynh_add_nginx_config"
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
port=$(ynh_app_setting_get --app=$app --key=port)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
2021-03-21 20:58:48 +01:00
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
2020-11-19 21:41:03 +01:00
Testing (#51) * Small fixes * 1.7.0 (#4) * Upgrde to v.1.7.0 * Set requirements to 3.8.1 * Update README.md * Upgrade to 1.7.1 (#6) * Add limitations * Avoid to buid frontend bundle * Remove PostegrSQL warning * Update README.md Add you should reload service for changes in config to be registered. * Add restart systemd tuto * Change version * Finding an available port * Upgrade to version 1.7.2 (#12) * Patch (#17) * Cleaning up * Update manifest.json * Cleaning up * Secure config file * Remove yarn * Update change_url * Update change_url * Revert "Remove yarn" This reverts commit a8cabf0c0addf8f9c4569b27ae04512db5c93df0. * Update change_url * Update systemd.service * Update systemd.service * Cleaning up * Fix * fix badges * Upgrade to version 1.8.0 (#21) * Upgrade to version 1.8.0 * Upgrade to 1.8.0 * Upgrade to 1.8.0 * Upgrade to version 1.8.1 * [autopatch] Update issue and PR templates (#25) Co-authored-by: Yunohost-Bot <> * Add templates * Upgrade to 1.8.2 * Update check_process * Add templates * Auto-update README * Set new requirements (#28) * Fix * Simplify config * Auto-update README Co-authored-by: Yunohost-Bot <> * Update manifest.json * Auto-update README * 1.9.0 (#31) * 1.9.0 * Update manifest.json * Auto-update README * Systemd hardening (#33) * Update systemd.service * Update app.src * Update manifest.json * 1.9.1 (#34) * Upgrade to 1.9.1 * 1.9.2 (#36) * Remove replace_string * Fix (#39) * Update manifest.json * Auto-update README * Update config.json.example * Update config.json.example * 1.9.3 * Auto-update README * 1.9.4 (#42) * 1.9.4 * Auto-update README Co-authored-by: yunohost-bot <yunohost@yunohost.org> * Auto-update README * Update manifest.json * Update _common.sh * set relative path for --keep opt * Update manifest.json * Auto-update README * 1.9.5 * Auto-update README * 1.9.6 * Auto-update README * Add more security as default (#47) * Add more security as default * Auto-update README * Update config.json.example * Update change_url Co-authored-by: yunohost-bot <yunohost@yunohost.org> * Update manifest.json * Auto-update README * Update install Co-authored-by: Eauchat <34686393+eauchat@users.noreply.github.com> Co-authored-by: Alexandre Aubin <alex.aubin@mailoo.org> Co-authored-by: YunoHost Bot <yunohost-bot@users.noreply.github.com> Co-authored-by: Yunohost-Bot <> Co-authored-by: yunohost-bot <yunohost@yunohost.org> Co-authored-by: yalh76 <yalh@yahoo.com>
2022-12-19 17:17:58 +01:00
allow_anonymous=$(ynh_app_setting_get --app=$app --key=allow_anonymous)
allow_email_registration=$(ynh_app_setting_get --app=$app --key=allow_email_registration)
2020-11-19 21:41:03 +01:00
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up HedgeDoc before changing its URL (may take a while)..." --weight=1
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# Remove the new domain config file, the remove script won't do it as it doesn't know yet its location.
ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
# restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# CHECK WHICH PARTS SHOULD BE CHANGED
#=================================================
change_domain=0
if [ "$old_domain" != "$new_domain" ]
then
change_domain=1
fi
change_path=0
if [ "$old_path" != "$new_path" ]
then
change_path=1
fi
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action=stop --log_path=systemd
2020-11-19 21:41:03 +01:00
#=================================================
# MODIFY URL IN NGINX CONF
#=================================================
ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
2020-12-24 16:31:32 +01:00
# Change the path in the NGINX config file
2020-11-19 21:41:03 +01:00
if [ $change_path -eq 1 ]
then
2020-12-24 16:31:32 +01:00
# Make a backup of the original NGINX config file if modified
2020-11-19 21:41:03 +01:00
ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
2020-12-24 16:31:32 +01:00
# Set global variables for NGINX helper
2020-11-19 21:41:03 +01:00
domain="$old_domain"
path_url="$new_path"
2020-12-24 16:31:32 +01:00
# Create a dedicated NGINX config
2020-11-19 21:41:03 +01:00
ynh_add_nginx_config
fi
2020-12-24 16:31:32 +01:00
# Change the domain for NGINX
2020-11-19 21:41:03 +01:00
if [ $change_domain -eq 1 ]
then
# Delete file checksum for the old conf file location
ynh_delete_file_checksum --file="$nginx_conf_path"
mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
# Store file checksum for the new config file location
ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
fi
#=================================================
# SPECIFIC MODIFICATIONS
#=================================================
2020-11-19 21:56:06 +01:00
# CONFIGURE HEDGEDOC
2020-11-19 21:41:03 +01:00
#=================================================
ynh_backup_if_checksum_is_different --file="$final_path/config.json"
domain=$new_domain
url_path=${new_path#/}
2020-11-19 21:41:03 +01:00
2021-06-19 16:49:27 +02:00
ynh_add_config --template="../conf/config.json.example" --destination="$final_path/config.json"
2020-11-19 21:41:03 +01:00
chmod 400 "$final_path/config.json"
chown $app:$app "$final_path/config.json"
2020-11-19 21:41:03 +01:00
#=================================================
# GENERIC FINALISATION
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
# Start a systemd service
2021-03-21 20:58:48 +01:00
ynh_systemd_action --service_name=$app --action=start --log_path=systemd --line_match="HTTP Server listening"
2020-11-19 21:41:03 +01:00
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Change of URL completed for $app" --last