syncthing: get GUI address from config
This commit is contained in:
parent
f76f819cd7
commit
f63aa737e6
|
@ -29,15 +29,36 @@ let
|
||||||
|
|
||||||
updateConfig = pkgs.writeDash "merge-syncthing-config" ''
|
updateConfig = pkgs.writeDash "merge-syncthing-config" ''
|
||||||
set -efu
|
set -efu
|
||||||
|
|
||||||
|
# XXX this assumes the GUI address to be "IPv4 address and port"
|
||||||
|
host=${shell.escape (elemAt (splitString ":" scfg.guiAddress) 0)}
|
||||||
|
port=${shell.escape (elemAt (splitString ":" scfg.guiAddress) 1)}
|
||||||
|
|
||||||
# wait for service to restart
|
# wait for service to restart
|
||||||
${pkgs.untilport}/bin/untilport localhost 8384
|
${pkgs.untilport}/bin/untilport "$host" "$port"
|
||||||
|
|
||||||
API_KEY=$(${getApiKey})
|
API_KEY=$(${getApiKey})
|
||||||
CFG=$(${pkgs.curl}/bin/curl -Ss -H "X-API-Key: $API_KEY" localhost:8384/rest/system/config)
|
|
||||||
echo "$CFG" | ${pkgs.jq}/bin/jq -s '.[] * {
|
_curl() {
|
||||||
"devices": ${builtins.toJSON devices},
|
${pkgs.curl}/bin/curl \
|
||||||
"folders": ${builtins.toJSON folders}
|
-Ss \
|
||||||
}' | ${pkgs.curl}/bin/curl -Ss -H "X-API-Key: $API_KEY" localhost:8384/rest/system/config -d @-
|
-H "X-API-Key: $API_KEY" \
|
||||||
${pkgs.curl}/bin/curl -Ss -H "X-API-Key: $API_KEY" localhost:8384/rest/system/restart -X POST
|
"http://$host:$port/rest""$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
old_config=$(_curl /system/config)
|
||||||
|
patch=${shell.escape (toJSON {
|
||||||
|
inherit devices folders;
|
||||||
|
})}
|
||||||
|
new_config=$(${pkgs.jq}/bin/jq -en \
|
||||||
|
--argjson old_config "$old_config" \
|
||||||
|
--argjson patch "$patch" \
|
||||||
|
'
|
||||||
|
$old_config * $patch
|
||||||
|
'
|
||||||
|
)
|
||||||
|
echo $new_config | _curl /system/config -d @-
|
||||||
|
_curl /system/restart -X POST
|
||||||
'';
|
'';
|
||||||
|
|
||||||
in
|
in
|
||||||
|
|
Loading…
Reference in a new issue