From 0b18e2c412cf9d89e30b8758ec707362433d7c3d Mon Sep 17 00:00:00 2001 From: Sylvain CECCHETTO Date: Sun, 20 Oct 2019 18:28:27 +0200 Subject: [PATCH] [+] Code documentation --- scripts/install | 44 +++++++++++---------- scripts/remove | 100 +++++++++++++++++++++++------------------------- scripts/restore | 31 ++++++++------- 3 files changed, 88 insertions(+), 87 deletions(-) diff --git a/scripts/install b/scripts/install index 36d2920..0d6a131 100644 --- a/scripts/install +++ b/scripts/install @@ -48,7 +48,7 @@ ynh_app_setting_set --app=$app --key=final_path --value=$final_path #================================================= # STANDARD MODIFICATIONS #================================================= -# FIND AND OPEN PORTS +# FIND AND OPEN PORTS (A) #================================================= ynh_script_progression --message="Configuring firewall..." --weight=16 @@ -65,7 +65,7 @@ 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 +# INSTALL DEPENDENCIES (B) #================================================= ynh_script_progression --message="Installing dependencies..." --weight=11 @@ -77,7 +77,7 @@ else fi #================================================= -# DOWNLOAD AND INSTALL TVHEADEND DEB PACKAGE +# DOWNLOAD TVHEADEND DEB PACKAGE #================================================= ynh_script_progression --message="Downloading and installing $app..." --weight=51 @@ -94,6 +94,10 @@ else ynh_exec_quiet "wget -q -O $tvheadend_deb_dst $tvheadend_deb_x86_32" fi +# The deb install automatically create the hts system user (C) +#================================================= +# INSTALL TVHEADEND DEB PACKAGE (D) +#================================================= ynh_package_install "$tvheadend_deb_dst" ynh_secure_remove --file="$temp_folder" @@ -102,14 +106,6 @@ ynh_secure_remove --file="$temp_folder" # we stop it before the configuration ynh_systemd_action --service_name=$app --action="stop" -#================================================= -# NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Configuring nginx web server..." --weight=2 - -# Create a dedicated nginx config -ynh_add_nginx_config - #================================================= # MODIFY TVHEADEND CONFIG FILES #================================================= @@ -134,7 +130,15 @@ ynh_store_file_checksum --file="/etc/default/tvheadend" ynh_store_file_checksum --file="$final_path/.hts/tvheadend/superuser" #================================================= -# SETUP LOGROTATE +# 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) #================================================= ynh_script_progression --message="Configuring log rotation..." --weight=1 @@ -144,17 +148,10 @@ chmod 666 /var/log/$app.log ynh_use_logrotate --logfile=/var/log/$app.log #================================================= -# ADVERTISE SERVICE IN ADMIN PANEL +# ADVERTISE SERVICE IN ADMIN PANEL (G) #================================================= yunohost service add $app --log "/var/log/$app.log" -#================================================= -# 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" - #================================================= # SETUP SSOWAT #================================================= @@ -169,6 +166,13 @@ ynh_script_progression --message="Reloading nginx web server..." --weight=1 ynh_systemd_action --service_name=nginx --action=reload +#================================================= +# START TVHEADEND SERVICE (H) +#================================================= +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/remove b/scripts/remove index dc89a56..19b3ea5 100644 --- a/scripts/remove +++ b/scripts/remove @@ -25,7 +25,15 @@ stream_port=$(ynh_app_setting_get --app=$app --key=stream_port) #================================================= # STANDARD REMOVE #================================================= -# REMOVE SERVICE FROM ADMIN PANEL +# STOP AND REMOVE TVHEADEND SERVICE (H) +#================================================= +ynh_script_progression --message="Stopping $app service..." --weight=1 + +# Remove the dedicated systemd config +ynh_remove_systemd_config + +#================================================= +# REMOVE SERVICE FROM ADMIN PANEL (G) #================================================= # Remove a service from the admin panel, added by `yunohost service add` if ynh_exec_warn_less yunohost service status $app >/dev/null @@ -35,38 +43,20 @@ then fi #================================================= -# STOP AND REMOVE TVHEADEND SERVICE +# REMOVE LOGROTATE CONFIGURATION (F) #================================================= -ynh_script_progression --message="Stopping $app service..." --weight=1 +ynh_script_progression --message="Removing logrotate configuration..." --weight=1 -# Remove the dedicated systemd config -ynh_remove_systemd_config +# Remove the app-specific logrotate config +ynh_remove_logrotate + +ynh_script_progression --message="Removing $app log file..." --weight=1 + +# Remove the log files +ynh_secure_remove --file="/var/log/$app.log" #================================================= -# REMOVE TVHEADEND -#================================================= -ynh_script_progression --message="Removing $app..." --weight=5 - -ynh_package_autopurge $app - -#================================================= -# REMOVE DEPENDENCIES -#================================================= -ynh_script_progression --message="Removing dependencies..." --weight=3 - -# Remove metapackage and its dependencies -ynh_remove_app_dependencies - -#================================================= -# REMOVE APP MAIN DIR -#================================================= -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 NGINX CONFIGURATION +# REMOVE NGINX CONFIGURATION (E) #================================================= ynh_script_progression --message="Removing nginx web server configuration..." --weight=1 @@ -74,15 +64,38 @@ ynh_script_progression --message="Removing nginx web server configuration..." -- ynh_remove_nginx_config #================================================= -# REMOVE LOGROTATE CONFIGURATION +# REMOVE TVHEADEND (D) #================================================= -ynh_script_progression --message="Removing logrotate configuration..." --weight=1 +ynh_script_progression --message="Removing $app..." --weight=5 -# Remove the app-specific logrotate config -ynh_remove_logrotate +ynh_package_autopurge $app #================================================= -# CLOSE TVHEADEND PORTS +# 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) +#================================================= +ynh_script_progression --message="Removing the dedicated hts system user..." --weight=1 + +# Delete a system user +ynh_system_user_delete --username=hts + +#================================================= +# REMOVE DEPENDENCIES (B) +#================================================= +ynh_script_progression --message="Removing dependencies..." --weight=3 + +# Remove metapackage and its dependencies +ynh_remove_app_dependencies + +#================================================= +# CLOSE TVHEADEND PORTS (A) #================================================= if yunohost firewall list | grep -q "\- $port$" then @@ -96,25 +109,6 @@ then ynh_exec_warn_less yunohost firewall disallow TCP $stream_port fi - -#================================================= -# SPECIFIC REMOVE -#================================================= -ynh_script_progression --message="Removing $app log file..." --weight=1 - -# Remove the log files -ynh_secure_remove --file="/var/log/$app.log" - -#================================================= -# GENERIC FINALIZATION -#================================================= -# REMOVE DEDICATED USER -#================================================= -ynh_script_progression --message="Removing the dedicated hts system user..." --weight=1 - -# Delete a system user -ynh_system_user_delete --username=hts - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/restore b/scripts/restore index 7926e38..bb432d2 100644 --- a/scripts/restore +++ b/scripts/restore @@ -39,7 +39,7 @@ test ! -d $final_path \ || ynh_die --message="There is already a directory: $final_path " #================================================= -# OPEN TVHEADEND PORTS +# OPEN TVHEADEND PORTS (A) #================================================= if yunohost firewall list | grep -q "\- $port$" then @@ -55,7 +55,7 @@ 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 +# INSTALL DEPENDENCIES (B) #================================================= ynh_script_progression --message="Installing dependencies..." --weight=11 @@ -67,9 +67,9 @@ else fi #================================================= -# INSTALL DEB PACKAGE +# DOWNLOAD TVHEADEND DEB PACKAGE #================================================= -ynh_script_progression --message="Installing $app..." --weight=51 +ynh_script_progression --message="Downloading and installing $app..." --weight=51 temp_folder="$(mktemp -d)" tvheadend_deb_dst="$temp_folder/tvheadend_deb.deb" @@ -84,19 +84,18 @@ else ynh_exec_quiet "wget -q -O $tvheadend_deb_dst $tvheadend_deb_x86_32" fi +# The deb install automatically create the hts system user (C) +#================================================= +# INSTALL TVHEADEND DEB PACKAGE (D) +#================================================= ynh_package_install "$tvheadend_deb_dst" ynh_secure_remove --file="$temp_folder" # Tvheadend automatically start after install -# we stop it +# we stop it before the configuration ynh_systemd_action --service_name=$app --action="stop" -#================================================= -# RESTORE THE NGINX CONFIGURATION -#================================================= -ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" - #================================================= # RESTORE THE APP CONFIG FILES #================================================= @@ -106,12 +105,17 @@ ynh_restore_file --origin_path="$final_path" ynh_restore_file --origin_path="/etc/default/tvheadend" #================================================= -# RESTORE THE LOGROTATE CONFIGURATION +# RESTORE THE NGINX CONFIGURATION (E) +#================================================= +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" + +#================================================= +# RESTORE THE LOGROTATE CONFIGURATION (F) #================================================= ynh_restore_file --origin_path="/etc/logrotate.d/$app" #================================================= -# ADVERTISE SERVICE IN ADMIN PANEL +# ADVERTISE SERVICE IN ADMIN PANEL (G) #================================================= yunohost service add $app --log "/var/log/$app.log" @@ -122,7 +126,6 @@ ynh_script_progression --message="Configuring SSOwat..." --weight=1 ynh_app_setting_set --app=$app --key=skipped_uris --value="/" - #================================================= # RELOAD NGINX #================================================= @@ -131,7 +134,7 @@ ynh_script_progression --message="Reloading nginx web server..." --weight=1 ynh_systemd_action --service_name=nginx --action=reload #================================================= -# START SYSTEMD SERVICE +# START TVHEADEND SERVICE (G) #================================================= ynh_script_progression --message="Starting $app service..." --weight=1