diff options
| -rwxr-xr-x | wetter | 19 |
1 files changed, 8 insertions, 11 deletions
@@ -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") |
