From 55ae609a2c2b689684a9eca2b5d34b6ede54c56e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Sun, 14 Jan 2024 21:36:05 +0100 Subject: [PATCH] Manifest v2 --- check_process | 21 ------ conf/nginx.conf | 16 ++--- doc/DISCLAIMER.md | 0 manifest.json | 56 ---------------- manifest.toml | 103 ++++++++++++++++++++++++++++ scripts/_common.sh | 46 +++++++++++-- scripts/backup | 22 +----- scripts/change_url | 110 ++---------------------------- scripts/install | 158 +++++-------------------------------------- scripts/remove | 69 ++----------------- scripts/restore | 124 ++++------------------------------ scripts/upgrade | 162 +++++++++------------------------------------ tests.toml | 9 +++ 13 files changed, 234 insertions(+), 662 deletions(-) delete mode 100644 check_process delete mode 100644 doc/DISCLAIMER.md delete mode 100644 manifest.json create mode 100644 manifest.toml create mode 100644 tests.toml diff --git a/check_process b/check_process deleted file mode 100644 index e6a36ed..0000000 --- a/check_process +++ /dev/null @@ -1,21 +0,0 @@ -;; Full test - ; Manifest - domain="domain.tld" - path="/path" - superuser="toto" - password="1Strong-Password" - port="9982" - ; Checks - pkg_linter=1 - setup_sub_dir=1 - setup_root=1 - setup_nourl=0 - setup_private=0 - setup_public=0 - upgrade=1 - # 4.3.1979~ynh9 - upgrade=1 from_commit=e82643952e5567db826790e1e4a353559f66f112 - backup_restore=1 - multi_instance=0 - port_already_use=1 - change_url=1 diff --git a/conf/nginx.conf b/conf/nginx.conf index 98fa867..d381b6e 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,13 +1,13 @@ #sub_path_only rewrite ^__PATH__$ __PATH__/ permanent; location __PATH__/ { - proxy_pass http://127.0.0.1:__PORT__; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; + proxy_pass http://127.0.0.1:__PORT__; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; - # Include SSOWAT user panel. - include conf.d/yunohost_panel.conf.inc; + # Include SSOWAT user panel. + include conf.d/yunohost_panel.conf.inc; } diff --git a/doc/DISCLAIMER.md b/doc/DISCLAIMER.md deleted file mode 100644 index e69de29..0000000 diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 214876c..0000000 --- a/manifest.json +++ /dev/null @@ -1,56 +0,0 @@ -{ - "name": "Tvheadend", - "id": "tvheadend", - "packaging_format": 1, - "description": { - "en": "TV streaming server and recorder", - "fr": "Serveur de streaming et d'enregistrement TV" - }, - "version": "4.3.2009~ynh10", - "url": "https://tvheadend.org", - "upstream": { - "license": "GPL-3.0", - "website": "https://tvheadend.org", - "userdoc": "https://tvheadend.org/projects/tvheadend/wiki", - "code": "https://github.com/tvheadend/tvheadend" - }, - "license": "GPL-3.0", - "maintainer": { - "name": "Sylvain Cecchetto", - "email": "cecchetto.sylvain@me.com" - }, - "requirements": { - "yunohost": ">= 4.3.0" - }, - "multi_instance": false, - "services": [ - "nginx" - ], - "arguments": { - "install" : [ - { - "name": "domain", - "type": "domain" - }, - { - "name": "path", - "type": "path", - "example": "/tvh", - "default": "/tvh" - }, - { - "name": "superuser", - "type": "string", - "ask": { - "en": "Choose the superuser name in order to login on Tvheadend", - "fr": "Choisissez le nom du superutilisateur pour la connexion à Tvheadend" - }, - "example": "johndoe" - }, - { - "name": "password", - "type": "password" - } - ] - } -} diff --git a/manifest.toml b/manifest.toml new file mode 100644 index 0000000..3ad1403 --- /dev/null +++ b/manifest.toml @@ -0,0 +1,103 @@ +#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/manifest.v2.schema.json + +packaging_format = 2 + +id = "tvheadend" +name = "Tvheadend" +description.en = "TV streaming server and recorder" +description.fr = "Serveur de streaming et d'enregistrement TV" + +version = "4.3.2009~ynh10" + +maintainers = ["Sylvain Cecchetto"] + +[upstream] +license = "GPL-3.0" +website = "https://tvheadend.org" +userdoc = "https://tvheadend.org/projects/tvheadend/wiki" +code = "https://github.com/tvheadend/tvheadend" + +[integration] +yunohost = ">= 4.3.0" +architectures = ["amd64", "armhf"] +multi_instance = false +ldap = "not_relevant" +sso = "not_relevant" +disk = "50M" # FIXME: replace with an **estimate** minimum disk requirement. e.g. 20M, 400M, 1G, ... +ram.build = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ... +ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ... + +[install] + [install.domain] + type = "domain" + + [install.path] + type = "path" + default = "/tvh" + + [install.superuser] + ask.en = "Choose the superuser name in order to login on Tvheadend" + ask.fr = "Choisissez le nom du superutilisateur pour la connexion à Tvheadend" + type = "string" + example = "johndoe" + + [install.password] + type = "password" + +[resources] + [resources.sources.main_buster] + amd64.url = "https://dl.cloudsmith.io/public/tvheadend/tvheadend/deb/debian/pool/buster/main/t/tv/tvheadend_4.3-2192~gc9b38a81a~buster/tvheadend_4.3-2192~gc9b38a81a~buster_amd64.deb" + amd64.sha256 = "faf486839aa96058b20bd14242cde15371072d69b92313f9a60c63fa21bfc27a" + armhf.url = "https://dl.cloudsmith.io/public/tvheadend/tvheadend/deb/debian/pool/buster/main/t/tv/tvheadend_4.3-2192~gc9b38a81a~buster/tvheadend_4.3-2192~gc9b38a81a~buster_armhf.deb" + armhf.sha256 = "8c5e16b2320f3de4bd145bdd4de8cd5be6298b3b61412c943435c756b1c508d2" + arm64.url = "https://dl.cloudsmith.io/public/tvheadend/tvheadend/deb/debian/pool/buster/main/t/tv/tvheadend_4.3-2192~gc9b38a81a~buster/tvheadend_4.3-2192~gc9b38a81a~buster_arm64.deb" + arm64.sha256 = "8e5464ab7d5634942fe5da7d68a773b1dcd09b4736c4994a2065705b556e25dc" + rename = "tvheadend.deb" + + format = "whatever" + extract = false + prefetch = false + autoupdate.strategy = "latest_github_tag" + autoupdate.asset = "tarball" + + [resources.sources.main_bullseye] + amd64.url = "https://dl.cloudsmith.io/public/tvheadend/tvheadend/deb/debian/pool/bullseye/main/t/tv/tvheadend_4.3-2192~gc9b38a81a~bullseye/tvheadend_4.3-2192~gc9b38a81a~bullseye_amd64.deb" + amd64.sha256 = "e8f027620c5af52a805809ff6b42ee321db775f92fb161a6e5875f936f577782" + armhf.url = "https://dl.cloudsmith.io/public/tvheadend/tvheadend/deb/debian/pool/bullseye/main/t/tv/tvheadend_4.3-2192~gc9b38a81a~bullseye/tvheadend_4.3-2192~gc9b38a81a~bullseye_armhf.deb" + armhf.sha256 = "2b34f372c6272e47880555dd67a1aba23b0410d4b69d5aee41483829bcb3ef89" + arm64.url = "https://dl.cloudsmith.io/public/tvheadend/tvheadend/deb/debian/pool/bullseye/main/t/tv/tvheadend_4.3-2192~gc9b38a81a~bullseye/tvheadend_4.3-2192~gc9b38a81a~bullseye_arm64.deb" + arm64.sha256 = "f672912eb67fe3ac9d469c55d87ce2dde097d441413c862eef758e49b140c5a8" + rename = "tvheadend.deb" + + format = "whatever" + extract = false + prefetch = false + autoupdate.strategy = "latest_github_tag" + autoupdate.asset = "tarball" + + [resources.system_user] + + [resources.install_dir] + + [resources.permissions] + main.url = "/" + + [resources.ports] + main.default = 9981 + stream.default = 9982 + stream.exposed = "TCP" + + [resources.apt] + packages = [ + "libavahi-client3", + "libavahi-common3", + "libc6", + "libdbus-1-3", + "libdvbcsa1", + "libpcre3", + "libssl1.1", + "libstdc++6", + "liburiparser1", + "zlib1g", + "bzip2", + ] diff --git a/scripts/_common.sh b/scripts/_common.sh index d5d23a8..6039510 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -4,18 +4,50 @@ # COMMON VARIABLES #================================================= -# dependencies used by the app -pkg_dependencies_x86="libavahi-client3 libavahi-common3 libc6 libdbus-1-3 libdvbcsa1 libpcre3 libssl1.1 libstdc++6 liburiparser1 zlib1g bzip2" -pkg_dependencies_rb="libavahi-client3 libavahi-common3 libc6 libdbus-1-3 libdvbcsa1 libpcre2-8-0 libssl1.1 liburiparser1 zlib1g bzip2" - -# deb package URLs -tvheadend_deb_x86="https://github.com/YunoHost-Apps/tvheadend_ynh/raw/debs/4.3.2009/tvheadend_4.3-2009%7Eg1295dd2be%7Estretch_amd64.deb" -tvheadend_deb_arm="https://github.com/YunoHost-Apps/tvheadend_ynh/raw/debs/4.3.2009/tvheadend_4.3-2009%7Eg1295dd2be%7Eraspbianstretch_armhf.deb" +debian=$(lsb_release --codename --short) +pkg_version="4.3-2192" #================================================= # PERSONAL HELPERS #================================================= +_install_tvheadend_package() { + # Download the package + if [ ! -f "$install_dir/tvheadend.deb" ]; then + ynh_setup_source --dest_dir="$install_dir" --source_id="main_$debian" + fi + + # 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 + + # Install the package + ynh_package_install \ + "$install_dir/tvheadend.deb" + + # The doc says it should be called only once, + # but the code says multiple calls are supported. + # Also, they're already installed so that should be quasi instantaneous. + ynh_install_app_dependencies \ + tvheadend="$pkg_version" + + # Mark packages as dependencies, to allow automatic removal + apt-mark auto tvheadend + + # Prevent tvheadend being upgraded through apt… + apt-mark hold tvheadend +} + +_uninstall_tvheadend_package() { + apt-mark unhold tvheadend + + ynh_package_autopurge tvheadend + + # Delete the system user created by the package + deluser hts --remove-home +} + #================================================= # EXPERIMENTAL HELPERS #================================================= diff --git a/scripts/backup b/scripts/backup index 48295d5..be1f6f2 100644 --- a/scripts/backup +++ b/scripts/backup @@ -10,26 +10,6 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -ynh_clean_setup () { - true -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# LOAD SETTINGS -#================================================= -ynh_print_info --message="Loading installation settings..." - -app=$YNH_APP_INSTANCE_NAME - -final_path=$(ynh_app_setting_get --app=$app --key=final_path) -domain=$(ynh_app_setting_get --app=$app --key=domain) - #================================================= # DECLARE DATA AND CONF FILES TO BACKUP #================================================= @@ -39,7 +19,7 @@ ynh_print_info --message="Declaring files to be backed up..." # BACKUP THE APP MAIN DIR #================================================= -ynh_backup --src_path="$final_path" +ynh_backup --src_path="$install_dir" #================================================= # BACKUP THE NGINX CONFIGURATION diff --git a/scripts/change_url b/scripts/change_url index b107e1f..2ceb94c 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -9,64 +9,6 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# RETRIEVE ARGUMENTS -#================================================= - -old_domain=$YNH_APP_OLD_DOMAIN -old_path=$YNH_APP_OLD_PATH - -new_domain=$YNH_APP_NEW_DOMAIN -new_path=$YNH_APP_NEW_PATH - -app=$YNH_APP_INSTANCE_NAME - -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." --weight=1 - -# Needed for helper "ynh_add_nginx_config" -final_path=$(ynh_app_setting_get --app=$app --key=final_path) - -conf_dir=$(ynh_app_setting_get --app=$app --key=conf_dir) -port=$(ynh_app_setting_get --app=$app --key=port) -stream_port=$(ynh_app_setting_get --app=$app --key=stream_port) - -#================================================= -# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP -#================================================= -ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." --weight=1 - -# Backup the current version of the app -ynh_backup_before_upgrade -ynh_clean_setup () { - ynh_clean_check_starting - # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location. - ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" - - # Restore it if the upgrade fails - ynh_restore_upgradebackup -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# CHECK WHICH PARTS SHOULD BE CHANGED -#================================================= - -change_domain=0 -if [ "$old_domain" != "$new_domain" ] -then - change_domain=1 -fi - -change_path=0 -if [ "$old_path" != "$new_path" ] -then - change_path=1 -fi - #================================================= # STANDARD MODIFICATIONS #================================================= @@ -81,51 +23,16 @@ ynh_systemd_action --service_name=$app --action="stop" #================================================= ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1 -nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf - -# Change the path in the NGINX config file -if [ $change_path -eq 1 ] -then - # Make a backup of the original NGINX config file if modified - ynh_backup_if_checksum_is_different --file="$nginx_conf_path" - # Set global variables for NGINX helper - domain="$old_domain" - path_url="$new_path" - # Create a dedicated NGINX config - ynh_add_nginx_config - - # Update Tvheadend configuration file - ynh_script_progression --message="Updating Tvheadend configuration..." --weight=1 - 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" - fi -fi - -# Change the domain for NGINX -if [ $change_domain -eq 1 ] -then - # Delete file checksum for the old conf file location - ynh_delete_file_checksum --file="$nginx_conf_path" - mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf - # Store file checksum for the new config file location - ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" -fi +ynh_change_url_nginx_config #================================================= # SPECIFIC MODIFICATIONS #================================================= -# ... -#================================================= - # Update Tvheadend configuration file -if [ $change_path -eq 1 ] -then +if [ "$change_path" -eq 1 ]; then + # Update Tvheadend configuration file ynh_script_progression --message="Updating Tvheadend configuration..." --weight=1 - if [ "$path_url" = "/" ] - then + if [ "$path" = "/" ]; then ynh_add_config --template="tvheadend_no_subpath" --destination="/etc/default/tvheadend" else ynh_add_config --template="tvheadend" --destination="/etc/default/tvheadend" @@ -140,14 +47,7 @@ fi ynh_script_progression --message="Starting a systemd service..." --weight=1 # Start a systemd service -ynh_systemd_action --service_name=$app --action="start" - -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." --weight=1 - -ynh_systemd_action --service_name=nginx --action=reload +ynh_systemd_action --service_name="$app" --action="start" #================================================= # END OF SCRIPT diff --git a/scripts/install b/scripts/install index 972189e..bd5157d 100644 --- a/scripts/install +++ b/scripts/install @@ -10,123 +10,18 @@ source _common.sh source /usr/share/yunohost/helpers #================================================= -# MANAGE SCRIPT FAILURE +# DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_script_progression --message="Downloading and installing $app package..." --weight=1 -ynh_clean_setup () { - ynh_clean_check_starting -} -# 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="This 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 $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 - -#================================================= -# NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Configuring NGINX web server..." --weight=2 - -# Create a dedicated NGINX config -ynh_add_nginx_config - -#================================================= -# 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" +chown -R "$app:www-data" "$install_dir" +_install_tvheadend_package # 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" +ynh_systemd_action --service_name="$app" --action="stop" #================================================= # MODIFY TVHEADEND CONFIG FILES @@ -134,30 +29,23 @@ ynh_systemd_action --service_name=$app --action="stop" 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" +conf_dir=$install_dir/.hts/tvheadend +ynh_app_setting_set --app="$app" --key=conf_dir --value="$conf_dir" +if [ "$path" = "/" ]; then + ynh_add_config --template="tvheadend_no_subpath" --destination="/etc/default/tvheadend" else - ynh_add_config --template="tvheadend" --destination="/etc/default/tvheadend" + ynh_add_config --template="tvheadend" --destination="/etc/default/tvheadend" fi #================================================= -# PREVENT TVHEADEND BEING UPGRADED THROUGHT APT +# SYSTEM CONFIGURATION #================================================= -ynh_script_progression --message="Prevent Tvheadend being upgraded throught APT..." --weight=1 +ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 -apt-mark hold tvheadend +# Create a dedicated NGINX config +ynh_add_nginx_config -#================================================= -# GENERIC FINALIZATION -#================================================= -# 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 $stream_port +yunohost service add "$app" --description="TV streaming server and recorder" --needs_exposed_ports $stream_port #================================================= # START SYSTEMD SERVICE @@ -165,21 +53,7 @@ yunohost service add $app --description="TV streaming server and recorder" --nee ynh_script_progression --message="Starting a systemd service..." --weight=1 # Start a systemd service -ynh_systemd_action --service_name=$app --action="start" - -#================================================= -# 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 +ynh_systemd_action --service_name="$app" --action="start" #================================================= # END OF SCRIPT diff --git a/scripts/remove b/scripts/remove index 82a0a09..dac0d28 100644 --- a/scripts/remove +++ b/scripts/remove @@ -9,20 +9,6 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." --weight=1 - -app=$YNH_APP_INSTANCE_NAME - -domain=$(ynh_app_setting_get --app=$app --key=domain) -port=$(ynh_app_setting_get --app=$app --key=port) -stream_port=$(ynh_app_setting_get --app=$app --key=stream_port) -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) - #================================================= # STANDARD REMOVE #================================================= @@ -30,8 +16,7 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= # Remove the service from the list of services known by YunoHost (added from `yunohost service add`) -if ynh_exec_warn_less yunohost service status $app >/dev/null -then +if ynh_exec_warn_less yunohost service status $app >/dev/null; then ynh_script_progression --message="Removing $app service integration..." --weight=1 yunohost service remove $app fi @@ -41,67 +26,27 @@ fi #================================================= ynh_script_progression --message="Stopping Tvheadend service..." --weight=2 -ynh_systemd_action --service_name=$app --action=stop -ynh_exec_quiet systemctl disable $app --quiet +ynh_systemd_action --service_name="$app" --action=stop +ynh_exec_quiet systemctl disable "$app" --quiet ynh_exec_quiet systemctl daemon-reload #================================================= # UNHOLD TVHEADEND FROM APT #================================================= -ynh_script_progression --message="Disable prevent Tvheadend being upgraded throught APT..." --weight=2 +ynh_script_progression --message="Removing the $app apt package..." --weight=2 -apt-mark unhold tvheadend +_uninstall_tvheadend_package #================================================= -# REMOVE TVHEADEND +# REMOVE SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Removing Tvheadend..." --weight=6 - -ynh_package_autopurge $app - -#================================================= -# REMOVE NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1 +ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 # Remove the dedicated NGINX config ynh_remove_nginx_config -#================================================= -# REMOVE DEPENDENCIES -#================================================= -ynh_script_progression --message="Removing dependencies..." --weight=3 - -# Remove metapackage and its dependencies -ynh_remove_app_dependencies - -#================================================= -# CLOSE A PORT -#================================================= - -if yunohost firewall list | grep -q "\- $stream_port$" -then - ynh_script_progression --message="Closing port $stream_port..." --weight=8 - ynh_exec_warn_less yunohost firewall disallow TCP $stream_port -fi - -#================================================= -# SPECIFIC REMOVE -#================================================= -# REMOVE VARIOUS FILES -#================================================= -ynh_script_progression --message="Removing various files..." - ynh_secure_remove --file="/etc/default/tvheadend" -#================================================= -# REMOVE DEDICATED USER -#================================================= -ynh_script_progression --message="Removing the dedicated system user..." --weight=1 - -# Delete a system user -deluser hts --remove-home - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/restore b/scripts/restore index a5e053c..9c063fe 100644 --- a/scripts/restore +++ b/scripts/restore @@ -11,108 +11,25 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers #================================================= -# MANAGE SCRIPT FAILURE +# RESTORE THE APP MAIN DIR #================================================= +ynh_script_progression --message="Restoring the app main directory..." --weight=1 -ynh_clean_setup () { - ynh_clean_check_starting -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors +ynh_restore_file --origin_path="$install_dir" + +chown -R "$app:www-data" "$install_dir" #================================================= -# LOAD SETTINGS +# DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Loading settings..." --weight=1 - -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) -conf_dir=$(ynh_app_setting_get --app=$app --key=conf_dir) -port=$(ynh_app_setting_get --app=$app --key=port) -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=16 - -test ! -d $final_path \ - || ynh_die --message="There is already a directory: $final_path " - -#================================================= -# STANDARD RESTORATION STEPS -#================================================= -# RESTORE THE NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1 - -ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" - -#================================================= -# OPEN TVHEADEND PORTS -#================================================= -ynh_script_progression --message="Configuring firewall..." --weight=15 - -if yunohost firewall list | grep -q "\- $stream_port$" -then - ynh_die --message="Port $stream_port already open (and maybe used by another application)" -fi - -ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $stream_port - -#================================================= -# INSTALL DEPENDENCIES -#================================================= -ynh_script_progression --message="Installing dependencies..." --weight=7 - -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=3 - -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=13 - -# 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" +ynh_script_progression --message="Reinstalling $app package..." --weight=1 +_install_tvheadend_package # 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" +ynh_systemd_action --service_name="$app" --action="stop" #================================================= # RESTORE TVHEADEND CONFIG FILES @@ -120,35 +37,22 @@ ynh_systemd_action --service_name=$app --action="stop" ynh_script_progression --message="Restoring Tvheadend main directory and config files..." --weight=1 ynh_restore_file --origin_path="/etc/default/tvheadend" -ynh_restore_file --origin_path="$final_path" #================================================= -# PREVENT TVHEADEND BEING UPGRADED THROUGHT APT +# RESTORE SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Prevent Tvheadend being upgraded throught APT..." --weight=1 +ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 -apt-mark hold tvheadend +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" -#================================================= -# 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 $stream_port +yunohost service add "$app" --description="TV streaming server and recorder" --needs_exposed_ports $stream_port #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="start" - -#================================================= -# GENERIC FINALIZATION -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." --weight=1 +ynh_systemd_action --service_name="$app" --action="start" ynh_systemd_action --service_name=nginx --action=reload diff --git a/scripts/upgrade b/scripts/upgrade index 062afc9..8e6119b 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -9,44 +9,6 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# LOAD SETTINGS -#================================================= -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) -conf_dir=$(ynh_app_setting_get --app=$app --key=conf_dir) -port=$(ynh_app_setting_get --app=$app --key=port) -stream_port=$(ynh_app_setting_get --app=$app --key=stream_port) - -#================================================= -# CHECK VERSION -#================================================= -ynh_script_progression --message="Checking version..." - -upgrade_type=$(ynh_check_app_version_changed) - -#================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP -#================================================= -ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=4 - -# Backup the current version of the app -ynh_backup_before_upgrade -ynh_clean_setup () { - ynh_clean_check_starting - # Restore it if the upgrade fails - ynh_restore_upgradebackup -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - #================================================= # STANDARD UPGRADE STEPS #================================================= @@ -54,118 +16,58 @@ ynh_abort_if_errors #================================================= ynh_script_progression --message="Stopping a systemd service..." --weight=3 -ynh_systemd_action --service_name=$app --action="stop" +ynh_systemd_action --service_name="$app" --action="stop" #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= -ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 +# ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 -# Cleaning legacy permissions -if ynh_legacy_permissions_exists; then - ynh_legacy_permissions_delete_all +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= +ynh_script_progression --message="Downloading and installing $app package..." --weight=1 - ynh_app_setting_delete --app=$app --key=is_public +chown -R "$app:www-data" "$install_dir" + +_install_tvheadend_package +# 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=$install_dir/.hts/tvheadend +ynh_app_setting_set --app="$app" --key=conf_dir --value="$conf_dir" +if [ "$path" = "/" ]; then + ynh_add_config --template="tvheadend_no_subpath" --destination="/etc/default/tvheadend" +else + ynh_add_config --template="tvheadend" --destination="/etc/default/tvheadend" fi #================================================= -# NGINX CONFIGURATION +# REAPPLY SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=2 +ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 # Create a dedicated NGINX config ynh_add_nginx_config -#================================================= -# UPGRADE TVHEADEND DEB PACKAGE -#================================================= - -if [ "$upgrade_type" == "UPGRADE_APP" ] -then - #================================================= - # UPGRADE DEPENDENCIES - #================================================= - ynh_script_progression --message="Upgrading 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="Upgrading Tvheadend..." --weight=24 - - DEBIAN_FRONTEND=noninteractive ynh_exec_warn_less dpkg --force-confold -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" - - #================================================= - # RESTORE TVHEADEND CONFIG FILES - #================================================= - ynh_script_progression --message="Restore/update configuration files..." --weight=1 - - # Copy and modify /etc/default/tvheadend - 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" - fi -fi - -#================================================= -# PREVENT TVHEADEND BEING UPGRADED THROUGHT APT -#================================================= - -apt-mark hold tvheadend - -#================================================= -# 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 $stream_port +yunohost service add "$app" --description="TV streaming server and recorder" --needs_exposed_ports $stream_port #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="start" - -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." --weight=1 - -ynh_systemd_action --service_name=nginx --action=reload +# Start a systemd service +ynh_systemd_action --service_name="$app" --action="start" #================================================= # END OF SCRIPT diff --git a/tests.toml b/tests.toml new file mode 100644 index 0000000..aa1eab1 --- /dev/null +++ b/tests.toml @@ -0,0 +1,9 @@ +test_format = 1.0 + +[default] + + # ------------ + # Tests to run + # ------------ + + test_upgrade_from.e82643952e5567db826790e1e4a353559f66f112.name = "4.3.1979~ynh9"