From a8ac13c16eada067247fda513611a368a671bcc4 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 21 Sep 2022 01:03:09 +0200 Subject: [PATCH] Apply last example_ynh --- .gitignore | 2 - conf/nginx.conf | 43 +++++++------- conf/systemd.service | 15 +++-- doc/DESCRIPTION.md | 7 +++ doc/DESCRIPTION_fr.md | 1 + doc/DISCLAIMER_fr.md | 6 -- manifest.json | 16 ++--- scripts/_common.sh | 2 +- scripts/backup | 21 ++++--- scripts/change_url | 3 +- scripts/install | 102 +++++++++++++++++++------------- scripts/remove | 46 ++++++++------- scripts/restore | 101 +++++++++++++++++--------------- scripts/upgrade | 133 +++++++++++++++++++++--------------------- 14 files changed, 268 insertions(+), 230 deletions(-) delete mode 100644 .gitignore create mode 100644 doc/DESCRIPTION.md create mode 100644 doc/DESCRIPTION_fr.md diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 783a4ae..0000000 --- a/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*~ -*.sw[op] diff --git a/conf/nginx.conf b/conf/nginx.conf index b2901aa..c904fa9 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -3,28 +3,27 @@ #sub_path_only rewrite ^__PATH__$ __PATH__/ permanent; location __PATH__/ { - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto https; - proxy_set_header X-Forwarded-Host $http_host; - proxy_set_header Host $http_host; - proxy_max_temp_file_size 0; - proxy_pass http://127.0.0.1:__PORT__; - proxy_redirect http:// https://; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto https; + proxy_set_header X-Forwarded-Host $http_host; + proxy_set_header Host $http_host; + proxy_max_temp_file_size 0; + proxy_pass http://127.0.0.1:__PORT__; + proxy_redirect http:// https://; - # set client body size to 500 MB - # Allows to upload zip file up to 500 MB - # See https://github.com/YunoHost-Apps/airsonic_ynh/issues/4 - client_max_body_size 500M; + # set client body size to 500 MB + # Allows to upload zip file up to 500 MB + # See https://github.com/YunoHost-Apps/airsonic_ynh/issues/4 + client_max_body_size 500M; - # Fix last DSub releases not able to connect with LDAP - # See https://github.com/airsonic/airsonic/issues/260 - sub_filter_types text/xml application/json; - sub_filter_once off; - sub_filter 'subsonic' 'madsonic'; - - # Include SSOWAT user panel. - # Removed since sub_filter_once directive is also used in this file -# include conf.d/yunohost_panel.conf.inc; -# proxy_set_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' www.gstatic.com; img-src 'self' *.akamaized.net; style-src 'self' 'unsafe-inline' fonts.googleapis.com; font-src 'self' fonts.gstatic.com; frame-src 'self'; object-src 'none'"; + # Fix last DSub releases not able to connect with LDAP + # See https://github.com/airsonic/airsonic/issues/260 + sub_filter_types text/xml application/json; + sub_filter_once off; + sub_filter 'subsonic' 'madsonic'; + + # Include SSOWAT user panel. + #include conf.d/yunohost_panel.conf.inc; + #proxy_set_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' www.gstatic.com; img-src 'self' *.akamaized.net; style-src 'self' 'unsafe-inline' fonts.googleapis.com; font-src 'self' fonts.gstatic.com; frame-src 'self'; object-src 'none'"; } diff --git a/conf/systemd.service b/conf/systemd.service index da45966..eee82fa 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -8,6 +8,8 @@ AssertPathExists=__FINALPATH__ [Service] Type=simple +User=__APP__ +Group=__APP__ Environment="JAVA_OPTS=-Xmx256m" Environment="JAVA_ARGS=" EnvironmentFile=-/etc/default/__APP__ @@ -17,22 +19,17 @@ ExecStart=/usr/bin/java \ -Dserver.context-path=${CONTEXT_PATH} \ -Dserver.port=${PORT} \ -jar ${JAVA_JAR} $JAVA_ARGS -User=__APP__ -Group=__APP__ # See https://www.freedesktop.org/software/systemd/man/systemd.exec.html # for details -DevicePolicy=closed DeviceAllow=char-alsa rw NoNewPrivileges=yes PrivateTmp=yes PrivateUsers=yes -ProtectControlGroups=yes -ProtectKernelModules=yes -ProtectKernelTunables=yes RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 RestrictNamespaces=yes RestrictRealtime=yes +DevicePolicy=closed SystemCallFilter=~@clock @debug @module @mount @obsolete @privileged @reboot @setuid @swap ReadWritePaths=__FINALPATH__ @@ -44,6 +41,9 @@ ReadWritePaths=__FINALPATH__ # if you don't want airsonic to be able to # write anything on your filesystem outside of AIRSONIC_HOME. ProtectSystem=full +ProtectControlGroups=yes +ProtectKernelModules=yes +ProtectKernelTunables=yes # You can uncomment the following line if you don't have any media # in /home/…. This will prevent airsonic from ever reading/writing anything there. @@ -54,6 +54,5 @@ ProtectSystem=full # and executeable, making hacker's lifes a bit harder. #MemoryDenyWriteExecute=yes - [Install] -WantedBy=multi-user.target \ No newline at end of file +WantedBy=multi-user.target diff --git a/doc/DESCRIPTION.md b/doc/DESCRIPTION.md new file mode 100644 index 0000000..43e68db --- /dev/null +++ b/doc/DESCRIPTION.md @@ -0,0 +1,7 @@ +Airsonic is a free, web-based media streamer, providing ubiquitous access to your music. Use it to share your music with friends, or to listen to your own music while at work. You can stream to multiple players simultaneously, for instance to one player in your kitchen and another in your living room. + +Airsonic is designed to handle very large music collections (hundreds of gigabytes). Although optimized for MP3 streaming, it works for any audio or video format that can stream over HTTP, for instance AAC and OGG. By using transcoder plug-ins, Airsonic supports on-the-fly conversion and streaming of virtually any audio format, including WMA, FLAC, APE, Musepack, WavPack and Shorten. + +If you have constrained bandwidth, you may set an upper limit for the bit rate of the music streams. Airsonic will then automatically re sample the music to a suitable bit rate. + +In addition to being a streaming media server, Airsonic works very well as a local jukebox. The intuitive web interface, as well as search and index facilities, are optimized for efficient browsing through large media libraries. Airsonic also comes with an integrated Podcast receiver, with many of the same features as you find in iTunes. diff --git a/doc/DESCRIPTION_fr.md b/doc/DESCRIPTION_fr.md new file mode 100644 index 0000000..c8e80e7 --- /dev/null +++ b/doc/DESCRIPTION_fr.md @@ -0,0 +1 @@ +Streamez et gérez votre collection de musique diff --git a/doc/DISCLAIMER_fr.md b/doc/DISCLAIMER_fr.md index b1f1a70..e69de29 100644 --- a/doc/DISCLAIMER_fr.md +++ b/doc/DISCLAIMER_fr.md @@ -1,6 +0,0 @@ -## Fonctionnalités spécifiques à YunoHost - -* Comptes LDAP YunoHost pris en charge : **oui** -* [Multimédia](https://github.com/YunoHost-Apps/yunohost.multimedia) géré -* Limite de mémoire RAM fixée à 256 Mb car Airsonic quittait souvant par manque de RAM (bonjour OOM killer) -* Voir https://www.reddit.com/r/airsonic/comments/doscco/jvm_memory_issues/ \ No newline at end of file diff --git a/manifest.json b/manifest.json index 797e2f3..fb0ccb7 100644 --- a/manifest.json +++ b/manifest.json @@ -17,18 +17,18 @@ }, "license": "GPL-3.0-or-later", "maintainer": { - "name": "Gofannon", - "email": "gofannon@riseup.net" + "name": "", + "email": "" }, "requirements": { - "yunohost": ">= 4.2.4" + "yunohost": ">= 11.0.0" }, "multi_instance": true, "services": [ "nginx" ], "arguments": { - "install" : [ + "install": [ { "name": "domain", "type": "domain" @@ -39,14 +39,14 @@ "example": "/airsonic", "default": "/airsonic" }, - { - "name": "admin", - "type": "user" - }, { "name": "is_public", "type": "boolean", "default": true + }, + { + "name": "admin", + "type": "user" } ] } diff --git a/scripts/_common.sh b/scripts/_common.sh index 4b38524..a863a98 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -4,7 +4,7 @@ # COMMON VARIABLES #================================================= -# dependencies used by the app +# dependencies used by the app (must be on a single line) pkg_dependencies="openjdk-8-jre|openjdk-11-jre ffmpeg" #================================================= diff --git a/scripts/backup b/scripts/backup index a27e558..52238cf 100644 --- a/scripts/backup +++ b/scripts/backup @@ -6,6 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= +# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers @@ -14,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 @@ -28,6 +29,7 @@ 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) +datadir=$(ynh_app_setting_get --app=$app --key=datadir) #================================================= # DECLARE DATA AND CONF FILES TO BACKUP @@ -40,6 +42,12 @@ ynh_print_info --message="Declaring files to be backed up..." ynh_backup --src_path="$final_path" +#================================================= +# BACKUP THE DATA DIR +#================================================= + +ynh_backup --src_path="$datadir" --is_big + #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= @@ -59,14 +67,13 @@ ynh_backup --src_path="/etc/logrotate.d/$app" #================================================= ynh_backup --src_path="/etc/systemd/system/$app.service" + +#================================================= +# BACKUP VARIOUS FILES +#================================================= + ynh_backup --src_path="/etc/default/$app" -#================================================= -# BACKUP DATA -#================================================= - -ynh_backup --src_path="/home/yunohost.app/$app" --is_big - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/change_url b/scripts/change_url index 563965e..23a3b63 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -33,7 +33,7 @@ port=$(ynh_app_setting_get --app=$app --key=port) path_url=$(ynh_app_setting_get --app=$app --key=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=1 @@ -122,6 +122,7 @@ ynh_add_config --template="../conf/systemd-sysconfig" --destination="/etc/defaul #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=12 +# Start a systemd service ynh_systemd_action --service_name=$app --action=start --log_path="$final_path/airsonic.log" --line_match="Started Application in" #================================================= diff --git a/scripts/install b/scripts/install index 6d583ee..d123d6f 100644 --- a/scripts/install +++ b/scripts/install @@ -18,7 +18,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 @@ -29,8 +29,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 app=$YNH_APP_INSTANCE_NAME @@ -61,7 +61,7 @@ ynh_app_setting_set --app=$app --key=admin --value=$admin #================================================= ynh_script_progression --message="Finding an available port..." --weight=1 -# Find a free port +# Find an available port port=$(ynh_find_port --port=8095) ynh_app_setting_set --app=$app --key=port --value=$port @@ -87,7 +87,7 @@ ynh_script_progression --message="Setting up source files..." --weight=82 ynh_app_setting_set --app=$app --key=final_path --value=$final_path # Download, check integrity, uncompress and patch the source from app.src -ynh_setup_source --dest_dir=$final_path +ynh_setup_source --dest_dir="$final_path" chmod 750 "$final_path" chmod -R o-rwx "$final_path" @@ -109,7 +109,7 @@ ynh_script_progression --message="Creating a data directory..." --weight=1 datadir=/home/yunohost.app/$app ynh_app_setting_set --app=$app --key=datadir --value=$datadir -mkdir -p /home/yunohost.app/$app/{Podcasts,Playlists} +mkdir -p $datadir/{Podcasts,Playlists} chmod 764 "$datadir" chmod -R o-rwx "$datadir" @@ -130,6 +130,7 @@ ynh_multimedia_addaccess $app #================================================= # ENABLE "TRANSCODE" #================================================= +ynh_script_progression --message="Enabling transcode..." --weight=1 ### For details, see https://airsonic.github.io/docs/transcode/ @@ -147,6 +148,20 @@ fi # Ensure links belong to the $app user chown $app $final_path/transcode +#================================================= +# ADD A CONFIGURATION +#================================================= +ynh_script_progression --message="Adding a configuration file..." --weight=1 + +ynh_add_config --template="../conf/systemd-sysconfig" --destination="/etc/default/$app" +chmod 400 "/etc/default/$app" +chown $app:$app "/etc/default/$app" + +# Copy configuration file of airsonic +ynh_add_config --template="../conf/airsonic.properties" --destination="$final_path/airsonic.properties" +chmod 400 "$final_path/airsonic.properties" +chown $app:$app "$final_path/airsonic.properties" + #================================================= # SETUP SYSTEMD #================================================= @@ -155,45 +170,20 @@ ynh_script_progression --message="Configuring a systemd service..." --weight=3 # Create a dedicated systemd config ynh_add_systemd_config -#================================================= -# MODIFY CONFIG FILES -#================================================= - -ynh_add_config --template="../conf/systemd-sysconfig" --destination="/etc/default/$app" -# Copy configuration file of airsonic -ynh_add_config --template="../conf/airsonic.properties" --destination="$final_path/airsonic.properties" - -#================================================= -# SETUP LOGROTATE -#================================================= -ynh_script_progression --message="Configuring log rotation..." --weight=1 - -# Use logrotate to manage application logfile(s) -ynh_use_logrotate $final_path/$app.log - -#================================================= -# ADVERTISE SERVICE IN ADMIN PANEL -#================================================= - -yunohost service add $app --description="Airsonic daemon" --log="$final_path/$app.log" - -#================================================= -# START SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=12 - -# Start a systemd service -ynh_systemd_action --service_name=$app --action=start --log_path="$final_path/$app.log" --line_match="Started Application in" - #================================================= # SETUP APPLICATION WITH CURL #================================================= +ynh_script_progression --message="Setuping application with CURL..." --weight=1 -# Set the app as temporarily public for cURL call +ynh_systemd_action --service_name=$app --action="start" --log_path="$final_path/$app.log" --line_match="Started Application in" + +# Set the app as temporarily public for curl call +ynh_script_progression --message="Configuring SSOwat..." --weight=1 +# Making the app public for curl ynh_permission_update --permission="main" --add="visitors" # Reload Nginx -ynh_systemd_action --service_name=nginx --action=reload +ynh_systemd_action --service_name=nginx --action="reload" ynh_script_progression --message="Finalizing installation..." --weight=10 @@ -225,9 +215,14 @@ token=$(echo -n $passwordAdmin$salt | md5sum | awk '{print $1}') ynh_local_curl "/rest/createUser.view" "u=admin" "t=$token" "s=$salt" "username=$admin" "password=a" "v=$VERSION" "c=myapp" "email=$mailadmin" "adminRole=Yes" "ldapAuthenticated=Yes" "settingsRole=Yes" "streamRole=Yes" "jukeboxRole=Yes" "downloadRole=Yes" "uploadRole=Yes" "playlistRole=Yes" "coverArtRole=Yes" "commentRole=Yes" "podcastRole=Yes" "shareRole=Yes" "videoConversionRole=Yes" +# Remove the public access +ynh_permission_update --permission="main" --remove="visitors" + #================================================= # USE MULTIMEDIA #================================================= +ynh_script_progression --message="Using multimedia..." --weight=1 + ynh_systemd_action --service_name=$app --action="stop" # Use multimedia folder @@ -238,15 +233,42 @@ ynh_script_progression --message="Restarting a systemd service..." --weight=12 # Start a systemd service ynh_systemd_action --service_name=$app --action="start" --log_path="$final_path/airsonic.log" --line_match="Started Application in" +#================================================= +# GENERIC FINALIZATION +#================================================= +# SETUP LOGROTATE +#================================================= +ynh_script_progression --message="Configuring log rotation..." --weight=1 + +# Use logrotate to manage application logfile(s) +ynh_use_logrotate $final_path/$app.log + +#================================================= +# INTEGRATE SERVICE IN YUNOHOST +#================================================= +ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 + +yunohost service add $app --description="Airsonic daemon" --log="$final_path/$app.log" + +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." --weight=12 + +# Start a systemd service +ynh_systemd_action --service_name=$app --action="restart" --log_path="$final_path/$app.log" --line_match="Started Application in" + #================================================= # SETUP SSOWAT #================================================= ynh_script_progression --message="Configuring permissions..." --weight=1 -# Make app public if necessary or protect it -if [ $is_public -eq 0 ] +# Make app public if necessary +if [ $is_public -eq 1 ] then - ynh_permission_update --permission="main" --remove="visitors" + # Everyone can access the app. + # The "main" permission is automatically created before the install script. + ynh_permission_update --permission="main" --add="visitors" fi #================================================= diff --git a/scripts/remove b/scripts/remove index 04721d0..8bf8d53 100644 --- a/scripts/remove +++ b/scripts/remove @@ -24,13 +24,13 @@ datadir=$(ynh_app_setting_get --app=$app --key=datadir) #================================================= # STANDARD REMOVE #================================================= -# REMOVE SERVICE FROM ADMIN PANEL +# REMOVE SERVICE INTEGRATION IN YUNOHOST #================================================= -# Remove a service from the admin panel, added by `yunohost service add` +# 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 - ynh_script_progression --message="Removing $app service..." --weight=2 + ynh_script_progression --message="Removing $app service integration..." --weight=1 yunohost service remove $app fi @@ -43,12 +43,12 @@ ynh_script_progression --message="Stopping and removing the systemd service..." ynh_remove_systemd_config #================================================= -# REMOVE DEPENDENCIES +# REMOVE LOGROTATE CONFIGURATION #================================================= -ynh_script_progression --message="Removing dependencies..." --weight=19 +ynh_script_progression --message="Removing logrotate configuration..." --weight=1 -# Remove metapackage and its dependencies -ynh_remove_app_dependencies +# Remove the app-specific logrotate config +ynh_remove_logrotate #================================================= # REMOVE APP MAIN DIR @@ -58,6 +58,17 @@ ynh_script_progression --message="Removing app main directory..." --weight=1 # Remove the app directory securely ynh_secure_remove --file="$final_path" +#================================================= +# REMOVE DATA DIR +#================================================= + +# Remove the data directory if --purge option is used +if [ "${YNH_APP_PURGE:-0}" -eq 1 ] +then + ynh_script_progression --message="Removing app data directory..." --weight=1 + ynh_secure_remove --file="$datadir" +fi + #================================================= # REMOVE NGINX CONFIGURATION #================================================= @@ -65,30 +76,21 @@ ynh_script_progression --message="Removing NGINX web server configuration..." -- # Remove the dedicated NGINX config ynh_remove_nginx_config -#================================================ -# REMOVE DATA DIR -#================================================ - -# Remove the data directory if --purge option is used -if [ "${YNH_APP_PURGE:-0}" -eq 1 ] -then - ynh_script_progression --message="Removing app data directory..." --weight=1 - ynh_secure_remove --file="/home/yunohost.app/$app" -fi #================================================= -# REMOVE LOGROTATE CONFIGURATION +# REMOVE DEPENDENCIES #================================================= -ynh_script_progression --message="Removing logrotate configuration..." --weight=1 +ynh_script_progression --message="Removing dependencies..." --weight=19 -# Remove the app-specific logrotate config -ynh_remove_logrotate +# Remove metapackage and its dependencies +ynh_remove_app_dependencies #================================================= # SPECIFIC REMOVE #================================================= -# REMOVE FILES +# REMOVE VARIOUS FILES #================================================= +ynh_script_progression --message="Removing various files..." --weight=1 ynh_secure_remove --file="/etc/default/$app" diff --git a/scripts/restore b/scripts/restore index 00b312d..402efd7 100644 --- a/scripts/restore +++ b/scripts/restore @@ -6,7 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= -#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts +# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers @@ -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 @@ -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 @@ -42,12 +42,6 @@ test ! -d $final_path \ #================================================= # STANDARD RESTORATION STEPS -#================================================= -# RESTORE THE NGINX CONFIGURATION -#================================================= - -ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" - #================================================= # RECREATE THE DEDICATED USER #================================================= @@ -67,6 +61,19 @@ chmod 750 "$final_path" chmod -R o-rwx "$final_path" chown -R $app:www-data "$final_path" +#================================================= +# RESTORE THE DATA DIRECTORY +#================================================= +ynh_script_progression --message="Restoring the data directory..." --weight=1 + +ynh_restore_file --origin_path="$datadir" --not_mandatory + +mkdir -p $datadir + +chmod 764 "$datadir" +chmod -R o-rwx "$datadir" +chown -R $app:www-data "$datadir" + #================================================= # SPECIFIC RESTORATION #================================================= @@ -77,9 +84,17 @@ ynh_script_progression --message="Reinstalling dependencies..." --weight=43 # Define and install dependencies ynh_install_app_dependencies $pkg_dependencies +#================================================= +# 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" + #================================================= # ENABLE "TRANSCODE" #================================================= +ynh_script_progression --message="Enabling transcode..." --weight=1 ### For details, see https://airsonic.github.io/docs/transcode/ @@ -98,46 +113,11 @@ fi chown $app $final_path/transcode #================================================= -# RESTORE SYSTEMD +# RESTORE VARIOUS FILES #================================================= -ynh_script_progression --message="Restoring the systemd configuration..." --weight=1 +ynh_script_progression --message="Restoring various files..." --weight=1 -ynh_restore_file --origin_path="/etc/systemd/system/$app.service" ynh_restore_file --origin_path="/etc/default/$app" -systemctl enable $app.service --quiet - -#================================================= -# ADVERTISE SERVICE IN ADMIN PANEL -#================================================= - -yunohost service add $app --description="Airsonic daemon" --log="$final_path/$app.log" - -#================================================= -# START SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=12 - -ynh_systemd_action --service_name=$app --action="start" --log_path="$final_path/$app.log" --line_match="Started Application in" - -#================================================= -# RESTORE THE LOGROTATE CONFIGURATION -#================================================= - -ynh_restore_file --origin_path="/etc/logrotate.d/$app" - -#================================================= -# RESTORE THE DATA DIRECTORY -#================================================= -ynh_script_progression --message="Restoring the data directory..." --weight=1 - -# Use --not_mandatory for the data directory, because if the backup has been made with BACKUP_CORE_ONLY, there's no data into the backup. -ynh_restore_file --origin_path="$datadir" --not_mandatory - -mkdir -p $datadir - -chmod 764 "$datadir" -chmod -R o-rwx "$datadir" -chown -R $app:www-data "$datadir" #================================================= # YUNOHOST MULTIMEDIA INTEGRATION @@ -150,6 +130,35 @@ ynh_multimedia_addfolder --source_dir="/home/yunohost.app/$app/Playlists" --dest # Allow airsonic to write into these directories ynh_multimedia_addaccess --user_name=$app +#================================================= +# RESTORE SYSTEMD +#================================================= +ynh_script_progression --message="Restoring the systemd configuration..." --weight=1 + +ynh_restore_file --origin_path="/etc/systemd/system/$app.service" +systemctl enable $app.service --quiet + +#================================================= +# RESTORE THE LOGROTATE CONFIGURATION +#================================================= +ynh_script_progression --message="Restoring the logrotate configuration..." --weight=1 + +ynh_restore_file --origin_path="/etc/logrotate.d/$app" + +#================================================= +# INTEGRATE SERVICE IN YUNOHOST +#================================================= +ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 + +yunohost service add $app --description="Airsonic daemon" --log="$final_path/$app.log" + +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." --weight=12 + +ynh_systemd_action --service_name=$app --action="start" --log_path="$final_path/$app.log" --line_match="Started Application in" + #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 013069b..23d6661 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -18,14 +18,15 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) -final_path=$(ynh_app_setting_get --app=$app --key=final_path) admin=$(ynh_app_setting_get --app=$app --key=admin) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) port=$(ynh_app_setting_get --app=$app --key=port) datadir=$(ynh_app_setting_get --app=$app --key=datadir) #================================================= # CHECK VERSION #================================================= +ynh_script_progression --message="Checking version..." --weight=1 upgrade_type=$(ynh_check_app_version_changed) @@ -37,14 +38,21 @@ ynh_script_progression --message="Backing up the app before upgrading (may take # Backup the current version of the app ynh_backup_before_upgrade ynh_clean_setup () { - ynh_clean_check_starting - - # restore it if the upgrade fails + # 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" + #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= @@ -74,14 +82,18 @@ if ynh_legacy_permissions_exists; then ynh_app_setting_delete --app=$app --key=is_public fi -#================================================= -# STANDARD UPGRADE STEPS -#================================================= -# STOP SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Stopping a systemd service..." --weight=1 +# Rename legacy folder to proper location +if [[ ! -e /home/yunohost.app/$app ]] && [[ -e /home/yunohost.$app ]] +then + mkdir -p /home/yunohost.app/ + mv /home/yunohost.$app /home/yunohost.app/$app +fi -ynh_systemd_action --service_name=$app --action="stop" +mkdir -p $datadir/{Podcasts,Playlists} + +chmod 764 "$datadir" +chmod -R o-rwx "$datadir" +chown -R $app:www-data "$datadir" #================================================= # CREATE DEDICATED USER @@ -107,6 +119,13 @@ chmod 750 "$final_path" chmod -R o-rwx "$final_path" chown -R $app:www-data "$final_path" +#================================================= +# UPGRADE DEPENDENCIES +#================================================= +ynh_script_progression --message="Upgrading dependencies..." --weight=4 + +ynh_install_app_dependencies $pkg_dependencies + #================================================= # NGINX CONFIGURATION #================================================= @@ -116,40 +135,7 @@ ynh_script_progression --message="Upgrading NGINX web server configuration..." - ynh_add_nginx_config #================================================= -# UPGRADE DEPENDENCIES -#================================================= -ynh_script_progression --message="Upgrading dependencies..." --weight=4 - -ynh_install_app_dependencies $pkg_dependencies - -# #================================================= -# # SPECIFIC UPGRADE -# #================================================= -# # CREATE DIRECTORIES -# #================================================= - -# mkdir -p /home/yunohost.app/$app/{Podcasts,Playlists} - -# #================================================= -# # SECURING FILES AND DIRECTORIES -# #================================================= - -# Rename legacy folder to proper location -if [[ ! -e /home/yunohost.app/$app ]] && [[ -e /home/yunohost.$app ]] -then - mkdir -p /home/yunohost.app/ - mv /home/yunohost.$app /home/yunohost.app/$app -fi - -mkdir -p /home/yunohost.app/$app/{Podcasts,Playlists} - -#================================================= -# SECURING FILES AND DIRECTORIES -#================================================= - -chown -R $app:www-data /home/yunohost.app/$app -chmod 764 /home/yunohost.app/$app - +# SPECIFIC UPGRADE #================================================= # YUNOHOST MULTIMEDIA INTEGRATION #================================================= @@ -175,6 +161,7 @@ ynh_multimedia_addaccess $app #================================================= # ENABLE "TRANSCODE" #================================================= +ynh_script_progression --message="Enabling transcode..." --weight=1 ### For details, see https://airsonic.github.io/docs/transcode/ @@ -193,19 +180,17 @@ fi chown $app $final_path/transcode #================================================= -# STORE THE CONFIG FILE CHECKSUM +# UPDATE A CONFIG FILE #================================================= +ynh_script_progression --message="Updating a configuration file..." --weight=1 + +ynh_add_config --template="../conf/systemd-sysconfig" --destination="/etc/default/$app" +chmod 400 "/etc/default/$app" +chown $app:$app "/etc/default/$app" -# Copy configuration file of airsonic ynh_add_config --template="../conf/airsonic.properties" --destination="$final_path/airsonic.properties" - -#================================================= -# SETUP LOGROTATE -#================================================= -ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1 - -# Use logrotate to manage app-specific logfile(s) -ynh_use_logrotate --non-append --logfile="$final_path/$app.log" +chmod 400 "$final_path/airsonic.properties" +chown $app:$app "$final_path/airsonic.properties" #================================================= # SETUP SYSTEMD @@ -215,20 +200,10 @@ ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 # Create a dedicated systemd config ynh_add_systemd_config -ynh_add_config --template="../conf/systemd-sysconfig" --destination="/etc/default/$app" - #================================================= -# ADVERTISE SERVICE IN ADMIN PANEL +# USE MULTIMEDIA #================================================= - -yunohost service add $app --description="Airsonic daemon" --log="$final_path/$app.log" - -#================================================= -# START SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=12 - -ynh_systemd_action --service_name=$app --action="start" --log_path="$final_path/airsonic.log" --line_match="Started Application in" +ynh_script_progression --message="Using multimedia..." --weight=1 # Use multimedia folder if needed if ! grep -q "/home/yunohost.multimedia/share/Music" $final_path/db/airsonic.script; then @@ -243,6 +218,30 @@ if ! grep -q "/home/yunohost.multimedia/share/Music" $final_path/db/airsonic.scr ynh_systemd_action --service_name=$app --action="start" --log_path="$final_path/airsonic.log" --line_match="Started Application in" fi +#================================================= +# GENERIC FINALIZATION +#================================================= +# SETUP LOGROTATE +#================================================= +ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1 + +# Use logrotate to manage app-specific logfile(s) +ynh_use_logrotate --non-append --logfile="$final_path/$app.log" + +#================================================= +# INTEGRATE SERVICE IN YUNOHOST +#================================================= +ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 + +yunohost service add $app --description="Airsonic daemon" --log="$final_path/$app.log" + +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." --weight=12 + +ynh_systemd_action --service_name=$app --action="start" --log_path="$final_path/airsonic.log" --line_match="Started Application in" + #================================================= # RELOAD NGINX #=================================================