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

180 lines
6.4 KiB
Text
Raw Normal View History

2017-09-28 12:47:55 +02:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
2021-12-20 10:42:16 +01:00
2017-09-28 12:47:55 +02:00
# Exit if an error occurs during the execution of the script
2019-10-15 15:56:27 +02:00
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
2021-12-20 10:42:16 +01:00
2019-10-15 15:56:27 +02:00
domain=$YNH_APP_ARG_DOMAIN
2019-10-16 13:19:40 +02:00
path_url=$YNH_APP_ARG_PATH
2019-10-15 15:56:27 +02:00
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
#=================================================
2021-09-30 14:53:52 +02:00
ynh_script_progression --message="Validating installation parameters..." --weight=1
2019-10-15 15:56:27 +02:00
2019-10-15 17:33:46 +02:00
final_path=/home/hts # Default path for Tvheadend deb package
2019-10-23 10:16:15 +02:00
test ! -e "$final_path" || ynh_die --message="The path $final_path already contains a folder"
2019-10-15 15:56:27 +02:00
# Register (book) web path
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
2021-09-30 14:53:52 +02:00
ynh_script_progression --message="Storing installation settings..." --weight=1
2019-10-15 15:56:27 +02:00
ynh_app_setting_set --app=$app --key=domain --value=$domain
2019-10-16 13:19:40 +02:00
ynh_app_setting_set --app=$app --key=path --value=$path_url
2019-10-15 15:56:27 +02:00
ynh_app_setting_set --app=$app --key=superuser --value=$superuser
2019-10-23 10:16:15 +02:00
ynh_app_setting_set --app=$app --key=password --value=$password
2019-10-15 17:33:46 +02:00
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
2019-10-15 15:56:27 +02:00
#=================================================
# STANDARD MODIFICATIONS
#=================================================
2019-10-23 10:16:15 +02:00
# FIND AND OPEN PORTS
2019-10-15 15:56:27 +02:00
#=================================================
2021-09-30 14:53:52 +02:00
ynh_script_progression --message="Finding available ports..." --weight=1
2019-10-15 15:56:27 +02:00
2021-09-30 14:53:52 +02:00
# Find available ports for web interface and streaming
2019-10-15 15:56:27 +02:00
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
2021-09-30 14:53:52 +02:00
# Open ports
ynh_script_progression --message="Configuring firewall..." --weight=15
2021-12-20 10:42:16 +01:00
ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $stream_port
2021-09-30 14:53:52 +02:00
2019-10-15 15:56:27 +02:00
#=================================================
2019-10-23 10:16:15 +02:00
# INSTALL DEPENDENCIES
2019-10-15 15:56:27 +02:00
#=================================================
2019-10-23 10:16:15 +02:00
ynh_script_progression --message="Installing dependencies..." --weight=15
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
#=================================================
2020-10-13 18:23:23 +02:00
ynh_script_progression --message="Downloading Tvheadend..." --weight=5
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
2019-10-23 10:16:15 +02:00
tvheadend_deb_url="$tvheadend_deb_arm"
2019-10-15 15:56:27 +02:00
else
2021-09-30 14:53:52 +02:00
tvheadend_deb_url="$tvheadend_deb_x86"
2019-10-15 15:56:27 +02:00
fi
2021-12-20 10:54:15 +01:00
ynh_exec_quiet wget -q -O $tvheadend_deb_dst $tvheadend_deb_url
2019-10-23 10:16:15 +02:00
2019-10-20 18:28:27 +02:00
#=================================================
2019-10-23 10:16:15 +02:00
# INSTALL TVHEADEND DEB PACKAGE
2019-10-20 18:28:27 +02:00
#=================================================
2020-10-13 18:23:23 +02:00
ynh_script_progression --message="Installing Tvheadend..." --weight=24
2019-10-23 10:16:15 +02:00
# 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
2019-10-15 15:56:27 +02:00
ynh_secure_remove --file="$temp_folder"
2019-10-23 10:16:15 +02:00
# The deb install automatically create the hts system user
2019-10-15 15:56:27 +02:00
# Tvheadend automatically start after install
2019-10-15 17:33:46 +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
# MODIFY TVHEADEND CONFIG FILES
2019-10-15 15:56:27 +02:00
#=================================================
2021-09-30 14:53:52 +02:00
ynh_script_progression --message="Update configuration files..." --weight=1
2019-10-15 17:33:46 +02:00
# Copy and modify /etc/default/tvheadend
2021-09-30 14:57:06 +02:00
conf_dir=$final_path/.hts/tvheadend
ynh_app_setting_set --app=$app --key=conf_dir --value=$conf_dir
2021-09-30 18:19:45 +02:00
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"
2021-12-15 21:02:36 +01:00
fi
2021-09-30 18:19:45 +02:00
2019-10-15 15:56:27 +02:00
#=================================================
2019-10-23 10:16:15 +02:00
# NGINX CONFIGURATION
2019-10-20 18:28:27 +02:00
#=================================================
2020-10-13 18:23:23 +02:00
ynh_script_progression --message="Configuring NGINX web server..." --weight=2
2019-10-20 18:28:27 +02:00
2020-10-13 18:23:23 +02:00
# Create a dedicated NGINX config
2019-10-20 18:28:27 +02:00
ynh_add_nginx_config
2019-10-15 15:56:27 +02:00
#=================================================
2021-09-30 14:53:52 +02:00
# INTEGRATE SERVICE IN YUNOHOST
2019-10-15 15:56:27 +02:00
#=================================================
2021-09-30 14:53:52 +02:00
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
2021-12-20 10:42:16 +01:00
yunohost service add $app --description="TV streaming server and recorder" --needs_exposed_ports $stream_port
2019-10-15 15:56:27 +02:00
#=================================================
# SETUP SSOWAT
#=================================================
2021-09-30 16:49:12 +02:00
ynh_script_progression --message="Configuring permissions..." --weight=1
2019-10-15 15:56:27 +02:00
2021-09-30 16:49:12 +02:00
ynh_permission_update --permission="main" --add="visitors"
2019-10-15 15:56:27 +02:00
#=================================================
# RELOAD NGINX
#=================================================
2020-10-13 18:23:23 +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
#=================================================
2019-10-23 10:16:15 +02:00
# PREVENT TVHEADEND BEING UPGRADED THROUGHT APT
#=================================================
2020-10-13 18:23:23 +02:00
ynh_script_progression --message="Prevent Tvheadend being upgraded throught APT..." --weight=1
apt-mark hold tvheadend
#=================================================
2019-10-23 10:16:15 +02:00
# START TVHEADEND SERVICE
2019-10-20 18:28:27 +02:00
#=================================================
2020-10-13 18:23:23 +02:00
ynh_script_progression --message="Starting Tvheadend service..." --weight=1
2019-10-20 18:28:27 +02:00
ynh_systemd_action --service_name=$app --action="start"
2019-10-20 18:28:27 +02:00
2019-10-15 15:56:27 +02:00
#=================================================
# END OF SCRIPT
#=================================================
2021-12-20 10:42:16 +01:00
ynh_script_progression --message="Installation of Tvheadend completed, HTSP port is $stream_port" --last