dotfiles/config/scripts/lip
Geoffrey “Frogeye” Preud'homme d1ae06e7ef Misc fixes
2023-07-25 13:23:56 +02:00

30 lines
476 B
Bash
Executable file

#!/usr/bin/env sh
set -euo pipefail
url="https://ip.frogeye.fr/json"
cachedir="$HOME/.cache/lip"
ip="${1:-}"
if [ $# -gt 0 ]
then
shift
jq_sel="$@"
else
jq_sel="del(.user_agent)"
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