dotfiles/hm/scripts/lip
Geoffrey Preud'homme 8e6203ce7d
scripts/lip: Fix
2024-02-01 16:24:19 +01:00

32 lines
560 B
Plaintext
Executable file

#!/usr/bin/env nix-shell
#! nix-shell -i bash --pure
#! nix-shell -p bash jq curl cacert findutils coreutils
set -euxo pipefail
url="https://ip.frogeye.fr/json"
cachedir="$HOME/.cache/lip"
ip="${1:-}"
jq_sel="del(.user_agent)"
if [ $# -gt 1 ]
then
shift
jq_sel="$@"
fi
if [ -n "$ip" ]
then
cachefile="$cachedir/$ip"
if ! find "$cachefile" -mtime -7 &> /dev/null
then
mkdir -p "$cachedir"
curl --silent "$url?ip=$ip" > "$cachefile"
fi
cat "$cachefile" | jq $jq_sel
else
curl --silent "$url" | jq $jq_sel
fi