1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/zeronet_ynh.git synced 2024-09-03 17:46:12 +02:00
zeronet_ynh/scripts/upgrade

160 lines
5.5 KiB
Text
Raw Normal View History

2020-11-09 13:27:06 +01:00
#!/bin/bash
2017-03-03 21:26:30 +01:00
2020-11-09 13:27:06 +01:00
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
2017-03-03 21:26:30 +01:00
source /usr/share/yunohost/helpers
2020-11-09 13:27:06 +01:00
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
2020-11-09 13:27:06 +01:00
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)
fs_port=$(ynh_app_setting_get --app=$app --key=fs_port)
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
password=$(ynh_app_setting_get --app=$app --key=password)
2017-03-03 21:26:30 +01:00
2020-11-09 13:27:06 +01:00
#=================================================
# CHECK VERSION
#=================================================
2017-03-03 21:26:30 +01:00
2020-11-09 13:27:06 +01:00
upgrade_type=$(ynh_check_app_version_changed)
2017-03-03 21:26:30 +01:00
2020-11-09 13:27:06 +01:00
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..."
2017-03-03 21:26:30 +01:00
2020-11-09 13:27:06 +01:00
# 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
2017-03-03 21:26:30 +01:00
2021-02-08 21:36:31 +01:00
# Cleaning legacy permissions
if ynh_legacy_permissions_exists; then
ynh_legacy_permissions_delete_all
ynh_app_setting_delete --app=$app --key=is_public
fi
2020-11-09 13:27:06 +01:00
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# restore it if the upgrade fails
ynh_restore_upgradebackup
2017-03-03 21:26:30 +01:00
}
2020-11-09 13:27:06 +01:00
# 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..."
ynh_systemd_action --service_name=$app --action="stop" --log_path="$datadir/log/debug-last.log"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading source files..."
# Download, check integrity, uncompress and patch the source from app.src
ynh_secure_remove --file="$final_path"
ynh_setup_source --dest_dir="$final_path"
fi
#=================================================
# NGINX CONFIGURATION
#=================================================
2020-11-26 11:35:22 +01:00
ynh_script_progression --message="Upgrading NGINX web server configuration..."
2020-11-09 13:27:06 +01:00
2020-11-26 11:35:22 +01:00
# Create a dedicated NGINX config
2020-11-09 13:27:06 +01:00
ynh_add_nginx_config
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..."
ynh_install_app_dependencies $pkg_dependencies
2020-11-26 11:29:29 +01:00
2021-02-08 19:54:55 +01:00
pip3 install gevent-websocket msgpack-python gevent base58 merkletools rsa PySocks pyasn1 websocket_client gevent-ws coincurve maxminddb
2020-11-09 13:27:06 +01:00
#=================================================
# 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 --home_dir=$datadir -s
2020-11-09 13:27:06 +01:00
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Upgrading systemd configuration..."
# Create a dedicated systemd config
ynh_add_systemd_config
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Enable password authentication for Zeronet
mv $final_path/plugins/disabled-UiPassword $final_path/plugins/UiPassword
2020-11-09 13:27:06 +01:00
# Set permissions on app files
chown -R $app: $final_path
chown -R $app: $datadir
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
2020-11-26 11:35:22 +01:00
ynh_add_systemd_config --service="$app" --template="systemd.service" --others_var="fs_port port domain datadir password"
yunohost service add $app --description "$app service" --log "$datadir/log/debug-last.log" --needs_exposed_ports "$fs_port"
2020-11-09 13:27:06 +01:00
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
ynh_systemd_action --service_name=$app --action="start" --log_path="$datadir/log/debug-last.log" --line_match="Ui.UiServer Web interface" --timeout=120
2020-11-09 13:27:06 +01:00
#=================================================
# RELOAD NGINX
#=================================================
2020-11-26 11:35:22 +01:00
ynh_script_progression --message="Reloading NGINX web server..."
2020-11-09 13:27:06 +01:00
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
2017-03-03 21:26:30 +01:00
2020-11-09 13:27:06 +01:00
ynh_script_progression --message="Upgrade of $app completed"