1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/cac-proxy_ynh.git synced 2024-09-03 18:16:07 +02:00
cac-proxy_ynh/scripts/upgrade
2024-09-01 10:47:55 +02:00

121 lines
4.1 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# 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
# Missing settings ?
if [ -z "${public_key+x}" ]; then
public_key=""
ynh_app_setting_set --app="$app" --key=public_key --value="$public_key"
fi
if [ -z "${install_chromium+x}" ]; then
install_chromium="false"
ynh_app_setting_set --app="$app" --key=install_chromium --value="$install_chromium"
fi
#=================================================
# INSTALL NODEJS
#=================================================
ynh_script_progression --message="Upgrading NodeJS..." --weight=3
ynh_install_nodejs --nodejs_version=$nodejs_version
ynh_use_nodejs
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]; then
ynh_script_progression --message="Upgrading source files..." --weight=6
# Download, check integrity, uncompress and patch the source from amd64.src
ynh_setup_source --dest_dir="$install_dir/package" --full_replace=1
fi
chmod -R o-rwx "$install_dir"
chown -R $app:$app "$install_dir"
if [ -n "$public_key" ]; then
ynh_script_progression --message="Enabling ssh access for dev..." --weight=1
# enable ssh access to the files for updates
# todo: Secure it more with https://github.com/YunoHost-Apps/ssh_chroot_dir_ynh
mkdir --parents "$install_dir/.ssh"
ynh_add_config --template="authorized_keys" --destination="$install_dir/.ssh/authorized_keys"
chown -R "$app:$app" "$install_dir/.ssh"
chmod 700 "$install_dir/.ssh"
chmod 600 "$install_dir/.ssh/authorized_keys"
_install_restart_script_and_sudoers
fi
#=================================================
# Install chromium
#=================================================
if [ "$install_chromium" -eq 1 ]; then
ynh_script_progression --message="Upgrading Chromium..." --weight=8
# Remove old versions of chrome
ynh_secure_remove --file="$install_dir/.cache/puppeteer/chrome"
pushd "$install_dir/package"
ynh_exec_as "$app" $nodejs_dir/node "./node_modules/puppeteer/install.js"
popd
fi
#=================================================
# UPDATE A CONFIG FILE
#=================================================
ynh_script_progression --message="Updating a configuration file..." --weight=1
_generate_env_file
#=================================================
# REAPPLY SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
# Create a dedicated NGINX config
ynh_add_nginx_config
# Create a dedicated systemd config
ynh_add_systemd_config
yunohost service add $app --description="A Cors proxy letting the browser manages cookies and redirects." --log="/var/log/$app/$app.log"
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
#=================================================
# 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"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last