-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathraspi-info-light
More file actions
192 lines (166 loc) · 7.59 KB
/
raspi-info-light
File metadata and controls
192 lines (166 loc) · 7.59 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
#!/bin/bash
#################################################################################
# _ _ __ _ _ _ _ #
# _ __ __ _ ___ _ __ (_) (_)_ __ / _| ___ | (_) __ _| |__ | |_ #
# | '__/ _` / __| '_ \| |_____| | '_ \| |_ / _ \ _____| | |/ _` | '_ \| __| #
# | | | (_| \__ \ |_) | |_____| | | | | _| (_) |_____| | | (_| | | | | |_ #
# |_| \__,_|___/ .__/|_| |_|_| |_|_| \___/ |_|_|\__, |_| |_|\__| #
# |_| |___/ #
# #
# #
# MIT License #
# Copyright (c) 2019-2026 Massimo Pissarello #
# #
#################################################################################
# INITIALIZE READONLY VARIABLES
readonly TIMEOUT_CMD="timeout 3"
readonly TIP=/usr/lib/raspi-info/shell-tips
readonly RASPMOD=$(tr -d '\0' </proc/device-tree/model)
readonly MEMTOT=$((`grep -i MemTotal /proc/meminfo | cut -f1 -dk | cut -f2 -d:` / (1024*1024) + 1))
# System detection function
show_system_info() {
if [[ "$RASPMOD" == "Raspberry Pi 4"* ]] || [[ "$RASPMOD" == "Raspberry Pi Compute Module 4"* ]] ||
[[ "$RASPMOD" == "Raspberry Pi Compute Module 5"* ]] || [[ "$RASPMOD" == "Raspberry Pi 400"* ]] ||
[[ "$RASPMOD" == "Raspberry Pi 5"* ]]; then
echo -e '\e[33m'"$RASPMOD with ${MEMTOT}GB RAM"
else
echo -e '\e[33m'"$RASPMOD"
fi
echo -e '\e[32m'"`lsb_release -d | awk '/Description:/ {printf "%s %s ", $2, $3}' && cat /etc/debian_version | tr -d '\n' && lsb_release -d | awk '/Description:/ {printf " %s", $5}'`"
# Uptime and load average
echo -e "Load average (1m, 5m, 15m)`uptime | awk -F'[a-z]:' '{print $2}'`"
}
# Temperature monitoring function with graphical representation
check_temperature() {
# Get temperature - works for both root and non-root users
readonly CPUTEMP_VALUE=$(cat /sys/class/thermal/thermal_zone0/temp)
readonly CPU_TEMP_CELSIUS=$((CPUTEMP_VALUE / 1000))
readonly CPU_TEMP_DECIMAL=$((CPUTEMP_VALUE % 1000 / 10))
readonly CPU_TEMP_FORMATTED="${CPU_TEMP_CELSIUS}.${CPU_TEMP_DECIMAL}°C"
# Define temperature thresholds
readonly TEMP_LOW=45
readonly TEMP_NORMAL=55
readonly TEMP_HIGH=65
readonly TEMP_CRITICAL=75
# Create visual bar graph based on temperature
readonly BAR_LENGTH=20
readonly TEMP_PERCENTAGE=$((CPU_TEMP_CELSIUS * 100 / TEMP_CRITICAL)) # Scale based on critical temp
readonly FILLED_BLOCKS=$((TEMP_PERCENTAGE * BAR_LENGTH / 100))
# Create the bar with gradient effect
BAR="["
for ((i=0; i<BAR_LENGTH; i++)); do
if [ $i -lt $FILLED_BLOCKS ]; then
if [ $CPU_TEMP_CELSIUS -lt $TEMP_LOW ]; then
BAR="${BAR}█" # Full block for better visibility
elif [ $CPU_TEMP_CELSIUS -lt $TEMP_NORMAL ]; then
BAR="${BAR}█"
elif [ $CPU_TEMP_CELSIUS -lt $TEMP_HIGH ]; then
BAR="${BAR}█"
else
BAR="${BAR}█"
fi
else
BAR="${BAR}░" # Light shade for empty space
fi
done
BAR="${BAR}]"
# Set color and message based on temperature
if [ "$CPUTEMP_VALUE" -lt $((TEMP_LOW * 1000)) ]; then
echo -e '\e[36m'"CPU ${CPU_TEMP_FORMATTED} $BAR LOW TEMPERATURE"'\e[0m'
elif [ "$CPUTEMP_VALUE" -lt $((TEMP_NORMAL * 1000)) ]; then
echo -e '\e[32m'"CPU ${CPU_TEMP_FORMATTED} $BAR NORMAL TEMPERATURE"'\e[0m'
elif [ "$CPUTEMP_VALUE" -lt $((TEMP_HIGH * 1000)) ]; then
echo -e '\e[33m'"CPU ${CPU_TEMP_FORMATTED} $BAR NORMAL-HIGH TEMPERATURE"'\e[0m'
elif [ "$CPUTEMP_VALUE" -lt $((TEMP_CRITICAL * 1000)) ]; then
echo -e '\e[31m'"CPU ${CPU_TEMP_FORMATTED} $BAR HIGH TEMPERATURE!"'\e[0m'
else
echo -e '\e[31m\e[1m'"CPU ${CPU_TEMP_FORMATTED} $BAR CRITICAL TEMPERATURE! SHUTDOWN RECOMMENDED!"'\e[0m'
# Log critical temperature event if logging is available and we're root
if [ -d "/var/log" ] && [ $(id -u) -eq 0 ]; then
echo "$(date): CRITICAL TEMPERATURE ALERT: ${CPU_TEMP_FORMATTED}" >> /var/log/raspi-temp-alerts.log
fi
fi
# Display throttling status if available (requires vcgencmd which usually needs root)
if command -v vcgencmd &> /dev/null && [ $(id -u) -eq 0 ]; then
THROTTLED=$(vcgencmd get_throttled)
THROTTLE_CODE=$(echo $THROTTLED | cut -d'=' -f2)
if [ "$THROTTLE_CODE" != "0x0" ]; then
echo -e '\e[33m'"Throttling detected: $THROTTLED"'\e[0m'
# Decode throttling flags
[ $((0x$THROTTLE_CODE & 0x1)) -ne 0 ] && echo -e '\e[33m'" - Under-voltage detected"'\e[0m'
[ $((0x$THROTTLE_CODE & 0x2)) -ne 0 ] && echo -e '\e[33m'" - ARM frequency capped"'\e[0m'
[ $((0x$THROTTLE_CODE & 0x4)) -ne 0 ] && echo -e '\e[33m'" - Currently throttled"'\e[0m'
[ $((0x$THROTTLE_CODE & 0x8)) -ne 0 ] && echo -e '\e[33m'" - Soft temperature limit active"'\e[0m'
fi
fi
}
# Network connectivity function
check_network() {
# Check Internet and IP with timeout
EXTIP=$($TIMEOUT_CMD dig TXT +short o-o.myaddr.l.google.com @ns1.google.com 2>/dev/null | sed -e 's/^"//' -e 's/"$//')
if [ -n "$EXTIP" ]; then
COUNTRY=$($TIMEOUT_CMD whois $EXTIP 2>/dev/null | grep -m 1 country: | awk '{print $2}')
echo -e "\e[32mInternet connected with IP $EXTIP ($COUNTRY)"
else
echo -e "\e[31m\e[1mInternet not connected"'\e[0m'
fi
INTERFACE=$(ip -o -f inet addr show | awk '/scope global/ {print $2, $4}')
echo -e -n '\e[32m'"Internal IP:" $INTERFACE
# WLAN quality
if [[ "$INTERFACE" =~ ^wlan[0-9]+$ ]]; then
echo -e -n '\e[33m'" "
iwgetid | awk '{ print $2}'
iwconfig wlan0 | grep -i "Bit Rate" | sed -e 's/^\s*//' -e '/^$/d'
iwconfig wlan0 | grep -i "Link Quality" | sed -e 's/^\s*//' -e '/^$/d'
else
echo
fi
}
# File system status function
show_filesystem() {
echo -e '\e[95m'
df -h | grep -v "tmpfs" | grep -v "udev"
echo -e '\e[0m'
}
# Date and time information function
show_time_info() {
echo -e '\e[96m'"Time now is `date +"%H:%M:%S"` in `timedatectl | awk '/Time zone:/ {print $3, $4, $5}'`"
echo -e "Uptime `uptime -p | sed "s/^[^ ]* //"`"
echo -e '\e[0m'
}
# Show shell tip and hostname with figlet
show_tip_and_hostname() {
readonly FIGLETCOLOR=`shuf -i91-96 -n1`
echo -e '\e[44m\e[1m'" Shell tip: `shuf -n 1 $TIP` "'\e[0m\e['$FIGLETCOLOR'm'
figlet `hostname -s`
}
# Version check function
check_version() {
VERSION=$(dpkg -s raspi-info | grep '^Version:' | awk '/:/ {print $2}')
UPVER=$($TIMEOUT_CMD curl -sSfL https://raw.githubusercontent.com/mapi68/raspi-info/master/version 2>/dev/null)
if [ -n "$UPVER" ] && [[ "$VERSION" -lt "$UPVER" ]]; then
echo -e '\e[1;33m'"NEW VERSION AVAILABLE: please run 'raspi-info-update'"
fi
}
# Check if reboot is required
check_reboot_required() {
if [ -f /var/run/reboot-required ]; then
echo -e '\e[1;31m'"***** SYSTEM RESTART REQUIRED *****"
fi
}
# Main function to run everything
main() {
clear
show_system_info
check_temperature
check_network
show_filesystem
show_time_info
show_tip_and_hostname
check_version
check_reboot_required
echo -e '\e[0m'"\c"
echo
}
# Execute main function
main