syncthing.sh: add pending folders support to option 1, allowing acceptance of incoming folder offers

This commit is contained in:
Justin Oros
2026-04-20 13:08:29 -07:00
parent 132d15357c
commit 78d4373c0d

View File

@@ -84,6 +84,63 @@ for device_id, info in devices.items():
fi fi
} }
show_pending_folders() {
header "Pending Folders"
local pending
pending=$(st_get /rest/cluster/pending/folders)
local count
count=$(echo "$pending" | python3 -c 'import sys,json; d=json.load(sys.stdin); print(len(d))')
if [ "$count" -eq 0 ]; then
warn "No pending folders."
return
fi
echo "$pending" | python3 -c '
import sys,json
d=json.load(sys.stdin)
for fid,info in d.items():
offered_by = list(info.get("offeredBy",{}).keys())
print(f" Folder ID: {fid}")
print(f" Offered by: {offered_by}")
print("")
'
read -rp "Accept a pending folder? [y/N]: " ACCEPT
ACCEPT="${ACCEPT:-n}"
if [[ "${ACCEPT,,}" != "y" ]]; then return; fi
local folder_ids
folder_ids=$(echo "$pending" | python3 -c 'import sys,json; [print(k) for k in json.load(sys.stdin)]')
local FOLDER_ID
if [ "$(echo "$folder_ids" | wc -l)" -eq 1 ]; then
FOLDER_ID="$folder_ids"
else
echo "Available pending folders:"
local i=1
while IFS= read -r fid; do
echo " $i) $fid"
i=$((i+1))
done <<< "$folder_ids"
read -rp "Choose folder number: " FOLDER_NUM
FOLDER_ID=$(echo "$folder_ids" | sed -n "${FOLDER_NUM}p")
fi
[ -n "$FOLDER_ID" ] || { warn "No folder selected."; return; }
echo ""
info "Available directories in /var/syncthing/data/:"
ls /var/syncthing/data/ 2>/dev/null | sed 's/^/ /' || true
echo ""
read -rp "Folder path on this device: " FOLDER_PATH
[ -n "$FOLDER_PATH" ] || { warn "Path cannot be empty."; return; }
read -rp "Folder label [$FOLDER_ID]: " FOLDER_LABEL
FOLDER_LABEL="${FOLDER_LABEL:-$FOLDER_ID}"
st_post /rest/config/folders "$(python3 -c "
import json
print(json.dumps({'id': '$FOLDER_ID', 'label': '$FOLDER_LABEL', 'path': '$FOLDER_PATH'}))
")"
info "Folder '$FOLDER_LABEL' added at $FOLDER_PATH."
}
add_device_by_pending() { add_device_by_pending() {
local pending="$1" local pending="$1"
local ids local ids
@@ -436,7 +493,7 @@ get_apikey
while true; do while true; do
header "Syncthing Manager" header "Syncthing Manager"
echo " 0) Show This Device's ID" echo " 0) Show This Device's ID"
echo " 1) Pending Devices" echo " 1) Pending Devices & Folders"
echo " 2) List Devices" echo " 2) List Devices"
echo " 3) Add Device" echo " 3) Add Device"
echo " 4) Remove Device" echo " 4) Remove Device"
@@ -451,7 +508,7 @@ while true; do
echo "" echo ""
case "$OPT" in case "$OPT" in
0) show_own_device_id ;; 0) show_own_device_id ;;
1) show_pending_devices ;; 1) show_pending_devices; show_pending_folders ;;
2) list_devices ;; 2) list_devices ;;
3) add_device ;; 3) add_device ;;
4) remove_device ;; 4) remove_device ;;