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/install
2021-11-29 19:11:05 +01:00

177 lines
6.5 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _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
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
superuser=$YNH_APP_ARG_SUPERUSER
password=$YNH_APP_ARG_PASSWORD
app=$YNH_APP_INSTANCE_NAME
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_script_progression --message="Validating installation parameters..." --weight=1
final_path=/home/hts # Default path for Tvheadend deb package
test ! -e "$final_path" || ynh_die --message="The path $final_path already contains a folder"
# Register (book) web path
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Storing installation settings..." --weight=1
ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=path --value=$path_url
ynh_app_setting_set --app=$app --key=superuser --value=$superuser
ynh_app_setting_set --app=$app --key=password --value=$password
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN PORTS
#=================================================
ynh_script_progression --message="Finding available ports..." --weight=1
# Find available ports for web interface and streaming
port=$(ynh_find_port --port=9981)
ynh_app_setting_set --app=$app --key=port --value=$port
stream_port=$(ynh_find_port --port=9982)
ynh_app_setting_set --app=$app --key=stream_port --value=$stream_port
# Open ports
ynh_script_progression --message="Configuring firewall..." --weight=15
ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port
ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $stream_port
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing 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="Installing Tvheadend..." --weight=24
# 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"
#=================================================
# MODIFY TVHEADEND CONFIG FILES
#=================================================
ynh_script_progression --message="Update configuration files..." --weight=1
# Copy and modify /etc/default/tvheadend
conf_dir=$final_path/.hts/tvheadend
ynh_app_setting_set --app=$app --key=conf_dir --value=$conf_dir
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"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..." --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 $port $stream_port
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Configuring permissions..." --weight=1
ynh_permission_update --permission="main" --add="visitors"
#=================================================
# 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
#=================================================
ynh_script_progression --message="Prevent Tvheadend being upgraded throught APT..." --weight=1
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="Installation of Tvheadend completed, HTTP port is $port and HTSP port is $stream_port" --last