Repository navigation
Expand file tree
/
Copy pathrigfetch.sh
More file actions
executable file
·586 lines (543 loc) · 15.7 KB
/
Copy pathrigfetch.sh
File metadata and controls
executable file
·586 lines (543 loc) · 15.7 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
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
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
#!/usr/bin/env bash
#
# rigfetch - a little and simple shell script for
# raspios or raspios derivates,
# default for fullRigg3DPI,
# like neofetch or pfetch.
#
# Inspired by "pfetch" <https://github.com/dylanaraps/pfetch.git>
#
# Copyright (C) 2020 Stephan Wendel <me@stephanwe.de>
#
# github: KwadFan
#
# This file may be distributed under the terms of the GNU GPLv3 license
#
#
# Signed-off-by: Stephan Wendel <me@stephanwe.de>
#
# shellcheck disable=SC1090
# shellcheck disable=SC2034
# shellcheck disable=SC2154
### Error Handling
set -e
### Set Colors
# Foreground
fg_black="$(tput setaf 0)"
fg_red="$(tput setaf 1)"
fg_green="$(tput setaf 2)"
fg_yellow="$(tput setaf 3)"
fg_blue="$(tput setaf 4)"
fg_purple="$(tput setaf 5)"
fg_cyan="$(tput setaf 6)"
fg_white="$(tput setaf 7)"
# Background
bg_black="$(tput setab 0)"
bg_red="$(tput setab 1)"
bg_green="$(tput setab 2)"
bg_yellow="$(tput setab 3)"
bg_blue="$(tput setab 4)"
bg_purple="$(tput setab 5)"
bg_cyan="$(tput setab 6)"
bg_white="$(tput setab 7)"
# reset colors
reset="$(tput sgr0)"
### Functions
# Be sure not running as privileged user.
verify_ready()
{
if [ "$EUID" -eq 0 ]; then
fail_msg "WARNING: DO NOT RUN AS ROOT!"
log_msg "WARNING: ${LOGNAME} TRIED TO RUN AS ROOT!" "${RIGFETCH_LOG}"
exit 1
fi
}
# Debugging
enable_debugging(){
case $RIG_DEBUG in
Y | y | YES | yes)
warn_msg "DEBUG ON"
set -x
;;
esac
}
# Self check and setup
locate_self() {
# In case of called by symolic link
local SELF=
if [ -f "${HOME}/rigged/rigfetch.sh" ]
then
SELF="${HOME}/rigged"
else
SELF="$(dirname "$(readlink -nf "$0")")"
fi
echo "$SELF"
}
### Set colors
set_color() {
# BC1 Color
case $BENCHY_FG_COLOR in
black)
BC1=$fg_black
;;
red)
BC1=$fg_red
;;
green)
BC1=$fg_green
;;
yellow)
BC1=$fg_yellow
;;
blue)
BC1=$fg_blue
;;
purple)
BC1=$fg_purple
;;
cyan)
BC1=$fg_cyan
;;
white)
BC1=$fg_white
;;
auto)
case $CHECK_FOR_UPDATES in
Y | y | YES | yes)
if [ "$(awk '{sub(/\(/, "",$2); print $2}' <<< $(rig_pkgs))" != "No" ]
then
case $AUTO_COLOR in
black)
BC1=$fg_black
;;
red)
BC1=$fg_red
;;
green)
BC1=$fg_green
;;
yellow)
BC1=$fg_yellow
;;
blue)
BC1=$fg_blue
;;
purple)
BC1=$fg_purple
;;
cyan)
BC1=$fg_cyan
;;
white)
BC1=$fg_white
;;
*)
BC1=$fg_purple
;;
esac
else
BC1=$fg_red
fi
;;
*)
BC1=$fg_purple
log_msg "You have to enable CHECK_FOR_UPDATES to use 'auto' color" "${RIGFETCH_LOG}"
;;
esac
;;
*)
BC1=$reset
;;
esac
# BC2 Color - Benchys Background
case $BENCHY_BG_COLOR in
black)
BC2=$bg_black
;;
red)
BC2=$bg_red
;;
green)
BC2=$bg_green
;;
yellow)
BC2=$bg_yellow
;;
blue)
BC2=$bg_blue
;;
purple)
BC2=$bg_purple
;;
cyan)
BC2=$bg_cyan
;;
white)
BC2=$bg_white
;;
*)
BC2=""
;;
esac
# TC Color - Text Color
case $TEXT_FG_COLOR in
black)
TC=$fg_black
;;
red)
TC=$fg_red
;;
green)
TC=$fg_green
;;
yellow)
TC=$fg_yellow
;;
blue)
TC=$fg_blue
;;
purple)
TC=$fg_purple
;;
cyan)
TC=$fg_cyan
;;
white)
TC=$fg_white
;;
*)
TC=$reset
;;
esac
# TB Color - Text Background Color
case $TEXT_BG_COLOR in
black)
TB=$bg_black
;;
red)
TB=$bg_red
;;
green)
TB=$bg_green
;;
yellow)
TB=$bg_yellow
;;
blue)
TB=$bg_blue
;;
purple)
TB=$bg_purple
;;
cyan)
TB=$bg_cyan
;;
white)
TB=$bg_white
;;
*)
TB=""
;;
esac
case $AT_SYMBOL_COLOR in
black)
ATC=$fg_black
;;
red)
ATC=$fg_red
;;
green)
ATC=$fg_green
;;
yellow)
ATC=$fg_yellow
;;
blue)
ATC=$fg_blue
;;
purple)
ATC=$fg_purple
;;
cyan)
ATC=$fg_cyan
;;
white)
ATC=$fg_white
;;
*)
ATC=$fg_white
;;
esac
}
### Arg parser
arg_parse() {
while [[ $# -gt 0 ]]
do
case "$@" in
-h | --help)
echo -e "Syntax: ""$0"" [Options]\n"
echo -e "Available Options are:\n"
echo -e "-l or \--showlog\tShould be obvious :)"
echo -e "-d or \--deletelog\tDeletes rigfetch's log file"
echo -e "\t\t\t(Usualy in /tmp/rigfetch.log)\v"
echo -e "-e or --editconfig\tOpens rigfetch's config file"
echo -e "If EDITOR Variable is set it opens with your Editor of Choice"
echo -e "Otherwise it uses 'nano' as fallback solution.\v"
echo -e "-b or --backup\t\tWill do a backup of the rigfetch.conf"
echo -e "--debug\t\t\tRIPS OUT ALL OF IT'S CUTENESS!"
echo -e "\tand show you his naked Pants oO ( equal to set -x )\v"
echo -e "-h or --help\t\t... must I really?\v"
echo -e "-v or --version\t\tSelf explaining.\v"
echo -e "Without options it throws a benchy :)"
echo -e "Now you are on your own..."
exit 0
;;
-b | --backup)
ok_msg "Copying rigfetch.conf to rigfetch.conf.bak"
cp --preserve=mode -f "${RIGFETCH_PATH}/config/rigfetch.conf" "${RIGFETCH_PATH}/config/rigfetch.conf.bak"
exit 0
;;
-d | --deletelog)
if [ -f "${RIGFETCH_LOG}" ]
then
std_msg "You are about to delete logfile..."
rm -i "${RIGFETCH_LOG}"
else
ok_msg "There is no Log to delete..."
fi
exit 0
;;
-e | --editconfig)
if [ -n "$EDITOR" ]
then
$EDITOR "${RIGFETCH_PATH}/config/rigfetch.conf"
else
/bin/nano "${RIGFETCH_PATH}/config/rigfetch.conf"
fi
exit 0
;;
-l | --showlog)
less "${RIGFETCH_LOG}"
exit 0
;;
-v | --version)
echo -e "rigfetch - Version: $(check_local_version "$(locate_self)")"
exit 0
;;
--debug)
set -x
RIG_DEBUG=YES
return 0
;;
*)
fail_msg "Syntax Error!"
std_msg "Please try ""$0"" --help or -h\n"
exit 1
;;
esac
done
}
### Gathering Informations
first_line() {
local OUTPUT
if [ -x "/bin/hostname" ]
then
OUTPUT="${TC}${TB}$(whoami)${ATC}@${reset}${TC}${TB}$(hostname -A)${reset}${TB} $(hostname -I)${reset}"
else
fail_msg "Command 'hostname' not found! Exiting..."
exit 1
fi
echo "${OUTPUT}"
}
rig_host() {
local product_name
local product_version
local product_model
if [ -f "/sys/devices/virtual/dmi/id/product_name" ]
then
read -r product_name < /sys/devices/virtual/dmi/id/product_name
fi
if [ -f "/sys/devices/virtual/dmi/id/product_version" ]
then
read -r product_version < /sys/devices/virtual/dmi/id/product_version
fi
if [ -f "/sys/firmware/devicetree/base/model" ]
then
read -r product_model < /sys/firmware/devicetree/base/model
fi
echo "$product_name $product_version $product_model"
}
rig_uptime() {
local UP
UP="$(LC_ALL=C uptime -p | sed 's/.*up.//; s/.week./w/; s/.day./d/; s/.hour./h/; s/.minut.*/m/' | tr -d ",")"
echo " ${UP}"
}
rig_mem() {
local mem_avail
mem_avail=$(LC_ALL=C free -m | grep Mem | awk '{print $2}')
local mem_used
mem_used=$(LC_ALL=C free -m | grep Mem | awk '{print $3}')
echo " ${mem_used}M/${mem_avail}M"
}
rig_fs() {
local fs
fs="$(LC_ALL=C df -h / | grep -e "/" | awk -F" " '{OFS="/" ;print $3,$2" ("$5")"}')"
echo " ${fs}"
}
rig_load() {
local load_avg
load_avg=$(LC_ALL=C uptime | rev | cut -d":" -f1 | rev | sed 's/ //1' )
echo " ${load_avg}"
}
rig_pkgs() {
local OUT
local updates_avail
# To speed up, parse log for aviable updates
if [ -f "${RIGFETCH_LOG}" ]
then
updates_avail="$(grep "System Updates" "${RIGFETCH_LOG}" | awk '{print $1}')"
else
updates_avail="$(count_sys_updates "${RIGFETCH_LOG}")"
fi
OUT="$(dpkg -l | grep -c "^ii")"
case $CHECK_FOR_UPDATES in
Y | y | YES | yes)
case "${updates_avail}" in
*0*)
OUT+=" (${fg_red}No Upgrades${reset})"
;;
*)
OUT+=" (${fg_red}${updates_avail} Upgradable${reset})"
;;
esac
;;
esac
echo -e " ${OUT}"
}
# Fetch Versions
# ( call rig_git_fetch "GITREPO" )
# ex.: rig_git_fetch "${RIG_KLIPPER_REPO}"
rig_git_fetch() {
local gitrepo
local gitpath
local OUT
local logpath
gitrepo="${1}"
logpath="${RIGFETCH_LOG}"
case "${gitrepo}" in
*klipper*)
gitpath="${RIG_KLIPPER_PATH}"
;;
*moonraker*)
gitpath="${RIG_MOONRAKER_PATH}"
;;
esac
OUT="$(check_local_version "${gitpath}" "${logpath}")"
case $CHECK_FOR_UPDATES in
Y | y | YES | yes)
OUT+=" (${fg_red}$(check_remote_version "${gitrepo}" "${logpath}")${reset})"
;;
esac
echo "${OUT}"
}
# Show Frontend Version
rig_frontend() {
local gitrepo
local path
local frontend
local OUT
gitrepo="${RIG_FRONTEND_REPO}"
path="${RIG_FRONTEND_PATH}"
frontend="${RIG_FRONTEND}"
OUT="$(frontend_local_version "${frontend}" "${path}" "${RIGFETCH_LOG}")"
case $CHECK_FOR_UPDATES in
Y | y | YES | yes)
OUT+=" (${fg_red}$(check_remote_version "${gitrepo}" "${logpath}")${reset})"
;;
esac
echo " ${OUT}"
}
### Print output
print_benchy() {
#local vars
local RS="${reset}"
if [ -z "${RIG_FRONTEND}" ]
then
RIG_FRONTEND="frontend"
fi
# Clear Screen
tput clear
# Print Stuff
echo -e "${BC1}${BC2}\v |3D| \t$(first_line)"
echo -e "${BC1}${BC2} 3D ${RS} ${TC}${TB}host\t${RS}$(rig_host)"
echo -e "${BC1}${BC2} MOONRAKER ${RS} ${TC}${TB}uptime\t${RS}$(rig_uptime)"
echo -e "${BC1}${BC2} 3O°'°OD ___________ ${RS} ${TC}${TB}mem\t${RS}$(rig_mem)${TC}${TB} sd${RS}$(rig_fs)"
echo -e "${BC1}${BC2} 3D 3D _/DKLIPPER3D/ ${RS} ${TC}${TB}loadavg\t${RS}$(rig_load)"
echo -e "${BC1}${BC2} o__3D3D___3D__/3D3D3D(O)3D/ ${RS} ${TC}${TB}pkgs\t${RS}$(rig_pkgs)"
echo -e "${BC1}${BC2} \3DOCTOPRINT3D3DRIGGED3D3/ ${RS} ${TC}${TB}klipper\t${RS} $(rig_git_fetch "${RIG_KLIPPER_REPO}")"
echo -e "${BC1}${BC2} \3DWC23D3DFLUIDDD3D3D3D/ ${RS} ${TC}${TB}moonraker${RS} $(rig_git_fetch "${RIG_MOONRAKER_REPO}")"
echo -e "${BC1}${BC2} \3D3D3D3DMAINSAIL3D3D/ ${RS} ${TC}${TB}${RIG_FRONTEND}\t${RS} $(rig_frontend)\v"
}
print_voron() {
#local vars
local RS="${reset}"
if [ -z "${RIG_FRONTEND}" ]
then
RIG_FRONTEND="frontend"
fi
# Clear Screen
tput clear
# Print Stuff
echo -e "${BC1}${BC2}\v rrrrr rrrrr ${RS} $(first_line)"
echo -e "${BC1}${BC2} rV000r 10002 ${RS} ${TC}${TB}host\t${RS}$(rig_host)"
echo -e "${BC1}${BC2} n0001 rIGG3d ${RS} ${TC}${TB}uptime\t${RS}$(rig_uptime)"
echo -e "${BC1}${BC2} moonr aker01 ${RS} ${TC}${TB}mem\t${RS}$(rig_mem)${TC}${TB} sd${RS}$(rig_fs)"
echo -e "${BC1}${BC2}rrrr r000V rrrrr ${RS} ${TC}${TB}loadavg\t${RS}$(rig_load)"
echo -e "${BC1}${BC2} rV000r 1000n ${RS} ${TC}${TB}pkgs\t${RS}$(rig_pkgs)"
echo -e "${BC1}${BC2} n0KLI1 pPERr ${RS} ${TC}${TB}klipper\t${RS} $(rig_git_fetch "${RIG_KLIPPER_REPO}")"
echo -e "${BC1}${BC2} r000Vr V0001 ${RS} ${TC}${TB}moonraker${RS} $(rig_git_fetch "${RIG_MOONRAKER_REPO}")"
echo -e "${BC1}${BC2} V0V0R rV24r ${RS} ${TC}${TB}${RIG_FRONTEND}\t${RS} $(rig_frontend)\v"
}
### Main
RIGFETCH_PATH="$(locate_self)"
# Includes
source "${RIGFETCH_PATH}/scripts/functions.sh"
source "${RIGFETCH_PATH}/config/rigfetch.conf"
# Check debugging on?
enable_debugging
# Are you root ? Forget it.. exiting
verify_ready
# Parse Args
arg_parse "$@"
# Set Colors
set_color
# Print Benchy
case "${BENCHY_STYLE}" in
benchy)
print_benchy
;;
voron)
print_voron
;;
*)
print_benchy
;;
esac
### Hints & Error Messages
# 'CHECK_FOR_UPDATES' auto color error
if [ "$(grep -c 'CHECK_FOR_UPDATES' "${RIGFETCH_LOG}")" -gt "0" ]
then
warn_msg "You need to set CHECK_FOR_UPDATES=Y to use 'auto' Color!"
fi
# Last apt Update more than 12h ago
if [ "$(($(date +%s)-$(last_apt_update)))" -ge "43200" ]
then
warn_msg "Your last 'apt update' was more than 12h ago!"
fi
# If something went wrong
if [ "$(grep -c 'Warning!' "${RIGFETCH_LOG}")" -gt "0" ]
then
fail_msg "OOPS, something went wrong! Check '${RIGFETCH_LOG}'!"
fi
# exit
exit 0