mirror of
https://codeberg.org/leana8959/.files.git
synced 2026-02-01 14:39:39 +00:00
packages/mullvad-status: init
This commit is contained in:
parent
9e33750fd9
commit
e3b843e00d
2 changed files with 47 additions and 0 deletions
33
nix/packages/by-name/mullvad-status/mullvad-status.sh
Normal file
33
nix/packages/by-name/mullvad-status/mullvad-status.sh
Normal 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
|
||||||
14
nix/packages/by-name/mullvad-status/package.nix
Normal file
14
nix/packages/by-name/mullvad-status/package.nix
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
writeShellApplication,
|
||||||
|
jq,
|
||||||
|
mullvad,
|
||||||
|
}:
|
||||||
|
|
||||||
|
writeShellApplication {
|
||||||
|
name = "mullvad-status";
|
||||||
|
runtimeInputs = [
|
||||||
|
mullvad
|
||||||
|
jq
|
||||||
|
];
|
||||||
|
text = builtins.readFile ./mullvad-status.sh;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue