-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathlounge.sh
executable file
·454 lines (440 loc) · 11.3 KB
/
lounge.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
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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
#!/bin/bash
## Brett 2021
user=$(whoami)
mkdir -p $HOME/.logs/
touch "$HOME/.logs/lounge.log"
log="$HOME/.logs/lounge.log"
function _deps() {
## Function for installing nvm.
if [[ ! -d $HOME/.nvm ]]; then
echo "Installing node"
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash >> "$log" 2>&1
echo "nvm installed."
else
echo "nvm is already installed."
fi
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
nvm install --lts >> "$log" 2>&1 || {
echo "node failed to install"
exit 1
}
echo "Node LTS installed."
echo "Installing Yarn"
npm install -g yarn >> "$log" 2>&1 || {
echo "Yarn failed to install"
exit 1
}
echo "Yarn installed."
}
function port() {
## Function for generating a random unused port
LOW_BOUND=$1
UPPER_BOUND=$2
comm -23 <(seq ${LOW_BOUND} ${UPPER_BOUND} | sort) <(ss -Htan | awk '{print $4}' | cut -d':' -f2 | sort -u) | shuf | head -n 1
}
function ssl_gen() {
echo "Generating SSL keys"
country="NL"
state="Amsterdam"
locality="North Holland"
organization="$(hostname -f)"
organizationalunit="$user"
commonname="$user"
ssl_password=""
mkdir -p "/home/$user/.ssl/"
openssl genrsa -out "$HOME/.ssl/$user-self-signed.key" 2048 >> /dev/null 2>&1
openssl req -new -key "$HOME/.ssl/$user-self-signed.key" -out "$HOME/.ssl/$user-self-signed.csr" -passin pass:$ssl_password -subj "/C=$country/ST=$state/L=$locality/O=$organization/OU=$organizationalunit/CN=$commonname" >> /dev/null 2>&1
openssl x509 -req -days 1095 -in "$HOME/.ssl/$user-self-signed.csr" -signkey "$HOME/.ssl/$user-self-signed.key" -out "$HOME/.ssl/$user-self-signed.crt" >> /dev/null 2>&1
chown -R "$user": "$HOME/.ssl"
chmod 750 "$HOME/.ssl"
echo "SSL Key Generated"
}
function _install() {
ssl_gen
## Function for node install of TheLounge
echo "Installing The Lounge"
yarn --non-interactive global add thelounge >> "$log" 2>&1
echo "Configuring The Lounge"
mkdir -p "$HOME/.thelounge/"
port=($(port 10000 12000))
cat > "$HOME/.thelounge/config.js" << EOF
"use strict";
module.exports = {
//
// Set the server mode.
// Public servers does not require authentication.
//
// Set to 'false' to enable users.
//
// @type boolean
// @default true
//
public: false,
//
// IP address or hostname for the web server to listen on.
// Setting this to undefined will listen on all interfaces.
//
// @type string
// @default undefined
//
host: undefined,
//
// Set the port to listen on.
//
// @type int
// @default 9000
//
port: ${port},
//
// Set the local IP to bind to for outgoing connections. Leave to undefined
// to let the operating system pick its preferred one.
//
// @type string
// @default undefined
//
bind: undefined,
//
// Sets whether the server is behind a reverse proxy and should honor the
// X-Forwarded-For header or not.
//
// @type boolean
// @default false
//
reverseProxy: false,
//
// Set the default theme.
// Find out how to add new themes at https://thelounge.github.io/docs/packages/themes
//
// @type string
// @default "example"
//
theme: "thelounge-theme-zenburn",
//
// Prefetch URLs
//
// If enabled, The Lounge will try to load thumbnails and site descriptions from
// URLs posted in channels.
//
// @type boolean
// @default false
//
prefetch: true,
//
// Store and proxy prefetched images and thumbnails.
// This improves security and privacy by not exposing client IP address,
// and always loading images from The Lounge instance and making all assets secure,
// which in result fixes mixed content warnings.
//
// If storage is enabled, The Lounge will fetch and store images and thumbnails
// in ~/.lounge/storage folder, or %HOME%/storage if --home is used.
//
// Images are deleted when they are no longer referenced by any message (controlled by maxHistory),
// and the folder is cleaned up on every The Lounge restart.
//
// @type boolean
// @default false
//
prefetchStorage: false,
//
// Prefetch URLs Image Preview size limit
//
// If prefetch is enabled, The Lounge will only display content under the maximum size.
// Specified value is in kilobytes. Default value is 512 kilobytes.
//
// @type int
// @default 512
//
prefetchMaxImageSize: 4096,
//
// Display network
//
// If set to false network settings will not be shown in the login form.
//
// @type boolean
// @default true
//
// displayNetwork: true,
//
// Lock network
//
// If set to true, users will not be able to modify host, port and tls
// settings and will be limited to the configured network.
//
// @type boolean
// @default false
//
lockNetwork: false,
//
// Hex IP
//
// If enabled, clients' username will be set to their IP encoded has hex.
// This is done to share the real user IP address with the server for host masking purposes.
//
// @type boolean
// @default false
//
useHexIp: false,
//
// WEBIRC support
//
// If enabled, The Lounge will pass the connecting user's host and IP to the
// IRC server. Note that this requires to obtain a password from the IRC network
// The Lounge will be connecting to and generally involves a lot of trust from the
// network you are connecting to.
//
// Format (standard): {"irc.example.net": "hunter1", "irc.example.org": "passw0rd"}
// Format (function):
// {"irc.example.net": function(client, args, trusted) {
// // here, we return a webirc object fed directly to \$(irc-framework)
// return {username: "thelounge", password: "hunter1", address: args.ip, hostname: "webirc/"+args.hostname};
// }}
//
// @type string | function(client, args):object(webirc)
// @default null
webirc: null,
//
// Maximum number of history lines per channel
//
// Defines the maximum number of history lines that will be kept in
// memory per channel/query, in order to reduce the memory usage of
// the server. Setting this to -1 will keep unlimited amount.
//
// @type integer
// @default 10000
maxHistory: 10000,
//
// Set socket.io transports
//
// @type array
// @default ["polling", "websocket"]
//
transports: ["polling", "websocket"],
//
// Run The Lounge using encrypted HTTP/2.
// This will fallback to regular HTTPS if HTTP/2 is not supported.
//
// @type object
// @default {}
//
https: {
//
// Enable HTTP/2 / HTTPS support.
//
// @type boolean
// @default false
//
enable: true,
//
// Path to the key.
//
// @type string
// @example "sslcert/key.pem"
// @default ""
//
key: "/home/$user/.ssl/$user-self-signed.key",
//
// Path to the certificate.
//
// @type string
// @example "sslcert/key-cert.pem"
// @default ""
//
certificate: "/home/$user/.ssl/$user-self-signed.crt",
//
// Path to the CA bundle.
//
// @type string
// @example "sslcert/bundle.pem"
// @default ""
//
ca: ""
},
//
// Run The Lounge with identd support.
//
// @type object
// @default {}
//
identd: {
//
// Run the identd daemon on server start.
//
// @type boolean
// @default false
//
enable: false,
//
// Port to listen for ident requests.
//
// @type int
// @default 113
//
port: 113
},
//
// Enable oidentd support using the specified file
//
// Example: oidentd: "~/.oidentd.conf",
//
// @type string
// @default null
//
oidentd: null,
//
// LDAP authentication settings (only available if public=false)
// @type object
// @default {}
//
ldap: {
//
// Enable LDAP user authentication
//
// @type boolean
// @default false
//
enable: false,
//
// LDAP server URL
//
// @type string
//
url: "ldaps://example.com",
//
// LDAP base dn
//
// @type string
//
baseDN: "ou=accounts,dc=example,dc=com",
//
// LDAP primary key
//
// @type string
// @default "uid"
//
primaryKey: "uid"
},
// Extra debugging
//
// @type object
// @default {}
//
debug: {
// Enables extra debugging output provided by irc-framework.
//
// @type boolean
// @default false
//
ircFramework: false,
// Enables logging raw IRC messages into each server window.
//
// @type boolean
// @default false
//
raw: false,
},
};
EOF
mkdir -p "$HOME/.thelounge/users/"
bash -c "thelounge install thelounge-theme-zenburn"
# Figger out if hostname is Swizzin, LW Swizzin, or SBIO
echo "thelounge will run on ${port}"
echo "Your Lounge instance is up and running at https://$(hostname -f):${port}"
}
function _systemd() {
## Function responsible for everything systemd
mkdir -p "$HOME/.config/systemd/user"
cat > "$HOME/.config/systemd/user/lounge.service" << EOSD
[Unit]
Description=The Lounge IRC client
After=znc.service
[Service]
Type=simple
Environment=NODE_VERSION=$(node -v | cut -d "v" -f 2 | cut -d "." -f 1)
ExecStart=$HOME/.nvm/nvm-exec $HOME/.yarn/bin/thelounge start
Restart=on-failure
RestartSec=5
StartLimitInterval=60s
StartLimitBurst=3
[Install]
WantedBy=default.target
EOSD
systemctl --user enable -q --now lounge.service >> "$log" 2>&1 || echo "Failed to start TheLounge, please check logs."
}
function _adduser() {
read -rep "Please set a password for your The Lounge user, ${user}> " -i "" password
crypt=$(node $HOME/.config/yarn/global/node_modules/bcryptjs/bin/bcrypt "${password}")
cat > "$HOME/.thelounge/users/${user}.json" << EOU
{
"password": "${crypt}",
"log": true,
"awayMessage": "",
"networks": [],
"sessions": {}
}
EOU
}
function _remove() {
## Function Removes lounge and config files.
systemctl --user disable -q lounge >> /dev/null 2>&1
systemctl --user stop -q lounge
npm uninstall -g thelounge --save >> /dev/null 2>&1
yarn --non-interactive global remove thelounge
rm -rf "$HOME/.thelounge" # just in case
rm -f "$HOME/.config/systemd/user/lounge.service"
rm -f "$HOME/install/.lounge.lock"
}
function upgrade() {
echo "Upgrading The Lounge"
echo "Stopping lounge.service"
systemctl --user -q stop lounge
npm remove -g thelounge
yarn --non-interactive global add thelounge
echo "Starting lounge.service"
systemctl --user -q start lounge
echo "The Lounge has been Upgraded."
}
echo 'This is unsupported software. You will not get help with this, please answer `yes` if you understand and wish to proceed'
if [[ -z ${eula} ]]; then
read -r eula
fi
if ! [[ $eula =~ yes ]]; then
echo "You did not accept the above. Exiting..."
exit 1
else
echo "Proceeding with installation"
fi
echo "Welcome to The Lounge installer..."
echo ""
echo "What do you like to do?"
echo "Logs are stored at ${log}"
echo "install = Install The Lounge"
echo "uninstall = Completely removes The Lounge"
echo "exit = Exits Installer"
while true; do
read -r -p "Enter it here: " choice
case $choice in
"install")
_deps
_install
_systemd
_adduser
break
;;
"uninstall")
_remove
break
;;
"upgrade")
upgrade
break
;;
"exit")
break
;;
*)
echo "Unknown Option."
;;
esac
done
exit