#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= # Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= ynh_clean_setup () { ynh_clean_check_starting } # Exit if an error occurs during the execution of the script ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= ynh_script_progression --message="Loading settings..." --weight=1 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 IF THE APP CAN BE RESTORED #================================================= ynh_script_progression --message="Validating restoration parameters..." --weight=16 test ! -d $final_path \ || ynh_die --message="There is already a directory: $final_path " #================================================= # STANDARD RESTORATION STEPS #================================================= # RESTORE THE NGINX CONFIGURATION #================================================= ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1 ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # OPEN TVHEADEND PORTS #================================================= ynh_script_progression --message="Configuring firewall..." --weight=15 if yunohost firewall list | grep -q "\- $stream_port$" then ynh_die --message="Port $stream_port already open (and maybe used by another application)" fi ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $stream_port #================================================= # INSTALL DEPENDENCIES #================================================= ynh_script_progression --message="Installing dependencies..." --weight=7 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=3 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="Installing Tvheadend..." --weight=13 # Pre-seed debconf database with answers of the interactive dpkg echo tvheadend tvheadend/admin_password password $password | debconf-set-selections echo tvheadend tvheadend/admin_username string $superuser | debconf-set-selections echo tvheadend tvheadend/last_notes note | debconf-set-selections DEBIAN_FRONTEND=noninteractive ynh_exec_warn_less dpkg -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="Restoring Tvheadend main directory and config files..." --weight=1 ynh_restore_file --origin_path="/etc/default/tvheadend" ynh_restore_file --origin_path="$final_path" #================================================= # PREVENT TVHEADEND BEING UPGRADED THROUGHT APT #================================================= ynh_script_progression --message="Prevent Tvheadend being upgraded throught APT..." --weight=1 apt-mark hold tvheadend #================================================= # 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 #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_systemd_action --service_name=$app --action="start" #================================================= # GENERIC FINALIZATION #================================================= # RELOAD NGINX #================================================= ynh_script_progression --message="Reloading NGINX web server..." --weight=1 ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Restoration completed for $app, HTSP port is $stream_port" --last