packages/mullvad-status: init

This commit is contained in:
Primrose 2026-01-10 22:28:56 +01:00
parent 9e33750fd9
commit e3b843e00d
Signed by: primrose
GPG key ID: 4E887A4CA9714ADA
2 changed files with 47 additions and 0 deletions

View file

@ -0,0 +1,33 @@
if ! type mullvad >/dev/null; then
echo -n "Mullvad unavailable"
exit 1
fi
MULLVAD_STATUS="$(mullvad status -j)"
function xmobarColor {
fg="$1"
x="$2"
echo -n "<fc=$fg>$x</fc>"
}
case "$(echo "$MULLVAD_STATUS" | jq -r ".state")" in
connected)
function has-feature {
echo "$MULLVAD_STATUS" | jq --exit-status ".details.feature_indicators|contains([\"$1\"])" >/dev/null
}
if has-feature "LockdownMode"; then
xmobarColor "green" "Mullvad On "
else
xmobarColor "orange" "Mullvad On"
fi
COUNTRY="$(echo "$MULLVAD_STATUS" | jq -r '.details.location.country')"
CITY="$(echo "$MULLVAD_STATUS" | jq -r '.details.location.city')"
echo -n " ($COUNTRY,$CITY)"
;;
disconnected)
xmobarColor "red" "Mullvad Off"
;;
esac

View file

@ -0,0 +1,14 @@
{
writeShellApplication,
jq,
mullvad,
}:
writeShellApplication {
name = "mullvad-status";
runtimeInputs = [
mullvad
jq
];
text = builtins.readFile ./mullvad-status.sh;
}