Skip to content

Commit

Permalink
Update wizards for SHARENAME
Browse files Browse the repository at this point in the history
- The upgrade wizard identifies an existing share name. If it's not found, an additional screen will appear for user confirmation.
  • Loading branch information
mreid-tt committed Jan 4, 2024
1 parent c23e8a4 commit 48b315a
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 10 deletions.
6 changes: 2 additions & 4 deletions spk/sabnzbd/src/wizard/install_uifile
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@
}
]
}, {
"desc": ""
}, {
"desc": "If you let the installer create the shared folder, it is created under the same volume as the package is installed.<br/>If you want to use a different volume for the share, you must create the shared folder in DSM Control Panel before, and enter the name of the existing share in the field above."
"desc": "If you let the installer handle it, the shared folder goes to the package's volume. To use a different volume, create the shared folder in DSM Control Panel before installation and input its name during setup."
}, {
"desc": ""
}, {
"desc": "This package runs as internal service user <b>'sc-sabnzbd'</b> in DSM. The shared folder above is configured at installation time to be accessible by this user.<p>Please read <a target=\"_blank\" href=\"https://github.com/SynoCommunity/spksrc/wiki/Permission-Management\">Permission Management</a> for details."
"desc": "This package utilizes the internal service user <b>'sc-sabnzbd'</b> in DSM. The shared folder mentioned is set up during installation to be accessible specifically by this user. For more detailed information, please consult the <a target=\"_blank\" href=\"https://github.com/SynoCommunity/spksrc/wiki/Permission-Management\">Permission Management</a> guide."
}
]
}
Expand Down
6 changes: 0 additions & 6 deletions spk/sabnzbd/src/wizard/upgrade_uifile

This file was deleted.

93 changes: 93 additions & 0 deletions spk/sabnzbd/src/wizard/upgrade_uifile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/bin/bash

page_append ()
{
if [ -z "$1" ]; then
echo "$2"
elif [ -z "$2" ]; then
echo "$1"
else
echo "$1,$2"
fi
}

CFG_FILE="/var/packages/${SYNOPKG_PKGNAME}/var/config.ini"
# Extract share path and name from application config
CONFIGURED_SHARE_PATH=$(awk -F' = ' '/^download_dir/{split($2, path, "/"); print "/" path[2] "/" path[3]}' "${CFG_FILE}")
CONFIGURED_SHARE_NAME=$(echo "${CONFIGURED_SHARE_PATH}" | awk -F'/' '{print $NF}')

VAR_FILE="/var/packages/${SYNOPKG_PKGNAME}/etc/installer-variables"
# Extract share path from installer variables or configured shares
PACKAGE_SHARE_PATH=$(awk -F'=' '/^SHARE_PATH=/{print $2}' "${VAR_FILE}" 2>/dev/null || echo "")
if [ -z "$PACKAGE_SHARE_PATH" ] && [ -d "/var/packages/${SYNOPKG_PKGNAME}/shares" ]; then
PACKAGE_SHARE_PATH=$(realpath "/var/packages/${SYNOPKG_PKGNAME}/shares/${CONFIGURED_SHARE_NAME}" 2>/dev/null || echo "")
fi
# Extract share name from installer variables or configured shares
PACKAGE_SHARE_NAME=$(awk -F'=' '/^SHARE_NAME=/{print $2}' "${VAR_FILE}" 2>/dev/null || echo "")
if [ -z "$PACKAGE_SHARE_NAME" ] && [ -d "/var/packages/${SYNOPKG_PKGNAME}/shares/${CONFIGURED_SHARE_NAME}" ]; then
PACKAGE_SHARE_NAME=${CONFIGURED_SHARE_NAME}
fi

WARNING_TEXT="IMPORTANT: If your download folder is not currently located in the specified share, a new share will be created. After the upgrade, you may need to manually update your configuration to reflect this new location."

# If consistent data share path, suppress user warning
if [ -n "$CONFIGURED_SHARE_PATH" ] && [ -n "$PACKAGE_SHARE_PATH" ] && [ "$CONFIGURED_SHARE_PATH" = "$PACKAGE_SHARE_PATH" ]; then
WARNING_TEXT=""
fi

# Check for data share
check_data_share ()
{
if [ -n "${PACKAGE_SHARE_NAME}" ]; then
return 0 # true
else
return 1 # false
fi
}

PAGE_SHARE_UPGRADE=$(/bin/cat<<EOF
{
"step_title": "Shared Folder Upgrade",
"invalid_next_disabled_v2": true,
"items": [{
"type": "textfield",
"desc": "The download folder for this package must now be located within a data share. As per the existing configuration, the identified data share for your downloads is:",
"subitems": [{
"key": "wizard_shared_folder_name",
"desc": "Shared Folder",
"defaultValue": "${CONFIGURED_SHARE_NAME}",
"validator": {
"allowBlank": false,
"regex": {
"expr": "/^[\\\w _-]+$/",
"errorText": "Subdirectories are not supported."
}
}
}]
},{
"desc": "${WARNING_TEXT}"
}]
}
EOF
)

PAGE_DSM_PERMISSIONS=$(/bin/cat<<EOF
{
"step_title": "DSM Permissions",
"items": [{
"desc": "Please read <a target=\"_blank\" href=\"https://github.com/SynoCommunity/spksrc/wiki/Permission-Management\">Permission Management</a> for details."
}]
}
EOF
)

main () {
local upgrade_page=""
if ! check_data_share; then
upgrade_page=$(page_append "$upgrade_page" "$PAGE_SHARE_UPGRADE")
fi
upgrade_page=$(page_append "$upgrade_page" "$PAGE_DSM_PERMISSIONS")
echo "[$upgrade_page]" > "${SYNOPKG_TEMP_LOGFILE}"
}

main "$@"

0 comments on commit 48b315a

Please sign in to comment.