Skip to content
This repository has been archived by the owner on Oct 30, 2019. It is now read-only.

Add MOTD to the Hassbian image #201

Merged
merged 10 commits into from
Oct 23, 2018
2 changes: 1 addition & 1 deletion package/DEBIAN/control
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: hassbian-scripts
Version: 0.9.1
Priority: optional
Architecture: all
Depends: bash, wget, git, python3, python3-venv, python3-pip, python3-dev, bluetooth, libbluetooth-dev, avahi-daemon, build-essential, libssl-dev, libffi-dev, python-dev, libudev-dev
Depends: bash, wget, git, python3, python3-venv, python3-pip, python3-dev, bluetooth, libbluetooth-dev, avahi-daemon, build-essential, libssl-dev, libffi-dev, python-dev,libudev-dev, zip, nodejs, apt-transport-https, bluez-hcidump, bc, figlet
Maintainer: Fredrik Lindqvist <github.com/Landrash>
Homepage: www.home-assistant.io
Description: Hassbian scripts
Expand Down
6 changes: 6 additions & 0 deletions package/etc/update-motd.d/10-display-hostname
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

/usr/bin/figlet "$(hostname)"



26 changes: 26 additions & 0 deletions package/etc/update-motd.d/20-sysinfo
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

# get load averages
IFS=" " read LOAD1 LOAD5 LOAD15 <<<$(/bin/cat /proc/loadavg | awk '{ print $1,$2,$3 }')
# get free memory
IFS=" " read USED FREE TOTAL <<<$(free -htm | grep "Mem" | awk {'print $3,$4,$2'})
# get processes
PROCESS=`ps -eo user=|sort|uniq -c | awk '{ print $2 " " $1 }'`
PROCESS_ALL=`echo "$PROCESS"| awk {'print $2'} | awk '{ SUM += $1} END { print SUM }'`
PROCESS_ROOT=`echo "$PROCESS"| grep root | awk {'print $2'}`
PROCESS_USER=`echo "$PROCESS"| grep -v root | awk {'print $2'} | awk '{ SUM += $1} END { print SUM }'`

W="\e[0;39m"
G="\e[1;32m"

echo -e "
${W}system info:
$W Distro......: $W`cat /etc/*release | grep "PRETTY_NAME" | cut -d "=" -f 2- | sed 's/"//g'`
$W Kernel......: $W`uname -sr`

$W Uptime......: $W`uptime -p`
$W Load........: $G$LOAD1$W (1m), $G$LOAD5$W (5m), $G$LOAD15$W (15m)
$W Processes...:$W $G$PROCESS_ROOT$W (root), $G$PROCESS_USER$W (user) | $G$PROCESS_ALL$W (total)

$W CPU.........: $W`cat /proc/cpuinfo | grep "model name" | cut -d ' ' -f3- | awk {'print $0'} | head -1`
$W Memory......: $G$USED$W used, $G$FREE$W free, $G$TOTAL$W in total$W"
34 changes: 34 additions & 0 deletions package/etc/update-motd.d/30-services
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

# set column width
COLUMNS=3
# colors
green="\e[1;32m"
red="\e[1;31m"
undim="\e[0m"

services=("home-assistant@homeassistant")
# sort services
IFS=$'\n' services=($(sort <<<"${services[*]}"))
unset IFS

service_status=()
# get status of all services
for service in "${services[@]}"; do
service_status+=($(systemctl is-active "$service"))
done

out=""
for i in ${!services[@]}; do
# color green if service is active, else red
if [[ "${service_status[$i]}" == "active" ]]; then
out+="${services[$i]}:,${green}${service_status[$i]}${undim}\\n"
else
out+="${services[$i]}:,${red}${service_status[$i]}${undim}\\n"
fi
# insert \n every $COLUMNS column
done
out+="\n"

printf "\nservices:\n"
printf "$out" | column -ts $',' | sed -e 's/^/ /'