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
|
2011-08-24 00:38:05 +02:00
|
|
|
# Optionnal : imagemagick
|
2010-03-01 21:09:04 +01:00
|
|
|
# Note : Works on Gnome and Xfce
|
|
|
|
#
|
|
|
|
###########################################
|
2011-03-01 01:16:16 +01:00
|
|
|
page=
|
|
|
|
|
2011-08-24 00:38:05 +02:00
|
|
|
function usage {
|
|
|
|
script_name=`basename "$0"`
|
|
|
|
echo "Usage $script_name [Day]"
|
|
|
|
echo "Day to displae (1 for today, 2 for yesterday, 3 for the day before ...)"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function is_a_number {
|
|
|
|
if echo $1 | grep '^[0-9]+$' &> /dev/null
|
|
|
|
then
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2011-03-01 01:16:16 +01:00
|
|
|
if [ $# != 0 ]
|
|
|
|
then
|
2011-08-24 00:38:05 +02:00
|
|
|
if is_a_number $1 ;
|
|
|
|
then
|
|
|
|
usage
|
|
|
|
exit
|
|
|
|
fi
|
2011-03-01 01:16:16 +01:00
|
|
|
page="/page/${1}"
|
|
|
|
fi
|
2010-03-01 21:09:04 +01:00
|
|
|
|
|
|
|
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
|
2011-08-24 00:38:05 +02:00
|
|
|
res=
|
|
|
|
if [ -e /usr/bin/xrandr ];
|
|
|
|
then
|
2016-10-21 17:32:05 +02:00
|
|
|
res=$(xrandr | grep '\*' | awk '{print $1}' | head -1)
|
2011-08-24 00:38:05 +02:00
|
|
|
else
|
|
|
|
res=$(xdpyinfo | grep dimensions | awk '{print $2}')
|
|
|
|
fi
|
2010-04-30 11:06:18 +02:00
|
|
|
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
|
2011-08-24 01:13:49 +02:00
|
|
|
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
|
|
|
|
|
2016-10-21 17:32:05 +02:00
|
|
|
wget -O - "http://www.bonjourmadame.fr${page}" | grep -Eo "(http://[0-9]+.media.tumblr.com/[0-9a-z]+/tumblr[^\"]+)" | head -n 1 | wget -q -i - -O $todaywp
|
2010-03-01 21:09:04 +01:00
|
|
|
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
|
2012-02-03 18:28:26 +01:00
|
|
|
gconftool-2 -t str --set /desktop/gnome/background/picture_options "centered" --type string --set /desktop/gnome/background/picture_filename $todaywp
|
2010-03-01 21:09:04 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
notify
|
|
|
|
|