This repository has been archived by the owner on Aug 7, 2024. It is now read-only.
forked from gagle/raspberrypi-motd
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmotd.sh
149 lines (116 loc) · 5.21 KB
/
motd.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
#!/bin/bash
clear
function color (){
echo "\e[$1m$2\e[0m"
}
function extend (){
local str="$1"
let spaces=60-${#1}
while [ $spaces -gt 0 ]; do
str="$str "
let spaces=spaces-1
done
echo "$str"
}
function center (){
local str="$1"
let spacesLeft=(78-${#1})/2
let spacesRight=78-spacesLeft-${#1}
while [ $spacesLeft -gt 0 ]; do
str=" $str"
let spacesLeft=spacesLeft-1
done
while [ $spacesRight -gt 0 ]; do
str="$str "
let spacesRight=spacesRight-1
done
echo "$str"
}
function sec2time (){
local input=$1
if [ $input -lt 60 ]; then
echo "$input seconds"
else
((days=input/86400))
((input=input%86400))
((hours=input/3600))
((input=input%3600))
((mins=input/60))
local daysPlural="s"
local hoursPlural="s"
local minsPlural="s"
if [ $days -eq 1 ]; then
daysPlural=""
fi
if [ $hours -eq 1 ]; then
hoursPlural=""
fi
if [ $mins -eq 1 ]; then
minsPlural=""
fi
echo "$days day$daysPlural, $hours hour$hoursPlural, $mins minute$minsPlural"
fi
}
borderColor=35
headerLeafColor=32
headerRaspberryColor=31
greetingsColor=36
statsLabelColor=33
borderLine="━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
borderTopLine=$(color $borderColor "┏$borderLine┓")
borderBottomLine=$(color $borderColor "┗$borderLine┛")
borderBar=$(color $borderColor "┃")
borderEmptyLine="$borderBar $borderBar"
# Header
header="$borderTopLine\n$borderEmptyLine\n"
header="$header$borderBar$(color $headerLeafColor " .~~. .~~. ")$borderBar\n"
header="$header$borderBar$(color $headerLeafColor " '. \ ' ' / .' ")$borderBar\n"
header="$header$borderBar$(color $headerRaspberryColor " .~ .~~~..~. _ _ ")$borderBar\n"
header="$header$borderBar$(color $headerRaspberryColor " : .~.'~'.~. : ___ ___ ___ ___| |_ ___ ___ ___ _ _ ___|_| ")$borderBar\n"
header="$header$borderBar$(color $headerRaspberryColor " ~ ( ) ( ) ~ | _| .'|_ -| . | . | -_| _| _| | | | . | | ")$borderBar\n"
header="$header$borderBar$(color $headerRaspberryColor " ( : '~'.~.'~' : ) |_| |__,|___| _|___|___|_| |_| |_ | | _|_| ")$borderBar\n"
header="$header$borderBar$(color $headerRaspberryColor " ~ .~ ( ) ~. ~ |_| |___| |_| ")$borderBar\n"
header="$header$borderBar$(color $headerRaspberryColor " ( : '~' : ) ")$borderBar\n"
header="$header$borderBar$(color $headerRaspberryColor " '~ .~~~. ~' ")$borderBar\n"
header="$header$borderBar$(color $headerRaspberryColor " '~' ")$borderBar"
me=$(whoami)
# Greetings
greetings="$borderBar$(color $greetingsColor "$(center "Welcome back, $me!")")$borderBar\n"
greetings="$greetings$borderBar$(color $greetingsColor "$(center "$(date +"%A, %d %B %Y, %T")")")$borderBar"
# System information
lastLoginIp="$(lastlog -u $me | sed -ne '2{p;q}' | cut -c 27-42)"
if [[ $lastLoginIp != "" ]]; then
login=$lastLoginIp
else
# Not enough logins
login="None"
fi
label1="$(extend "$login")"
label1="$borderBar $(color $statsLabelColor "Last Login....:") $label1$borderBar"
uptime="$(sec2time $(cut -d "." -f 1 /proc/uptime))"
uptime="$uptime ($(date -d "@"$(grep btime /proc/stat | cut -d " " -f 2) +"%d-%m-%Y %H:%M:%S"))"
label2="$(extend "$uptime")"
label2="$borderBar $(color $statsLabelColor "Uptime........:") $label2$borderBar"
label3="$(extend "$(free -m | awk 'NR==2 { printf "Total: %sMB, Used: %sMB, Free: %sMB",$2,$3,$4; }')")"
label3="$borderBar $(color $statsLabelColor "Memory........:") $label3$borderBar"
label4="$(extend "$(df -h ~ | awk 'NR==2 { printf "Total: %sB, Used: %sB, Free: %sB",$2,$3,$4; }')")"
label4="$borderBar $(color $statsLabelColor "Home space....:") $label4$borderBar"
proCount=$(ps ax | wc -l | tr -d " ")
label5="$(extend "Total $proCount running")"
label5="$borderBar $(color $statsLabelColor "Procesess.....:") $label5$borderBar"
cpuTemp0=$(cat /sys/class/thermal/thermal_zone0/temp)
cpuTemp1=$(($cpuTemp0/1000))
cpuTemp2=$(($cpuTemp0/100))
cpuTempM=$(($cpuTemp2 % $cpuTemp1))
TODAY=$(date)
gpuTemp0=$(/opt/vc/bin/vcgencmd measure_temp)
gpuTemp0=${gpuTemp0//\'/°}
gpuTemp0=${gpuTemp0//temp=/}
cpuTemp=$cpuTemp1"."$cpuTempM"'C"
label6="$(extend "$cpuTemp")"
label6="$borderBar $(color $statsLabelColor "CPU Temp......:") $label6$borderBar"
label7="$(extend "$gpuTemp0")"
label7="$borderBar $(color $statsLabelColor "GPU Temp......:") $label7$borderBar"
stats="$label1\n$label2\n$label3\n$label4\n$label5\n$label6\n$label7"
# Print motd
echo -e "$header\n$borderEmptyLine\n$greetings\n$borderEmptyLine\n$stats\n$borderEmptyLine\n$borderBottomLine"