From 20cb5be3ee0bd3ae5baf366b54dd08bbafc16daf Mon Sep 17 00:00:00 2001 From: yalh76 Date: Thu, 14 Jul 2022 20:03:31 +0200 Subject: [PATCH] Apply example_ynh --- check_process | 10 +-- doc/DESCRIPTION.md | 1 + doc/DESCRIPTION_fr.md | 1 + manifest.json | 16 ++--- scripts/_common.sh | 20 +++--- scripts/backup | 2 +- scripts/change_url | 11 +-- scripts/install | 94 +++++++++++--------------- scripts/remove | 60 ++++++++--------- scripts/restore | 136 ++++++++++++++++++-------------------- scripts/update_version.sh | 6 +- scripts/upgrade | 118 ++++++++++++++++----------------- 12 files changed, 221 insertions(+), 254 deletions(-) create mode 100644 doc/DESCRIPTION.md create mode 100644 doc/DESCRIPTION_fr.md diff --git a/check_process b/check_process index f2acfeb..4c97cf6 100644 --- a/check_process +++ b/check_process @@ -1,12 +1,9 @@ -# See here for more information -# https://github.com/YunoHost/package_check#syntax-check_process-file - ;; Test complet ; Manifest domain="domain.tld" path="/path" - admin="john" is_public=1 + admin="john" discovery=1 ; Checks pkg_linter=1 @@ -16,6 +13,8 @@ setup_private=1 setup_public=1 upgrade=1 + # 10.8.0~ynh1 + upgrade=1 from_commit=384dcd2ff1dbf4b0085edb7f12e4d15f00508e2b backup_restore=1 multi_instance=0 port_already_use=0 @@ -23,6 +22,3 @@ ;;; Options Email= Notification=none -;;; Upgrade options -# ; commit= -# name= diff --git a/doc/DESCRIPTION.md b/doc/DESCRIPTION.md new file mode 100644 index 0000000..7772641 --- /dev/null +++ b/doc/DESCRIPTION.md @@ -0,0 +1 @@ +Jellyfin enables you to collect, manage, and stream your media. Run the Jellyfin server on your system and gain access to the leading free-software entertainment system, bells and whistles included. diff --git a/doc/DESCRIPTION_fr.md b/doc/DESCRIPTION_fr.md new file mode 100644 index 0000000..265e5f6 --- /dev/null +++ b/doc/DESCRIPTION_fr.md @@ -0,0 +1 @@ +Jellyfin vous permet de collecter, gérer et diffuser vos médias. Exécutez le serveur Jellyfin sur votre système et accédez au principal système de divertissement à logiciel libre. diff --git a/manifest.json b/manifest.json index b126c30..8ec8ac6 100644 --- a/manifest.json +++ b/manifest.json @@ -17,8 +17,8 @@ }, "license": "GPL-2.0-only", "maintainer": { - "name": "tituspijean", - "email": "tituspijean@outlook.com" + "name": "tituspijean", + "email": "tituspijean@outlook.com" }, "previous_maintainers": [ { @@ -27,14 +27,14 @@ } ], "requirements": { - "yunohost": ">=4.3" + "yunohost": ">= 4.3.0" }, "multi_instance": false, "services": [ "nginx" ], "arguments": { - "install" : [ + "install": [ { "name": "domain", "type": "domain" @@ -45,10 +45,6 @@ "example": "/jellyfin", "default": "/jellyfin" }, - { - "name": "admin", - "type": "user" - }, { "name": "is_public", "type": "boolean", @@ -58,6 +54,10 @@ "fr": "Jellyfin a son propre système de connexion, vous devriez la laisser publique pour permettre la connexion de clients externes (app mobile, etc.)." } }, + { + "name": "admin", + "type": "user" + }, { "name": "discovery", "type": "boolean", diff --git a/scripts/_common.sh b/scripts/_common.sh index ad67e18..bd789d2 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -11,8 +11,6 @@ version=$(echo "$pkg_version" | cut -d '-' -f 1) ffmpeg_pkg_version="5.0.1-5" ldap_pkg_version="15.0.0.0" -architecture=$(dpkg --print-architecture) - discovery_service_port=1900 discovery_client_port=7359 @@ -48,7 +46,7 @@ case "$debian" in bullseye) ffmpeg_deps+=( libvpx6 libx264-160 libx265-192 ) ;; *) echo "Unknown release: $debian" >&2; exit 1 ;; esac -case "$architecture" in +case "$YNH_ARCH" in arm64) : ;; armhf) : ;; *) ffmpeg_deps+=( libdrm-intel1 libopencl1 ) ;; @@ -64,15 +62,15 @@ pkg_dependencies="${ffmpeg_deps[*]} ${jellyfin_deps[*]}" install_jellyfin_packages() { # In case of a new version, the url change from - # https://repo.jellyfin.org/releases/server/debian/versions/stable/server/X.X.X/jellyfin-server_X.X.X-1_$architecture.deb to - # https://repo.jellyfin.org/archive/debian/stable/X.X.X/server/jellyfin-server_X.X.X-1_$architecture.deb + # https://repo.jellyfin.org/releases/server/debian/versions/stable/server/X.X.X/jellyfin-server_X.X.X-1_$YNH_ARCH.deb to + # https://repo.jellyfin.org/archive/debian/stable/X.X.X/server/jellyfin-server_X.X.X-1_$YNH_ARCH.deb for pkg in web server; do - src_url=$(grep 'SOURCE_URL=' "$YNH_APP_BASEDIR/conf/$pkg.$debian.$architecture.src" | cut -d= -f2-) + src_url=$(grep 'SOURCE_URL=' "$YNH_APP_BASEDIR/conf/$pkg.$debian.$YNH_ARCH.src" | cut -d= -f2-) if ! curl --output /dev/null --silent --head --fail "$src_url"; then ynh_replace_string \ --match_string="releases/server/debian/versions/stable/$pkg/$version/" \ --replace_string="archive/debian/stable/$version/$pkg/" \ - --target_file="$YNH_APP_BASEDIR/conf/$pkg.$debian.$architecture.src" + --target_file="$YNH_APP_BASEDIR/conf/$pkg.$debian.$YNH_ARCH.src" fi done @@ -80,16 +78,16 @@ install_jellyfin_packages() { tempdir="$(mktemp -d)" # Download the deb files - ynh_setup_source --dest_dir=$tempdir --source_id="ffmpeg.$debian.$architecture" - ynh_setup_source --dest_dir=$tempdir --source_id="server.$debian.$architecture" - ynh_setup_source --dest_dir=$tempdir --source_id="web.$debian.$architecture" + ynh_setup_source --dest_dir=$tempdir --source_id="ffmpeg.$debian.$YNH_ARCH" + ynh_setup_source --dest_dir=$tempdir --source_id="server.$debian.$YNH_ARCH" + ynh_setup_source --dest_dir=$tempdir --source_id="web.$debian.$YNH_ARCH" # Install the packages ynh_exec_warn_less dpkg --force-confdef --force-confnew -i $tempdir/jellyfin-ffmpeg5.deb ynh_exec_warn_less dpkg --force-confdef --force-confnew -i $tempdir/jellyfin-server.deb ynh_exec_warn_less dpkg --force-confdef --force-confnew -i $tempdir/jellyfin-web.deb - rm -rf "$tempdir" + ynh_secure_remove --file="$tempdir" # The doc says it should be called only once, # but the code says multiple calls are supported. diff --git a/scripts/backup b/scripts/backup index 18038d9..41b31c9 100644 --- a/scripts/backup +++ b/scripts/backup @@ -15,7 +15,7 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - ynh_clean_check_starting + true } # Exit if an error occurs during the execution of the script ynh_abort_if_errors diff --git a/scripts/change_url b/scripts/change_url index b802be2..a7a6077 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -21,9 +21,6 @@ new_path=$YNH_APP_NEW_PATH app=$YNH_APP_INSTANCE_NAME -port=$(ynh_app_setting_get --app="$app" --key=port) -config_path=$(ynh_app_setting_get --app="$app" --key=config_path) - #================================================= # LOAD SETTINGS #================================================= @@ -32,14 +29,19 @@ 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) +# Add settings here as needed by your application +port=$(ynh_app_setting_get --app=$app --key=port) +config_path=$(ynh_app_setting_get --app=$app --key=config_path) + #================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP #================================================= ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." --weight=10 # 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" @@ -127,6 +129,7 @@ fi #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=2 +# Start a systemd service ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Startup complete" --timeout=15 #================================================= diff --git a/scripts/install b/scripts/install index f18c9ed..8d2b3eb 100644 --- a/scripts/install +++ b/scripts/install @@ -25,8 +25,8 @@ ynh_abort_if_errors domain=$YNH_APP_ARG_DOMAIN path_url=$YNH_APP_ARG_PATH -admin=$YNH_APP_ARG_ADMIN is_public=$YNH_APP_ARG_IS_PUBLIC +admin=$YNH_APP_ARG_ADMIN discovery=$YNH_APP_ARG_DISCOVERY app=$YNH_APP_INSTANCE_NAME @@ -41,9 +41,8 @@ config_path=/etc/jellyfin test ! -e "$final_path" || ynh_die --message="There is already a directory: $final_path " test ! -e "$config_path" || ynh_die --message="There is already a directory: $config_path " -architecture=$(dpkg --print-architecture) -if [[ ! "$architecture" =~ ^(amd64|arm64|armhf)$ ]]; then - ynh_die "Jellyfin is not compatible with your architecture, $architecture, which is neither amd64, arm64, or armhf." 1 +if [[ ! "$YNH_ARCH" =~ ^(amd64|arm64|armhf)$ ]]; then + ynh_die "Jellyfin is not compatible with your architecture, $YNH_ARCH, which is neither amd64, arm64, or armhf." 1 fi # Register (book) web path @@ -76,23 +75,23 @@ discovery_service=$discovery discovery_client=$discovery if [ $discovery -eq 1 ]; then - ynh_script_progression --message="Configuring firewall..." --weight=1 + ynh_script_progression --message="Configuring firewall..." --weight=1 - # Open port 1900 for service auto-discovery - if ynh_port_available --port=$discovery_service_port; then - ynh_exec_warn_less yunohost firewall allow UDP $discovery_service_port - else - discovery_service=0 - ynh_print_warn --message="Port $discovery_service_port (for service auto-discovery) is not available. Continuing nonetheless." - fi + # Open port 1900 for service auto-discovery + if ynh_port_available --port=$discovery_service_port; then + ynh_exec_warn_less yunohost firewall allow UDP $discovery_service_port + else + discovery_service=0 + ynh_print_warn --message="Port $discovery_service_port (for service auto-discovery) is not available. Continuing nonetheless." + fi - # Open port 7359 for client auto-discovery - if ynh_port_available --port=$discovery_client_port; then - ynh_exec_warn_less yunohost firewall allow UDP $discovery_client_port - else - discovery_client=0 - ynh_print_warn --message="Port $discovery_client_port (for client auto-discovery) is not available. Continuing nonetheless." - fi + # Open port 7359 for client auto-discovery + if ynh_port_available --port=$discovery_client_port; then + ynh_exec_warn_less yunohost firewall allow UDP $discovery_client_port + else + discovery_client=0 + ynh_print_warn --message="Port $discovery_client_port (for client auto-discovery) is not available. Continuing nonetheless." + fi fi ynh_app_setting_set --app=$app --key=discovery_service --value=$discovery_service @@ -104,14 +103,21 @@ ynh_app_setting_set --app=$app --key=discovery_client --value=$discovery_client ynh_script_progression --message="Installing dependencies..." --weight=5 ynh_install_app_dependencies $pkg_dependencies - -#================================================= -# INSTALL PACKAGES -#================================================= -ynh_script_progression --message="Installing packages..." --weight=1 - install_jellyfin_packages +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Configuring system user..." --weight=2 + +# Create a system user +ynh_system_user_create --username=$app --home_dir="$final_path" + +if grep -q "^render:" /etc/group; then + # Add user to render group + adduser $app render +fi + #================================================= # NGINX CONFIGURATION #================================================= @@ -121,40 +127,29 @@ ynh_script_progression --message="Configuring NGINX web server..." --weight=6 ynh_add_nginx_config #================================================= -# CREATE DEDICATED USER +# SPECIFIC SETUP #================================================= -ynh_script_progression --message="Configuring system user..." --weight=2 - -# Create a system user -ynh_system_user_create --username=$app - -if grep -q "^render:" /etc/group; then - # Add user to render group - adduser $app render -fi - +# ADD A CONFIGURATION #================================================= -# MODIFY A CONFIG FILE -#================================================= -ynh_print_info --message="Waiting 30s to let Jellyfin fully start a first time..." -sleep 30 - -ynh_script_progression --message="Configuring the settings..." --weight=1 +ynh_script_progression --message="Adding a configuration file..." --weight=1 +ynh_systemd_action --service_name=$app --action="restart" --log_path="systemd" --line_match="Started Jellyfin Media Server" --timeout=30 ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" --line_match="Stopped Jellyfin Media Server" --timeout=15 ynh_add_config --template="system.xml" --destination="$config_path/system.xml" ynh_add_config --template="network.xml" --destination="$config_path/network.xml" ynh_add_config --template="logging.json" --destination="$config_path/logging.json" +chown -R $app: $config_path #================================================= # INSTALL LDAP PLUGIN #================================================= ynh_script_progression --message="Installing LDAP plugin..." --weight=2 -ynh_setup_source --dest_dir="/var/lib/jellyfin/plugins/LDAP Authentication" --source_id=ldap -mkdir -p /var/lib/jellyfin/plugins/configurations/ -ynh_add_config --template="LDAP-Auth.xml" --destination="/var/lib/jellyfin/plugins/configurations/LDAP-Auth.xml" +ynh_setup_source --dest_dir="$final_path/plugins/LDAP Authentication" --source_id=ldap +mkdir -p $final_path/plugins/configurations/ +ynh_add_config --template="LDAP-Auth.xml" --destination="$final_path/plugins/configurations/LDAP-Auth.xml" +chown -R $app: $final_path #================================================= # YUNOHOST MULTIMEDIA INTEGRATION @@ -168,15 +163,6 @@ ynh_multimedia_addaccess $app #================================================= # GENERIC FINALIZATION -#================================================= -# SECURE FILES AND DIRECTORIES -#================================================= -ynh_script_progression --message="Securing files and directories..." - -# Set permissions to app files -chown -R $app: $final_path -chown -R $app: $config_path - #================================================= # SETUP LOGROTATE #================================================= diff --git a/scripts/remove b/scripts/remove index d00068e..9da6118 100644 --- a/scripts/remove +++ b/scripts/remove @@ -36,30 +36,12 @@ then fi #================================================= -# REMOVE DEPENDENCIES +# REMOVE LOGROTATE CONFIGURATION #================================================= -ynh_script_progression --message="Removing dependencies..." --weight=3 +ynh_script_progression --message="Removing logrotate configuration..." --weight=1 -ynh_remove_app_dependencies - -#================================================= -# REMOVE PACKAGES -#================================================= -ynh_script_progression --message="Removing packages..." --weight=1 - -dpkg --remove jellyfin-web -dpkg --remove jellyfin-server -dpkg --remove jellyfin-ffmpeg5 - -#================================================= -# REMOVE APP DIRECTORIES -#================================================= -ynh_script_progression --message="Removing app directories..." --weight=1 - -# Remove the app directory securely -ynh_secure_remove --file="$final_path" -ynh_secure_remove --file="$config_path" -ynh_secure_remove --file="/etc/systemd/system/jellyfin.service.d" +# Remove the app-specific logrotate config +ynh_remove_logrotate #================================================= # REMOVE NGINX CONFIGURATION @@ -70,29 +52,43 @@ ynh_script_progression --message="Removing NGINX web server configuration..." -- ynh_remove_nginx_config #================================================= -# REMOVE LOGROTATE CONFIGURATION +# REMOVE DEPENDENCIES #================================================= -ynh_script_progression --message="Removing logrotate configuration..." --weight=1 +ynh_script_progression --message="Removing dependencies..." --weight=3 -# Remove the app-specific logrotate config -ynh_remove_logrotate +# Remove metapackage and its dependencies +ynh_remove_app_dependencies +dpkg --remove jellyfin-web +dpkg --remove jellyfin-server +dpkg --remove jellyfin-ffmpeg5 #================================================= # CLOSE A PORT #================================================= -if [[ $discovery_service -eq 1 ]] && yunohost firewall list | grep -q "\- 1900$" +if [[ $discovery_service -eq 1 ]] && yunohost firewall list | grep -q "\- $discovery_service_port$" then - ynh_script_progression --message="Closing port 1900..." --weight=1 - ynh_exec_warn_less yunohost firewall disallow UDP 1900 + ynh_script_progression --message="Closing port $discovery_service_port..." --weight=1 + ynh_exec_warn_less yunohost firewall disallow UDP $discovery_service_port fi -if [[ $discovery_client -eq 1 ]] && yunohost firewall list | grep -q "\- 7359$" +if [[ $discovery_client -eq 1 ]] && yunohost firewall list | grep -q "\- $discovery_client_port$" then - ynh_script_progression --message="Closing port 7359..." --weight=1 - ynh_exec_warn_less yunohost firewall disallow UDP 7359 + ynh_script_progression --message="Closing port $discovery_client_port..." --weight=1 + ynh_exec_warn_less yunohost firewall disallow UDP $discovery_client_port fi +#================================================= +# SPECIFIC REMOVE +#================================================= +# REMOVE VARIOUS FILES +#================================================= +ynh_script_progression --message="Removing various files..." --weight=1 + +ynh_secure_remove --file="$final_path" +ynh_secure_remove --file="$config_path" +ynh_secure_remove --file="/etc/systemd/system/jellyfin.service.d" + #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/restore b/scripts/restore index fc05ad9..8902b59 100644 --- a/scripts/restore +++ b/scripts/restore @@ -23,7 +23,7 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading settings..." --weight=1 +ynh_script_progression --message="Loading installation settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME @@ -43,13 +43,65 @@ test ! -d $final_path \ test ! -d $config_path \ || ynh_die --message="There is already a directory: $config_path " -architecture=$(dpkg --print-architecture) -if [[ ! "$architecture" =~ ^(amd64|arm64|armhf)$ ]]; then - ynh_die "Jellyfin is not compatible with your architecture, $architecture, which is neither amd64, arm64, or armhf." 1 +if [[ ! "$YNH_ARCH" =~ ^(amd64|arm64|armhf)$ ]]; then + ynh_die "Jellyfin is not compatible with your architecture, $YNH_ARCH, which is neither amd64, arm64, or armhf." 1 fi #================================================= # STANDARD RESTORATION STEPS +#================================================= +# RECREATE THE DEDICATED USER +#================================================= +ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 + +# Create the dedicated user (if not existing) +ynh_system_user_create --username=$app + +if grep -q "^render:" /etc/group; then + # Add user to render group + adduser $app render +fi + +#================================================= +# RESTORE THE APP MAIN DIR +#================================================= +ynh_script_progression --message="Restoring the app main directory..." --weight=2 + +ynh_restore_file --origin_path="$final_path" +ynh_restore_file --origin_path="$config_path" +ynh_restore_file --origin_path="/etc/default/jellyfin" --not_mandatory + +chown -R $app: $final_path +chown -R $app: $config_path + +#================================================= +# SPECIFIC RESTORATION +#================================================= +# REINSTALL DEPENDENCIES +#================================================= +ynh_script_progression --message="Reinstalling dependencies..." --weight=5 + +# Define and install dependencies +ynh_install_app_dependencies $pkg_dependencies +install_jellyfin_packages + +#================================================= +# RESTORE THE NGINX CONFIGURATION +#================================================= +ynh_script_progression --message="Restoring the NGINX web server configuration..." + +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" + +#================================================= +# YUNOHOST MULTIMEDIA INTEGRATION +#================================================= +ynh_script_progression --message="Adding multimedia directories..." --weight=2 + +# Build YunoHost multimedia directories +ynh_multimedia_build_main_dir +# Allow Jellyfin to write into these directories +ynh_multimedia_addaccess $app + #================================================= # OPEN PORTS #================================================= @@ -80,54 +132,20 @@ fi ynh_app_setting_set --app=$app --key=discovery_service --value=$discovery_service ynh_app_setting_set --app=$app --key=discovery_client --value=$discovery_client -#================================================= -# RESTORE THE NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the NGINX web server configuration..." - -ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" - -#================================================= -# RESTORE THE APP MAIN DIR -#================================================= -ynh_script_progression --message="Restoring the app main directory..." --weight=2 - -ynh_restore_file --origin_path="$final_path" -ynh_restore_file --origin_path="$config_path" -ynh_restore_file --origin_path="/etc/default/jellyfin" --not_mandatory - -#================================================= -# RECREATE THE DEDICATED USER -#================================================= -ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 - -# Create the dedicated user (if not existing) -ynh_system_user_create --username=$app - -#================================================= -# SPECIFIC RESTORATION -#================================================= -# REINSTALL DEPENDENCIES -#================================================= -ynh_script_progression --message="Reinstalling dependencies..." --weight=5 - -# Define and install dependencies -ynh_install_app_dependencies $pkg_dependencies - -#================================================= -# REINSTALL PACKAGES -#================================================= -ynh_script_progression --message="Reinstalling packages..." --weight=7 - -install_jellyfin_packages - #================================================= # RESTORE SYSTEMD #================================================= ynh_script_progression --message="Restoring the systemd configuration..." --weight=1 ynh_restore_file --origin_path="/etc/systemd/system/jellyfin.service.d" --not_mandatory -systemctl enable jellyfin.service --quiet +systemctl enable $app.service --quiet + +#================================================= +# RESTORE THE LOGROTATE CONFIGURATION +#================================================= +ynh_script_progression --message="Restoring the logrotate configuration..." --time --weight=1 + +ynh_restore_file --origin_path="/etc/logrotate.d/$app" #================================================= # INTEGRATE SERVICE IN YUNOHOST @@ -142,22 +160,6 @@ needed_ports=() # Integrate service and require to expose the ports if needed yunohost service add $app --description="Jellyfin media center" ${needed_ports:+--needs_exposed_ports} "${needed_ports[@]}" -#================================================= -# RESTORE THE LOGROTATE CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the logrotate configuration..." --time --weight=1 - -ynh_restore_file --origin_path="/etc/logrotate.d/$app" - -#================================================= -# RESTORE USER RIGHTS -#================================================= -ynh_script_progression --message="Restoring user rights..." - -# Restore permissions on app files -chown -R $app: $final_path -chown -R $app: $config_path - #================================================= # START SYSTEMD SERVICE #================================================= @@ -165,16 +167,6 @@ ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_systemd_action --service_name=$app --action="restart" --log_path="systemd" --line_match="Started Jellyfin Media Server" --timeout=15 -#================================================= -# YUNOHOST MULTIMEDIA INTEGRATION -#================================================= -ynh_script_progression --message="Adding multimedia directories..." --weight=2 - -# Build YunoHost multimedia directories -ynh_multimedia_build_main_dir -# Allow Jellyfin to write into these directories -ynh_multimedia_addaccess $app - #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/update_version.sh b/scripts/update_version.sh index 8b56568..556f8eb 100755 --- a/scripts/update_version.sh +++ b/scripts/update_version.sh @@ -73,9 +73,9 @@ debians=("buster" "bullseye") architectures=("amd64" "arm64" "armhf") for debian in "${debians[@]}"; do for architecture in "${architectures[@]}"; do - prepare_source --template="../conf/ffmpeg.src.default" --destination="../conf/ffmpeg.$debian.$architecture.src" --architecture="$architecture" - prepare_source --template="../conf/web.src.default" --destination="../conf/web.$debian.$architecture.src" --architecture="$architecture" - prepare_source --template="../conf/server.src.default" --destination="../conf/server.$debian.$architecture.src" --architecture="$architecture" + prepare_source --template="../conf/ffmpeg.src.default" --destination="../conf/ffmpeg.$debian.$YNH_ARCH.src" --architecture="$YNH_ARCH" + prepare_source --template="../conf/web.src.default" --destination="../conf/web.$debian.$YNH_ARCH.src" --architecture="$YNH_ARCH" + prepare_source --template="../conf/server.src.default" --destination="../conf/server.$debian.$YNH_ARCH.src" --architecture="$YNH_ARCH" done done diff --git a/scripts/upgrade b/scripts/upgrade index bf76cb7..fd1e215 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -15,6 +15,7 @@ source /usr/share/yunohost/helpers ynh_script_progression --message="Loading installation 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) admin=$(ynh_app_setting_get --app=$app --key=admin) @@ -30,14 +31,37 @@ 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=3 + +# 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 +#================================================= +# STOP SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Stopping a systemd service..." --weight=1 + +ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" --line_match="Stopped Jellyfin Media Server" --timeout=15 + #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 -architecture=$(dpkg --print-architecture) -if [[ ! "$architecture" =~ ^(amd64|arm64|armhf)$ ]]; then - ynh_die "Jellyfin is not compatible with your architecture, $architecture, which is neither amd64, arm64, or armhf." 1 +if [[ ! "$YNH_ARCH" =~ ^(amd64|arm64|armhf)$ ]]; then + ynh_die "Jellyfin is not compatible with your architecture, $YNH_ARCH, which is neither amd64, arm64, or armhf." 1 fi # If path keys do not exist, create them @@ -77,26 +101,6 @@ if [ ! -f "/etc/logrotate.d/$app" ]; then ynh_use_logrotate fi -#================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP -#================================================= -ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=3 - -# Backup the current version of the app -ynh_backup_before_upgrade -ynh_clean_setup () { - # 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 -#================================================= -# OPEN PORTS -#================================================= - discovery_service=$discovery discovery_client=$discovery @@ -123,13 +127,26 @@ fi ynh_app_setting_set --app=$app --key=discovery_service --value=$discovery_service ynh_app_setting_set --app=$app --key=discovery_client --value=$discovery_client +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 + +# Create a dedicated user (if not existing) +ynh_system_user_create --username=$app + +if grep -q "^render:" /etc/group; then + # Add user to render group + adduser $app render +fi #================================================= -# STOP SYSTEMD SERVICE +# UPGRADE DEPENDENCIES #================================================= -ynh_script_progression --message="Stopping a systemd service..." --weight=1 +ynh_script_progression --message="Upgrading dependencies..." --weight=5 -ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" --line_match="Stopped Jellyfin Media Server" --timeout=15 +ynh_install_app_dependencies $pkg_dependencies +install_jellyfin_packages #================================================= # NGINX CONFIGURATION @@ -140,45 +157,30 @@ ynh_script_progression --message="Upgrading NGINX web server configuration..." - ynh_add_nginx_config #================================================= -# UPGRADE DEPENDENCIES +# SPECIFIC UPGRADE #================================================= -ynh_script_progression --message="Upgrading dependencies..." --weight=5 +# UPDATE A CONFIG FILE +#================================================= +ynh_script_progression --message="Updating a configuration file..." --weight=2 -ynh_install_app_dependencies $pkg_dependencies - -#================================================= -# UPGRADE packages -#================================================= -ynh_script_progression --message="Upgrading packages..." --weight=3 - -install_jellyfin_packages - -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 - -# Create a dedicated user (if not existing) -ynh_system_user_create --username=$app - -#================================================= -# MODIFY A CONFIG FILE -#================================================= -ynh_script_progression --message="Setting up configuration files..." --weight=2 +ynh_systemd_action --service_name=$app --action="restart" --log_path="systemd" --line_match="Started Jellyfin Media Server" --timeout=30 +ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" --line_match="Stopped Jellyfin Media Server" --timeout=15 # TODO: investigate if we can avoid overriding system.xml #ynh_add_config --template="system.xml" --destination="$config_path/system.xml" ynh_add_config --template="network.xml" --destination="$config_path/network.xml" ynh_add_config --template="logging.json" --destination="$config_path/logging.json" +chown -R $app: $config_path #================================================= # INSTALL LDAP PLUGIN #================================================= ynh_script_progression --message="Installing LDAP plugin..." --weight=2 -ynh_setup_source --dest_dir="/var/lib/jellyfin/plugins/LDAP Authentication" --source_id=ldap -mkdir -p /var/lib/jellyfin/plugins/configurations/ -ynh_add_config --template="LDAP-Auth.xml" --destination="/var/lib/jellyfin/plugins/configurations/LDAP-Auth.xml" +ynh_setup_source --dest_dir="$final_path/plugins/LDAP Authentication" --source_id=ldap +mkdir -p $final_path/plugins/configurations/ +ynh_add_config --template="LDAP-Auth.xml" --destination="$final_path/plugins/configurations/LDAP-Auth.xml" +chown -R $app: $final_path #================================================= # YUNOHOST MULTIMEDIA INTEGRATION @@ -192,20 +194,12 @@ ynh_multimedia_addaccess $app #================================================= # GENERIC FINALIZATION -#================================================= -# SECURE FILES AND DIRECTORIES -#================================================= - -# Set permissions on app files -chown -R $app: $final_path -chown -R $app: $config_path - #================================================= # SETUP LOGROTATE #================================================= -ynh_script_progression --message="Configuring log rotation..." --weight=1 +ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1 -# Use logrotate to manage application logfile(s) +# Use logrotate to manage app-specific logfile(s) ynh_use_logrotate --non-append #=================================================