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

180 lines
5.8 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
#=================================================
2022-07-12 03:19:44 +02:00
ynh_script_progression --message="Checking 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
#=================================================
# 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 () {
2022-07-12 03:19:44 +02:00
ynh_clean_check_starting
# Restore it if the upgrade fails
2020-11-09 13:27:06 +01:00
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..."
2021-05-23 09:48:04 +02:00
ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd"
2020-11-09 13:27:06 +01:00
2021-05-22 13:13:46 +02:00
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..."
# 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
# Cleaning legacy permissions
if ynh_legacy_permissions_exists; then
ynh_legacy_permissions_delete_all
ynh_app_setting_delete --app=$app --key=is_public
fi
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..."
# Create a dedicated user (if not existing)
2022-07-12 03:19:44 +02:00
ynh_system_user_create --username=$app --home_dir="$final_path"
2021-05-22 13:13:46 +02:00
2020-11-09 13:27:06 +01:00
#=================================================
# 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
2021-05-22 13:13:46 +02:00
ynh_secure_remove --file="$final_path"
2020-11-09 13:27:06 +01:00
ynh_setup_source --dest_dir="$final_path"
fi
2021-05-22 13:13:46 +02:00
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
2020-11-09 13:27:06 +01:00
#=================================================
2022-07-12 03:19:44 +02:00
# UPGRADE DEPENDENCIES
2020-11-09 13:27:06 +01:00
#=================================================
2022-07-12 03:19:44 +02:00
ynh_script_progression --message="Upgrading dependencies..."
2020-11-09 13:27:06 +01:00
2022-07-12 03:19:44 +02:00
ynh_install_app_dependencies $pkg_dependencies
2020-11-09 13:27:06 +01:00
#=================================================
2022-07-12 03:19:44 +02:00
# NGINX CONFIGURATION
2020-11-09 13:27:06 +01:00
#=================================================
2022-07-12 03:19:44 +02:00
ynh_script_progression --message="Upgrading NGINX web server configuration..."
2020-11-09 13:27:06 +01:00
2022-07-12 03:19:44 +02:00
# Create a dedicated NGINX config
ynh_add_nginx_config
2020-11-09 13:27:06 +01:00
#=================================================
2021-05-22 13:13:46 +02:00
# SPECIFIC UPGRADE
2021-05-23 09:48:04 +02:00
#=================================================
# BUILDING ZERONET
#=================================================
ynh_script_progression --message="Building zeronet..."
pushd "$final_path"
2021-05-27 23:47:07 +02:00
python3 -m venv venv
venv/bin/pip install --upgrade pip
venv/bin/pip install -r requirements.txt
2021-05-23 09:48:04 +02:00
popd
2020-11-09 13:27:06 +01:00
#=================================================
2021-05-22 13:13:46 +02:00
# CREATE DATA DIR
#=================================================
ynh_script_progression --message="Creating data directory..."
2020-11-09 13:27:06 +01:00
2021-05-22 13:13:46 +02:00
mkdir -p $datadir/data
mkdir -p $datadir/log
chmod 750 "$datadir"
chmod -R o-rwx "$datadir"
chown -R $app:$app "$datadir"
# Enable password authentication for Zeronet
mv $final_path/plugins/disabled-UiPassword $final_path/plugins/UiPassword
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
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
2020-11-26 11:35:22 +01:00
2021-05-23 09:48:04 +02:00
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..."
2021-05-23 09:48:04 +02:00
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --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"