diff --git a/bmotd.sh b/bmotd.sh index f34b939..3fbaa93 100755 --- a/bmotd.sh +++ b/bmotd.sh @@ -27,19 +27,22 @@ main () { case "$1" in enable) echo -e "\nEnabling bmotd.sh" - + + # copy to INSTPATH + cp "$(readlink -f $0)" "$INSTPATH" + # check if crontab present command -v crontab >/dev/null 2>&1 || ( echo "Error: couldn't find crontab. Exiting..."; exit 1) + # Check if motd writable + test -w $MOTD || ( echo "Unable to write $MOTD . To enable update permissions. Exiting..."; exit 1 ) + # Check if script is already in crontab, if not add itself - CRON_ENTRY="* * * * * $(realpath "$0")" + CRON_ENTRY="* * * * * $INSTPATH" crontab -l 2>/dev/null | grep -q "$CRON_ENTRY" || ( crontab -l 2>/dev/null; echo "$CRON_ENTRY" ) | crontab - echo -e "Success! Check it yourself with crontab -l" - # Check if motd writable - test -w $MOTD || echo "Unable to write $MOTD . To enable update permissions." - echo "Exiting." exit 0 ;;