summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-01-20 21:50:18 +0100
committertv <tv@krebsco.de>2026-01-20 21:54:03 +0100
commitedd174fda0492752454229a30b0ab801db523550 (patch)
tree764c5f97149b036bbd1cbbeb68bb3e657a9079f6
parent076b6a1bd9f7e96a96c2488ee823d5e75a60a597 (diff)
WETTER_CACHE_DIR: use XDG_CACHE_HOME as fallback
Co-authored-by: kmein <kmein@posteo.de>
-rwxr-xr-xwetter21
1 files changed, 12 insertions, 9 deletions
diff --git a/wetter b/wetter
index 0fb3407..dc5a109 100755
--- a/wetter
+++ b/wetter
@@ -8,9 +8,9 @@
# wetter [LONGITUDE,LATITUDE]
#
# ENVIRONMENT
-# WETTER_CACHE_DIR
-# If set, the specified location will be used to cache HTTP
-# responses.
+# WETTER_CACHE_DIR (default: $XDG_CACHE_HOME/wetter or nothing)
+# If set to a non-empty string, the specified directory will be
+# used to cache HTTP responses.
#
# WETTER_API_ROOT_URL
# WETTER_TOKEN_URL
@@ -34,15 +34,18 @@ main() {
token_url=${WETTER_TOKEN_URL-https://api.weatherpro.com/v1/token/weather}
api_root_url=${WETTER_API_ROOT_URL-https://point-forecast-weatherpro.meteogroup.com}
- cache_dir=${WETTER_CACHE_DIR-}
- if test -z "$cache_dir"; then
- debug "no cache directory set: caching disabled"
+ if test -n "${WETTER_CACHE_DIR+x}" && test -z "$WETTER_CACHE_DIR"; then
+ debug "WETTER_CACHE_DIR set to the empty string: caching disabled"
+ cache_dir=
token_cache=
- elif ! test -d "$cache_dir"; then
- debug "cache directory $cache_dir does not exist: caching disabled"
+ elif test -z "${XDG_CACHE_HOME-}"; then
+ debug "neither WETTER_CACHE_DIR nor XDG_CACHE_HOME set: caching disabled"
+ cache_dir=
token_cache=
else
- token_cache=$WETTER_CACHE_DIR/api.weatherpro.com%1Fv1%1Ftoken%1Fweather
+ cache_dir=${WETTER_CACHE_DIR-${XDG_CACHE_HOME-$HOME/.cache}/wetter}
+ token_cache=$cache_dir/api.weatherpro.com%1Fv1%1Ftoken%1Fweather
+ mkdir -p "$cache_dir"
fi
token=$(get_token "$token_url" "$token_cache")