diff --git a/README.md b/README.md
index def40eb..5d8e226 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-##
CouchPotato
+# CouchPotato for YunoHost
[](https://dash.yunohost.org/appci/app/couchpotato)  
[](https://install-app.yunohost.org/?app=couchpotato)
diff --git a/check_process b/check_process
index 1c48cbc..e04a105 100644
--- a/check_process
+++ b/check_process
@@ -1,12 +1,7 @@
-# See here for more information
-# https://github.com/YunoHost/package_check#syntax-check_process-file
-
-# Move this file from check_process.default to check_process when you have filled it.
-
;; Test complet
; Manifest
- domain="domain.tld" (DOMAIN)
- path="/couchpotato" (PATH)"
+ domain="domain.tld"
+ path="/path"
; Checks
pkg_linter=1
setup_sub_dir=1
diff --git a/conf/couchpotato.conf b/conf/couchpotato.conf
index 36654f6..308afb7 100644
--- a/conf/couchpotato.conf
+++ b/conf/couchpotato.conf
@@ -4,7 +4,7 @@ username =
ssl_key =
proxy_server =
ssl_cert =
-data_dir = __DATADIR__
+data_dir = __APP_DATA_DIR__
use_proxy = 0
permission_file = 0755
proxy_password =
@@ -43,7 +43,7 @@ to = /home/yunohost.multimedia/share/Video/Movies
enabled = __RENAMER__
[blackhole]
-directory = __WATCHDIR__
+directory = __TRANSMISSION_WATCHDIR__
manual = 0
enabled = __BLACKHOLE__
create_subdir = 0
@@ -54,7 +54,7 @@ magnet_file = 0
username = transmission
stalled_as_failed = True
delete_failed = True
-rpc_url = __RPCURL__
+rpc_url = __TRANSMISSION_RPCURL__
manual = 0
enabled = __RPC__
paused = False
@@ -62,7 +62,7 @@ host = 127.0.0.1:9091
delete_files = True
directory =
remove_complete = True
-password = __RPCPASSWORD__
+password = __TRNASMISSION_RPCPASSWORD__
[suggestion]
enabled = True
diff --git a/manifest.json b/manifest.json
index 9c25a8d..d714c1e 100644
--- a/manifest.json
+++ b/manifest.json
@@ -3,8 +3,8 @@
"id": "couchpotato",
"packaging_format": 1,
"description": {
- "en": "Automatic movie downloader",
- "fr": "Téléchargement automatisé de film"
+ "en": "Automatic movie downloader",
+ "fr": "Téléchargement automatisé de film"
},
"version": "3.0.1~ynh1",
"url": "https://couchpota.to/",
@@ -15,7 +15,7 @@
"url": "https://github.com/Snipees"
},
"requirements": {
- "yunohost": ">= 3.8.1"
+ "yunohost": ">= 4.2.0"
},
"multi_instance": false,
"services": [
@@ -26,19 +26,11 @@
{
"name": "domain",
"type": "domain",
- "ask": {
- "en": "Choose a domain for CouchPotato",
- "fr": "Choisissez un domaine pour CouchPotato"
- },
"example": "example.com"
},
{
"name": "path",
"type": "path",
- "ask": {
- "en": "Choose a path for CouchPotato",
- "fr": "Choisissez un chemin pour CouchPotato"
- },
"example": "/couchpotato",
"default": "/couchpotato"
}
diff --git a/scripts/backup b/scripts/backup
index 710fad2..e495c37 100644
--- a/scripts/backup
+++ b/scripts/backup
@@ -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
@@ -67,7 +67,7 @@ ynh_backup --src_path="/etc/systemd/system/$app.service"
#=================================================
# Backup data
-ynh_backup --src_path="$app_data_dir"
+ynh_backup --src_path="$app_data_dir" --is_big
#=================================================
# END OF SCRIPT
diff --git a/scripts/install b/scripts/install
index e0ba804..3514502 100644
--- a/scripts/install
+++ b/scripts/install
@@ -8,7 +8,6 @@
source _common.sh
source ynh_install_python
-source ynh_multimedia_3
source /usr/share/yunohost/helpers
#=================================================
@@ -38,9 +37,6 @@ ynh_script_progression --message="Validating installation parameters..."
final_path=/opt/yunohost/$app
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
-app_data_dir=/home/yunohost.app/$app
-test ! -e "$app_data_dir" || ynh_die --message="This path already contains a folder"
-
# Register (book) web path
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
@@ -65,10 +61,11 @@ port=$(ynh_find_port --port=5050)
ynh_app_setting_set --app=$app --key=port --value=$port
# Optional: Expose this port publicly
-# (N.B. : you only need to do this if the app actually needs to expose the port publicly.
+# (N.B.: you only need to do this if the app actually needs to expose the port publicly.
# If you do this and the app doesn't actually need you are CREATING SECURITY HOLES IN THE SERVER !)
# Open the port
+# ynh_script_progression --message="Configuring firewall..."
# ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port
#=================================================
@@ -78,23 +75,6 @@ ynh_script_progression --message="Installing dependencies..."
ynh_install_app_dependencies $pkg_dependencies
-#=================================================
-# DOWNLOAD, CHECK AND UNPACK SOURCE
-#=================================================
-ynh_script_progression --message="Setting up source files..."
-
-ynh_app_setting_set --app=$app --key=final_path --value=$final_path
-# Download, check integrity, uncompress and patch the source from app.src
-git clone $source $final_path
-
-#=================================================
-# NGINX CONFIGURATION
-#=================================================
-ynh_script_progression --message="Configuring nginx web server..."
-
-# Create a dedicated nginx config
-ynh_add_nginx_config
-
#=================================================
# CREATE DEDICATED USER
#=================================================
@@ -103,6 +83,27 @@ ynh_script_progression --message="Configuring system user..."
# Create a system user
ynh_system_user_create --username=$app --home_dir=$final_path
+#=================================================
+# DOWNLOAD, CHECK AND UNPACK SOURCE
+#=================================================
+ynh_script_progression --message="Setting up source files..."
+
+ynh_app_setting_set --app=$app --key=final_path --value=$final_path
+# Download, check integrity, uncompress and patch the source from app.src
+git clone $source "$final_path"
+
+chmod 750 "$final_path"
+chmod -R o-rwx "$final_path"
+chown -R $app:$app "$final_path"
+
+#=================================================
+# NGINX CONFIGURATION
+#=================================================
+ynh_script_progression --message="Configuring NGINX web server..."
+
+# Create a dedicated NGINX config
+ynh_add_nginx_config
+
#=================================================
# SPECIFIC SETUP
#=================================================
@@ -111,16 +112,16 @@ ynh_system_user_create --username=$app --home_dir=$final_path
ynh_script_progression --message="Make data directory..."
# Make directories
-mkdir -p $app_data_dir
+mkdir -p "$app_data_dir"
+chmod 750 "$app_data_dir"
+chmod -R o-rwx "$app_data_dir"
+chown -R $app:$app "$app_data_dir"
#=================================================
# BUILD COUCHPOTATO
#=================================================
ynh_script_progression --message="Building CouchPotato..."
-# Set permissions to app files
-chown -R "$app": "$final_path"
-
ynh_install_python --python_version=$python_version
pushd $final_path
@@ -133,22 +134,24 @@ popd
#=================================================
ynh_script_progression --message="Install YunoHost multimedia..."
+# Creates the "Movies" subfolder in "Video"
+mkdir -p "$MEDIA_DIRECTORY/share/Video/Movies"
+
ynh_multimedia_build_main_dir
# Give write access to the yunohost.multimedia directory so that Couchpotato can move Movies to the Movie directory
ynh_multimedia_addaccess $app
-# Creates the "Movies" subfolder in "Video"
-mkdir -p "/home/yunohost.multimedia/share/Video/Movies"
-
-# Fix permissions
-/home/yunohost.multimedia/ynh_media_build.sh
-
#=================================================
# CONFIGURE TRANSMISSION
#=================================================
ynh_script_progression --message="Configuring transmission..."
+# Variable initialization
+rpc=""
+blackhole=""
+renamer=""
+
# Transmission link: Preferred method is direct RPC link. If not available, switch to watchdir.
transmission_rpcurl=""
transmission_rpcpassword=""
@@ -156,59 +159,60 @@ transmission_watchdir=""
# Check if Transmission is installed
if [[ -z $(yunohost app list -i -f transmission | grep -v 'apps:') ]]; then
+
ynh_script_progression --message="Transmission is not installed. Disabling link to CouchPotato..."
- ynh_replace_string --match_string="__RPC__" --replace_string="0" --target_file="../conf/couchpotato.conf" # Disable Transmission RPC
- ynh_replace_string --match_string="__BLACKHOLE__" --replace_string="0" --target_file="../conf/couchpotato.conf" # Disable Transmission Watchdir
- ynh_replace_string --match_string="__RENAMER__" --replace_string="0" --target_file="../conf/couchpotato.conf" # Disable Renamer
+ rpc="0"
+ blackhole="0"
+ renamer="0"
else
ynh_script_progression --message="Transmission is installed. Trying to link it to CouchPotato..."
# Check if the transmission password is in settings
if [[ -n $(ynh_app_setting_get --app=transmission --key=rpcpassword || true) ]]; then
ynh_script_progression --message="Transmission will be linked to CouchPotato directly"
+
transmission_rpcurl="$(ynh_app_setting_get --app=transmission --key=path)transmission"
transmission_rpcpassword=$(ynh_app_setting_get --app=transmission --key=rpcpassword)
- ynh_replace_string --match_string="__RPC__" --replace_string="1" --target_file="../conf/couchpotato.conf" # Enable Transmission RPC
- ynh_replace_string --match_string="__BLACKHOLE__" --replace_string="0" --target_file="../conf/couchpotato.conf" # Disable Transmission Watchdir
- ynh_replace_string --match_string="__RENAMER__" --replace_string="1" --target_file="../conf/couchpotato.conf" # Enable Renamer
- # If transmission uses YunoHost multimedia, use its folder for the renamer
+ rpc="1" # Enable Transmission RPC
+ blackhole="0" # Disable Transmission Watchdir
+ renamer="1" # Enable Renamer
+ # If transmission uses YunoHost multimedia, use its folder for the renamer
else
- # Check if transmission has watchdir enabled
+ # Check if transmission has watchdir enabled
if [[ -n $(ynh_app_setting_get --app=transmission --key=watchdir || true) ]]; then
ynh_script_progression --message="Transmission will be linked to CouchPotato with watchdir"
+
transmission_watchdir=$(ynh_app_setting_get --app=transmission --key=watchdir)
- ynh_replace_string --match_string="__RPC__" --replace_string="0" --target_file="../conf/couchpotato.conf" # Disable Transmission RPC
- ynh_replace_string --match_string="__BLACKHOLE__" --replace_string="1" --target_file="../conf/couchpotato.conf" # Enable Transmission Watchdir
- ynh_replace_string --match_string="__RENAMER__" --replace_string="1" --target_file="../conf/couchpotato.conf" # Enable Renamer
- # If transmission uses YunoHost multimedia, use its folder for the renamer
+ rpc="0" # Disable Transmission RPC
+ blackhole="1" # Enable Transmission Watchdir
+ renamer="1" # Enable Renamer
+ # If transmission uses YunoHost multimedia, use its folder for the renamer
else
ynh_script_progression --message="Cannot link Couchpotato to Transmission because Transmission has no RPC password or watchdir available."
- ynh_replace_string --match_string="__RPC__" --replace_string="0" --target_file="../conf/couchpotato.conf" # Disable Transmission RPC
- ynh_replace_string --match_string="__BLACKHOLE__" --replace_string="0" --target_file="../conf/couchpotato.conf" # Disable Transmission Watchdir
- ynh_replace_string --match_string="__RENAMER__" --replace_string="0" --target_file="../conf/couchpotato.conf" # Disable Renamer
+
+ rpc="0" # Disable Transmission RPC
+ blackhole="0" # Disable Transmission Watchdir
+ renamer="0" # Disable Renamer
fi
fi
fi
#=================================================
-# MODIFY A CONFIG FILE
+# ADD A CONFIGURATION
#=================================================
-ynh_script_progression --message="Modifying a config file..."
+ynh_script_progression --message="Adding a configuration file..."
-app_config_file="${final_path}/settings.conf"
+ynh_add_config --template="../conf/couchpotato.conf" --destination="$final_path/settings.conf"
-# Configure App
-ynh_replace_string --match_string="__RPCURL__" --replace_string="$transmission_rpcurl" --target_file="../conf/couchpotato.conf"
-ynh_replace_string --match_string="__RPCPASSWORD__" --replace_string="$transmission_rpcpassword" --target_file="../conf/couchpotato.conf"
-ynh_replace_string --match_string="__WATCHDIR__" --replace_string="$transmission_watchdir" --target_file="../conf/couchpotato.conf"
+chmod 400 "$final_path/settings.conf"
+chown $app:$app "$final_path/settings.conf"
-ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="../conf/couchpotato.conf"
-ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="../conf/couchpotato.conf"
-ynh_replace_string --match_string="__DATADIR__" --replace_string="$app_data_dir" --target_file="../conf/couchpotato.conf"
+#=================================================
+# SETUP SYSTEMD
+#=================================================
+ynh_script_progression --message="Configuring a systemd service..."
-cp -a ../conf/couchpotato.conf $app_config_file
-
-# Calculate and store the config file checksum into the app settings
-ynh_store_file_checksum --file="$app_config_file"
+# Create a dedicated systemd config
+ynh_add_systemd_config
#=================================================
# CONFIGURE LOGS
@@ -222,25 +226,8 @@ chown -R $app $app_logs_dir
chmod +x -R $app_logs_dir
ynh_replace_string --match_string="self.log_dir =.*" --replace_string="self.log_dir = '$app_logs_dir'" --target_file="$final_path/CouchPotato.py"
-#=================================================
-# SETUP SYSTEMD
-#=================================================
-ynh_script_progression --message="Configuring a systemd service..."
-
-# Create a dedicated systemd config
-ynh_add_systemd_config --others_var="app_data_dir python_version"
-
#=================================================
# GENERIC FINALIZATION
-#=================================================
-# SECURE FILES AND DIRECTORIES
-#=================================================
-ynh_script_progression --message="Securing files and directories..."
-
-# Set permissions to app files
-chown -R $app:$app $final_path
-chown -R $app:$app $app_data_dir
-
#=================================================
# SETUP LOGROTATE
#=================================================
@@ -254,7 +241,7 @@ ynh_use_logrotate
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
-yunohost service add $app --description "CouchPotato Daemon" --log "/var/log/$app/$app.log"
+yunohost service add $app --description="CouchPotato Daemon" --log="/var/log/$app/$app.log"
#=================================================
# START SYSTEMD SERVICE
@@ -267,16 +254,19 @@ ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$ap
#=================================================
# SETUP SSOWAT
#=================================================
-ynh_script_progression --message="Configuring SSOwat..."
+ynh_script_progression --message="Configuring permissions..."
+
ynh_permission_update --permission="main" --add="visitors"
-# Open the /api path so that external applications can connect
-
+# Everyone can access to the api part
+# We don't want to display the tile in the sso so we put --show_tile="false"
+# And we don't want that the YunoHost Admin can remove visitors group to this permission, so we put --protected="true"
+ynh_permission_create --permission="api" --url="/api" --allowed="visitors" --show_tile="false" --protected="true"
#=================================================
# RELOAD NGINX
#=================================================
-ynh_script_progression --message="Reloading nginx web server..."
+ynh_script_progression --message="Reloading NGINX web server..."
ynh_systemd_action --service_name=nginx --action=reload
diff --git a/scripts/remove b/scripts/remove
index aea6ed0..e736c1c 100644
--- a/scripts/remove
+++ b/scripts/remove
@@ -93,9 +93,6 @@ fi
#=================================================
ynh_script_progression --message="Removing various files..."
-# Remove a directory securely
-ynh_secure_remove --file="$app_data_dir"
-
# Remove the log files
ynh_secure_remove --file="/var/log/$app"
diff --git a/scripts/restore b/scripts/restore
index 98b7537..aea0572 100644
--- a/scripts/restore
+++ b/scripts/restore
@@ -6,10 +6,9 @@
# 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 ../settings/scripts/ynh_install_python
-source ../settings/scripts/ynh_multimedia_3
source /usr/share/yunohost/helpers
#=================================================
@@ -25,7 +24,7 @@ ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
-ynh_script_progression --message="Loading settings..."
+ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
@@ -43,25 +42,16 @@ 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 $app_data_dir \
- || ynh_die --message="There is already a directory: $app_data_dir "
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
-ynh_script_progression --message="Restoring the nginx configuration..."
+ynh_script_progression --message="Restoring the NGINX 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..."
-
-ynh_restore_file --origin_path="$final_path"
-
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
@@ -71,12 +61,15 @@ ynh_script_progression --message="Recreating the dedicated system user..."
ynh_system_user_create --username=$app --home_dir=$final_path
#=================================================
-# RESTORE USER RIGHTS
+# RESTORE THE APP MAIN DIR
#=================================================
-ynh_script_progression --message="Restoring user rights..."
+ynh_script_progression --message="Restoring the app main directory..."
-# Restore permissions on app files
-chown -R $app:$app $final_path
+ynh_restore_file --origin_path="$final_path"
+
+chmod 750 "$final_path"
+chmod -R o-rwx "$final_path"
+chown -R $app:$app "$final_path"
#=================================================
# SPECIFIC RESTORATION
@@ -93,9 +86,6 @@ ynh_install_app_dependencies $pkg_dependencies
#=================================================
ynh_script_progression --message="Building CouchPotato..."
-# Set permissions to app files
-chown -R "$app": "$final_path"
-
ynh_install_python --python_version=$python_version
pushd $final_path
@@ -109,26 +99,26 @@ popd
#=================================================
ynh_script_progression --message="Restoring the data directory..."
-ynh_restore_file --origin_path="$app_data_dir"
+ynh_restore_file --origin_path="$app_data_dir" --not_mandatory
-chown -R $app:$app $app_data_dir
+mkdir -p "$app_data_dir"
+chmod 750 "$app_data_dir"
+chmod -R o-rwx "$app_data_dir"
+chown -R $app:$app "$app_data_dir"
#=================================================
# INSTALL YUNOHOST MULTIMEDIA
#=================================================
ynh_script_progression --message="Install YunoHost multimedia..."
+# Creates the "Movies" subfolder in "Video"
+mkdir -p "$MEDIA_DIRECTORY/share/Video/Movies"
+
ynh_multimedia_build_main_dir
# Give write access to the yunohost.multimedia directory so that Couchpotato can move Movies to the Movie directory
ynh_multimedia_addaccess $app
-# Creates the "Movies" subfolder in "Video"
-mkdir -p "/home/yunohost.multimedia/share/Video/Movies"
-
-# Fix permissions
-/home/yunohost.multimedia/ynh_media_build.sh
-
#=================================================
# CONFIGURE LOGS
#=================================================
@@ -147,14 +137,14 @@ ynh_replace_string --match_string="self.log_dir =.*" --replace_string="self.log_
ynh_script_progression --message="Restoring the systemd configuration..."
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
-systemctl enable $app.service
+systemctl enable $app.service --quiet
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
-yunohost service add $app --description "A short description of the app" --log "/var/log/$app/$app.log"
+yunohost service add $app --description="CouchPotato Daemon" --log="/var/log/$app/$app.log"
#=================================================
# START SYSTEMD SERVICE
@@ -175,7 +165,7 @@ ynh_restore_file --origin_path="/etc/logrotate.d/$app"
#=================================================
# RELOAD NGINX
#=================================================
-ynh_script_progression --message="Reloading nginx web server..."
+ynh_script_progression --message="Reloading NGINX web server..."
ynh_systemd_action --service_name=nginx --action=reload
diff --git a/scripts/upgrade b/scripts/upgrade
index cf1b005..ee2789f 100644
--- a/scripts/upgrade
+++ b/scripts/upgrade
@@ -8,7 +8,6 @@
source _common.sh
source ynh_install_python
-source ynh_multimedia_3
source /usr/share/yunohost/helpers
#=================================================
@@ -24,10 +23,6 @@ port=$(ynh_app_setting_get --app=$app --key=port)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
app_data_dir=$(ynh_app_setting_get --app=$app --key=app_data_dir)
-# Destinations definitions
-app_logs_dir="/var/log/$app"
-app_python_bin="/usr/bin/python"
-
#=================================================
# CHECK VERSION
#=================================================
@@ -35,26 +30,34 @@ 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)..."
+
+# 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
+#=================================================
+# STOP SYSTEMD SERVICE
+#=================================================
+ynh_script_progression --message="Stopping a systemd service..."
+
+ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
+
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..."
-# Fix is_public as a boolean value
-if [ "$is_public" = "Yes" ]; then
- ynh_app_setting_set --app=$app --key=is_public --value=1
- is_public=1
-elif [ "$is_public" = "No" ]; then
- ynh_app_setting_set --app=$app --key=is_public --value=0
- is_public=0
-fi
-# Cancel upgrade if the version is too old
-if [[ -n $(ynh_app_setting_get $app method) ]]; then
- ynh_die "Your current version is too old and cannot be upgraded.\
- If you had a local install, please remove the app and reinstall it.\
- If you had a remote install, please remove the app and install redirect_ynh for this purpose instead."
-fi
-
# If final_path doesn't exist, create it
if [ -z "$final_path" ]; then
final_path=/opt/yunohost/$app
@@ -67,80 +70,18 @@ if [ -z "$app_data_dir" ]; then
ynh_app_setting_set --app=$app --key=app_data_dir --value=$app_data_dir
fi
-#=================================================
-# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
-#=================================================
-ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
-
-# 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
-
-#=================================================
-# Migrate legacy permissions to new system
-#=================================================
-if ynh_legacy_permissions_exists
-then
+# Cleaning legacy permissions
+if ynh_legacy_permissions_exists; then
ynh_legacy_permissions_delete_all
ynh_app_setting_delete --app=$app --key=is_public
fi
-#=================================================
-# CHECK THE PATH
-#=================================================
-
-# Normalize the URL path syntax
-# N.B. : this is for app installations before YunoHost 2.7
-# where this value might be something like /foo/ or foo/
-# instead of /foo ....
-# If nobody installed your app before 2.7, then you may
-# safely remove this line
-path_url=$(ynh_normalize_url_path --path_url=$path_url)
-
-#=================================================
-# STANDARD UPGRADE STEPS
-#=================================================
-# STOP SYSTEMD SERVICE
-#=================================================
-ynh_script_progression --message="Stopping a systemd service..."
-
-ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
-
-#=================================================
-# DOWNLOAD, CHECK AND UNPACK SOURCE
-#=================================================
-
-if [ "$upgrade_type" == "UPGRADE_APP" ]
-then
- ynh_script_progression --message="Upgrading source files..."
-
- # Download, check integrity, uncompress and patch the source from app.src
- pushd $final_path
- git pull
- popd
+# Create a permission if needed
+if ! ynh_permission_exists --permission="api"; then
+ ynh_permission_create --permission="api" --url="/api" --allowed="visitors" --show_tile="false" --protected="true"
fi
-#=================================================
-# NGINX CONFIGURATION
-#=================================================
-ynh_script_progression --message="Upgrading nginx web server configuration..."
-
-# Create a dedicated nginx config
-ynh_add_nginx_config
-
-#=================================================
-# UPGRADE DEPENDENCIES
-#=================================================
-ynh_script_progression --message="Upgrading dependencies..."
-
-ynh_install_app_dependencies $pkg_dependencies
-
#=================================================
# CREATE DEDICATED USER
#=================================================
@@ -149,6 +90,39 @@ ynh_script_progression --message="Making sure dedicated system user exists..."
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir=$final_path
+#=================================================
+# DOWNLOAD, CHECK AND UNPACK SOURCE
+#=================================================
+
+if [ "$upgrade_type" == "UPGRADE_APP" ]
+then
+ ynh_script_progression --message="Upgrading source files..."
+
+ # Download, check integrity, uncompress and patch the source from app.src
+ pushd "$final_path"
+ git pull
+ popd
+fi
+
+chmod 750 "$final_path"
+chmod -R o-rwx "$final_path"
+chown -R $app:$app "$final_path"
+
+#=================================================
+# NGINX CONFIGURATION
+#=================================================
+ynh_script_progression --message="Upgrading NGINX web server configuration..."
+
+# Create a dedicated NGINX config
+ynh_add_nginx_config
+
+#=================================================
+# UPGRADE DEPENDENCIES
+#=================================================
+ynh_script_progression --message="Upgrading dependencies..."
+
+ynh_install_app_dependencies $pkg_dependencies
+
#=================================================
# SPECIFIC UPGRADE
#=================================================
@@ -156,9 +130,6 @@ ynh_system_user_create --username=$app --home_dir=$final_path
#=================================================
ynh_script_progression --message="Building CouchPotato..."
-# Set permissions to app files
-chown -R "$app": "$final_path"
-
ynh_install_python --python_version=$python_version
pushd $final_path
@@ -171,22 +142,24 @@ popd
#=================================================
ynh_script_progression --message="Install YunoHost multimedia..."
+# Creates the "Movies" subfolder in "Video"
+mkdir -p "$MEDIA_DIRECTORY/share/Video/Movies"
+
ynh_multimedia_build_main_dir
# Give write access to the yunohost.multimedia directory so that Couchpotato can move Movies to the Movie directory
ynh_multimedia_addaccess $app
-# Creates the "Movies" subfolder in "Video"
-mkdir -p "/home/yunohost.multimedia/share/Video/Movies"
-
-# Fix permissions
-/home/yunohost.multimedia/ynh_media_build.sh
-
#=================================================
# CONFIGURE TRANSMISSION
#=================================================
ynh_script_progression --message="Configuring transmission..."
+# Variable initialization
+rpc=""
+blackhole=""
+renamer=""
+
# Transmission link: Preferred method is direct RPC link. If not available, switch to watchdir.
transmission_rpcurl=""
transmission_rpcpassword=""
@@ -194,61 +167,52 @@ transmission_watchdir=""
# Check if Transmission is installed
if [[ -z $(yunohost app list -i -f transmission | grep -v 'apps:') ]]; then
+
ynh_script_progression --message="Transmission is not installed. Disabling link to CouchPotato..."
- ynh_replace_string --match_string="__RPC__" --replace_string="0" --target_file="../conf/couchpotato.conf" # Disable Transmission RPC
- ynh_replace_string --match_string="__BLACKHOLE__" --replace_string="0" --target_file="../conf/couchpotato.conf" # Disable Transmission Watchdir
- ynh_replace_string --match_string="__RENAMER__" --replace_string="0" --target_file="../conf/couchpotato.conf" # Disable Renamer
+ rpc="0"
+ blackhole="0"
+ renamer="0"
else
ynh_script_progression --message="Transmission is installed. Trying to link it to CouchPotato..."
# Check if the transmission password is in settings
if [[ -n $(ynh_app_setting_get --app=transmission --key=rpcpassword || true) ]]; then
ynh_script_progression --message="Transmission will be linked to CouchPotato directly"
+
transmission_rpcurl="$(ynh_app_setting_get --app=transmission --key=path)transmission"
transmission_rpcpassword=$(ynh_app_setting_get --app=transmission --key=rpcpassword)
- ynh_replace_string --match_string="__RPC__" --replace_string="1" --target_file="../conf/couchpotato.conf" # Enable Transmission RPC
- ynh_replace_string --match_string="__BLACKHOLE__" --replace_string="0" --target_file="../conf/couchpotato.conf" # Disable Transmission Watchdir
- ynh_replace_string --match_string="__RENAMER__" --replace_string="1" --target_file="../conf/couchpotato.conf" # Enable Renamer
- # If transmission uses YunoHost multimedia, use its folder for the renamer
+ rpc="1" # Enable Transmission RPC
+ blackhole="0" # Disable Transmission Watchdir
+ renamer="1" # Enable Renamer
+ # If transmission uses YunoHost multimedia, use its folder for the renamer
else
- # Check if transmission has watchdir enabled
+ # Check if transmission has watchdir enabled
if [[ -n $(ynh_app_setting_get --app=transmission --key=watchdir || true) ]]; then
ynh_script_progression --message="Transmission will be linked to CouchPotato with watchdir"
+
transmission_watchdir=$(ynh_app_setting_get --app=transmission --key=watchdir)
- ynh_replace_string --match_string="__RPC__" --replace_string="0" --target_file="../conf/couchpotato.conf" # Disable Transmission RPC
- ynh_replace_string --match_string="__BLACKHOLE__" --replace_string="1" --target_file="../conf/couchpotato.conf" # Enable Transmission Watchdir
- ynh_replace_string --match_string="__RENAMER__" --replace_string="1" --target_file="../conf/couchpotato.conf" # Enable Renamer
- # If transmission uses YunoHost multimedia, use its folder for the renamer
+ rpc="0" # Disable Transmission RPC
+ blackhole="1" # Enable Transmission Watchdir
+ renamer="1" # Enable Renamer
+ # If transmission uses YunoHost multimedia, use its folder for the renamer
else
ynh_script_progression --message="Cannot link Couchpotato to Transmission because Transmission has no RPC password or watchdir available."
- ynh_replace_string --match_string="__RPC__" --replace_string="0" --target_file="../conf/couchpotato.conf" # Disable Transmission RPC
- ynh_replace_string --match_string="__BLACKHOLE__" --replace_string="0" --target_file="../conf/couchpotato.conf" # Disable Transmission Watchdir
- ynh_replace_string --match_string="__RENAMER__" --replace_string="0" --target_file="../conf/couchpotato.conf" # Disable Renamer
+
+ rpc="0" # Disable Transmission RPC
+ blackhole="0" # Disable Transmission Watchdir
+ renamer="0" # Disable Renamer
fi
fi
fi
#=================================================
-# MODIFY A CONFIG FILE
+# UPDATE A CONFIG FILE
#=================================================
-ynh_script_progression --message="Modifying a config file..."
+ynh_script_progression --message="Updating a configuration file..."
-app_config_file="${final_path}/settings.conf"
+ynh_add_config --template="../conf/couchpotato.conf" --destination="$final_path/settings.conf"
-# Configure App
-ynh_replace_string --match_string="__RPCURL__" --replace_string="$transmission_rpcurl" --target_file="../conf/couchpotato.conf"
-ynh_replace_string --match_string="__RPCPASSWORD__" --replace_string="$transmission_rpcpassword" --target_file="../conf/couchpotato.conf"
-ynh_replace_string --match_string="__WATCHDIR__" --replace_string="$transmission_watchdir" --target_file="../conf/couchpotato.conf"
-
-ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="../conf/couchpotato.conf"
-ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="../conf/couchpotato.conf"
-ynh_replace_string --match_string="__DATADIR__" --replace_string="$app_data_dir" --target_file="../conf/couchpotato.conf"
-
-ynh_backup_if_checksum_is_different --file=$app_config_file
-
-cp -a ../conf/couchpotato.conf $app_config_file
-
-# Calculate and store the config file checksum into the app settings
-ynh_store_file_checksum --file="$app_config_file"
+chmod 400 "$final_path/settings.conf"
+chown $app:$app "$final_path/settings.conf"
#=================================================
# CONFIGURE LOGS
@@ -259,6 +223,16 @@ ynh_script_progression --message="Configuring logs..."
app_logs_dir="/var/log/$app"
ynh_replace_string --match_string="self.log_dir =.*" --replace_string="self.log_dir = '$app_logs_dir'" --target_file="$final_path/CouchPotato.py"
+#=================================================
+# SETUP SYSTEMD
+#=================================================
+ynh_script_progression --message="Upgrading systemd configuration..."
+
+# Create a dedicated systemd config
+ynh_add_systemd_config
+
+#=================================================
+# GENERIC FINALIZATION
#=================================================
# SETUP LOGROTATE
#=================================================
@@ -268,31 +242,11 @@ ynh_script_progression --message="Upgrading logrotate configuration..."
ynh_use_logrotate --non-append
#=================================================
-# SETUP SYSTEMD
+# INTEGRATE SERVICE IN YUNOHOST
#=================================================
-ynh_script_progression --message="Upgrading systemd configuration..."
+ynh_script_progression --message="Integrating service in YunoHost..."
-# Create a dedicated systemd config
-ynh_add_systemd_config --others_var="app_data_dir python_version"
-
-#=================================================
-# GENERIC FINALIZATION
-#=================================================
-# SECURE FILES AND DIRECTORIES
-#=================================================
-ynh_script_progression --message="Securing files and directories..."
-
-# Set permissions on app files
-chown -R $app:$app $final_path
-chown -R $app:$app $app_data_dir
-
-#=================================================
-# SETUP SSOWAT
-#=================================================
-ynh_script_progression --message="Upgrading SSOwat configuration..."
-
-# Open the /api path so that external applications can connect
-ynh_app_setting_set --app=$app --key=unprotected_uris --value="/api"
+yunohost service add $app --description="CouchPotato Daemon" --log="/var/log/$app/$app.log"
#=================================================
# START SYSTEMD SERVICE
@@ -304,7 +258,7 @@ ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$ap
#=================================================
# RELOAD NGINX
#=================================================
-ynh_script_progression --message="Reloading nginx web server..."
+ynh_script_progression --message="Reloading NGINX web server..."
ynh_systemd_action --service_name=nginx --action=reload
diff --git a/scripts/ynh_multimedia_3 b/scripts/ynh_multimedia_3
deleted file mode 100644
index edf680c..0000000
--- a/scripts/ynh_multimedia_3
+++ /dev/null
@@ -1,78 +0,0 @@
-#!/bin/bash
-
-# Install or update the main directory yunohost.multimedia
-#
-# usage: ynh_multimedia_build_main_dir
-ynh_multimedia_build_main_dir () {
- local ynh_media_release="v1.2"
- local checksum="806a827ba1902d6911095602a9221181"
-
- # Download yunohost.multimedia scripts
- wget -nv https://github.com/YunoHost-Apps/yunohost.multimedia/archive/${ynh_media_release}.tar.gz
-
- # Check the control sum
- echo "${checksum} ${ynh_media_release}.tar.gz" | md5sum -c --status \
- || ynh_die "Corrupt source"
-
- # Check if the package acl is installed. Or install it.
- ynh_package_is_installed 'acl' \
- || ynh_package_install acl
-
- # Extract
- mkdir yunohost.multimedia-master
- tar -xf ${ynh_media_release}.tar.gz -C yunohost.multimedia-master --strip-components 1
- ./yunohost.multimedia-master/script/ynh_media_build.sh
-}
-
-# Add a directory in yunohost.multimedia
-# This "directory" will be a symbolic link to a existing directory.
-#
-# usage: ynh_multimedia_addfolder "Source directory" "Destination directory"
-#
-# | arg: -s, --source_dir= - Source directory - The real directory which contains your medias.
-# | arg: -d, --dest_dir= - Destination directory - The name and the place of the symbolic link, relative to "/home/yunohost.multimedia"
-ynh_multimedia_addfolder () {
- # Declare an array to define the options of this helper.
- declare -Ar args_array=( [s]=source_dir= [d]=dest_dir= )
- local source_dir
- local dest_dir
- # Manage arguments with getopts
- ynh_handle_getopts_args "$@"
-
- ./yunohost.multimedia-master/script/ynh_media_addfolder.sh --source="$source_dir" --dest="$dest_dir"
-}
-
-# Move a directory in yunohost.multimedia, and replace by a symbolic link
-#
-# usage: ynh_multimedia_movefolder "Source directory" "Destination directory"
-#
-# | arg: -s, --source_dir= - Source directory - The real directory which contains your medias.
-# It will be moved to "Destination directory"
-# A symbolic link will replace it.
-# | arg: -d, --dest_dir= - Destination directory - The new name and place of the directory, relative to "/home/yunohost.multimedia"
-ynh_multimedia_movefolder () {
- # Declare an array to define the options of this helper.
- declare -Ar args_array=( [s]=source_dir= [d]=dest_dir= )
- local source_dir
- local dest_dir
- # Manage arguments with getopts
- ynh_handle_getopts_args "$@"
-
- ./yunohost.multimedia-master/script/ynh_media_addfolder.sh --inv --source="$source_dir" --dest="$dest_dir"
-}
-
-# Allow an user to have an write authorisation in multimedia directories
-#
-# usage: ynh_multimedia_addaccess user_name
-#
-# | arg: -u, --user_name= - The name of the user which gain this access.
-ynh_multimedia_addaccess () {
- # Declare an array to define the options of this helper.
- declare -Ar args_array=( [u]=user_name=)
- local user_name
- # Manage arguments with getopts
- ynh_handle_getopts_args "$@"
-
- groupadd -f multimedia
- usermod -a -G multimedia $user_name
-}