2019-10-15 15:56:27 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
source ../settings/scripts/_common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2019-10-15 16:25:54 +02:00
|
|
|
ynh_script_progression --message="Loading settings..." --weight=1
|
2019-10-15 15:56:27 +02:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
2019-10-16 13:19:40 +02:00
|
|
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
2019-10-15 17:33:46 +02:00
|
|
|
superuser=$(ynh_app_setting_get --app=$app --key=superuser)
|
2019-10-15 15:56:27 +02:00
|
|
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
|
|
|
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
|
|
|
|
#=================================================
|
2019-10-15 16:25:54 +02:00
|
|
|
ynh_script_progression --message="Validating restoration parameters..." --weight=1
|
2019-10-15 15:56:27 +02:00
|
|
|
|
|
|
|
ynh_webpath_available --domain=$domain --path_url=$path_url \
|
|
|
|
|| ynh_die --message="Path not available: ${domain}${path_url}"
|
|
|
|
test ! -d $final_path \
|
|
|
|
|| ynh_die --message="There is already a directory: $final_path "
|
|
|
|
|
|
|
|
#=================================================
|
2019-10-20 18:28:27 +02:00
|
|
|
# OPEN TVHEADEND PORTS (A)
|
2019-10-15 15:56:27 +02:00
|
|
|
#=================================================
|
|
|
|
if yunohost firewall list | grep -q "\- $port$"
|
|
|
|
then
|
|
|
|
ynh_die --message="Port $port already open (and maybe used by another application)"
|
|
|
|
fi
|
|
|
|
|
|
|
|
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 $port
|
|
|
|
ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $stream_port
|
|
|
|
|
|
|
|
#=================================================
|
2019-10-20 18:28:27 +02:00
|
|
|
# INSTALL DEPENDENCIES (B)
|
2019-10-15 15:56:27 +02:00
|
|
|
#=================================================
|
2019-10-15 16:25:54 +02:00
|
|
|
ynh_script_progression --message="Installing dependencies..." --weight=11
|
2019-10-15 15:56:27 +02:00
|
|
|
|
|
|
|
if [ -n "$(uname -m | grep arm)" ]
|
|
|
|
then
|
|
|
|
ynh_install_app_dependencies $pkg_dependencies_rb
|
|
|
|
else
|
|
|
|
ynh_install_app_dependencies $pkg_dependencies_x86
|
|
|
|
fi
|
|
|
|
|
|
|
|
#=================================================
|
2019-10-20 18:28:27 +02:00
|
|
|
# DOWNLOAD TVHEADEND DEB PACKAGE
|
2019-10-15 15:56:27 +02:00
|
|
|
#=================================================
|
2019-10-20 18:28:27 +02:00
|
|
|
ynh_script_progression --message="Downloading and installing $app..." --weight=51
|
2019-10-15 15:56:27 +02:00
|
|
|
|
|
|
|
temp_folder="$(mktemp -d)"
|
|
|
|
tvheadend_deb_dst="$temp_folder/tvheadend_deb.deb"
|
|
|
|
|
|
|
|
if [ -n "$(uname -m | grep arm)" ]
|
|
|
|
then
|
|
|
|
ynh_exec_quiet "wget -q -O $tvheadend_deb_dst $tvheadend_deb_arm"
|
|
|
|
elif [ -n "$(uname -m | grep x86_64)" ]
|
|
|
|
then
|
|
|
|
ynh_exec_quiet "wget -q -O $tvheadend_deb_dst $tvheadend_deb_x86_64"
|
|
|
|
else
|
|
|
|
ynh_exec_quiet "wget -q -O $tvheadend_deb_dst $tvheadend_deb_x86_32"
|
|
|
|
fi
|
|
|
|
|
2019-10-20 18:28:27 +02:00
|
|
|
# The deb install automatically create the hts system user (C)
|
|
|
|
#=================================================
|
|
|
|
# INSTALL TVHEADEND DEB PACKAGE (D)
|
|
|
|
#=================================================
|
2019-10-15 15:56:27 +02:00
|
|
|
ynh_package_install "$tvheadend_deb_dst"
|
|
|
|
|
|
|
|
ynh_secure_remove --file="$temp_folder"
|
|
|
|
|
|
|
|
# Tvheadend automatically start after install
|
2019-10-20 18:28:27 +02:00
|
|
|
# we stop it before the configuration
|
2019-10-15 15:56:27 +02:00
|
|
|
ynh_systemd_action --service_name=$app --action="stop"
|
|
|
|
|
|
|
|
#=================================================
|
2019-10-15 17:33:46 +02:00
|
|
|
# RESTORE THE APP CONFIG FILES
|
2019-10-15 15:56:27 +02:00
|
|
|
#=================================================
|
2019-10-15 16:25:54 +02:00
|
|
|
ynh_script_progression --message="Restoring $app config..." --weight=2
|
2019-10-15 15:56:27 +02:00
|
|
|
|
|
|
|
ynh_restore_file --origin_path="$final_path"
|
|
|
|
ynh_restore_file --origin_path="/etc/default/tvheadend"
|
|
|
|
|
|
|
|
#=================================================
|
2019-10-20 18:28:27 +02:00
|
|
|
# RESTORE THE NGINX CONFIGURATION (E)
|
|
|
|
#=================================================
|
|
|
|
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE THE LOGROTATE CONFIGURATION (F)
|
2019-10-15 15:56:27 +02:00
|
|
|
#=================================================
|
|
|
|
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
|
|
|
|
|
|
|
|
#=================================================
|
2019-10-20 18:28:27 +02:00
|
|
|
# ADVERTISE SERVICE IN ADMIN PANEL (G)
|
2019-10-15 15:56:27 +02:00
|
|
|
#=================================================
|
|
|
|
yunohost service add $app --log "/var/log/$app.log"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
2019-10-15 16:25:54 +02:00
|
|
|
ynh_script_progression --message="Configuring SSOwat..." --weight=1
|
2019-10-15 15:56:27 +02:00
|
|
|
|
|
|
|
ynh_app_setting_set --app=$app --key=skipped_uris --value="/"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2019-10-15 16:25:54 +02:00
|
|
|
ynh_script_progression --message="Reloading nginx web server..." --weight=1
|
2019-10-15 15:56:27 +02:00
|
|
|
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
|
|
|
#=================================================
|
2019-10-20 18:28:27 +02:00
|
|
|
# START TVHEADEND SERVICE (G)
|
2019-10-15 15:56:27 +02:00
|
|
|
#=================================================
|
2019-10-15 16:25:54 +02:00
|
|
|
ynh_script_progression --message="Starting $app service..." --weight=1
|
2019-10-15 15:56:27 +02:00
|
|
|
|
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app.log"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
2019-10-16 10:12:57 +02:00
|
|
|
ynh_script_progression --message="Installation of $app completed, HTTP port is $port and HTSP port is $stream_port" --last
|
2019-10-15 15:56:27 +02:00
|
|
|
|