forked from finn/tinyboard
syncthing.sh: fix remaining shell variable interpolation in python3 -c strings across add_device_by_pending, remove_device, and unshare_folder
This commit is contained in:
14
syncthing.sh
14
syncthing.sh
@@ -96,20 +96,20 @@ add_device_by_pending() {
|
|||||||
if [ ${#id_list[@]} -eq 1 ]; then
|
if [ ${#id_list[@]} -eq 1 ]; then
|
||||||
DEVICE_ID="${id_list[0]}"
|
DEVICE_ID="${id_list[0]}"
|
||||||
local pending_name
|
local pending_name
|
||||||
pending_name=$(echo "$pending" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d['${DEVICE_ID}'].get('name',''))")
|
pending_name=$(echo "$pending" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d[sys.argv[1]].get('name',''))" "$DEVICE_ID")
|
||||||
else
|
else
|
||||||
echo "Pending devices:"
|
echo "Pending devices:"
|
||||||
local i=1
|
local i=1
|
||||||
for id in "${id_list[@]}"; do
|
for id in "${id_list[@]}"; do
|
||||||
local name
|
local name
|
||||||
name=$(echo "$pending" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d['${id}'].get('name','(unknown)'))")
|
name=$(echo "$pending" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d[sys.argv[1]].get('name','(unknown)'))" "$id")
|
||||||
echo " $i) $name — $id"
|
echo " $i) $name — $id"
|
||||||
i=$((i+1))
|
i=$((i+1))
|
||||||
done
|
done
|
||||||
read -rp "Choose [1-${#id_list[@]}]: " CHOICE
|
read -rp "Choose [1-${#id_list[@]}]: " CHOICE
|
||||||
[[ "$CHOICE" =~ ^[0-9]+$ ]] && [ "$CHOICE" -ge 1 ] && [ "$CHOICE" -le "${#id_list[@]}" ] || die "Invalid choice."
|
[[ "$CHOICE" =~ ^[0-9]+$ ]] && [ "$CHOICE" -ge 1 ] && [ "$CHOICE" -le "${#id_list[@]}" ] || die "Invalid choice."
|
||||||
DEVICE_ID="${id_list[$((CHOICE-1))]}"
|
DEVICE_ID="${id_list[$((CHOICE-1))]}"
|
||||||
pending_name=$(echo "$pending" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d['${DEVICE_ID}'].get('name',''))")
|
pending_name=$(echo "$pending" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d[sys.argv[1]].get('name',''))" "$DEVICE_ID")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
read -rp "Device name [${pending_name:-new-device}]: " DEVICE_NAME
|
read -rp "Device name [${pending_name:-new-device}]: " DEVICE_NAME
|
||||||
@@ -185,9 +185,9 @@ for i, d in enumerate(json.load(sys.stdin), 1):
|
|||||||
shared_folders=$(echo "$folders" | python3 -c "
|
shared_folders=$(echo "$folders" | python3 -c "
|
||||||
import sys, json
|
import sys, json
|
||||||
folders = json.load(sys.stdin)
|
folders = json.load(sys.stdin)
|
||||||
shared = [f['label'] or f['id'] for f in folders if any(dev['deviceID']=='${device_id}' for dev in f.get('devices',[]))]
|
shared = [f['label'] or f['id'] for f in folders if any(dev['deviceID']==sys.argv[1] for dev in f.get('devices',[]))]
|
||||||
print('\n'.join(shared))
|
print('\n'.join(shared))
|
||||||
")
|
" "$device_id")
|
||||||
if [ -n "$shared_folders" ]; then
|
if [ -n "$shared_folders" ]; then
|
||||||
warn "Device '${device_name}' is still sharing these folders:"
|
warn "Device '${device_name}' is still sharing these folders:"
|
||||||
echo "$shared_folders" | sed 's/^/ /'
|
echo "$shared_folders" | sed 's/^/ /'
|
||||||
@@ -373,7 +373,7 @@ for i, f in enumerate(json.load(sys.stdin), 1):
|
|||||||
local i=1
|
local i=1
|
||||||
while IFS= read -r did; do
|
while IFS= read -r did; do
|
||||||
local dname
|
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']=='${did}']; print(match[0] if match else '${did}')")
|
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 " $i) $dname — $did"
|
echo " $i) $dname — $did"
|
||||||
i=$((i+1))
|
i=$((i+1))
|
||||||
done <<< "$shared_ids"
|
done <<< "$shared_ids"
|
||||||
@@ -386,7 +386,7 @@ for i, f in enumerate(json.load(sys.stdin), 1):
|
|||||||
local target_id
|
local target_id
|
||||||
target_id=$(echo "$shared_ids" | sed -n "${D_CHOICE}p")
|
target_id=$(echo "$shared_ids" | sed -n "${D_CHOICE}p")
|
||||||
local target_name
|
local target_name
|
||||||
target_name=$(echo "$devices" | python3 -c "import sys,json; devs=json.load(sys.stdin); match=[d['name'] for d in devs if d['deviceID']=='${target_id}']; print(match[0] if match else '${target_id}')")
|
target_name=$(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])" "$target_id")
|
||||||
|
|
||||||
read -rp "Unshare '${folder_label}' from '${target_name}'? [y/N]: " CONFIRM
|
read -rp "Unshare '${folder_label}' from '${target_name}'? [y/N]: " CONFIRM
|
||||||
[[ "${CONFIRM,,}" == "y" ]] || { info "Aborted."; return; }
|
[[ "${CONFIRM,,}" == "y" ]] || { info "Aborted."; return; }
|
||||||
|
|||||||
Reference in New Issue
Block a user