forked from Feminist-Software-Foundation/Muzei-Bash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinmuzei.sh
executable file
·194 lines (178 loc) · 5.46 KB
/
linmuzei.sh
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
#!/usr/bin/env bash
# linmuzei is a Muzei port for the GNU/Linux operating
# system. linmuzei is a fork of Muzei-Bash by the
# Feminist Software Foundation. You can see the original code at
# <http://github.com/Feminist-Software-Foundation/Muzei-Bash>
# Copyright (C) 2014 Alp Pirli
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://gnu.org/licenses/>.
######Initial stuff######
muzeiDir=~/Pictures/Muzei
mkdir -p $muzeiDir/Wallpaper
cd $muzeiDir
######Needed packages part 1 and OS control######
case "$OSTYPE" in
linux* | *BSD* | darwin*) echo "OS is compatible." ;;
*) echo "Get a proper OS, kid." && exit ;;
esac
pack=(jq sed curl)
for p in $pack
do
if ! [ "$(which $p)" ]
then
echo "You need $p to use this."
exit
fi
done
######Checking for updates######
if ! [ -f ./muzeich.json ]
then
curl -o muzeich.json 'https://muzeiapi.appspot.com/featured?cachebust=1'
else
curl -o muzeich2.json 'https://muzeiapi.appspot.com/featured?cachebust=1'
if [ "$(cmp muzeich.json muzeich2.json)" ]
then
mv muzeich2.json muzeich.json
else
rm muzeich2.json
echo "No wallpaper update. Exiting."
exit
fi
fi
######Deleting old .xinitrc line for feh/hsetroot/nitrogen if it exists######
if [ -f ~/.xinitrc ]
then
echo "Deleting old .xinitrc line..."
if [ "$(cat ~/.xinitrc | grep '^hsetroot -cover')" ]
then
sed -i "/^hsetroot -cover/d" ~/.xinitrc
elif [ "$(cat ~/.xinitrc | grep '^sh ~/.fehbg')" ]
then
sed -i "/^sh ~\/.fehbg/d" ~/.xinitrc
elif [ "$(cat ~/.xinitrc | grep '^nitrogen --restore')" ]
then
sed -i "/^nitrogen --restore/d" ~/.xinitrc
fi
fi
######Parse the Muzei JSON######
imageUri=`jq '.imageUri' $muzeiDir/muzeich.json | sed s/\"//g`
imageFile=`basename $imageUri`
title=`jq '.title' $muzeiDir/muzeich.json | sed s/\"//g`
byline=`jq '.byline' $muzeiDir/muzeich.json | sed s/\"//g`
######Clean up old wallpapers######
cd Wallpaper
if [ "$(ls)" ]
then
echo "Cleaning up old files..."
rm *
fi
######Get the latest wallpaper######
if [ -f $imageFile ]
then
echo "File $imageFile exists."
else
echo "File $imageFile does not exist, downloading..."
curl -O $imageUri
fi
######Functions for autostarting feh, hsetroot and nitrogen######
function feh_xinitSet(){
if ! [ -f ~/.xinitrc ] || ! [ "$(cat ~/.xinitrc | grep ^exec)" ]
then
echo "sh ~/.fehbg &" >> ~/.xinitrc
else
sed -i "s#^exec #sh ~/.fehbg \&\nexec #" ~/.xinitrc
fi
}
function hsetroot_xinitSet(){
if ! [ -f ~/.xinitrc ] || ! [ "$(cat ~/.xinitrc | grep ^exec)" ]
then
echo "hsetroot -cover $muzeiDir/Wallpaper/$imageFile &" >> ~/.xinitrc
else
sed -i "s#^exec #hsetroot -cover $muzeiDir/Wallpaper/$imageFile \&\nexec #" ~/.xinitrc
fi
}
function nitrogen_xinitSet(){
if ! [ -f ~/.xinitrc ] || ! [ "$(cat ~/.xinitrc | grep ^exec)" ]
then
echo "nitrogen --restore &" >> ~/.xinitrc
else
sed -i "s#^exec #nitrogen --restore \&\nexec #" ~/.xinitrc
fi
}
######Set the wallpaper######
function setWallpaperLinux(){
if [ "$(pidof gnome-settings-daemon)" ]
then
echo "Gnome-settings-daemons detected, setting wallpaper with gsettings..."
gsettings set org.gnome.desktop.background picture-uri file://$muzeiDir/Wallpaper/$imageFile
else
if [ -f ~/.xinitrc ]
then
if [ "$(which feh)" ]
then
echo "Gnome-settings-daemons not running, setting wallpaper with feh..."
feh $imageFile
feh_xinitSet
elif [ "$(which hsetroot)" ]
then
echo "Gnome-settings-daemons not running, setting wallpaper with hsetroot..."
hsetroot -cover $imageFile
hsetroot_xinitSet
elif [ "$(which nitrogen)" ]
then
echo "Gnome-settings-daemons not running, setting wallpaper with nitrogen..."
nitrogen $imageFile
nitrogen_xinitSet
else
echo "You need to have either feh, hsetroot or nitrogen, bruhbruh."
exit
fi
else
echo "You should have a ~/.xinitrc file."
exit
fi
fi
}
function setWallpaperOSX(){
defaults write com.apple.desktop Background "{default = {ImageFilePath='$muzeiDir/Wallpaper/$imageFile'; };}"
killall Dock
}
case "$OSTYPE" in
linux* | *BSD*) setWallpaperLinux ;;
darwin*) setWallpaperOSX ;;
esac
######Send a notification / Needed packages part 2######
cd $muzeiDir
if [ -f MuzeiLogo.png ];
then
echo "Logo already exists."
else
echo "Logo doesn't exist, downloading..."
curl -O "https://raw.github.com/aepirli/Muzei-Bash/master/MuzeiLogo.png"
fi
case "$OSTYPE" in
linux* | *BSD*)
if ! [ "$(which notify-send)" ]
then
echo "Please install a notification server if you want to see a notification."
else
notify-send "New wallpaper: '$title'" "$byline" -i $muzeiDir/MuzeiLogo.png
fi
;;
darwin*)
if ! [ "$(which terminal-notifier)" ]
then
echo "Please install terminal-notifier for a better experience."
else
terminal-notifier -title "Muzei-Bash" -message "New wallpaper: '$title'" "$byline"
fi
;;
esac