diff --git a/conf/config.xml b/conf/config.xml
new file mode 100644
index 0000000..93d4be9
--- /dev/null
+++ b/conf/config.xml
@@ -0,0 +1,16 @@
+
+ info
+ 127.0.0.1
+ False
+
+ __PORT__
+ __PATH__
+ __API_KEY__
+ None
+ BuiltIn
+ master
+ __PORT__
+ False
+
+ False
+
diff --git a/conf/systemd.service b/conf/systemd.service
index c928967..7eadf74 100644
--- a/conf/systemd.service
+++ b/conf/systemd.service
@@ -7,7 +7,7 @@ Type=simple
User=__APP__
Group=__APP__
WorkingDirectory=__FINALPATH__/
-ExecStart=__FINALPATH__/Radarr -nobrowser -data=__FINALPATH__/.data
+ExecStart=__FINALPATH__/Radarr -nobrowser -data=__DATA_PATH__
TimeoutStopSec=20
KillMode=process
diff --git a/scripts/backup b/scripts/backup
index 0670178..8555a32 100755
--- a/scripts/backup
+++ b/scripts/backup
@@ -29,6 +29,7 @@ ynh_print_info --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
+data_path=$(ynh_app_setting_get --app=$app --key=data_path)
domain=$(ynh_app_setting_get --app=$app --key=domain)
#=================================================
@@ -47,6 +48,12 @@ ynh_print_info --message="Declaring files to be backed up..."
ynh_backup --src_path="$final_path"
+#=================================================
+# BACKUP THE APP DATA DIR
+#=================================================
+
+ynh_backup --src_path="$data_path"
+
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
diff --git a/scripts/change_url b/scripts/change_url
index 1339e40..e13bc6e 100644
--- a/scripts/change_url
+++ b/scripts/change_url
@@ -28,7 +28,9 @@ ynh_script_progression --message="Loading installation settings..." --time --wei
# Needed for helper "ynh_add_nginx_config"
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
+data_path=$(ynh_app_setting_get --app=$app --key=data_path)
port=$(ynh_app_setting_get --app=$app --key=port)
+api_key=$(ynh_app_setting_get --app=$app --key=api_key)
#=================================================
# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP
@@ -104,9 +106,15 @@ fi
#=================================================
# SPECIFIC MODIFICATIONS
#=================================================
-# ...
+# UPDATE CONFIGURATION FILE
#=================================================
+ynh_exec_warn_less 'ynh_add_config --template="../conf/config.xml" --destination="$data_path/config.xml"'
+
+chmod 750 "$data_path/config.xml"
+chmod o-rwx "$data_path/config.xml"
+chown $app "$data_path/config.xml"
+
#=================================================
# GENERIC FINALISATION
#=================================================
diff --git a/scripts/install b/scripts/install
index e8f9e19..b4066b2 100755
--- a/scripts/install
+++ b/scripts/install
@@ -35,8 +35,11 @@ app=$YNH_APP_INSTANCE_NAME
#=================================================
ynh_script_progression --message="Validating installation parameters..." --weight=1
-final_path=/opt/yunohost.app/$app
-test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
+final_path=/opt/yunohost/$app
+test ! -e "$final_path" || ynh_die --message="Installation path ($final_path) already exists"
+
+data_path=/home/yunohost.app/$app
+test ! -e "$data_path" || ynh_die --message="Data directory ($data_path) already exists"
# Register (book) web path
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
@@ -87,10 +90,8 @@ 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" --source_id="app.$architecture"
-mkdir -p "$final_path/.data/logs"
-chmod 750 "$final_path"
-chmod -R o-rwx "$final_path"
-chown -R $app:$app "$final_path"
+ynh_app_setting_set --app=$app --key=data_path --value=$data_path
+mkdir -p "$data_path/logs"
#=================================================
# NGINX CONFIGURATION
@@ -115,14 +116,23 @@ ynh_add_systemd_config
#=================================================
ynh_script_progression --message="Configuring Radarr..." --weight=2
-# Start a systemd service
-ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Starting Web Server"
-# Start a systemd service
-ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd"
+api_key=$(ynh_string_random --length=32)
+ynh_app_setting_set --app=$app --key=api_key --value=$api_key
-ynh_replace_string --match_string="7878" --replace_string="$port" --target_file="$final_path/.data/config.xml"
-ynh_replace_string --match_string="" --replace_string="$path_url" --target_file="$final_path/.data/config.xml"
-ynh_replace_string --match_string="\*" --replace_string="127.0.0.1" --target_file="$final_path/.data/config.xml"
+ynh_add_config --template="../conf/config.xml" --destination="$data_path/config.xml"
+
+#=================================================
+# SETUP FILE PERMISSIONS
+#=================================================
+ynh_script_progression --message="Setting files permissions and ownership..." --weight=1
+
+chmod 750 "$final_path"
+chmod -R o-rwx "$final_path"
+chown -R $app: "$final_path"
+
+chmod 750 "$data_path"
+chmod -R o-rwx "$data_path"
+chown -R $app: "$data_path"
#=================================================
# YUNOHOST MULTIMEDIA INTEGRATION
@@ -143,14 +153,14 @@ ynh_script_progression --message="Configuring log rotation..." --weight=1
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
-ynh_use_logrotate --logfile="$final_path/.data/logs"
+ynh_use_logrotate --logfile="$data_path/logs"
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
-yunohost service add $app --description="Radarr daemon" --log="$final_path/.data/logs/radarr.txt"
+yunohost service add $app --description="Radarr daemon" --log="$data_path/logs/radarr.txt"
#=================================================
# START SYSTEMD SERVICE
diff --git a/scripts/remove b/scripts/remove
index 6a5a83e..582f1c6 100755
--- 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)
+data_path=$(ynh_app_setting_get --app=$app --key=data_path)
#=================================================
# STANDARD REMOVE
@@ -57,6 +58,14 @@ ynh_script_progression --message="Removing app main directory..." --weight=1
# Remove the app directory securely
ynh_secure_remove --file="$final_path"
+#=================================================
+# REMOVE APP DATA DIR
+#=================================================
+ynh_script_progression --message="Removing app data directory..." --weight=1
+
+# Remove the app directory securely
+ynh_secure_remove --file="$data_path"
+
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
diff --git a/scripts/restore b/scripts/restore
index 16de336..668ce1e 100755
--- a/scripts/restore
+++ b/scripts/restore
@@ -31,17 +31,19 @@ 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)
+data_path=$(ynh_app_setting_get --app=$app --key=data_path)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_script_progression --message="Validating restoration parameters..." --weight=1
-ynh_webpath_available --domain=$domain --path_url=$path_url \
- || ynh_die --message="Path not available: ${domain}${path_url}"
test ! -d $final_path \
|| ynh_die --message="There is already a directory: $final_path "
+test ! -d $data_path \
+ || ynh_die --message="There is already a directory: $data_path "
+
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
@@ -66,16 +68,21 @@ ynh_script_progression --message="Restoring the app main directory..." --weight=
ynh_restore_file --origin_path="$final_path"
-# FIXME: this should be managed by the core in the future
-# Here, as a packager, you may have to tweak the ownerhsip/permissions
-# such that the appropriate users (e.g. maybe www-data) can access
-# files in some cases.
-# But FOR THE LOVE OF GOD, do not allow r/x for "others" on the entire folder -
-# this will be treated as a security issue.
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
+#=================================================
+# RESTORE THE APP DATA DIR
+#=================================================
+ynh_script_progression --message="Restoring the app data directory..." --weight=2
+
+ynh_restore_file --origin_path="$data_path"
+
+chmod 750 "$data_path"
+chmod -R o-rwx "$data_path"
+chown -R $app: "$data_path"
+
#=================================================
# YUNOHOST MULTIMEDIA INTEGRATION
#=================================================
@@ -109,7 +116,7 @@ systemctl enable $app.service --quiet
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
-yunohost service add $app --description="Radarr daemon" --log="$final_path/.data/logs/radarr.txt"
+yunohost service add $app --description="Radarr daemon" --log="$data_path/logs/radarr.txt"
#=================================================
# START SYSTEMD SERVICE
diff --git a/scripts/upgrade b/scripts/upgrade
index b78dc2a..a206022 100644
--- a/scripts/upgrade
+++ b/scripts/upgrade
@@ -21,6 +21,7 @@ path_url=$(ynh_app_setting_get --app=$app --key=path)
admin=$(ynh_app_setting_get --app=$app --key=admin)
port=$(ynh_app_setting_get --app=$app --key=port)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
+data_path=$(ynh_app_setting_get --app=$app --key=data_path)
#=================================================
# CHECK VERSION
@@ -67,6 +68,13 @@ if ! ynh_permission_exists --permission="api"; then
ynh_permission_create --permission="api" --url="/api" --allowed="visitors" --show_tile="false" --protected="true"
fi
+# Move data directory if needed
+if [ -z "$data_path" ]; then
+ data_path=/home/yunohost.app/$app
+ ynh_app_setting_set --app=$app --key=data_path --value=$data_path
+ mv "$final_path/.data" "/home/yunohost.app/$app"
+fi
+
#=================================================
# CREATE DEDICATED USER
#=================================================
@@ -89,10 +97,14 @@ then
ynh_setup_source --dest_dir="$final_path" --source_id="app.$architecture"
fi
-mkdir -p "$final_path/.data/logs"
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
-chown -R $app:www-data "$final_path"
+chown -R $app: "$final_path"
+
+mkdir -p "$data_path/logs"
+chmod 750 "$data_path"
+chmod -R o-rwx "$data_path"
+chown -R $app: "$data_path"
#=================================================
# NGINX CONFIGURATION
@@ -128,14 +140,14 @@ ynh_script_progression --message="Upgrading logrotate configuration..." --weight
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
-ynh_use_logrotate --non-append --logfile="$final_path/.data/logs"
+ynh_use_logrotate --non-append --logfile="$data_path/logs"
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
-yunohost service add $app --description="Radarr daemon" --log="$final_path/.data/logs/radarr.txt"
+yunohost service add $app --description="Radarr daemon" --log="$data_path/logs/radarr.txt"
#=================================================
# START SYSTEMD SERVICE