nix-setup/metronom-login.script.nix
2026-05-21 23:52:56 +02:00

23 lines
617 B
Nix

{ pkgs }:
pkgs.writeShellScriptBin "metronom-login" ''
#!/bin/sh
# mullvad disconnect
sleep 2
netif="$(cat ~/.direct-netif)"
echo "netif is (~/.direct-netif) $netif"
ip="$(dig -1 wifi.metronom.de @10.101.1.1 A)"
echo "ip is $ip"
csrf="$(curl --interface $(cat ~/.direct-netif) "$ip/de/" | grep CSRFToken | sed -E 's/.*value="([0-9a-f]*)".*/\1/')"
echo "csrf is $csrf"
resp="$(curl --interface $(cat ~/.direct-netif) "$ip/de/" -X POST -H "Cookie: csrf=$csrf" --data-raw "login=true&CSRFToken=$csrf" | wc -l)"
# mullvad connect
if [ $resp = 0 ] ; then
echo OK
else
echo unsuccessful
exit 1
fi
''