From 21801fb998455bc2c866eefd75f150bbbd53d1ca Mon Sep 17 00:00:00 2001 From: Sylvain CECCHETTO Date: Wed, 23 Oct 2019 10:16:15 +0200 Subject: [PATCH] [+] Code cleanup --- check_process | 5 ++-- manifest.json | 2 +- scripts/backup | 18 +++++++------ scripts/change_url | 17 ++++++------ scripts/install | 48 +++++++++++++++++---------------- scripts/remove | 53 +++++++++++++++++++----------------- scripts/restore | 50 +++++++++++++++++++++------------- scripts/upgrade | 67 +++++++++++++++++++++++++++++++--------------- 8 files changed, 154 insertions(+), 106 deletions(-) diff --git a/check_process b/check_process index c2f6792..e35316d 100644 --- a/check_process +++ b/check_process @@ -1,4 +1,4 @@ -;; Test complet +;; Full test ; Manifest domain="domain.tld" (DOMAIN) path="/path" (PATH) @@ -14,7 +14,8 @@ upgrade=1 backup_restore=1 multi_instance=0 - port_already_use=0 + incorrect_path=1 + port_already_use=1 change_url=1 ;;; Levels # If the level 5 (Package linter) is forced to 1. Please add justifications here. diff --git a/manifest.json b/manifest.json index 8b37bb6..f4593c9 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "Tvheadend is a TV streaming server and recorder for Linux, FreeBSD and Android supporting DVB-S, DVB-S2, DVB-C, DVB-T, ATSC, ISDB-T, IPTV, SAT>IP and HDHomeRun as input sources", "fr": "Tvheadend est un serveur streaming TV pour Linux et supporte les sources d'entrées DVB-S, DVB-S2, DVB-C, DVB-T, ATSC, ISDB-T, IPTV, SAT>IP et HDHomeRun" }, - "version": "4.2.8-34~ynh3", + "version": "4.2.8-34~ynh4", "url": "https://tvheadend.org", "license": "free", "maintainer": { diff --git a/scripts/backup b/scripts/backup index aeb1b7d..5bda5fb 100644 --- a/scripts/backup +++ b/scripts/backup @@ -25,6 +25,7 @@ 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) port=$(ynh_app_setting_get --app=$app --key=port) stream_port=$(ynh_app_setting_get --app=$app --key=stream_port) @@ -32,19 +33,19 @@ stream_port=$(ynh_app_setting_get --app=$app --key=stream_port) #================================================= # STANDARD BACKUP STEPS #================================================= -# STOP SYSTEMD SERVICE +# STOP TVHEADEND SERVICE #================================================= ynh_script_progression --message="Stopping $app service..." --weight=1 ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app.log" #================================================= -# BACKUP THE APP MAIN DIR +# BACKUP THE APP MAIN DIR AND CONFIG FILES #================================================= -ynh_script_progression --message="Backing up $app config..." --weight=4 +ynh_script_progression --message="Backing up $app main directory and config files..." --weight=4 -ynh_backup --src_path="$final_path" ynh_backup --src_path="/etc/default/tvheadend" +ynh_backup --src_path="$final_path" #================================================= # BACKUP THE NGINX CONFIGURATION @@ -56,14 +57,15 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # SPECIFIC BACKUP #================================================= -# BACKUP LOGROTATE +# BACKUP LOGROTATE AND LOG FILE #================================================= -ynh_script_progression --message="Backing up logrotate configuration..." --weight=1 +ynh_script_progression --message="Backing up logrotate configuration and log file..." --weight=1 ynh_backup --src_path="/etc/logrotate.d/$app" +ynh_backup --src_path="/var/log/$app.log" #================================================= -# START SYSTEMD SERVICE +# START TVHEADEND SERVICE #================================================= ynh_script_progression --message="Starting $app service..." --weight=1 @@ -72,6 +74,6 @@ ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$ap #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." --time --last +ynh_script_progression --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." --last diff --git a/scripts/change_url b/scripts/change_url index b74fb5b..091aa4c 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -27,6 +27,7 @@ ynh_script_progression --message="Loading installation settings..." --weight=1 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) port=$(ynh_app_setting_get --app=$app --key=port) stream_port=$(ynh_app_setting_get --app=$app --key=stream_port) @@ -49,7 +50,7 @@ fi #================================================= # STANDARD MODIFICATIONS #================================================= -# STOP SYSTEMD SERVICE +# STOP TVHEADEND SERVICE #================================================= ynh_script_progression --message="Stopping $app service..." --weight=1 @@ -102,13 +103,6 @@ ynh_store_file_checksum --file="/etc/default/tvheadend" #================================================= # GENERIC FINALISATION -#================================================= -# START SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Starting $app service..." --weight=1 - -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app.log" - #================================================= # RELOAD NGINX #================================================= @@ -116,6 +110,13 @@ ynh_script_progression --message="Reloading nginx web server..." --weight=1 ynh_systemd_action --service_name=nginx --action=reload +#================================================= +# START TVHEADEND SERVICE +#================================================= +ynh_script_progression --message="Starting $app service..." --weight=1 + +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app.log" + #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/install b/scripts/install index bdaa297..52df7a9 100644 --- a/scripts/install +++ b/scripts/install @@ -30,7 +30,7 @@ app=$YNH_APP_INSTANCE_NAME ynh_script_progression --message="Validating installation parameters..." --weight=2 final_path=/home/hts # Default path for Tvheadend deb package -test ! -e "$final_path" || ynh_die --message="This path already contains a folder" +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 @@ -38,19 +38,20 @@ 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_script_progression --message="Storing installation settings..." --weight=2 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 (A) +# FIND AND OPEN PORTS #================================================= -ynh_script_progression --message="Configuring firewall..." --weight=16 +ynh_script_progression --message="Configuring firewall..." --weight=15 # Find a free port for the web server port=$(ynh_find_port --port=9981) @@ -65,9 +66,9 @@ ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $stream_port ynh_app_setting_set --app=$app --key=stream_port --value=$stream_port #================================================= -# INSTALL DEPENDENCIES (B) +# INSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Installing dependencies..." --weight=11 +ynh_script_progression --message="Installing dependencies..." --weight=15 if [ -n "$(uname -m | grep arm)" ] then @@ -79,29 +80,35 @@ fi #================================================= # DOWNLOAD TVHEADEND DEB PACKAGE #================================================= -ynh_script_progression --message="Downloading and installing $app..." --weight=51 +ynh_script_progression --message="Downloading $app..." --weight=5 temp_folder="$(mktemp -d)" tvheadend_deb_dst="$temp_folder/tvheadend_deb.deb" +tvheadend_deb_url="" if [ -n "$(uname -m | grep arm)" ] then - ynh_exec_quiet "wget -q -O $tvheadend_deb_dst $tvheadend_deb_arm" + tvheadend_deb_url="$tvheadend_deb_arm" elif [ -n "$(uname -m | grep x86_64)" ] then - ynh_exec_quiet "wget -q -O $tvheadend_deb_dst $tvheadend_deb_x86_64" + tvheadend_deb_url="$tvheadend_deb_x86_64" else - ynh_exec_quiet "wget -q -O $tvheadend_deb_dst $tvheadend_deb_x86_32" + tvheadend_deb_url="$tvheadend_deb_x86_32" fi -# The deb install automatically create the hts system user (C) +ynh_exec_quiet "wget -q -O $tvheadend_deb_dst $tvheadend_deb_url" + #================================================= -# INSTALL TVHEADEND DEB PACKAGE (D) +# INSTALL TVHEADEND DEB PACKAGE #================================================= +ynh_script_progression --message="Installing $app..." --weight=24 + ynh_package_install "$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" @@ -116,21 +123,16 @@ ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_f ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="/etc/default/tvheadend" 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" +ynh_store_file_checksum --file="/etc/default/tvheadend" # Copy and modify /home/hts/.hts/tvheadend/superuser 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" - -#================================================= -# STORE CONFIG FILES CHECKSUM -#================================================= -# Calculate and store config files checksum into the app settings -ynh_store_file_checksum --file="/etc/default/tvheadend" ynh_store_file_checksum --file="$final_path/.hts/tvheadend/superuser" #================================================= -# NGINX CONFIGURATION (E) +# NGINX CONFIGURATION #================================================= ynh_script_progression --message="Configuring nginx web server..." --weight=2 @@ -138,7 +140,7 @@ ynh_script_progression --message="Configuring nginx web server..." --weight=2 ynh_add_nginx_config #================================================= -# SETUP LOGROTATE (F) +# SETUP LOGROTATE #================================================= ynh_script_progression --message="Configuring log rotation..." --weight=1 @@ -148,7 +150,7 @@ chmod 666 /var/log/$app.log ynh_use_logrotate --logfile=/var/log/$app.log #================================================= -# ADVERTISE SERVICE IN ADMIN PANEL (G) +# ADVERTISE SERVICE IN ADMIN PANEL #================================================= yunohost service add $app --log "/var/log/$app.log" @@ -167,14 +169,14 @@ ynh_script_progression --message="Reloading nginx web server..." --weight=1 ynh_systemd_action --service_name=nginx --action=reload #================================================= -# PREVENT TVHEADEND BEING UPGRADED THROUGHT APT (H) +# PREVENT TVHEADEND BEING UPGRADED THROUGHT APT #================================================= ynh_script_progression --message="Prevent $app being upgraded throught APT..." --weight=1 apt-mark hold tvheadend #================================================= -# START TVHEADEND SERVICE (I) +# START TVHEADEND SERVICE #================================================= ynh_script_progression --message="Starting $app service..." --weight=1 diff --git a/scripts/remove b/scripts/remove index 2a2f42e..c73df90 100644 --- a/scripts/remove +++ b/scripts/remove @@ -18,6 +18,7 @@ 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) port=$(ynh_app_setting_get --app=$app --key=port) stream_port=$(ynh_app_setting_get --app=$app --key=stream_port) @@ -25,22 +26,23 @@ stream_port=$(ynh_app_setting_get --app=$app --key=stream_port) #================================================= # STANDARD REMOVE #================================================= -# STOP AND REMOVE TVHEADEND SERVICE (I) +# STOP AND DISABLE TVHEADEND SERVICE #================================================= -ynh_script_progression --message="Stopping $app service..." --weight=1 +ynh_script_progression --message="Stopping $app service..." --weight=2 -# Remove the dedicated systemd config -ynh_remove_systemd_config +ynh_systemd_action --service_name=$app --action=stop +ynh_exec_quiet systemctl disable $app +ynh_exec_quiet systemctl daemon-reload #================================================= -# UNHOLD TVHEADEND FROM APT (H) +# UNHOLD TVHEADEND FROM APT #================================================= -ynh_script_progression --message="Diasble prevent $app being upgraded throught APT..." --weight=1 +ynh_script_progression --message="Disable prevent $app being upgraded throught APT..." --weight=2 apt-mark unhold tvheadend #================================================= -# REMOVE SERVICE FROM ADMIN PANEL (G) +# REMOVE SERVICE FROM ADMIN PANEL #================================================= # Remove a service from the admin panel, added by `yunohost service add` if ynh_exec_warn_less yunohost service status $app >/dev/null @@ -50,7 +52,7 @@ then fi #================================================= -# REMOVE LOGROTATE CONFIGURATION (F) +# REMOVE LOGROTATE CONFIGURATION #================================================= ynh_script_progression --message="Removing logrotate configuration..." --weight=1 @@ -63,7 +65,7 @@ ynh_script_progression --message="Removing $app log file..." --weight=1 ynh_secure_remove --file="/var/log/$app.log" #================================================= -# REMOVE NGINX CONFIGURATION (E) +# REMOVE NGINX CONFIGURATION #================================================= ynh_script_progression --message="Removing nginx web server configuration..." --weight=1 @@ -71,22 +73,23 @@ ynh_script_progression --message="Removing nginx web server configuration..." -- ynh_remove_nginx_config #================================================= -# REMOVE TVHEADEND (D) +# REMOVE APP MAIN DIR AND CONFIG FILES #================================================= -ynh_script_progression --message="Removing $app..." --weight=5 +ynh_script_progression --message="Removing $app main directory and config files..." --weight=2 + +# Remove the app directory securely (/home/hts folder) +ynh_secure_remove --file="$final_path" +ynh_secure_remove --file="/etc/default/tvheadend" + +#================================================= +# REMOVE TVHEADEND +#================================================= +ynh_script_progression --message="Removing $app..." --weight=6 ynh_package_autopurge $app #================================================= -# REMOVE APP MAIN DIR (C) -#================================================= -ynh_script_progression --message="Removing $app main directory..." --weight=1 - -# Remove the app directory securely (/home/hts folder) -ynh_secure_remove --file="$final_path" - -#================================================= -# REMOVE DEDICATED USER (C) +# REMOVE DEDICATED USER #================================================= ynh_script_progression --message="Removing the dedicated hts system user..." --weight=1 @@ -94,7 +97,7 @@ ynh_script_progression --message="Removing the dedicated hts system user..." --w ynh_system_user_delete --username=hts #================================================= -# REMOVE DEPENDENCIES (B) +# REMOVE DEPENDENCIES #================================================= ynh_script_progression --message="Removing dependencies..." --weight=3 @@ -102,22 +105,22 @@ ynh_script_progression --message="Removing dependencies..." --weight=3 ynh_remove_app_dependencies #================================================= -# CLOSE TVHEADEND PORTS (A) +# CLOSE TVHEADEND PORTS #================================================= if yunohost firewall list | grep -q "\- $port$" then - ynh_script_progression --message="Closing port $port..." --weight=4 + ynh_script_progression --message="Closing port $port..." --weight=8 ynh_exec_warn_less yunohost firewall disallow TCP $port fi if yunohost firewall list | grep -q "\- $stream_port$" then - ynh_script_progression --message="Closing port $stream_port..." --weight=4 + ynh_script_progression --message="Closing port $stream_port..." --weight=8 ynh_exec_warn_less yunohost firewall disallow TCP $stream_port fi #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Removal of $app completed" --time --last +ynh_script_progression --message="Removal of $app completed" --last diff --git a/scripts/restore b/scripts/restore index eff8d44..33f6a35 100644 --- a/scripts/restore +++ b/scripts/restore @@ -24,6 +24,7 @@ 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) port=$(ynh_app_setting_get --app=$app --key=port) stream_port=$(ynh_app_setting_get --app=$app --key=stream_port) @@ -31,7 +32,7 @@ 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=1 +ynh_script_progression --message="Validating restoration parameters..." --weight=16 ynh_webpath_available --domain=$domain --path_url=$path_url \ || ynh_die --message="Path not available: ${domain}${path_url}" @@ -39,7 +40,9 @@ test ! -d $final_path \ || ynh_die --message="There is already a directory: $final_path " #================================================= -# OPEN TVHEADEND PORTS (A) +# STANDARD MODIFICATIONS +#================================================= +# OPEN TVHEADEND PORTS #================================================= if yunohost firewall list | grep -q "\- $port$" then @@ -55,9 +58,9 @@ 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 (B) +# INSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Installing dependencies..." --weight=11 +ynh_script_progression --message="Installing dependencies..." --weight=7 if [ -n "$(uname -m | grep arm)" ] then @@ -69,53 +72,64 @@ fi #================================================= # DOWNLOAD TVHEADEND DEB PACKAGE #================================================= -ynh_script_progression --message="Downloading and installing $app..." --weight=51 +ynh_script_progression --message="Downloading $app..." --weight=3 temp_folder="$(mktemp -d)" tvheadend_deb_dst="$temp_folder/tvheadend_deb.deb" +tvheadend_deb_url="" if [ -n "$(uname -m | grep arm)" ] then - ynh_exec_quiet "wget -q -O $tvheadend_deb_dst $tvheadend_deb_arm" + tvheadend_deb_url="$tvheadend_deb_arm" elif [ -n "$(uname -m | grep x86_64)" ] then - ynh_exec_quiet "wget -q -O $tvheadend_deb_dst $tvheadend_deb_x86_64" + tvheadend_deb_url="$tvheadend_deb_x86_64" else - ynh_exec_quiet "wget -q -O $tvheadend_deb_dst $tvheadend_deb_x86_32" + tvheadend_deb_url="$tvheadend_deb_x86_32" fi -# The deb install automatically create the hts system user (C) +ynh_exec_quiet "wget -q -O $tvheadend_deb_dst $tvheadend_deb_url" + #================================================= -# INSTALL TVHEADEND DEB PACKAGE (D) +# INSTALL TVHEADEND DEB PACKAGE #================================================= +ynh_script_progression --message="Installing $app..." --weight=13 + ynh_package_install "$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 THE APP CONFIG FILES +# RESTORE TVHEADEND CONFIG FILES #================================================= -ynh_script_progression --message="Restoring $app config..." --weight=2 +ynh_script_progression --message="Restoring $app main directory and config files..." --weight=1 -ynh_restore_file --origin_path="$final_path" ynh_restore_file --origin_path="/etc/default/tvheadend" +ynh_restore_file --origin_path="$final_path" #================================================= -# RESTORE THE NGINX CONFIGURATION (E) +# RESTORE THE NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Restoring nginx web server configuration..." --weight=1 + ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= -# RESTORE THE LOGROTATE CONFIGURATION (F) +# RESTORE THE LOGROTATE CONFIGURATION AND LOG FILE #================================================= +ynh_script_progression --message="Restoring logrotate configuration and log file..." --weight=1 + ynh_restore_file --origin_path="/etc/logrotate.d/$app" +ynh_restore_file --origin_path="/var/log/$app.log" #================================================= -# ADVERTISE SERVICE IN ADMIN PANEL (G) +# ADVERTISE SERVICE IN ADMIN PANEL #================================================= yunohost service add $app --log "/var/log/$app.log" @@ -134,14 +148,14 @@ ynh_script_progression --message="Reloading nginx web server..." --weight=1 ynh_systemd_action --service_name=nginx --action=reload #================================================= -# PREVENT TVHEADEND BEING UPGRADED THROUGHT APT (G) +# PREVENT TVHEADEND BEING UPGRADED THROUGHT APT #================================================= ynh_script_progression --message="Prevent $app being upgraded throught APT..." --weight=1 apt-mark hold tvheadend #================================================= -# START TVHEADEND SERVICE (I) +# START TVHEADEND SERVICE #================================================= ynh_script_progression --message="Starting $app service..." --weight=1 diff --git a/scripts/upgrade b/scripts/upgrade index 46cff78..ac29b52 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -11,13 +11,14 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --weight=1 +ynh_script_progression --message="Loading installation settings..." --weight=2 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) port=$(ynh_app_setting_get --app=$app --key=port) stream_port=$(ynh_app_setting_get --app=$app --key=stream_port) @@ -46,14 +47,14 @@ ynh_abort_if_errors #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping $app service..." --weight=1 +ynh_script_progression --message="Stopping $app service..." --weight=3 ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app.log" #================================================= # UPGRADE DEPENDENCIES #================================================= -ynh_script_progression --message="Upgrading dependencies..." --weight=11 +ynh_script_progression --message="Upgrading dependencies..." --weight=15 if [ -n "$(uname -m | grep arm)" ] then @@ -63,43 +64,55 @@ else fi #================================================= -# INSTALL DEB PACKAGE +# UPGRADE TVHEADEND DEB PACKAGE #================================================= if [ "$upgrade_type" == "UPGRADE_APP" ] then - ynh_script_progression --message="Upgrading $app..." --weight=51 + #================================================= + # DOWNLOAD TVHEADEND DEB PACKAGE + #================================================= + ynh_script_progression --message="Downloading $app..." --weight=5 temp_folder="$(mktemp -d)" tvheadend_deb_dst="$temp_folder/tvheadend_deb.deb" + tvheadend_deb_url="" if [ -n "$(uname -m | grep arm)" ] then - ynh_exec_quiet "wget -q -O $tvheadend_deb_dst $tvheadend_deb_arm" + tvheadend_deb_url="$tvheadend_deb_arm" elif [ -n "$(uname -m | grep x86_64)" ] then - ynh_exec_quiet "wget -q -O $tvheadend_deb_dst $tvheadend_deb_x86_64" + tvheadend_deb_url="$tvheadend_deb_x86_64" else - ynh_exec_quiet "wget -q -O $tvheadend_deb_dst $tvheadend_deb_x86_32" + tvheadend_deb_url="$tvheadend_deb_x86_32" fi + ynh_exec_quiet "wget -q -O $tvheadend_deb_dst $tvheadend_deb_url" + + #================================================= + # INSTALL TVHEADEND DEB PACKAGE + #================================================= + ynh_script_progression --message="Upgrading $app..." --weight=24 + ynh_package_install "$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" + + # Deb install seems to remove the superuser config, let's restore it + # Copy and modify /home/hts/.hts/tvheadend/superuser + 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" + ynh_store_file_checksum --file="$final_path/.hts/tvheadend/superuser" + fi - -#================================================= -# PREVENT TVHEADEND BEING UPGRADED THROUGHT APT -#================================================= -apt-mark hold tvheadend - -#================================================= -# START SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Starting $app service..." --weight=1 - -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app.log" - #================================================= # SETUP SSOWAT #================================================= @@ -114,6 +127,18 @@ ynh_script_progression --message="Reloading nginx web server..." --weight=1 ynh_systemd_action --service_name=nginx --action=reload +#================================================= +# PREVENT TVHEADEND BEING UPGRADED THROUGHT APT +#================================================= +apt-mark hold tvheadend + +#================================================= +# START TVHEADEND SERVICE +#================================================= +ynh_script_progression --message="Starting $app service..." --weight=1 + +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app.log" + #================================================= # END OF SCRIPT #=================================================