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
|
|
|
|
#=================================================
|
|
|
|
# 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
|
|
|
|
#=================================================
|
|
|
|
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
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Validating installation parameters..." --weight=2
|
|
|
|
|
2019-10-15 17:33:46 +02:00
|
|
|
final_path=/home/hts # Default path for Tvheadend deb package
|
2019-10-15 15:56:27 +02:00
|
|
|
test ! -e "$final_path" || ynh_die --message="This 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
|
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-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-20 18:28:27 +02:00
|
|
|
# FIND AND OPEN PORTS (A)
|
2019-10-15 15:56:27 +02:00
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring firewall..." --weight=16
|
|
|
|
|
|
|
|
# Find a free port for the web server
|
|
|
|
port=$(ynh_find_port --port=9981)
|
|
|
|
# Open this port
|
|
|
|
ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port
|
|
|
|
ynh_app_setting_set --app=$app --key=port --value=$port
|
|
|
|
|
|
|
|
# Find a free port for the streaming server
|
|
|
|
stream_port=$(ynh_find_port --port=9982)
|
|
|
|
# Open this port
|
|
|
|
ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $stream_port
|
|
|
|
ynh_app_setting_set --app=$app --key=stream_port --value=$stream_port
|
|
|
|
|
|
|
|
#=================================================
|
2019-10-20 18:28:27 +02:00
|
|
|
# INSTALL DEPENDENCIES (B)
|
2019-10-15 15:56:27 +02:00
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Installing dependencies..." --weight=11
|
|
|
|
|
|
|
|
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-15 17:33:46 +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-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
|
|
|
#=================================================
|
2019-10-15 17:33:46 +02:00
|
|
|
# Copy and modify /etc/default/tvheadend
|
2019-10-15 15:56:27 +02:00
|
|
|
cp ../conf/tvheadend /etc/default/tvheadend
|
|
|
|
ynh_replace_string --match_string="__CONF_DIR__" --replace_string="$final_path/.hts/tvheadend" --target_file="/etc/default/tvheadend"
|
|
|
|
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="/etc/default/tvheadend"
|
2019-10-16 13:19:40 +02:00
|
|
|
ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="/etc/default/tvheadend"
|
2019-10-15 15:56:27 +02:00
|
|
|
ynh_replace_string --match_string="__STREAM_PORT__" --replace_string="$stream_port" --target_file="/etc/default/tvheadend"
|
|
|
|
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="/etc/default/tvheadend"
|
|
|
|
|
2019-10-15 17:33:46 +02:00
|
|
|
# Copy and modify /home/hts/.hts/tvheadend/superuser
|
2019-10-15 15:56:27 +02:00
|
|
|
cp ../conf/superuser $final_path/.hts/tvheadend/superuser
|
|
|
|
ynh_replace_string --match_string="__SUPERUSER__" --replace_string="$superuser" --target_file="$final_path/.hts/tvheadend/superuser"
|
|
|
|
ynh_replace_string --match_string="__PASSWORD__" --replace_string="$password" --target_file="$final_path/.hts/tvheadend/superuser"
|
|
|
|
|
|
|
|
#=================================================
|
2019-10-15 17:33:46 +02:00
|
|
|
# STORE CONFIG FILES CHECKSUM
|
2019-10-15 15:56:27 +02:00
|
|
|
#=================================================
|
2019-10-15 17:33:46 +02:00
|
|
|
# Calculate and store config files checksum into the app settings
|
2019-10-15 15:56:27 +02:00
|
|
|
ynh_store_file_checksum --file="/etc/default/tvheadend"
|
|
|
|
ynh_store_file_checksum --file="$final_path/.hts/tvheadend/superuser"
|
|
|
|
|
|
|
|
#=================================================
|
2019-10-20 18:28:27 +02:00
|
|
|
# NGINX CONFIGURATION (E)
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring nginx web server..." --weight=2
|
|
|
|
|
|
|
|
# Create a dedicated nginx config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE (F)
|
2019-10-15 15:56:27 +02:00
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring log rotation..." --weight=1
|
|
|
|
|
|
|
|
# Use logrotate to manage application logfile(s)
|
|
|
|
touch /var/log/$app.log
|
|
|
|
chmod 666 /var/log/$app.log
|
|
|
|
ynh_use_logrotate --logfile=/var/log/$app.log
|
|
|
|
|
|
|
|
#=================================================
|
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
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring SSOwat..." --weight=1
|
|
|
|
|
|
|
|
ynh_app_setting_set --app=$app --key=skipped_uris --value="/"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Reloading nginx web server..." --weight=1
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
2019-10-20 18:28:27 +02:00
|
|
|
#=================================================
|
2019-10-21 18:20:08 +02:00
|
|
|
# PREVENT TVHEADEND BEING UPGRADED THROUGHT APT (H)
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Prevent $app being upgraded throught APT..." --weight=1
|
|
|
|
|
|
|
|
apt-mark hold tvheadend
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START TVHEADEND SERVICE (I)
|
2019-10-20 18:28:27 +02:00
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Starting $app service..." --weight=1
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app.log"
|
|
|
|
|
2019-10-15 15:56:27 +02:00
|
|
|
#=================================================
|
|
|
|
# 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
|
|
|
|