forked from finn/tinyboard
syncthing.sh: auto-unshare folder from all devices before removal if shared
This commit is contained in:
31
syncthing.sh
31
syncthing.sh
@@ -268,8 +268,35 @@ for i, f in enumerate(json.load(sys.stdin), 1):
|
||||
folder_id=$(echo "$folders" | python3 -c "import sys,json; f=json.load(sys.stdin)[$((CHOICE-1))]; print(f['id'])")
|
||||
folder_label=$(echo "$folders" | python3 -c "import sys,json; f=json.load(sys.stdin)[$((CHOICE-1))]; print(f['label'] or f['id'])")
|
||||
|
||||
read -rp "Remove folder '${folder_label}'? [y/N]: " CONFIRM
|
||||
[[ "${CONFIRM,,}" == "y" ]] || { info "Aborted."; return; }
|
||||
local folder_config shared_devices
|
||||
folder_config=$(st_get "/rest/config/folders/${folder_id}")
|
||||
shared_devices=$(echo "$folder_config" | python3 -c "import sys,json; [print(d['deviceID']) for d in json.load(sys.stdin).get('devices',[])]")
|
||||
|
||||
if [ -n "$shared_devices" ]; then
|
||||
local devices
|
||||
devices=$(st_get /rest/config/devices)
|
||||
warn "Folder '${folder_label}' is currently shared with:"
|
||||
while IFS= read -r did; do
|
||||
local dname
|
||||
dname=$(echo "$devices" | python3 -c "import sys,json; devs=json.load(sys.stdin); match=[d['name'] for d in devs if d['deviceID']==sys.argv[1]]; print(match[0] if match else sys.argv[1])" "$did")
|
||||
echo " - $dname"
|
||||
done <<< "$shared_devices"
|
||||
warn "It will be unshared from all devices before removal."
|
||||
read -rp "Proceed? [y/N]: " CONFIRM
|
||||
[[ "${CONFIRM,,}" == "y" ]] || { info "Aborted."; return; }
|
||||
local updated
|
||||
updated=$(echo "$folder_config" | python3 -c "
|
||||
import sys, json
|
||||
f = json.load(sys.stdin)
|
||||
f['devices'] = []
|
||||
print(json.dumps(f))
|
||||
")
|
||||
st_put "/rest/config/folders/${folder_id}" "$updated" >/dev/null
|
||||
info "Folder '${folder_label}' unshared from all devices."
|
||||
else
|
||||
read -rp "Remove folder '${folder_label}'? [y/N]: " CONFIRM
|
||||
[[ "${CONFIRM,,}" == "y" ]] || { info "Aborted."; return; }
|
||||
fi
|
||||
|
||||
st_delete "/rest/config/folders/${folder_id}" >/dev/null
|
||||
info "Folder '${folder_label}' removed."
|
||||
|
||||
Reference in New Issue
Block a user