-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathlightcordctl
360 lines (324 loc) · 11.4 KB
/
lightcordctl
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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
#!/usr/bin/env bash
# Lightcord unified Linux installer by https://github.com/GermanBread
# Honorable mention for former POSIX compliance: https://github.com/pryme-svg
# ___ ___ ___ ___ ___ _____
# ___ / /\ /__/\ ___ / /\ / /\ / /\ / /::\
# / /\ / /:/_ \ \:\ / /\ / /:/ / /::\ / /::\ / /:/\:\
# ___ ___ / /:/ / /:/ /\ \__\:\ / /:/ / /:/ / /:/\:\ / /:/\:\ / /:/ \:\
# /__/\ / /\ /__/::\ / /:/_/::\ ___ / /::\ / /:/ / /:/ ___ / /:/ \:\ / /:/~/:/ /__/:/ \__\:|
# \ \:\ / /:/ \__\/\:\__ /__/:/__\/\:\ /__/\ /:/\:\ / /::\ /__/:/ / /\ /__/:/ \__\:\ /__/:/ /:/___ \ \:\ / /:/
# \ \:\ /:/ \ \:\/\ \ \:\ /~~/:/ \ \:\/:/__\/ /__/:/\:\ \ \:\ / /:/ \ \:\ / /:/ \ \:\/:::::/ \ \:\ /:/
# \ \:\/:/ \__\::/ \ \:\ /:/ \ \::/ \__\/ \:\ \ \:\ /:/ \ \:\ /:/ \ \::/~~~~ \ \:\/:/
# \ \::/ /__/:/ \ \:\/:/ \ \:\ \ \:\ \ \:\/:/ \ \:\/:/ \ \:\ \ \::/
# \__\/ \__\/ \ \::/ \ \:\ \__\/ \ \::/ \ \::/ \ \:\ \__\/
# \__\/ \__\/ \__\/ \__\/ \__\/
#
# DO NOT CHANGE
#
# URL for downloads
LC='https://github.com/Lightcord/Lightcord/releases/latest/download/lightcord-linux-x64.zip'
ICON='https://raw.githubusercontent.com/Lightcord/Lightcord/master/discord.png'
DESKTOP='https://raw.githubusercontent.com/Lightcord/Lightcord/master/Lightcord.desktop'
APPIMAGE='https://github.com/Lightcord/Lightcord/releases/latest/download/Lightcord-linux-x86_64.AppImage'
Step() {
tput setaf 8
tput bold
printf "==> "
tput setaf 15
printf "$*\n"
tput sgr0
}
Info() {
tput setaf 6
printf " --> "
printf "$*\n"
tput sgr0
}
Warning() {
tput setaf 3
tput bold
printf " ->> "
tput setaf 11
printf "$*\n"
tput sgr0
}
Error() {
tput setaf 1
tput bold
printf " =>> "
tput setaf 9
printf "$*\n"
tput sgr0
tput cnorm
exit 1
}
ListHeader() {
tput smul
(CheckForProgram lolcat) && \
printf "$1\n" | lolcat -S 58 -F .2 || \
printf "$1\n"
tput sgr0
}
ListItem() {
#(CheckForProgram lolcat) && \
#printf "[$1]" | lolcat -S $1 -F .2 || \
printf "[$1]"
printf " $2\n"
}
FakeListItem() {
tput setaf 8
printf "[$1]"
printf " $2\n"
tput sgr0
}
LogoSplash() {
cat << "logo_end"
__ ____________ __________________ ____ ____
/ / / _/ ____/ / / /_ __/ ____/ __ \/ __ \/ __ \
/ / / // / __/ /_/ / / / / / / / / / /_/ / / / /
/ /____/ // /_/ / __ / / / / /___/ /_/ / _, _/ /_/ /
/_____/___/\____/_/ /_/ /_/ \____/\____/_/ |_/_____/
Linux installer
logo_end
}
CreditSplash() {
printf " "
tput smul
printf "Written with"
tput sgr0
tput setaf 1
tput bold
tput blink
printf " <3 "
tput sgr0
tput smul
printf "by "
tput bold
printf "pryme-svg"
tput sgr0
tput smul
printf " and "
tput bold
printf "GermanBread"
tput sgr0
printf "\n\n"
}
# 0 = OK
CheckForProgram() {
command -v $* >/dev/null
return $?
}
# 0 = OK
CheckForLibrary() {
(whereis -b "$1" | grep .so) >/dev/null
return $?
}
# 0 = OK
Confirmation() {
tput bold
printf "$1 [Y/n] "
tput sgr0
read _choice
[[ $_choice = [nN] ]] && return 1 || return 0
}
# 0 = OK
InvertedConfirmation() {
tput bold
printf "$1 [y/N] "
tput sgr0
read _choice
[[ $_choice = [yY] ]] && return 0 || return 1
}
Download() {
wget -qq -O $1 $2
}
Discontinued() {
Warning 'Lightcord has been officially discontinued. Please choose the uninstall option instead.'
Info '(override with "export IGNORE_ABANDONED=true")'
Error 'Installing Lightcord is not recommended!'
}
[ "$TERM" = "dumb" ] && exit 0
(CheckForProgram wget) || \
Error '"wget" is not installed, this script uses wget to download files'
(CheckForProgram unzip) || \
Error '"unzip" is not installed, this script uses unzip to decompress zip archives'
(CheckForProgram sudo) || \
Error '"sudo" is not installed, this script depends on this command for privilege escalation. Global installation will therefore not be available'
CheckForLibrary libnspr4.so
_status=$?
CheckForLibrary libnss3.so
_status=$(($_status+$?))
if [ $_status -ne 0 ]; then
Warning "Some required libraries seem to not be installed!\n\tMake sure that both 'libnspr4.so' and 'libnss3.so' are present in '/lib'"
(CheckForProgram pacman) && \
Info "$(tput setaf 12 && tput bold)Arch Linux or Arch-based$(tput sgr0 && tput setaf 15)\n\tsudo pacman -S nss nspr"
(CheckForProgram apt) && \
Info "$(tput setaf 13 && tput bold)Debian or Debian-based$(tput sgr0 && tput setaf 15)\n\tsudo apt install libnspr4 libnss3"
fi
unset _status
(CheckForProgram lolcat) && \
LogoSplash | lolcat -S 58 -F .2 || \
LogoSplash
CreditSplash
tput civis
ListHeader "Select scope"
[ -d /etc/nixos ] && \
FakeListItem 1 "Global" || \
ListItem 1 "Global"
ListItem 2 "Local"
while ! [[ $_scope = [12] ]]; do
tput sc
read -n 1 _scope
tput rc
done
echo
if [ -d /etc/nixos ]; then
Warning "A installation on NixOS is completely broken! " && \
(InvertedConfirmation "Continue anyways?") || \
exit 1
fi
ListHeader "Select mode"
ListItem 1 "Install"
ListItem 2 "Install (AppImage)"
ListItem 3 "Update"
ListItem 4 "Uninstall"
while ! [[ $_mode = [1234] ]]; do
tput sc
read -n 1 _mode
tput rc
done
echo
Step "The following will be done:"
case $_scope in
1)
Info "Manage system-wide installation"
;;
2)
Info "Manage user installation"
;;
esac
case $_mode in
1)
Info "Install Lightcord"
;;
2)
Info "Install Lightcord AppImage"
;;
3)
Info "Update Lightcord"
;;
4)
Info "Uninstall Lightcord"
;;
esac
tput cnorm
(Confirmation "Continue?") || \
exit 1
tput civis
[[ $_mode = [123] ]] && [ "$IGNORE_ABANDONED" != "true" ] && Discontinued
[[ $_mode = [123] ]] && _operation=1
[[ $_mode = [4] ]] && _operation=2
_downloadcache=$(mktemp -d)
case $_scope in
1)
case $_operation in
1)
Info "Downloading assets"
case $_mode in
1)
Download $_downloadcache/Lightcord.zip $LC
;;
2)
Download $_downloadcache/Lightcord.AppImage $APPIMAGE
;;
3)
[ -e /opt/Lightcord/appimage ] && \
Download $_downloadcache/Lightcord.AppImage $APPIMAGE || \
Download $_downloadcache/Lightcord.zip $LC
;;
esac
Download $_downloadcache/Lightcord.desktop $DESKTOP
Download $_downloadcache/lightcord.png $ICON
Info "Preparing assets"
unzip -qq $_downloadcache/Lightcord.zip -d $_downloadcache/Lightcord 2>/dev/null
mv $_downloadcache/Lightcord/{lightcord,Lightcord} 2>/dev/null
mkdir -p $_downloadcache/Lightcord
touch $_downloadcache/Lightcord/script
[ $_mode = 2 ] && \
touch $_downloadcache/Lightcord/appimage
chmod +x $_downloadcache/Lightcord.AppImage 2>/dev/null
mv $_downloadcache/Lightcord{.AppImage,/Lightcord} 2>/dev/null
Step "Privilege elevation required"
sudo -K
[ "$(sudo -p "Enter your password here: " id -u)" != "0" ] && \
Error "Authentication failed"
Info "Installing assets"
sudo mkdir -p /{opt/Lightcord,usr/share/{applications,pixmaps}}/
sudo mv -f $_downloadcache/Lightcord/* /opt/Lightcord/
sudo mv -f $_downloadcache/Lightcord.desktop /usr/share/applications/
sudo mv -f $_downloadcache/lightcord.png /usr/share/pixmaps/
sudo ln -s /opt/Lightcord/Lightcord /usr/bin/lightcord
;;
2)
Step "Privilege elevation required"
sudo -K
[ "$(sudo -p "Enter your password here: " id -u)" != "0" ] && \
Error "Authentication failed"
Info "Deleting Lightcord"
sudo rm -rf /opt/Lightcord/
sudo rm -f /usr/share/pixmaps/lightcord.png
sudo rm -f /usr/share/applications/Lightcord.desktop
sudo rm -f /usr/bin/lightcord
;;
esac
;;
2)
case $_operation in
1)
Info "Downloading assets"
case $_mode in
1)
Download $_downloadcache/Lightcord.zip $LC
;;
2)
Download $_downloadcache/Lightcord.AppImage $APPIMAGE
;;
3)
[ -e ~/.Lightcord/isappimage ] && \
Download $_downloadcache/Lightcord.AppImage $APPIMAGE || \
Download $_downloadcache/Lightcord.zip $LC
;;
esac
Download $_downloadcache/Lightcord.desktop $DESKTOP
Download $_downloadcache/lightcord.png $ICON
Info "Preparing assets"
unzip -qq $_downloadcache/Lightcord.zip -d $_downloadcache/Lightcord 2>/dev/null
mv $_downloadcache/Lightcord/{lightcord,Lightcord} 2>/dev/null
mkdir -p $_downloadcache/Lightcord
touch $_downloadcache/Lightcord/script
[ $_mode = 2 ] && \
touch $_downloadcache/Lightcord/isappimage
chmod +x $_downloadcache/Lightcord.AppImage 2>/dev/null
mv $_downloadcache/Lightcord{.AppImage,/Lightcord} 2>/dev/null
sed -i "s,/opt/Lightcord/Lightcord,~/.Lightcord/Lightcord,g" $_downloadcache/Lightcord.desktop
Info "Installing assets"
mkdir -p ~/.{Lightcord,local/{bin,share/{applications,icons/hicolor/512x512/apps}}}/
mv -f $_downloadcache/Lightcord/* ~/.Lightcord/
mv -f $_downloadcache/Lightcord.desktop ~/.local/share/applications/
mv -f $_downloadcache/lightcord.png ~/.local/share/icons/hicolor/512x512/apps/
ln -s ~/.Lightcord/Lightcord ~/.local/bin/lightcord
chmod +x ~/.local/bin/lightcord
;;
2)
Info "Deleting Lightcord"
rm -rf ~/.Lightcord/
rm -f ~/.local/share/applications/Lightcord.desktop
rm -f ~/.local/share/icons/hicolor/512x512/apps/lightcord.png
rm -f ~/.local/bin/lightcord
;;
esac
;;
esac
rm -rf $_downloadcache
unset LC ICON DESKTOP APPIMAGE _downloadcache _operation _mode _scope _choice
tput cnorm