diff --git a/bmotd.sh b/bmotd.sh index 860b502..f34b939 100755 --- a/bmotd.sh +++ b/bmotd.sh @@ -4,42 +4,24 @@ # # Config -MOTD="/etc/motd" +MOTD="/etc/motd2" INSTPATH="/etc/bmotd.sh" CACHEPATH="/var/cache/bmotd/" # Check if root main () { - isRoot && echo 'You are root' || echo 'You are NOT root' + # print help + if [ $# -lt 1 ]; then + printHelp + fi - # Gather information - HOSTNAME=$(hostname -s) - FQDN=$(hostname -f) - OSID=$(cat /etc/*-release 2>/dev/null | awk -F'=' '/^ID=/ { print $2; count++ } END { if (!count) print "Unknown" }') - KERNEL=$(uname -r) - EXTERNAL=$(dig TXT +short o-o.myaddr.l.google.com @ns1.google.com | tr -d '"') - - # Get number of updates awaiting - test -f ~/.pisscache || PKG_REFRESH=1 - [[ $(date +%H%M) == "1510" ]] && PKG_REFRESH=1 - if [ $PKG_REFRESH ]; then - case "$OSID" in - debian|osmc|linuxmint) - PKG_NU=$(apt-get --just-print upgrade | awk '/^[0-9]/ { print $1; exit }') - ;; - arch|archarm) - PKG_NU=$(pacman -Qu | wc -l) - ;; - *) - PKG_NU="-1" - esac - echo $PKG_NU > ~/.pisscache + # check if root + isRoot + if [[ $? -ne 0 ]]; then + echo 'Script needs root privileges to alter motd. Re-run with sudo.' + exit 0 fi - PKG_NU=$(cat ~/.pisscache) - - # Test if /etc/motd writable and run motd generator if so - test -w $MOTD && motdGen # check arguments case "$1" in @@ -67,9 +49,41 @@ main () { exit 0 ;; esac + + # Gather information + HOSTNAME=$(hostname -s) + FQDN=$(hostname -f) + OSID=$(cat /etc/*-release 2>/dev/null | awk -F'=' '/^ID=/ { print $2; count++ } END { if (!count) print "Unknown" }') + KERNEL=$(uname -r) + EXTERNAL=$(dig TXT +short o-o.myaddr.l.google.com @ns1.google.com | tr -d '"') + + # Get number of updates awaiting + test -f ~/.pisscache || PKG_REFRESH=1 + [[ $(date +%H%M) == "1510" ]] && PKG_REFRESH=1 + if [ $PKG_REFRESH ]; then + case "$OSID" in + debian|osmc|linuxmint) + PKG_NU=$(apt-get --just-print upgrade | awk '/^[0-9]/ { print $1; exit }') + ;; + arch|archarm) + PKG_NU=$(pacman -Qu | wc -l) + ;; + *) + PKG_NU="-1" + esac + echo $PKG_NU > ~/.pisscache + fi + PKG_NU=$(cat ~/.pisscache) + # Test if /etc/motd writable and run motd generator if so + test -w $MOTD && motdGen + } +function printHelp { + printf "HALP" + exit 0; +} function prettyPrint { declare -A a