config/scripts/getMadame.sh
2010-03-11 00:50:28 +01:00

80 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
###########################################
#
# Get the daily picture from http://www.bonjourmadame.fr on your desktop
#
# Author : Magetys
# Link : http://www.magetys.com
# Version : 1.0.1
# Dependency : libnotify-bin
# Note : Works on Gnome and Xfce
#
###########################################
function chkinternet {
if [ `wget -q -O - google.com | grep -c "<title>Google</title>"` != 0 ]
then
echo 1
else
echo 0
fi
}
function fixdbus {
export DISPLAY=0
while read line
do
echo $line | grep -vqe "^#"
if [ $? -eq 0 ]; then export $line; fi
done < ~/.dbus/session-bus/$(cat /var/lib/dbus/machine-id)-$DISPLAY
echo Dbus fixed OK
}
# please install libnotify-bin to popup notification
function notify {
if [[ -e /usr/bin/notify-send ]]
then
notify-send "Bonjour $USER" "Je suis arrivee sur ton bureau" -i $todaywp
fi
}
dirprefix=$HOME/Images
fileprefix=$dirprefix/bonjourmadame-wp-
todaywp=$fileprefix$(date +%y-%m-%d-%H-%M).jpg
while [ $(chkinternet) != "1" ]; do sleep 15; done
echo Internet connection OK
if [[ ! -d $dirprefix ]]
then
echo "Creating $dirprefix";
mkdir $dirprefix;
fi
wget -O - http://www.bonjourmadame.fr | grep -Eo "(http://www.bonjourmadame.fr/photo/[^\"]+)|(http://[0-9]+.media.tumblr.com/tumblr[^\"]+)" | head -n 1 | wget -q -i - -O $todaywp
echo Photo downloaded OK
ls $fileprefix* | sort -r | tail -n +2 | xargs rm -f
fixdbus
if [[ -e /usr/bin/xfconf-query ]]
then
xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitor0/image-path -s $todaywp
elif [[ -e /usr/bin/feh ]]
then
feh --bg-scale $todaywp
elif [[ -e /usr/bin/gconftool-2 ]]
then
gconftool-2 --type string --set /desktop/gnome/background/picture_filename $todaywp
fi
notify