summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-08-04 20:17:15 +0200
committertv <tv@krebsco.de>2026-08-04 20:17:15 +0200
commit9fb0a80f450dfdf8cc2752cb854e8a03b32d14d0 (patch)
treea9dae178e49f594405405325ec4c6befa0e003a5
parent718d2fb12728ae278a292cec34f5db84f5787cd3 (diff)
admit XDG_CACHE_HOME
-rwxr-xr-xwetter19
1 files changed, 8 insertions, 11 deletions
diff --git a/wetter b/wetter
index 9a3bfe5..e2fc937 100755
--- a/wetter
+++ b/wetter
@@ -8,9 +8,9 @@
# wetter [LATITUDE,LONGITUDE]
#
# ENVIRONMENT
-# 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_CACHE_DIR
+# If set, the specified location will be used to cache HTTP
+# responses.
#
# WETTER_API_ROOT_URL
# WETTER_TOKEN_URL
@@ -37,18 +37,15 @@ 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}
- 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=
+ cache_dir=${WETTER_CACHE_DIR-${XDG_CACHE_HOME-$HOME/.cache}/wetter}
+ if test -z "$cache_dir"; then
+ debug "no cache directory set: caching disabled"
token_cache=
- elif test -z "${XDG_CACHE_HOME-}"; then
- debug "neither WETTER_CACHE_DIR nor XDG_CACHE_HOME set: caching disabled"
- cache_dir=
+ elif ! test -d "$cache_dir"; then
+ debug "cache directory $cache_dir does not exist: caching disabled"
token_cache=
else
- 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")