-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
191 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/bin/bash | ||
|
||
function color (){ | ||
echo "\e[$1m$2\e[0m" | ||
} | ||
|
||
function findDeviceModel (){ | ||
deviceName="" | ||
local deviceModel=$(tr -d '\0' < /sys/firmware/devicetree/base/model) | ||
local hostName=$(hostname) | ||
|
||
if [ $hostName ]; then | ||
deviceName="$deviceModel - $hostName" | ||
else | ||
deviceName="$deviceModel" | ||
fi | ||
} | ||
|
||
# Colors | ||
deviceColor="38;5;110" | ||
greetingsColor="38;5;5" | ||
userColor="38;5;110" | ||
codenameColor="38;5;108" | ||
me=$(logname) | ||
findDeviceModel | ||
|
||
# Device Info | ||
deviceLabel=" $(color $deviceColor " $deviceName ")" | ||
|
||
# Greetings | ||
me="$(color $userColor " $me ")" | ||
codename="$(grep 'VERSION_CODENAME' /etc/os-release | cut -d '=' -f 2)" | ||
greetings="$(color $greetingsColor " * Welcome") $me $(color $greetingsColor To) $(color $codenameColor $codename)\n" | ||
greetings="$greetings$(color $greetingsColor " * $(date +"%a %b %d %Y, %I:%M:%S %p")")\n" | ||
|
||
# OS | ||
greetings="$greetings$(color $greetingsColor " * $(uname -srm)")" | ||
|
||
# uname -snrvm | ||
echo -e "\n$deviceLabel" | ||
echo -e "\n$greetings" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#!/bin/bash | ||
|
||
function color (){ | ||
echo "\e[$1m$2\e[0m" | ||
} | ||
|
||
function sec2time (){ | ||
local input=$1 | ||
|
||
((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 0 || $days -eq 1 ]]; then | ||
daysPlural="" | ||
fi | ||
if [[ $hours -eq 0 || $hours -eq 1 ]]; then | ||
hoursPlural="" | ||
fi | ||
if [[ $mins -eq 0 || $mins -eq 1 ]]; then | ||
minsPlural="" | ||
fi | ||
echo "$days day$daysPlural $hours hr$hoursPlural $mins min$minsPlural" | ||
} | ||
|
||
# Colors | ||
statsLabelColor="38;5;2" | ||
bulletColor="38;5;243" | ||
infoColor="38;5;1" | ||
dimInfoColor="38;5;7;2" | ||
me=$(logname) | ||
|
||
# Last Login | ||
read loginIP loginDate <<< $(last $me --time-format iso -2 | awk 'NR==1 { print $3,$4 }') | ||
if [[ $loginDate == *T* ]]; then | ||
login="$(date -d $loginDate +"%a %b %d %Y, %I:%M %p") $(color $dimInfoColor "* $loginIP")" | ||
else | ||
# First Login | ||
login="None" | ||
fi | ||
|
||
# Stats | ||
label1="$login" | ||
label1="$(color $statsLabelColor "Last login:") $(color $infoColor "$label1")" | ||
|
||
label2="$(vcgencmd measure_temp | cut -c "6-9")°C" | ||
label2="$(color $statsLabelColor "Temp:") $(color $bulletColor "...")$(color $statsLabelColor ".") $(color $infoColor $label2)" | ||
|
||
uptime="$(sec2time $(cut -d "." -f 1 /proc/uptime))" | ||
uptime="$uptime $(color $dimInfoColor "* $(date -d "@"$(grep btime /proc/stat | cut -d " " -f 2) +"%m-%d-%y %H:%M")")" | ||
|
||
label3="$uptime" | ||
label3="$(color $statsLabelColor "Uptime:") $(color $bulletColor "..")$(color $statsLabelColor ".") $(color $infoColor "$label3")" | ||
|
||
label4="$(awk -v a="$(awk '/cpu /{print $2+$3+$4+$5+$6+$7+$8+$9+$10,$5}' /proc/stat; sleep 0.3)" '/cpu /{split(a,b," "); printf "%.1f%%", 100*(($2+$3+$4+$5+$6+$7+$8+$9+$10-b[1])-($5-b[2]))/($2+$3+$4+$5+$6+$7+$8+$9+$10-b[1])}' /proc/stat)" | ||
label4="$(color $statsLabelColor "Cpu:") $(color $bulletColor "....")$(color $statsLabelColor ".") $(color $infoColor $label4)" | ||
|
||
label5="$(df -h ~ | awk 'NR==2 { printf "%sB / %sB \\e[38;5;144m* Free: %sB\\e[0m",$3,$2,$4; }')" | ||
label5="$(color $statsLabelColor "Disk:") $(color $bulletColor "....")$(color $statsLabelColor ".") $(color $infoColor "$label5")" | ||
|
||
label6="$(/bin/ls -d /proc/[0-9]* | wc -l)" | ||
label6="$(color $statsLabelColor "Procs:") $(color $bulletColor "..")$(color $statsLabelColor ".") $(color $infoColor $label6)" | ||
|
||
label7="$(free -h --si | awk 'NR==2 { printf "%sB / %sB \\e[38;5;144m* Free: %sB\\e[0m",$3,$2,$4; }')" | ||
label7="$(color $statsLabelColor "Memory:") $(color $bulletColor "..")$(color $statsLabelColor ".") $(color $infoColor "$label7")" | ||
|
||
label8="$(hostname -I)" | ||
label8="$(color $statsLabelColor "IP:") $(color $bulletColor ".....")$(color $statsLabelColor ".") $(color $infoColor $label8)" | ||
|
||
echo | ||
# Two Entries Per Line | ||
echo -e " $label2\r $label1" | ||
echo -e " $label4\r $label3" | ||
echo -e " $label6\r $label5" | ||
echo -e " $label8\r $label7" | ||
echo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# MOTD | ||
|
||
credit to: [ar51an/raspberrypi-motd](https://github.com/ar51an/raspberrypi-motd.git) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG | ||
trap 'echo "$0: \"${last_command}\" command failed with exit code $?"' ERR | ||
|
||
# get the path to this script | ||
APP_PATH=`dirname "$0"` | ||
APP_PATH=`( cd "$APP_PATH" && pwd )` | ||
|
||
unattended=0 | ||
subinstall_params="" | ||
for param in "$@" | ||
do | ||
echo $param | ||
if [ $param="--unattended" ]; then | ||
echo "installing in unattended mode" | ||
unattended=1 | ||
subinstall_params="--unattended" | ||
fi | ||
done | ||
|
||
default=y | ||
while true; do | ||
if [[ "$unattended" == "1" ]] | ||
then | ||
resp=$default | ||
else | ||
[[ -t 0 ]] && { read -t 10 -n 2 -p $'\e[1;32mInstall mode of the day (MOTD)? [y/n] (default: '"$default"$')\e[0m\n' resp || resp=$default ; } | ||
fi | ||
response=`echo $resp | sed -r 's/(.*)$/\1=/'` | ||
|
||
if [[ $response =~ ^(y|Y)=$ ]] | ||
then | ||
|
||
toilet Setting up MOTD | ||
|
||
if [ -f /etc/motd ]; then | ||
sudo mv /etc/motd /etc/motd.bak | ||
fi | ||
|
||
if [ -f /etc/update-motd.d/10-uname ]; then | ||
sudo rm /etc/update-motd.d/10-uname | ||
fi | ||
|
||
sudo sed -i 's/#PrintLastLog yes/PrintLastLog no/' /etc/ssh/sshd_config | ||
sudo systemctl restart sshd | ||
|
||
sudo ln -fs $APP_PATH/11-welcome /etc/update-motd.d/ | ||
sudo ln -fs $APP_PATH/15-system /etc/update-motd.d/ | ||
|
||
break | ||
elif [[ $response =~ ^(n|N)=$ ]] | ||
then | ||
break | ||
else | ||
echo " What? \"$resp\" is not a correct answer. Try y+Enter." | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters