From 366c0518fc67ac095310c0dfaf68499784136195 Mon Sep 17 00:00:00 2001 From: ericgaspar Date: Sun, 16 Oct 2022 21:05:19 +0200 Subject: [PATCH] add datadir --- conf/systemd.service | 6 +++--- scripts/backup | 13 +++++++------ scripts/change_url | 9 ++++----- scripts/install | 25 ++++++++++++++++++------- scripts/remove | 22 ++++++++++++---------- scripts/restore | 24 ++++++++++++++---------- scripts/upgrade | 24 +++++++++++++++++------- 7 files changed, 75 insertions(+), 48 deletions(-) diff --git a/conf/systemd.service b/conf/systemd.service index 2a18a96..583c9dd 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -1,18 +1,18 @@ [Unit] Description=Navidrome Music Server and Streamer compatible with Subsonic/Airsonic After=remote-fs.target network.target -AssertPathExists=__CONFIG_PATH__ +AssertPathExists=__DATADIR__ [Service] Type=simple User=__APP__ Group=__APP__ WorkingDirectory=__CONFIG_PATH__/ -ExecStart=__FINALPATH__/__APP__ --configfile "__CONFIG_PATH__/navidrome.toml" +ExecStart=__FINALPATH__/__APP__ --configfile "__DATADIR__/navidrome.toml" TimeoutStopSec=20 KillMode=process Restart=on-failure -ReadWritePaths=__CONFIG_PATH__ +ReadWritePaths=__DATADIR__ # Sandboxing options to harden security # Depending on specificities of your service/app, you may need to tweak these diff --git a/scripts/backup b/scripts/backup index 5c650a0..12e075a 100644 --- a/scripts/backup +++ b/scripts/backup @@ -26,6 +26,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 @@ -38,6 +39,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 #================================================= @@ -52,12 +59,6 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_backup --src_path="/etc/systemd/system/$app.service" -#================================================= -# BACKUP VARIOUS FILES -#================================================= - -ynh_backup --src_path="/var/lib/$app" - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/change_url b/scripts/change_url index 2c083c3..4f0ba02 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -29,6 +29,7 @@ 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) port=$(ynh_app_setting_get --app=$app --key=port) +datadir=$(ynh_app_setting_get --app=$app --key=datadir) enable_downloads=$(ynh_app_setting_get --app=$app --key=enable_downloads) scanner_extractor=$(ynh_app_setting_get --app=$app --key=scanner_extractor) @@ -112,13 +113,11 @@ fi #================================================= ynh_script_progression --message="Modifying a config file..." --weight=1 -config_path="/var/lib/$app" path_url="$new_path" +ynh_add_config --template="../conf/navidrome.toml" --destination="$datadir/navidrome.toml" -ynh_add_config --template="../conf/navidrome.toml" --destination="$config_path/navidrome.toml" - -chmod 600 "$config_path/navidrome.toml" -chown -R $app:$app "$config_path" +chmod 600 "$datadir/navidrome.toml" +chown -R $app:$app "$datadir/navidrome.toml" #================================================= # GENERIC FINALISATION diff --git a/scripts/install b/scripts/install index d233900..20e525b 100644 --- a/scripts/install +++ b/scripts/install @@ -41,7 +41,7 @@ welcome_message="" #================================================= ynh_script_progression --message="Validating installation parameters..." --weight=1 -final_path=/opt/yunohost/$app +final_path=/var/www/$app test ! -e "$final_path" || ynh_die --message="This path already contains a folder" # Register (book) web path @@ -108,6 +108,20 @@ ynh_script_progression --message="Configuring NGINX web server..." --weight=3 # Create a dedicated NGINX config ynh_add_nginx_config +#================================================= +# CREATE DATA DIRECTORY +#================================================= +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 $datadir + +chmod 750 "$datadir" +chmod -R o-rwx "$datadir" +chown -R $app:www-data "$datadir" + #================================================= # SPECIFIC SETUP #================================================= @@ -122,14 +136,11 @@ ynh_multimedia_build_main_dir #================================================= ynh_script_progression --message="Adding a configuration file..." --weight=1 -config_path="/var/lib/$app" -mkdir -p "$config_path" - # Main config File -ynh_add_config --template="../conf/navidrome.toml" --destination="$config_path/navidrome.toml" +ynh_add_config --template="../conf/navidrome.toml" --destination="$datadir/navidrome.toml" -chmod 600 "$config_path/navidrome.toml" -chown -R $app:$app "$config_path" +chmod 600 "$datadir/navidrome.toml" +chown -R $app:$app "$datadir/navidrome.toml" #================================================= # SETUP SYSTEMD diff --git a/scripts/remove b/scripts/remove index 1a8cd1c..1767f81 100644 --- a/scripts/remove +++ b/scripts/remove @@ -19,6 +19,7 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) port=$(ynh_app_setting_get --app=$app --key=port) final_path=$(ynh_app_setting_get --app=$app --key=final_path) +datadir=$(ynh_app_setting_get --app=$app --key=datadir) #================================================= # STANDARD REMOVE @@ -49,6 +50,17 @@ ynh_script_progression --message="Removing app main directory..." --weight=6 # 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,16 +77,6 @@ ynh_script_progression --message="Removing dependencies..." --weight=1 # Remove metapackage and its dependencies ynh_remove_app_dependencies -#================================================= -# SPECIFIC REMOVE -#================================================= -# REMOVE VARIOUS FILES -#================================================= -ynh_script_progression --message="Removing various files..." --weight=6 - -# Remove the config directory securely -ynh_secure_remove --file="/var/lib/$app" - #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/restore b/scripts/restore index 706452d..b292509 100644 --- a/scripts/restore +++ b/scripts/restore @@ -30,6 +30,7 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) final_path=$(ynh_app_setting_get --app=$app --key=final_path) +datadir=$(ynh_app_setting_get --app=$app --key=datadir) #================================================= # CHECK IF THE APP CAN BE RESTORED @@ -60,6 +61,19 @@ chmod 750 "$final_path" chmod -R o-rwx "$final_path" chown -R $app:$app "$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 750 "$datadir" +chmod -R o-rwx "$datadir" +chown -R $app:www-data "$datadir" + #================================================= # SPECIFIC RESTORATION #================================================= @@ -77,16 +91,6 @@ ynh_script_progression --message="Restoring the NGINX web server configuration.. ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" -#================================================= -# RESTORE VARIOUS FILES -#================================================= -ynh_script_progression --message="Restoring various files..." --weight=2 - -ynh_restore_file --origin_path="/var/lib/$app" - -chmod 600 "/var/lib/$app/navidrome.toml" -chown -R $app "/var/lib/$app" - #================================================= # RESTORE SYSTEMD #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 48ad7e5..d3016a3 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -21,6 +21,7 @@ path_url=$(ynh_app_setting_get --app=$app --key=path) language=$(ynh_app_setting_get --app=$app --key=language) 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) enable_downloads=$(ynh_app_setting_get --app=$app --key=enable_downloads) scanner_extractor=$(ynh_app_setting_get --app=$app --key=scanner_extractor) @@ -70,6 +71,17 @@ if ynh_legacy_permissions_exists; then ynh_app_setting_delete --app=$app --key=is_public fi +if [ -z "$datadir" ]; then + datadir=/home/yunohost.app/$app + ynh_app_setting_set --app=$app --key=datadir --value=$datadir + + mkdir -p $datadir + + chmod 750 "$datadir" + chmod -R o-rwx "$datadir" + chown -R $app:www-data "$datadir" +fi + if [ -z "$language" ]; then language="en" ynh_app_setting_set --app=$app --key=language --value=$language @@ -145,15 +157,13 @@ ynh_add_nginx_config #================================================= # UPDATE A CONFIG FILE #================================================= -# ynh_script_progression --message="Updating a configuration file..." +ynh_script_progression --message="Updating a configuration file..." -# config_path="/var/lib/$app" +# Uncomment when there is new options added upstream +ynh_add_config --template="../conf/navidrome.toml" --destination="$datadir/navidrome.toml" -# # Uncomment when there is new options added upstream -# ynh_add_config --template="../conf/navidrome.toml" --destination="$config_path/navidrome.toml" - -# chmod 600 "$config_path/navidrome.toml" -# chown -R $app:$app "$config_path" +chmod 600 "$datadir/navidrome.toml" +chown -R $app:$app "$datadir/navidrome.toml" #================================================= # SETUP SYSTEMD