changed order of startup, added printing help condition

master
czoczo 7 years ago
parent 7c618c5742
commit 676d1aeca9
  1. 70
      bmotd.sh

@ -4,42 +4,24 @@
# #
# Config # Config
MOTD="/etc/motd" MOTD="/etc/motd2"
INSTPATH="/etc/bmotd.sh" INSTPATH="/etc/bmotd.sh"
CACHEPATH="/var/cache/bmotd/" CACHEPATH="/var/cache/bmotd/"
# Check if root # Check if root
main () { main () {
isRoot && echo 'You are root' || echo 'You are NOT root' # print help
if [ $# -lt 1 ]; then
# Gather information printHelp
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 fi
PKG_NU=$(cat ~/.pisscache)
# Test if /etc/motd writable and run motd generator if so # check if root
test -w $MOTD && motdGen isRoot
if [[ $? -ne 0 ]]; then
echo 'Script needs root privileges to alter motd. Re-run with sudo.'
exit 0
fi
# check arguments # check arguments
case "$1" in case "$1" in
@ -68,8 +50,40 @@ main () {
;; ;;
esac 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 { function prettyPrint {
declare -A a declare -A a

Loading…
Cancel
Save