1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/tvheadend_ynh.git synced 2024-10-01 13:34:50 +02:00
tvheadend_ynh/scripts/upgrade
2021-12-20 10:54:15 +01:00

175 lines
6 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=2
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
superuser=$(ynh_app_setting_get --app=$app --key=superuser)
password=$(ynh_app_setting_get --app=$app --key=password)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
conf_dir=$(ynh_app_setting_get --app=$app --key=conf_dir)
port=$(ynh_app_setting_get --app=$app --key=port)
stream_port=$(ynh_app_setting_get --app=$app --key=stream_port)
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up Tvheadend before upgrading (may take a while)..." --weight=4
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# restore it if the upgrade fails
ynh_restore_upgradebackup
}
# 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 Tvheadend service..." --weight=3
ynh_systemd_action --service_name=$app --action="stop"
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
if ynh_legacy_permissions_exists; then
ynh_legacy_permissions_delete_all
ynh_app_setting_delete --app=$app --key=is_public
fi
if ! ynh_permission_exists --permission="main"; then
# Create the required permissions
ynh_permission_create --permission="main" --allowed="visitors"
fi
#=================================================
# UPGRADE TVHEADEND DEB PACKAGE
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..." --weight=15
if [ -n "$(uname -m | grep arm)" ]
then
ynh_install_app_dependencies $pkg_dependencies_rb
else
ynh_install_app_dependencies $pkg_dependencies_x86
fi
#=================================================
# DOWNLOAD TVHEADEND DEB PACKAGE
#=================================================
ynh_script_progression --message="Downloading Tvheadend..." --weight=5
temp_folder="$(mktemp -d)"
tvheadend_deb_dst="$temp_folder/tvheadend_deb.deb"
if [ -n "$(uname -m | grep arm)" ]
then
tvheadend_deb_url="$tvheadend_deb_arm"
else
tvheadend_deb_url="$tvheadend_deb_x86"
fi
ynh_exec_quiet wget -q -O $tvheadend_deb_dst $tvheadend_deb_url
#=================================================
# INSTALL TVHEADEND DEB PACKAGE
#=================================================
ynh_script_progression --message="Upgrading Tvheadend..." --weight=24
DEBIAN_FRONTEND=noninteractive ynh_exec_warn_less dpkg --force-confold -i $tvheadend_deb_dst
ynh_secure_remove --file="$temp_folder"
# The deb install automatically create the hts system user
# Tvheadend automatically start after install
# we stop it before the configuration
ynh_systemd_action --service_name=$app --action="stop"
#=================================================
# RESTORE TVHEADEND CONFIG FILES
#=================================================
ynh_script_progression --message="Restore/update configuration files..." --weight=1
# Copy and modify /etc/default/tvheadend
if [ "$path_url" = "/" ]
then
ynh_add_config --template="tvheadend_no_subpath" --destination="/etc/default/tvheadend"
else
ynh_add_config --template="tvheadend" --destination="/etc/default/tvheadend"
fi
fi
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=2
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add $app --description="TV streaming server and recorder" --needs_exposed_ports $stream_port
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# PREVENT TVHEADEND BEING UPGRADED THROUGHT APT
#=================================================
apt-mark hold tvheadend
#=================================================
# START TVHEADEND SERVICE
#=================================================
ynh_script_progression --message="Starting Tvheadend service..." --weight=1
ynh_systemd_action --service_name=$app --action="start"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of Tvheadend completed, HTSP port is $stream_port" --last