Skip to content

Commit

Permalink
Test install wizard refinement
Browse files Browse the repository at this point in the history
  • Loading branch information
mreid-tt committed Mar 16, 2023
1 parent 136d70d commit 2a5b76d
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 95 deletions.
1 change: 1 addition & 0 deletions spk/transmission/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ WIZARDS_DIR = src/wizard/

SERVICE_USER = auto
SERVICE_WIZARD_SHARE = wizard_download_dir
USE_DATA_SHARE_WORKER = yes
SERVICE_SETUP = src/service-setup.sh
SERVICE_PORT = 9091
SERVICE_PORT_TITLE = $(DISPLAY_NAME)
Expand Down
7 changes: 3 additions & 4 deletions spk/transmission/src/service-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ service_postinst ()
{
if [ "${SYNOPKG_PKG_STATUS}" = "INSTALL" ]; then
# Capture wizard variables
TXN_VOLUME=${wizard_volume:=/volume1}
TXN_DNLOAD=${wizard_download_dir:=downloads}
TXN_DNLOAD=${wizard_download_dir:=/volume1/downloads}
TXN_FOLDRS=("complete" "incomplete" "watch-transmission")
TXN_PATHS=()

# Create the managed folders
for item in "${TXN_FOLDRS[@]}"; do
folder="$TXN_VOLUME/$TXN_DNLOAD/$item"
folder="$TXN_DNLOAD/$item"
if [ "${SYNOPKG_DSM_VERSION_MAJOR}" -ge 7 ]; then
mkdir -p "$folder"
else
Expand All @@ -51,7 +50,7 @@ service_postinst ()
fi
else
if [ "${TXN_FOLDRS[$i]}" = "complete" ]; then
sed -e "s|@download_dir@|${TXN_VOLUME}/${TXN_DNLOAD}|g" -i "${CFG_FILE}"
sed -e "s|@download_dir@|${TXN_DNLOAD}|g" -i "${CFG_FILE}"
else
sed -e "s|@${TXN_FOLDRS[$i]}_dir_enabled@|false|g" \
-e "/@${TXN_FOLDRS[$i]}_dir@/d" \
Expand Down
91 changes: 0 additions & 91 deletions spk/transmission/src/wizard/install_uifile

This file was deleted.

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

quote_json () {
sed -e 's|\\|\\\\|g' -e 's|\"|\\\"|g'
}

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

wizard_download_share_validator()
{
DOWNLOAD_SHARE=$(/bin/cat<<EOF
{
var value = arguments[0];
var step = arguments[2];
step.items.map['wizard_download_dir'].setValue(step.items.map['wizard_download_volume'].value + '/' + value);
return true;
}
EOF
)
echo "$DOWNLOAD_SHARE" | quote_json
}

wizard_download_volume_validator()
{
DOWNLOAD_VOLUME=$(/bin/cat<<EOF
{
var value = arguments[0];
var step = arguments[2];
step.items.map['wizard_download_dir'].setValue('/' + value + '/' + step.items.map['wizard_download_share'].value);
return true;
}
EOF
)
echo "$DOWNLOAD_VOLUME" | quote_json
}

PAGE_BASE_CONFIG=$(/bin/cat<<EOF
{
"step_title": "Basic configuration",
"items": [{
"type": "combobox",
"desc": "Please select a volume to use for the download folder",
"subitems": [{
"key": "wizard_download_volume",
"desc": "Volume name",
"defaultValue": "volume1",
"displayField": "display_name",
"valueField": "volume_path",
"editable": false,
"mode": "remote",
"api_store": {
"api": "SYNO.Core.Storage.Volume",
"method": "list",
"version": 1,
"baseParams": {
"limit": -1,
"offset": 0,
"location": "internal"
},
"root": "volumes",
"idProperty": "volume_path",
"fields": [
"display_name",
"volume_path"
]
},
"validator": {
"fn": "$(wizard_download_volume_validator)"
}
}]
},
{
"type": "textfield",
"desc": "Download shared folder (using the volume chosen above)",
"subitems": [{
"key": "wizard_download_share",
"desc": "Download shared folder",
"defaultValue": "downloads",
"validator": {
"allowBlank": false,
"regex": {
"expr": "$(echo "/^[\\w _-]+$/" | quote_json)",
"errorText": "Subdirectories are not supported."
},
"fn": "$(wizard_download_share_validator)"
}
},
{
"key": "wizard_download_dir",
"desc": "Full path to the shared download folder",
"defaultValue": "/volume1/downloads",
"hidden": true
}
]
}
]
},
{
"step_title": "Basic configuration",
"items": [{
"type": "textfield",
"desc": "Web interface username. Defaults to admin",
"subitems": [{
"key": "wizard_username",
"desc": "Username"
}]
},
{
"type": "password",
"desc": "Web interface password. Defaults to admin",
"subitems": [{
"key": "wizard_password",
"desc": "Password"
}]
}
]
},
{
"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 install_page=""
install_page=$(page_append "$install_page" "$PAGE_BASE_CONFIG")
echo "[$install_page]" > "${SYNOPKG_TEMP_LOGFILE}"
}

main "$@"

0 comments on commit 2a5b76d

Please sign in to comment.