/
bootscreen.sh
executable file
·146 lines (122 loc) · 3.62 KB
/
bootscreen.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
#!/bin/bash
# Global variables
ver=$(/usr/local/bin/nems-info nemsver)
host=$(/bin/hostname)
# Should set screen resolution on each board
# See: https://linuxhint.com/set_screen_resolution_linux_kernel_boot/
# Don't allow TTY to go blank
/usr/bin/setterm -blank 0
# See the blank timout (seconds): cat /sys/module/kernel/parameters/consoleblank
display_screen() {
if [[ $2 == 'warning' ]]; then
conf=/usr/local/share/nems/nems-scripts/settings/dialog.warning
else
conf=/usr/local/share/nems/nems-scripts/settings/dialog.normal
fi
env DIALOGRC=$conf dialog --title "$1" \
--no-collapse \
--infobox "$output" 20 72
}
if [[ ! -e /var/log/nems/patches.log ]]; then
touch /var/log/nems/patches.log
fi
while ! grep -q "PATCH-000002" /var/log/nems/patches.log; do
output="\n\nFilesystem is being resized.\n\nNEMS will reboot. Please standby..."
display_screen "NEMS Linux $ver"
sleep 10
done
# Loading screen
output="\n\nNEMS Linux is loading..."
display_screen "NEMS Linux $ver"
sleep 10
while :
do
alias=$(/usr/local/bin/nems-info alias)
veravail=$(/usr/local/bin/nems-info nemsveravail)
users=$(/usr/local/bin/nems-info users)
cpupercent=$(/usr/local/bin/nems-info cpupercent)
diskusage=$(/usr/local/bin/nems-info diskusage)
temperatureC=$(/usr/local/bin/nems-info temperature)
# There's no way a CPU with a reported temp would be 0, so assume unknown
if (( ${temperatureC%.*} == 0 )); then
temperatureF=0;
temps=''
else
temperatureF=$(echo "scale=1;((9/5) * $temperatureC) + 32" |bc)
temps="\nCPU Temperature: $temperatureF°F / $temperatureC°C"
fi
online=$(/usr/local/bin/nems-info online)
if [[ $online == 1 ]]; then
internet="Online"
elif [[ $online == 0 ]]; then
internet="Offline"
else
internet="Unknown"
fi
ip=$(/usr/local/bin/nems-info ip)
init=$(/usr/local/bin/nems-info init)
platform_name=$(/usr/local/bin/nems-info platform-name)
if [[ $init == "0" ]]; then
output_init="Your NEMS server is not yet initialized. Please run: sudo nems-init"
fi
if (( $(echo "$veravail > $ver" |bc -l) )); then
current="- $veravail is Available."
else
current=""
fi
output="\
NEMS Version: $ver $current\n\
Server Alias: $alias\n\
Platform: $platform_name\n\
Hostname: $host.local\n\
IP Address: $ip\n\
CPU Usage: $(LC_ALL=C /usr/bin/printf '%.*f\n' 1 $cpupercent)% $temps\n\
Disk Usage: $(LC_ALL=C /usr/bin/printf '%.*f\n' 1 $diskusage)%\n\
Active Sessions: $users\n\
Internet Status: $internet\n\
\n$output_init\n\
\n\
To login, use SSH or press CTRL-ALT-F2\n\
\n\
For help, visit: docs.nemslinux.com"
display_screen "NEMS Server Overview"
sleep 10
hosts=$(/usr/local/bin/nems-info hosts)
services=$(/usr/local/bin/nems-info services)
update=$(/usr/local/bin/nems-info update)
fixes=$(/usr/local/bin/nems-info fixes)
if [[ $update == 1 ]]; then
timertmp=$(/usr/local/bin/nems-info fileage /var/run/nems-update.pid)
updating="Running ($timertmp)"
else
updating="Idle"
fi
if [[ $fixes == 1 ]]; then
timertmp=$(/usr/local/bin/nems-info fileage /var/run/nems-fixes.pid)
fixing="Running ($timertmp)"
else
fixing="Idle"
fi
# General overview
output="\
Hosts: $hosts\n\
Services: $services\n\
NEMS Update: $updating\n\
NEMS Fixes: $fixing\n\
"
display_screen "NEMS Linux $ver"
sleep 10
# NEMS Warning Light Current State Screen
if [[ -e /var/log/nems/nems-tools/currentstate ]]; then
output=$(cat /var/log/nems/nems-tools/currentstate)
if [[ $output == *"CRITICAL"* ]]; then
conf="warning"
timer=45
else
conf="normal"
timer=10
fi
display_screen "NEMS Current State" $conf
sleep $timer
fi
done