-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathwall.sh
More file actions
executable file
·324 lines (291 loc) · 8.42 KB
/
wall.sh
File metadata and controls
executable file
·324 lines (291 loc) · 8.42 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
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#!/bin/bash
###################################
## instantos wallpaper generator ##
###################################
source /usr/share/instantwallpaper/wallutils.sh
if [ "$(pgrep instantwallper | wc -l)" -gt 200 ]; then
echo "recursion loop detected, exiting"
exit 1
fi
echousage() {
echo 'usage: instantwallpaper [action]
gui open gui settings for setting a custom wallpaper
clear remove custom wallpaper and reset to default wallpaper behaviour
set set custom image as wallpaper
customlogo set custom image as logo (requires alpha channel)
logo set custom image with logo as wallpaper
offline run instantwallpaper in offline mode
fetch fetch selection of wallpapers to choose from
select select wallpaper from fetched selection
restore restore current wallpaper in case of rendering errors
bing generate wallpaper from daily bing photo
google generate wallpaper from random chromecast wallpaper
haven generate wallpaper from wallpaperhaven
color fg bg generate colored wallpaper with instantOS logo'
exit
}
# fetch monitor resolution
setupres
if ! [ -e "$(xdg-user-dir PICTURES)/wallpapers/readme.txt" ]; then
echo "setting up readme"
mkdir -p "$(xdg-user-dir PICTURES)/wallpapers"
cp /usr/share/backgrounds/readme.jpg "$(xdg-user-dir PICTURES)"/wallpapers/readme.jpg
echo "wallpapers are not preinstalled by default to reduce installation size
you can installl them by running
instantwallpaper fetch" >"$(xdg-user-dir PICTURES)"/wallpapers/readme.txt
fi
case "$1" in
clear)
if [ -e ~/instantos/wallpapers/custom.png ]; then
echo "clearing custom wallpaper"
rm ~/instantos/wallpapers/custom.png
rm -f "$HOME/.fehbg"
instantwallpaper
else
echo "no custom wallpaper was found"
fi
exit
;;
gui)
guiwall
instantwallpaper set "$WALLPATH"
exit
;;
set)
# allow setting a custom image as a wallpaper
if [ -n "$2" ]; then
if [ -e "$2" ] && file "$2" | grep -q "image data"; then
rm ~/instantos/wallpapers/custom.png
mkdir -p ~/instantos/wallpapers &>/dev/null
cp "$2" ~/instantos/wallpapers/custom.png
ifeh ~/instantos/wallpapers/custom.png
exit
else
echo "$2 is not an image"
exit 1
fi
fi
;;
customlogo)
# allow setting a custom image as a logo
if [ -n "$2" ]; then
if [ -e "$2" ] && file "$2" | grep -q "image data"; then
rm ~/instantos/wallpapers/customlogo.png
mkdir -p ~/instantos/wallpapers &>/dev/null
cp "$2" ~/instantos/wallpapers/customlogo.png
ifeh ~/instantos/wallpapers/customlogo.png
exit
else
echo "$2 is not an image"
exit 1
fi
fi
;;
logo)
echo "setting custom image with logo as wallpaper"
shift 1
if [ -z "$1" ]; then
guiwall
else
WALLPATH="$1"
checkwall "$1" || exit 1
fi
rm -rf /tmp/logowallpaper
mkdir /tmp/logowallpaper
cp "$WALLPATH" /tmp/logowallpaper/tempwall.jpg
cd /tmp/logowallpaper || exit
compwallpaper tempwall.jpg
instantwallpaper set instantwallpaper.png
rm -rf /tmp/logowallpaper
;;
offline)
fallbackwallpaper
;;
fetch)
fetchwallpapers
exit
;;
select)
WALLDIR="$(xdg-user-dir PICTURES)"/wallpapers
if ! [ -e "$WALLDIR"/10.jpg ]; then
st -e bash -c "instantwallpaper fetch"
else
echo "wallpapers already downloaded"
fi
WALLPATH=$(zenity --file-selection --filename="$WALLDIR/" --file-filter='Image files (png, jpg) | *.png *.jpg')
if [ -n "$WALLPATH" ]; then
if checkwall "$WALLPATH"; then
ifeh "$WALLPATH"
else
exit 1
fi
else
echo "no wallpaper selected"
fi
exit
;;
restore)
echo 'restoring wallpaper'
if [ -e ~/instantos/wallpapers/custom.png ]; then
ifeh ~/instantos/wallpapers/custom.png
else
if [ -e ~/instantos/wallpapers/instantwallpaper.png ]; then
ifeh ~/instantos/wallpapers/instantwallpaper.png
else
ifeh /usr/share/instantwallpaper/defaultphoto.png
fi
fi
exit
;;
color)
echo 'setting colored wallpaper'
THEME="$(iconf theme:arc)"
if [ -n "$2" ]; then
FGCOLOR="$2"
else
FGCOLOR="$(grep foreground /usr/share/instantthemes/colors/"$THEME".theme | grep -o '#.*')"
fi
if [ -n "$3" ]; then
BGCOLOR="$3"
else
BGCOLOR="$(grep background /usr/share/instantthemes/colors/"$THEME".theme | grep -o '#.*')"
fi
echo "theme $THEME"
echo "bg color $BGCOLOR"
echo "fg color $FGCOLOR"
mkdir -p ~/instantos/wallpapers/color
cd ~/instantos/wallpapers/color || exit 1
defaultwall "$FGCOLOR" "$BGCOLOR" "customcolor"
[ -e "customcolor.png" ] || {
notify-send 'failed to set colored wallpaper'
exit 1
}
instantwallpaper set customcolor.png
exit
;;
-h)
echousage
;;
--help)
echousage
;;
esac
! checkinternet && fallbackwallpaper && exit
# detect custom wallpaper from elsewhere
if [ -e ~/instantos/wallpapers/custom.png ]; then
cd ~/instantos/wallpapers || exit 1
imgresize custom.png "$RESOLUTION"
ifeh custom.png
exit
fi
# allow manually overriding wallpaper with feh
if [ -e "$HOME/.fehbg" ]; then
if [ -z "$1" ] || grep -q 'offline' <<<"$1"; then
if ! grep -Fq "$HOME/instantos/wallpapers/" "$HOME/.fehbg"; then
echo "using feh wallpaper"
sh "$HOME/.fehbg"
exit
fi
fi
fi
source /usr/share/paperbash/import.sh || source <(curl -Ls https://git.io/JerLG)
pb instantos
cd || exit 1
mkdir -p "$HOME"/instantos/wallpapers/default &>/dev/null
cd "$HOME"/instantos/wallpapers || exit 1
randomwallpaper() {
array[0]="googlewallpaper"
array[1]="bingwallpaper"
array[2]="wallist"
array[3]="wallhaven"
array[4]="viviwall"
size=${#array[@]}
index=$(($RANDOM % $size))
WALLCOMMAND=${array[$index]}
echo $WALLCOMMAND
$WALLCOMMAND
}
RESOLUTION=$(iconf max:1920x1080)
export RESOLUTION
# fetch logo overlay
instantoverlay
if ! [ -e ./default/"$(getinstanttheme)".png ]; then
echo "generating default wallpaper"
cd default || exit 1
defaultwall
cd .. || exit 1
fi
# generate the default wallpaper with a scraped photo and the logo
genwallpaper() {
ifeh default/"$(getinstanttheme)".png
if [ -n "$1" ]; then
case "$1" in
b*)
bingwallpaper
;;
h*)
wallhaven
;;
l*)
wallist
;;
g*)
googlewallpaper
;;
v*)
viviwall
;;
*)
randomwallpaper
;;
esac
else
randomwallpaper
if [ -e ~/instantos/wallpapers/instantwallpaper.png ]; then
oldsum="$(md5sum ~/instantos/wallpapers/instantwallpaper.png | awk '{ print $1 }')"
fi
fi
compwallpaper
}
if [ -n "$1" ]; then
genwallpaper "$1"
elif ! [ -e ~/instantos/wallpapers/instantwallpaper.png ]; then
# generate if no wallpaper is found
genwallpaper w
else
# generate new wallpaper every wednesday
if date +%u | grep -q '3'; then
if ! [ -e ~/instantos/wallpapers/wednesday ]; then
echo "it is wallpaper wednesday my dudes"
genwallpaper
touch ~/instantos/wallpapers/wednesday
else
echo "wallpaper wednesday already happened"
fi
else
# not wednesday, remove wednesday indicator
if [ -e ~/instantos/wallpapers/wednesday ]; then
echo "removing cache file"
rm ~/instantos/wallpapers/wednesday
fi
fi
fi
if [ -z "$3" ]; then
ifeh instantwallpaper.png
if [ -n "$oldsum" ]; then
newsum="$(md5sum ~/instantos/wallpapers/instantwallpaper.png | awk '{ print $1 }')"
# generate new wallpaper if hash sums are equal
if [ "$newsum" = "$oldsum" ]; then
echo "regenerating failed wallpaper"
checkinternet || exit 1
WALLCOUNT="$(pgrep -f instantwallpaper | wc -l)"
if [ "$WALLCOUNT" -gt 80 ]; then
exit 1
fi
instantwallpaper w
sleep 20
fi
fi
else
echo "feh silenced"
fi