#
#################################################################################
cd ~ || exit
-which crontab > /dev/null || exit
+which crontab > /dev/null || exit 0
CRON="$(cat_crontab)"
[ -n "$CRON" ] || exit
-[ "$(crontab -l)" != "$CRON" ] || exit
+[ "$(crontab -l)" = "$CRON" ] && exit
[ "$VERBOSE" -gt "0" ] && echo "Update crontab"
#echo "<$CRON>"
echo "$CRON" | crontab
#
#################################################################################
+################################################################################
#
# Checks and globals
#
+################################################################################
+
+# Ensure this script is run from the root of the repository
+REPO_ROOT="$(git rev-parse --show-toplevel)"
+[ -n "$REPO_ROOT" ] || exit
+cd "$REPO_ROOT" || exit
-#exec echo $0
-#eval "ls -1 "$0" | awk '{print $3}'"
CURRENT_USER="$(whoami)"
-FILE_USER="$(stat --format '%U' "$0")"
-#if [ "$(whoami)" != "$(stat --format '%U' "$0")" ]
+FILE_USER="$(stat --format '%U' "$REPO_ROOT")"
if [ "$CURRENT_USER" != "$FILE_USER" ]
then
- echo "Wrong user: $CURRENT_USER != $FILE_USER"
+ echo "Wrong user: $CURRENT_USER != $FILE_USER repo=$REPO_ROOT"
#exec sudo -u "$FILE_USER" "$0"
#su "$FILE_USER" -c "$0"
exit -1
fi
-#[ -z "$UID" ] && UID=`id -u`
-# NB 08.10.24 if [ "$UID" != "0" ] && echo "$NAME: please login as root." 1>&2 && exit 1
-
-# Ensure this script is run from the root of the repository
-REPO_ROOT="$(git rev-parse --show-toplevel)"
-[ -n "$REPO_ROOT" ] || exit
REPO_NAME="$(basename -s .git $(git remote get-url origin))"
[ -n "$REPO_NAME" ] || exit