feat(wireguard): support printing multiple configs at once

This commit is contained in:
oddlama 2023-04-15 16:55:50 +02:00
parent 1630e37afd
commit 2e45d3f423
No known key found for this signature in database
GPG key ID: 14EFE510775FE39A

View file

@ -30,15 +30,14 @@ in
| ${pkgs.coreutils}/bin/cut -d$'\t' -f1)
[[ -n "$json_sel" ]] || exit 1
# TODO for each output line
# TODO maybe just call a json -> make script that gives wireguard config to make this easier
while IFS= read -r line; do
wgName=$(${pkgs.jq}/bin/jq -r .wgName <<< "$line")
serverNode=$(${pkgs.jq}/bin/jq -r .serverNode <<< "$line")
peer=$(${pkgs.jq}/bin/jq -r .peer <<< "$line")
echo "======== $wgName.$serverNode.$peer ========"
wgName=$(${pkgs.jq}/bin/jq -r .wgName <<< "$json_sel")
serverNode=$(${pkgs.jq}/bin/jq -r .serverNode <<< "$json_sel")
peer=$(${pkgs.jq}/bin/jq -r .peer <<< "$json_sel")
createConfigScript=$(nix build --no-link --print-out-paths --impure --show-trace --expr \
'let flk = builtins.getFlake "${../../.}"; in (flk.extraLib.wireguard "'"$wgName"'").wgQuickConfigScript "${pkgs.system}" "'"$serverNode"'" "'"$peer"'"')
"$createConfigScript" | tee /dev/tty | ${pkgs.qrencode}/bin/qrencode -t ansiutf8
createConfigScript=$(nix build --no-link --print-out-paths --impure --show-trace --expr \
'let flk = builtins.getFlake "${../../.}"; in (flk.extraLib.wireguard "'"$wgName"'").wgQuickConfigScript "${pkgs.system}" "'"$serverNode"'" "'"$peer"'"')
"$createConfigScript" | tee /dev/tty | ${pkgs.qrencode}/bin/qrencode -t ansiutf8
done <<< "$json_sel"
''