|
|
|
@ -3,45 +3,95 @@ |
|
|
|
|
# background-weather.sh |
|
|
|
|
# Gets a background and sets it depending on the time of day and season. |
|
|
|
|
|
|
|
|
|
# Get the true path to the wallpapers directory |
|
|
|
|
if [ -L "$0" ] ; then |
|
|
|
|
true_file=$(readlink -f "$0"); |
|
|
|
|
base_dir=$( cd "$(dirname "$true_file")" ; pwd -P ); |
|
|
|
|
else |
|
|
|
|
base_dir=$( cd "$(dirname "$0")" ; pwd -P ); |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
# Defaults |
|
|
|
|
weather="clear"; |
|
|
|
|
latlon=false; |
|
|
|
|
file_name=""; |
|
|
|
|
WEATHER="clear"; |
|
|
|
|
test=false; |
|
|
|
|
LAT=false; |
|
|
|
|
LNG=false; |
|
|
|
|
OW_API_KEY=""; |
|
|
|
|
CITY=""; |
|
|
|
|
CONFIG=""; |
|
|
|
|
img_file_name=""; |
|
|
|
|
wallpapers_dir="$base_dir/wallpapers"; |
|
|
|
|
|
|
|
|
|
# Import config file |
|
|
|
|
declare -a configs=( |
|
|
|
|
"/etc/background-weather.conf" |
|
|
|
|
"$base_dir/background-weather.conf" |
|
|
|
|
"/home/$USER/.config/background-weather/background-weather.conf" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
for config_file in "${configs[@]}"; do |
|
|
|
|
if [ -f "$config_file" ]; then |
|
|
|
|
CONFIG="$config_file" |
|
|
|
|
break; |
|
|
|
|
fi |
|
|
|
|
done |
|
|
|
|
|
|
|
|
|
if [ "$CONFIG" != "" ]; then |
|
|
|
|
set -a # export all variables from config |
|
|
|
|
source "$CONFIG" |
|
|
|
|
set +a # stop exporting |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
# Get options |
|
|
|
|
# Get options (override config) |
|
|
|
|
options=$@ |
|
|
|
|
arguments=($options) |
|
|
|
|
index=0 |
|
|
|
|
for argument in $options ; do |
|
|
|
|
index=`expr $index + 1` |
|
|
|
|
case $argument in |
|
|
|
|
"-w") |
|
|
|
|
weather="${arguments[index]}" |
|
|
|
|
"--weather"|"-w") |
|
|
|
|
WEATHER="${arguments[index]}" |
|
|
|
|
;; |
|
|
|
|
"--api-key") |
|
|
|
|
OW_API_KEY="${arguments[index]}" |
|
|
|
|
;; |
|
|
|
|
"--lat") |
|
|
|
|
LAT="${arguments[index]}" |
|
|
|
|
;; |
|
|
|
|
"-l") |
|
|
|
|
latlon="${arguments[index]}" |
|
|
|
|
"--lng") |
|
|
|
|
LNG="${arguments[index]}" |
|
|
|
|
;; |
|
|
|
|
"-f") |
|
|
|
|
file_name="${arguments[index]}" |
|
|
|
|
"--config") |
|
|
|
|
CONFIG="${arguments[index]}" |
|
|
|
|
;; |
|
|
|
|
"--test") |
|
|
|
|
"--img") |
|
|
|
|
img_file_name="${arguments[index]}" |
|
|
|
|
;; |
|
|
|
|
"--test"|"-t") |
|
|
|
|
test="${arguments[index]}" |
|
|
|
|
;; |
|
|
|
|
|
|
|
|
|
esac |
|
|
|
|
done |
|
|
|
|
|
|
|
|
|
# Get the true path to the wallpapers directory |
|
|
|
|
if [ -L "$0" ] ; then |
|
|
|
|
true_file=$(readlink -f "$0"); |
|
|
|
|
base_dir=$( cd "$(dirname "$true_file")" ; pwd -P ); |
|
|
|
|
else |
|
|
|
|
base_dir=$( cd "$(dirname "$0")" ; pwd -P ); |
|
|
|
|
if [ "$LAT" != false ] && [ "$LNG" != false ] && [ "$OW_API_KEY" != "" ]; then |
|
|
|
|
OW_API_URL="https://api.openweathermap.org/data/2.5/weather?lat=$LAT&lon=$LNG&appid=$OW_API_KEY" |
|
|
|
|
|
|
|
|
|
# Get __WEATHER__ from JSON response: |
|
|
|
|
# e.g {"coord":{"lon":12.345,"lat":12.345},"weather":[{"id":800,"main":"__WEATHER__", ... |
|
|
|
|
if [ -x "$(command -v jq)" ]; then |
|
|
|
|
WEATHER=$(curl --silent $OW_API_URL | jq -r '.weather[0].main') |
|
|
|
|
else |
|
|
|
|
WEATHER=$(curl --silent "$OW_API_URL" --stderr - \ |
|
|
|
|
| grep -E -o ',"main":"[0-9a-zA-Z]*",' \ |
|
|
|
|
| sed 's/,"main":"//g' \ |
|
|
|
|
| head -c -3) |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
# To lowercase |
|
|
|
|
WEATHER=$(echo "$WEATHER" | sed -e 's/\(.*\)/\L\1/') |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
wallpapers_dir="$base_dir/wallpapers"; |
|
|
|
|
|
|
|
|
|
# DOY = Current Day of Year (without leading zeroes) |
|
|
|
|
DOY=$(date '+%-j'); |
|
|
|
|
|
|
|
|
@ -63,69 +113,69 @@ else |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
# TODO: To adjust light according to latitude to modify hours |
|
|
|
|
#HR=$(( $latlon )) |
|
|
|
|
set -a # export all variables created next |
|
|
|
|
|
|
|
|
|
# Get file by hour time |
|
|
|
|
if [ "$file_name" = "" ]; then |
|
|
|
|
if [ "$img_file_name" = "" ]; then |
|
|
|
|
case "$HR" in |
|
|
|
|
0) file_name="00-mid-night.png" ;; |
|
|
|
|
1) file_name="01-late-night.png" ;; |
|
|
|
|
2) file_name="02-early-vigil.png" ;; |
|
|
|
|
3) file_name="03-mid-vigil.png" ;; |
|
|
|
|
4) file_name="04-late-vigil.png" ;; |
|
|
|
|
5) file_name="05-dawn.png" ;; |
|
|
|
|
6) file_name="06-early-morning.png" ;; |
|
|
|
|
7) file_name="07-mid-morning.png" ;; |
|
|
|
|
8) file_name="08-late-morning.png" ;; |
|
|
|
|
9) file_name="09-early-forenoon.png" ;; |
|
|
|
|
10) file_name="10-mid-forenoon.png" ;; |
|
|
|
|
11) file_name="11-late-forenoon.png" ;; |
|
|
|
|
12) file_name="12-noon.png" ;; |
|
|
|
|
13) file_name="13-early-afternoon.png" ;; |
|
|
|
|
14) file_name="14-mid-afternoon.png" ;; |
|
|
|
|
15) file_name="15-late-afternoon.png" ;; |
|
|
|
|
16) file_name="16-early-evening.png" ;; |
|
|
|
|
17) file_name="17-mid-evening.png" ;; |
|
|
|
|
18) file_name="18-late-evening.png" ;; |
|
|
|
|
19) file_name="19-early-dusk.png" ;; |
|
|
|
|
20) file_name="20-mid-dusk.png" ;; |
|
|
|
|
21) file_name="21-late-dusk.png" ;; |
|
|
|
|
22) file_name="22-sunset.png" ;; |
|
|
|
|
23) file_name="23-early-night.png" ;; |
|
|
|
|
0) img_file_name="00-mid-night.png" ;; |
|
|
|
|
1) img_file_name="01-late-night.png" ;; |
|
|
|
|
2) img_file_name="02-early-vigil.png" ;; |
|
|
|
|
3) img_file_name="03-mid-vigil.png" ;; |
|
|
|
|
4) img_file_name="04-late-vigil.png" ;; |
|
|
|
|
5) img_file_name="05-dawn.png" ;; |
|
|
|
|
6) img_file_name="06-early-morning.png" ;; |
|
|
|
|
7) img_file_name="07-mid-morning.png" ;; |
|
|
|
|
8) img_file_name="08-late-morning.png" ;; |
|
|
|
|
9) img_file_name="09-early-forenoon.png" ;; |
|
|
|
|
10) img_file_name="10-mid-forenoon.png" ;; |
|
|
|
|
11) img_file_name="11-late-forenoon.png" ;; |
|
|
|
|
12) img_file_name="12-noon.png" ;; |
|
|
|
|
13) img_file_name="13-early-afternoon.png" ;; |
|
|
|
|
14) img_file_name="14-mid-afternoon.png" ;; |
|
|
|
|
15) img_file_name="15-late-afternoon.png" ;; |
|
|
|
|
16) img_file_name="16-early-evening.png" ;; |
|
|
|
|
17) img_file_name="17-mid-evening.png" ;; |
|
|
|
|
18) img_file_name="18-late-evening.png" ;; |
|
|
|
|
19) img_file_name="19-early-dusk.png" ;; |
|
|
|
|
20) img_file_name="20-mid-dusk.png" ;; |
|
|
|
|
21) img_file_name="21-late-dusk.png" ;; |
|
|
|
|
22) img_file_name="22-sunset.png" ;; |
|
|
|
|
23) img_file_name="23-early-night.png" ;; |
|
|
|
|
esac |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
# Put path together |
|
|
|
|
if [ -f "$wallpapers_dir/$season/$weather/$file_name" ]; then |
|
|
|
|
if [ -f "$wallpapers_dir/$season/$WEATHER/$img_file_name" ]; then |
|
|
|
|
# ./wallpapers/spring/clear/00-filename.png |
|
|
|
|
path="$wallpapers_dir/$season/$weather/$file_name" |
|
|
|
|
path="$wallpapers_dir/$season/$WEATHER/$img_file_name" |
|
|
|
|
|
|
|
|
|
elif [ -f "$wallpapers_dir/$season/$file_name" ]; then |
|
|
|
|
elif [ -f "$wallpapers_dir/$season/$img_file_name" ]; then |
|
|
|
|
# ./wallpapers/spring/00-filename.png |
|
|
|
|
path="$wallpapers_dir/$season/$file_name" |
|
|
|
|
path="$wallpapers_dir/$season/$img_file_name" |
|
|
|
|
|
|
|
|
|
else |
|
|
|
|
# ./wallpapers/00-filename.png |
|
|
|
|
path="$wallpapers_dir/$file_name" |
|
|
|
|
path="$wallpapers_dir/$img_file_name" |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
# Check for file |
|
|
|
|
if [ ! -f "$path" ]; then |
|
|
|
|
if [ ! -f "$img_path" ]; then |
|
|
|
|
echo "File dos not exist:" |
|
|
|
|
echo "$path" |
|
|
|
|
echo "$img_path" |
|
|
|
|
exit 1; |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
# Check for test mode |
|
|
|
|
if ! [ "$test" = false ] ; then |
|
|
|
|
echo "Path: $path"; |
|
|
|
|
echo "Path: $img_path"; |
|
|
|
|
exit; |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
# Set the background link: |
|
|
|
|
|
|
|
|
|
# feh --bg-fill "$path" |
|
|
|
|
# ls -n /etc/alternatives/desktop-background "$path" |
|
|
|
|
# feh --bg-fill "$img_path" |
|
|
|
|
# ls -n /etc/alternatives/desktop-background "$img_path" |
|
|
|
|
|
|
|
|
|
# (do x11 mambo to set a wallpaper, ugh) |
|
|
|
|
export DISPLAY=:0 |
|
|
|
@ -134,20 +184,20 @@ export XDG_RUNTIME_DIR="/run/user/$UID" |
|
|
|
|
|
|
|
|
|
if [ -x "$(command -v pcmanfm)" ]; then |
|
|
|
|
# For Raspbian |
|
|
|
|
pcmanfm --wallpaper-mode=stretch --set-wallpaper="$path" |
|
|
|
|
pcmanfm --wallpaper-mode=stretch --set-wallpaper="$img_path" |
|
|
|
|
elif [ -x "$(command -v gsettings)" ]; then |
|
|
|
|
# Gnome 3.22.2 |
|
|
|
|
gsettings set org.gnome.desktop.background picture-uri "file://$path" |
|
|
|
|
gsettings set org.gnome.desktop.background picture-uri "file://$img_path" |
|
|
|
|
elif [ -x "$(command -v xfconf-query)" ]; then |
|
|
|
|
# XFCE |
|
|
|
|
xfconf-query --channel xfce4-desktop --property /backdrop/screen0/monitor0/image-path --set $path |
|
|
|
|
xfconf-query --channel xfce4-desktop --property /backdrop/screen0/monitor0/image-path --set $img_path |
|
|
|
|
xfdesktop --reload |
|
|
|
|
#xfconf-query --channel xfce4-desktop --list # lists all related properties, in case screen0/monitor0 isn't the one. |
|
|
|
|
elif [ -x "$(command -v feh)" ]; then |
|
|
|
|
# feh, used sometimes by i3 and AwesomeWM |
|
|
|
|
feh --bg-scale $path |
|
|
|
|
feh --bg-scale $img_path |
|
|
|
|
else |
|
|
|
|
echo "No suitable background manager found." |
|
|
|
|
echo "File found:" |
|
|
|
|
echo "$path" |
|
|
|
|
echo "$img_path" |
|
|
|
|
fi |
|
|
|
|