1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/archivebox_ynh.git synced 2024-09-03 18:15:54 +02:00
archivebox_ynh/scripts/upgrade

164 lines
5.4 KiB
Text
Raw Normal View History

2021-08-13 15:42:21 +02:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
2021-08-23 10:32:06 +02:00
ynh_script_progression --message="Stopping a systemd service..." --weight=1
2021-08-13 15:42:21 +02:00
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
2022-09-22 00:37:16 +02:00
#=================================================
# 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
2022-09-22 02:55:19 +02:00
tempdir="$(mktemp -d)"
ynh_setup_source --dest_dir="$tempdir"
2023-06-23 10:01:09 +02:00
mkdir -p $install_dir
2022-09-22 00:37:16 +02:00
fi
2023-06-23 10:01:09 +02:00
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
2022-09-22 00:37:16 +02:00
2022-09-21 23:51:10 +02:00
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
2023-06-23 10:08:31 +02:00
ynh_script_progression --message="Upgrading dependencies..." --weight=1
2022-09-21 23:51:10 +02:00
2022-09-22 20:53:09 +02:00
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
2022-09-21 23:51:10 +02:00
2022-01-27 21:05:27 +01:00
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
2022-09-21 23:51:10 +02:00
# SPECIFIC UPGRADE
2021-08-13 15:42:21 +02:00
#=================================================
# UPGRADE VIA PIP
2021-08-13 15:42:21 +02:00
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
2021-08-23 10:32:06 +02:00
ynh_script_progression --message="Upgrading via pip" --weight=1
2022-09-22 00:10:01 +02:00
ynh_use_nodejs
2023-06-23 10:01:09 +02:00
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
2023-06-23 10:01:09 +02:00
source "${install_dir}/venv/bin/activate"
set -o nounset
2023-06-23 10:01:09 +02:00
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
2023-06-23 10:01:09 +02:00
archivebox_cmd="$install_dir/venv/bin/archivebox"
2022-09-22 00:37:16 +02:00
fi
#=================================================
# UPGRADE NODE DEPENDENCIES
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
2023-06-23 10:08:31 +02:00
ynh_script_progression --message="Upgrading node dependencies..."
2022-09-22 00:37:16 +02:00
2023-06-23 10:01:09 +02:00
cp -f $tempdir/package.json "$install_dir/package.json"
cp -f $tempdir/package-lock.json "$install_dir/package-lock.json"
2022-09-22 02:55:19 +02:00
ynh_secure_remove --file="$tempdir"
2023-06-23 10:01:09 +02:00
pushd $install_dir
2022-09-22 00:37:16 +02:00
ynh_use_nodejs
ynh_exec_warn_less ynh_exec_as $app $ynh_node_load_PATH $ynh_npm ci
popd
fi
2022-09-22 00:37:16 +02:00
#=================================================
# UPDATE A CONFIG FILE
#=================================================
ynh_script_progression --message="Updating a configuration file..." --weight=1
2023-06-23 10:01:09 +02:00
ynh_store_file_checksum --file="$data_dir/ArchiveBox.conf"
ynh_add_config --template="../conf/ArchiveBox.conf" --destination="$data_dir/ArchiveBox.conf"
2022-09-22 00:37:16 +02:00
2023-06-23 10:01:09 +02:00
chmod 600 "$data_dir/ArchiveBox.conf"
chown $app:$app "$data_dir/ArchiveBox.conf"
2022-09-22 00:37:16 +02:00
#=================================================
# FINISH ARCHIVEBOX SETUP
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
# rerun archivebox setup (its idempotent, so it should be ok during upgrade)
2021-08-23 10:32:06 +02:00
ynh_script_progression --message="Finishing Archivebox Setup" --weight=1
2023-06-23 10:01:09 +02:00
pushd $data_dir
2022-09-22 20:53:09 +02:00
ynh_exec_warn_less ynh_exec_as $app $ynh_node_load_PATH $archivebox_cmd init --setup
2022-09-22 00:10:01 +02:00
popd
2021-08-13 15:42:21 +02:00
fi
#=================================================
# SETUP SYSTEMD
#=================================================
2021-08-23 10:32:06 +02:00
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
2021-08-13 15:42:21 +02:00
# Create a dedicated systemd config
ynh_add_systemd_config
#=================================================
# GENERIC FINALIZATION
#=================================================
# SETUP LOGROTATE
#=================================================
2021-08-23 10:32:06 +02:00
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
2021-08-13 15:42:21 +02:00
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
2021-08-23 10:32:06 +02:00
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
2021-08-13 15:42:21 +02:00
2021-08-19 15:53:54 +02:00
yunohost service add $app --description="Self-hosted internet archiving" --log="/var/log/$app/$app.log"
2021-08-13 15:42:21 +02:00
#=================================================
# START SYSTEMD SERVICE
#=================================================
2021-08-23 10:32:06 +02:00
ynh_script_progression --message="Starting a systemd service..." --weight=1
2021-08-13 15:42:21 +02:00
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
#=================================================
# END OF SCRIPT
#=================================================
2021-08-23 10:32:06 +02:00
ynh_script_progression --message="Upgrade of $app completed" --last