2010-03-01 21:09:04 +01:00
|
|
|
#!/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
|
|
|
|
}
|
|
|
|
|
2010-04-30 11:06:18 +02:00
|
|
|
function resize {
|
|
|
|
# Get screen size
|
|
|
|
res=$(xdpyinfo | grep dimensions | awk '{print $2}')
|
|
|
|
tailleX=$(echo $res | awk -F "x" '{print $1}');
|
|
|
|
tailleY=$(echo $res | awk -F "x" '{print $2}');
|
2011-01-12 16:38:14 +01:00
|
|
|
echo "Screen Size is X: $tailleX, Y: $tailleY"
|
2010-04-30 11:06:18 +02:00
|
|
|
# Get image size
|
|
|
|
res=$(identify -format '%w %h\n' $1)
|
|
|
|
imgX=$(echo $res | awk '{print $1}')
|
|
|
|
imgY=$(echo $res | awk '{print $2}')
|
|
|
|
echo "Original Image Size is X: $imgX, Y: $imgY"
|
|
|
|
# Calculate resize factor
|
|
|
|
mult=0
|
|
|
|
div=0
|
2011-01-12 16:38:14 +01:00
|
|
|
# If using $tailleX and $imgX as factor scale for Y -> use it! It will perfectly fitt for X and do the best for Y
|
|
|
|
if [ $tailleY -gt $((($tailleX*$imgY)/$imgX)) ];
|
2010-04-30 11:06:18 +02:00
|
|
|
then
|
|
|
|
mult=$tailleX
|
|
|
|
div=$imgX
|
|
|
|
else
|
|
|
|
mult=$tailleY
|
|
|
|
div=$imgY
|
|
|
|
fi
|
|
|
|
res=$((($imgX*$mult)/$div))'x'$((($imgY*$mult)/$div))
|
|
|
|
echo "New size is $res"
|
|
|
|
`mogrify -resize $res $1`;
|
|
|
|
}
|
2010-03-11 00:50:28 +01:00
|
|
|
|
2010-03-01 21:09:04 +01:00
|
|
|
# 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
|
|
|
|
}
|
|
|
|
|
2010-03-11 00:50:28 +01:00
|
|
|
dirprefix=$HOME/Images
|
|
|
|
fileprefix=$dirprefix/bonjourmadame-wp-
|
2010-03-01 21:09:04 +01:00
|
|
|
|
|
|
|
todaywp=$fileprefix$(date +%y-%m-%d-%H-%M).jpg
|
|
|
|
|
|
|
|
while [ $(chkinternet) != "1" ]; do sleep 15; done
|
|
|
|
echo Internet connection OK
|
|
|
|
|
2010-03-11 00:50:28 +01:00
|
|
|
if [[ ! -d $dirprefix ]]
|
|
|
|
then
|
|
|
|
echo "Creating $dirprefix";
|
|
|
|
mkdir $dirprefix;
|
|
|
|
fi
|
|
|
|
|
2010-03-01 21:09:04 +01:00
|
|
|
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
|
|
|
|
|
2010-12-13 19:04:35 +01:00
|
|
|
#ls $fileprefix* | sort -r | tail -n +2 | xargs rm -f
|
2010-04-30 11:06:18 +02:00
|
|
|
if [[ -e /usr/bin/identify ]]
|
|
|
|
then
|
|
|
|
resize $todaywp;
|
|
|
|
echo Photo Resize OK;
|
|
|
|
fi
|
2010-03-01 21:09:04 +01:00
|
|
|
|
|
|
|
fixdbus
|
|
|
|
|
2010-04-30 11:06:18 +02:00
|
|
|
|
|
|
|
if [[ -e /usr/bin/feh ]]
|
|
|
|
then
|
2011-01-12 16:38:14 +01:00
|
|
|
DISPLAY=:0 feh --bg-center $todaywp
|
2010-04-30 11:06:18 +02:00
|
|
|
fi
|
2010-03-01 21:09:04 +01:00
|
|
|
if [[ -e /usr/bin/xfconf-query ]]
|
|
|
|
then
|
|
|
|
xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitor0/image-path -s $todaywp
|
2010-04-30 11:06:18 +02:00
|
|
|
fi
|
|
|
|
if [[ -e /usr/bin/gconftool-2 ]]
|
2010-03-01 21:09:04 +01:00
|
|
|
then
|
|
|
|
gconftool-2 --type string --set /desktop/gnome/background/picture_filename $todaywp
|
|
|
|
fi
|
|
|
|
|
|
|
|
notify
|
|
|
|
|