-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwallcake.sh.bak
More file actions
87 lines (80 loc) · 2.27 KB
/
wallcake.sh.bak
File metadata and controls
87 lines (80 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/sh
#wallcake 1.2: download random picture online and set it as wallpaper
#fwonce <fwonce@gmail.com>
#last modified: 2011-02-01
idle_time=15m
tmp_dir=/tmp/wallcake
tmp_pic=$tmp_dir/cake.jpg
tmp_lck=$tmp_dir/.lock
wp_repo=/media/DOC/pictures/wallpapers
query_url='http://wallbase.net/random/21/eqeq/1366x768/0/100/20'
url_base='http://wallbase.net/wallpaper/'
#handle argument
while getopts s:i:r:h option; do
case "$option" in
s)
if [ -f $tmp_lck ]; then
echo "new wallpaper being applied, can't save previous one."
exit 1
else
cp -iv $tmp_pic $wp_repo/$OPTARG.jpg
exit 0
fi
;;
i)
#TODO verify NUMBER, see info coreutils 'sleep invocation'
idle_time=$OPTARG
;;
r)
if [ ! -d $OPTARG ]; then
echo "Not a directory: $OPTARG"
exit 1
else
wp_repo=$OPTARG
fi
;;
h)
echo "Wallcake v1.0 retrives wallpapers from wallbase.net automatically"
echo ""
echo "-s new_name"
echo " save current wallpaper"
echo "-i idle_time"
echo " idle time after wallpaper changed"
echo "-r directory"
echo " directory in which the selected wallpaper will be saved (when -s is applied)"
exit 0
;;
esac
done
#take the first random shot
find $wp_repo -type f -iregex '.*\(jpg\|png\)' -print0 |
shuf -n1 -z |
xargs -0 feh --bg-scale
if [ ! -d $tmp_dir ]; then
mkdir $tmp_dir
fi
while true; do
#idle time
sleep $idle_time
ping_result=`ping -c 1 wallbase.net |
grep 'from' |
wc -l`
if [ $ping_result -eq 0 ]; then
echo "Network unavailable, will try $idle_time later."
continue
fi
#wallbase.net random SFW wallpapers
seed=`rand -M 20`
url_ref=`curl -s -L $query_url |
grep -m$seed 'div class="thumb"' |
tail -n 1 |
sed "s/[^0-9]*\([0-9]\+\).*/\1/"`
url_pic=`curl -s -L $url_base$url_ref |
grep -m1 'rozne' |
sed "s/[^']\+'\(http[^']*\)'.*/\1/"`
#finally start to download the picture
touch $tmp_lck
curl -s -e $url_base$url_ref -L $url_pic > $tmp_pic
rm $tmp_lck
feh --bg-scale $tmp_pic
done