From: Nicolas Boisselier Date: Mon, 8 Aug 2016 16:10:49 +0000 (+0200) Subject: cleanup X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=67dad5c2c5ffbc9715c2881499a9e91285a753a5;p=nb.git cleanup --- diff --git a/bin/nb-update b/bin/nb-update index b08fc692..ba04e1c5 100755 --- a/bin/nb-update +++ b/bin/nb-update @@ -10,6 +10,8 @@ . "${BASH_SOURCE%/*}/../etc/profile" || exit declare -r NAME="$(basename "${0}")" declare -r TMP="/tmp/$NAME.tmp" +declare CLEANUP=0 +[ "$1" = "-cleanup" ] && CLEANUP=1 ##################################################################### # Git Connection check @@ -72,12 +74,13 @@ for repo in $(nb-repo-dirs); do echo ">git pull $repo (user=$user)" cmd="GIT_SSH=$GIT_SSH cd \"$repo\" && git pull" + [ "$CLEANUP" = "1" ] && cmd="$cmd && git gc" if [ 1 = 1 ] && ! git_conn_check; then [ 1 = 1 ] - elif [ "$USER" == "$user" ]; then + elif [ "$USER" = "$user" ]; then bash -c "$cmd" - elif [ "$USER" == "root" ]; then + elif [ "$USER" = "root" ]; then su $user -c "$cmd" else echo "Ignore $repo: current user=$USER repo user=$user" @@ -107,7 +110,7 @@ rm -f "$TMP" ##################################################################### # End # -if [ "$ex" == "0" ]; then +if [ "$ex" = "0" ]; then printf ">OK\n" else printf ">ERR\n" diff --git a/etc/cron/nb b/etc/cron/nb index a7f55b50..2a676af4 100644 --- a/etc/cron/nb +++ b/etc/cron/nb @@ -9,4 +9,5 @@ PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/nb/bin # m h dom mon dow user command # */15 09-23 * * * root nb-update >/var/log/nb.log 2>&1 || cat /var/log/nb.log -0 00-08 * * * root nb-update >/var/log/nb.log 2>&1 || cat /var/log/nb.log +0 00 * * * root nb-update -cleanup >/var/log/nb.log 2>&1 || cat /var/log/nb.log +0 01-08 * * * root nb-update >/var/log/nb.log 2>&1 || cat /var/log/nb.log