-
Notifications
You must be signed in to change notification settings - Fork 0
/
mksldshw
executable file
·239 lines (198 loc) · 6.46 KB
/
mksldshw
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/bin/bash
########## Make Slideshow Wallpaper by Freedman ##########
readonly _OutputFile=background.xml
readonly _StaticTime=595.0
readonly _TransitionTime=5.0
readonly _FileType="gif|jpg|png|bmp"
# readonly _SortFiles=Alphabetic
readonly _SortFiles=Random
readonly _Depth=30 # at most levels of directories been include
# The line under here helps to setup the wallpaper automaticlly,
# comment it with octothorpe if you want do that yourself.
readonly _Autoset=on _AutosetPath=$HOME/.config
readonly _StartNow=on
function find_image_files() {
BOARD_ImgFils=$(
find -L $PWD \
-maxdepth $_Depth \
-regextype posix-extended \
-iregex \
".*\.($_FileType)" \
2> /dev/null
)
if [ "$_SortFiles" == "Random" ] ; then
BOARD_ImgFils=$( echo -e "$BOARD_ImgFils" | sort -R )
elif [ "$_SortFiles" == "Alphabetic" ] ; then
BOARD_ImgFils=$( echo -e "$BOARD_ImgFils" | sort )
fi
}
function error_exit_if_too_less_image_file() {
local FilTotl=$( echo -e "$BOARD_ImgFils" \
| wc -l \
| cut -d " " -f1
)
if [ $FilTotl -lt 2 ] ; then
/usr/bin/zenity --warning \
--title='Error!' \
--text='Need two image files at least!' \
> /dev/null 2>&1
echo -e '\nError!\nNeed two image files at least!\n'
exit 1
fi
}
function generate_slide_show_xml() {
eval $( date +"
local Yer=%Y
Mnth=%m
Day=%d
Hour=%H
Minute=%M
Second=%S
")
local Head=" <static>\n <duration>$_StaticTime</duration>\n <file>"
local Tail="</file>\n </static>"
local FrmHead=" <transition>\n <duration>$_TransitionTime</duration>\n <from>"
local FrmTail="</from>"
local ToHead=" <to>"
local ToTail="</to>\n </transition>"
local FstFil
if [ "$_StartNow" != "on" ] ; then Hour=00 Minute=00 Second=00 ; fi
echo "<background>"
echo " <starttime>"
echo " <year>$Yer</year>"
echo " <month>$Mnth</month>"
echo " <day>$Day</day>"
echo " <hour>$Hour</hour>"
echo " <minute>$Minute</minute>"
echo " <second>$Second</second>"
echo " </starttime>"
echo "<!-- This animation starts at $Yer/$Mnth/$Day $Hour:$Minute:$Second. -->"
if [ "$_TransitionTime" == "0" ] ; then
echo -e "$BOARD_ImgFils" | sed "s|^\(.*\)$|$Head\0$Tail|"
else
FstFil=$( echo -e "$BOARD_ImgFils" | head -n 1 )
echo -e "${Head}${FstFil}${Tail}"
echo -e "${FrmHead}${FstFil}${FrmTail}"
echo -e "$BOARD_ImgFils" \
| tail -n +2 \
| sed "s|^\(.*\)$|$ToHead\0$ToTail\n$Head\0$Tail\n$FrmHead\0$FrmTail|"
echo -e "${ToHead}${FstFil}${ToTail}"
fi
echo "</background>"
}
function distribution_n_release() {
local distri reles issue
distri="$(lsb_release -i 2> /dev/null)"
distri="$(echo $distri)"
distri="${distri##* }"
issue="$(head -n1 /etc/issue)"
issue="$(echo $issue)"
issue="${issue%% *}"
eval $(grep -e "^NAME=" -e "^VERSION=" /etc/os-release 2> /dev/null)
if [ -z "$distri" ] && [ ${#issue} -gt 2 ] ; then
distri="$issue"
reles="$( grep [0-9] /etc/issue \
| head -n1 \
| sed 's/^[^0-9]*//' )"
elif [ "$NAME" == "Fedora" ] || [ "$NAME" == "CentOS Linux" ] ; then
distri="${NAME%% *}"
reles="$VERSION"
elif [ "$issue" == "LMDE" ] ; then
distri="$issue"
reles="$(lsb_release -r)"
reles="$(echo $reles)"
reles="${reles##* }"
else
reles="$(lsb_release -r)"
reles="$(echo $reles)"
reles="${reles##* }"
fi
echo $distri $reles
}
function move_output_file() {
if [ -z "$_AutosetPath" ] ; then
_AutosetPath="$PWD"
else
mkdir -p "$_AutosetPath"
mv -f "$_OutputFile" "$_AutosetPath/$_OutputFile"
fi
}
function set_background() {
local gnome_version distro
distro="$( distribution_n_release )"
case "$distro" in
"Ubuntu 15."*|"Ubuntu 1"[246]".04"|"CentOS 7"* |"Fedora 2"[234]*)
case "$DESKTOP_SESSION" in
ubuntu*|gnome*)
move_output_file
gsettings set org.gnome.desktop.background picture-uri \
"file://$_AutosetPath/$_OutputFile"
;;
cinnamon*)
move_output_file
gsettings set org.cinnamon.desktop.background picture-uri \
"file://$_AutosetPath/$_OutputFile"
;;
mate)
move_output_file
gsettings set org.mate.background picture-filename \
"$_AutosetPath/$_OutputFile"
;;
esac
;;
"Ubuntu 10."*)
if [ "$DESKTOP_SESSION" == "gnome" ] ; then
move_output_file
gconftool --set --type=string \
/desktop/gnome/background/picture_filename \
"$_AutosetPath/$_OutputFile"
fi
;;
"Debian 8"*)
case "$XDG_CURRENT_DESKTOP" in
GNOME*)
move_output_file
gsettings set org.gnome.desktop.background picture-uri \
"file://$_AutosetPath/$_OutputFile"
;;
X-Cinnamon)
move_output_file
gsettings set org.cinnamon.desktop.background picture-uri \
"file://$_AutosetPath/$_OutputFile"
;;
MATE)
move_output_file
gsettings set org.mate.background picture-filename \
"$_AutosetPath/$_OutputFile"
;;
esac
;;
"LinuxMint 1"[78]*|"LMDE 2")
if [ "$XDG_CURRENT_DESKTOP" == "X-Cinnamon" ] ; then
move_output_file
gsettings set org.cinnamon.desktop.background picture-uri \
"file://$_AutosetPath/$_OutputFile"
elif [ "$DESKTOP_SESSION" == "mate" ] ; then
move_output_file
gsettings set org.mate.background picture-filename \
"$_AutosetPath/$_OutputFile"
fi
;;
*)
gnome_version=$(gnome-session --version)
gnome_version=${gnome_version#* }
if [ "${gnome_version%%.*}" == "3" ] ; then
move_output_file
gsettings set org.gnome.desktop.background picture-uri \
"file://$_AutosetPath/$_OutputFile"
fi
;;
esac
}
function main() {
find_image_files
error_exit_if_too_less_image_file
generate_slide_show_xml > $_OutputFile
if [ "$_Autoset" == "on" ] ; then set_background ; fi
}
main