mirror of
https://github.com/YunoHost-Apps/archivebox_ynh.git
synced 2024-09-03 18:15:54 +02:00
225 lines
8 KiB
Bash
225 lines
8 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# LOAD SETTINGS
|
|
#=================================================
|
|
#REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=1
|
|
|
|
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
|
|
|
|
#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|
#REMOVEME? #path=$YNH_APP_ARG_PATH
|
|
# we can only add support for subpaths once this is resolved in archivebox
|
|
# https://github.com/ArchiveBox/ArchiveBox/issues/724
|
|
path="/"
|
|
#REMOVEME? language=$(ynh_app_setting_get --app=$app --key=language)
|
|
#REMOVEME? admin=$(ynh_app_setting_get --app=$app --key=admin)
|
|
#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir)
|
|
#REMOVEME? port=$(ynh_app_setting_get --app=$app --key=port)
|
|
#REMOVEME? data_dir=$(ynh_app_setting_get --app=$app --key=data_dir)
|
|
|
|
#=================================================
|
|
# CHECK VERSION
|
|
#=================================================
|
|
ynh_script_progression --message="Checking version..." --weight=1
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
#=================================================
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
#=================================================
|
|
#REMOVEME? ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1
|
|
|
|
# Backup the current version of the app
|
|
#REMOVEME? ynh_backup_before_upgrade
|
|
#REMOVEME? ynh_clean_setup () {
|
|
# Restore it if the upgrade fails
|
|
#REMOVEME? ynh_restore_upgradebackup
|
|
}
|
|
# Exit if an error occurs during the execution of the script
|
|
#REMOVEME? ynh_abort_if_errors
|
|
|
|
#=================================================
|
|
# STANDARD UPGRADE STEPS
|
|
#=================================================
|
|
# STOP SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Stopping a systemd service..." --weight=1
|
|
|
|
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..." --weight=1
|
|
|
|
# Cleaning legacy permissions
|
|
#REMOVEME? if ynh_legacy_permissions_exists; then
|
|
#REMOVEME? ynh_legacy_permissions_delete_all
|
|
|
|
ynh_app_setting_delete --app=$app --key=is_public
|
|
fi
|
|
|
|
#=================================================
|
|
# CREATE DEDICATED USER
|
|
#=================================================
|
|
#REMOVEME? ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
|
|
|
|
# Create a dedicated user (if not existing)
|
|
#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir"
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
then
|
|
ynh_script_progression --message="Upgrading source files..." --weight=1
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
tempdir="$(mktemp -d)"
|
|
ynh_setup_source --dest_dir="$tempdir"
|
|
mkdir -p $install_dir
|
|
fi
|
|
|
|
chmod 750 "$install_dir"
|
|
chmod -R o-rwx "$install_dir"
|
|
chown -R $app:www-data "$install_dir"
|
|
|
|
#=================================================
|
|
# UPGRADE DEPENDENCIES
|
|
#=================================================
|
|
#REMOVEME? ynh_script_progression --message="Upgrading dependencies..." --weight=1
|
|
|
|
#REMOVEME? ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
|
|
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
|
|
|
|
#=================================================
|
|
# NGINX CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
|
|
|
|
# Create a dedicated NGINX config
|
|
ynh_add_nginx_config
|
|
|
|
#=================================================
|
|
# SPECIFIC UPGRADE
|
|
#=================================================
|
|
# UPGRADE VIA PIP
|
|
#=================================================
|
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
then
|
|
ynh_script_progression --message="Upgrading via pip" --weight=1
|
|
ynh_use_nodejs
|
|
python3 -m venv "${install_dir}/venv"
|
|
cp ../conf/requirements.txt "$install_dir/requirements.txt"
|
|
chown -R "$app" "$install_dir"
|
|
|
|
#run source in a 'sub shell'
|
|
(
|
|
set +o nounset
|
|
source "${install_dir}/venv/bin/activate"
|
|
set -o nounset
|
|
ynh_exec_as $app $install_dir/venv/bin/pip install --upgrade pip
|
|
ynh_exec_as $app $install_dir/venv/bin/pip install -r "$install_dir/requirements.txt"
|
|
)
|
|
|
|
# we use this virtualenv archivebox for further commands now
|
|
archivebox_cmd="$install_dir/venv/bin/archivebox"
|
|
fi
|
|
|
|
#=================================================
|
|
# UPGRADE NODE DEPENDENCIES
|
|
#=================================================
|
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
then
|
|
#REMOVEME? ynh_script_progression --message="Upgrading node dependencies..."
|
|
|
|
cp -f $tempdir/package.json "$install_dir/package.json"
|
|
cp -f $tempdir/package-lock.json "$install_dir/package-lock.json"
|
|
ynh_secure_remove --file="$tempdir"
|
|
pushd $install_dir
|
|
ynh_use_nodejs
|
|
ynh_exec_warn_less ynh_exec_as $app $ynh_node_load_PATH $ynh_npm ci
|
|
popd
|
|
fi
|
|
|
|
#=================================================
|
|
# UPDATE A CONFIG FILE
|
|
#=================================================
|
|
ynh_script_progression --message="Updating a configuration file..." --weight=1
|
|
|
|
ynh_store_file_checksum --file="$data_dir/ArchiveBox.conf"
|
|
ynh_add_config --template="../conf/ArchiveBox.conf" --destination="$data_dir/ArchiveBox.conf"
|
|
|
|
chmod 600 "$data_dir/ArchiveBox.conf"
|
|
chown $app:$app "$data_dir/ArchiveBox.conf"
|
|
|
|
#=================================================
|
|
# FINISH ARCHIVEBOX SETUP
|
|
#=================================================
|
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
then
|
|
# rerun archivebox setup (its idempotent, so it should be ok during upgrade)
|
|
ynh_script_progression --message="Finishing Archivebox Setup" --weight=1
|
|
pushd $data_dir
|
|
ynh_exec_warn_less ynh_exec_as $app $ynh_node_load_PATH $archivebox_cmd init --setup
|
|
popd
|
|
fi
|
|
|
|
#=================================================
|
|
# SETUP SYSTEMD
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
|
|
|
|
# Create a dedicated systemd config
|
|
ynh_add_systemd_config
|
|
|
|
#=================================================
|
|
# GENERIC FINALIZATION
|
|
#=================================================
|
|
# SETUP LOGROTATE
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
|
|
|
|
# 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..." --weight=1
|
|
|
|
yunohost service add $app --description="Self-hosted internet archiving" --log="/var/log/$app/$app.log"
|
|
|
|
#=================================================
|
|
# START SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
|
|
|
|
#=================================================
|
|
# RELOAD NGINX
|
|
#=================================================
|
|
#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." --weight=1
|
|
|
|
#REMOVEME? ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|