54 lines
1.3 KiB
Plaintext
54 lines
1.3 KiB
Plaintext
|
#!/usr/bin/env bash
|
||
|
pictureuri="picture-uri"
|
||
|
|
||
|
validate_config() {
|
||
|
if [ -z "$WALLPAPER_DIR" ]; then
|
||
|
quit "Error: The wallpaper directory environment variable (WALLPAPER_DIR) has not been set."
|
||
|
fi
|
||
|
|
||
|
if [ ! -e "$WALLPAPER_DIR" ]; then
|
||
|
quit "Error: The wallpaper directory \"$WALLPAPER_DIR\" does not exist."
|
||
|
fi
|
||
|
|
||
|
if [ ! -d "$WALLPAPER_DIR" ]; then
|
||
|
quit "Error: The wallpaper directory \"$WALLPAPER_DIR\" is not a directory."
|
||
|
fi
|
||
|
|
||
|
if [ ! -r "$WALLPAPER_DIR" ]; then
|
||
|
quit "Error: The wallpaper directory \"$WALLPAPER_DIR\" is not accessible. "
|
||
|
fi
|
||
|
}
|
||
|
prepare() {
|
||
|
get_wallpaper
|
||
|
validate_wallpaper
|
||
|
}
|
||
|
get_wallpaper() {
|
||
|
selection="$(find "$WALLPAPER_DIR" -type f -name "*.jpg" -o -name "*.png" | shuf -n1)"
|
||
|
}
|
||
|
validate_wallpaper() {
|
||
|
if [ ! -f "$selection" ]; then
|
||
|
quit "Error: The wallpaper \"$WALLPAPER_DIR\" is not a file."
|
||
|
fi
|
||
|
|
||
|
if [ ! -r "$selection" ]; then
|
||
|
quit "Error: The wallpaper \"$WALLPAPER_DIR\" is not accessible."
|
||
|
fi
|
||
|
}
|
||
|
set_wallpaper() {
|
||
|
gsettings set org.gnome.desktop.background "$pictureuri" "file://$selection"
|
||
|
}
|
||
|
quit() {
|
||
|
if [[ "$1" = 0 ]]
|
||
|
then
|
||
|
exit 0
|
||
|
else
|
||
|
printf "%b\n" "$1"
|
||
|
exit 1
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
validate_config
|
||
|
prepare
|
||
|
set_wallpaper
|
||
|
quit 0
|