REPO_NAME="$(basename -s .git $(git remote get-url origin))"
[ -n "$REPO_NAME" ] || exit
+################################################################################
#
-# Git hooks
+# Functions
#
-echo ">git-setup-hooks.sh"
-git-setup-hooks.sh | sed 's/^/ /'
+#################################################################################
+usage() {
+echo "
+=head1 NAME
+
+${NAME}
+
+=head1 SYNOPSIS
+
+Git pull repos
+ -nop, --no-post Don't post stats infos
+ -c, --cleanup Clean .git dir
+ -v, --verbose Print verbose mode
+ -d, --debug Print debug messages
+ -h, --help Print this help (alternatives: --man, --help2man)
+"
+}
+
+#################################################################################
+#
+# Args
+#
+#################################################################################
+CLEANUP=0
+PULL=0
+DEBUG=0
+VERBOSE=0
+while [ $# -gt 0 ]; do
+
+ case "$1" in
+ --cleanup|-c) CLEANUP=1 ;;
+ --pull|-pull) PULL=1 ;;
+
+ -*help|-h) usage | pod2text --width 250; exit 0 ;;
+ --man) usage | pod2man | man -l -; exit 0 ;;
+ --help2man) usage | pod2man; exit 0 ;;
+
+ --verbose|-v) VERBOSE=$(($VERBOSE+1)) ;;
+
+ --debug|-d) DEBUG=$(($DEBUG+1)) ;;
+
+ *) echo "Unknow option: $1 at $0!"; exit -1; ;;
+
+ esac
+ shift
+
+done
+
+#################################################################################
#
+# Main
+#
+#################################################################################
+exec {F_INDENT1}> >(sed 's/^/ /')
+exec {F_INDENT2}> >(sed 's/^/ /')
+trap 'exec {F_INDENT1}>&-; exec {F_INDENT2}>&-; echo BYE' EXIT
+
+if [ "$PULL" = "1" ]; then
+
+#V=1
+#echo ${V:-2}
+#(date;false) >&$F_INDENT2; exit
+
+#----------------------------------------------------------
+# Git pull
+#
+REPO_BRANCH=$(git branch --show-current) || exit
+[ -n "$REPO_BRANCH" ] || exit
+
+if [ -r ~/.ssh/agent.sh ]
+then
+ . ~/.ssh/agent.sh || exit
+fi
+#git_conn_check || exit
+
+echo ">Pull $REPO_NAME branch=$REPO_BRANCH user=$(whoami) path=$REPO_ROOT"
+git pull >&$F_INDENT1 || exit
+if [ "$CLEANUP" = "1" ]
+then
+ echo " >git gc cleanup"
+ git gc >&$F_INDENT1 || exit
+fi
+#echo
+
+fi # PULL
+#----------------------------------------------------------
+# Git hooks
+#
+echo " >git-setup-hooks.sh"
+git-setup-hooks.sh >&$F_INDENT2 || exit
+
+#----------------------------------------------------------
# *-install
#
if [ -x bin/$REPO_NAME-install ]
then
- echo ">$REPO_NAME-install"
- bin/$REPO_NAME-install | sed 's/^/ /'
+ echo " >$REPO_NAME-install"
+ bin/$REPO_NAME-install >&$F_INDENT2 || exit
fi
+
+#----------------------------------------------------------
+# git status
+#
+echo " >git status"
+git status --short
LOCK="/run/nb/$NAME.lock"
[ -z "$UID" ] && UID="$(id -u)"
-DEBUG=0
-[ "$1" = "-debug" ] && DEBUG=1 && shift
+################################################################################
+#
+# Functions
+#
+#################################################################################
+usage() {
+echo "
+=head1 NAME
+
+${NAME}
+=head1 SYNOPSIS
+
+Git pull repos
+
+ -nop, --no-post Don't post stats infos
+ -c, --cleanup Clean .git dir
+ -v, --verbose Print verbose mode
+ -d, --debug Print debug messages
+ -h, --help Print this help (alternatives: --man, --help2man)
+"
+}
+
+DEBUG=0
CLEANUP=0
-[ "$1" = "-cleanup" ] && CLEANUP=1 && shift
+POST_INFO=1
+PULL=0
+#################################################################################
+#
+# Args
+#
+#################################################################################
+#shopt -s extglob
+#${1?"Usage: $0 ARGUMENT"}
+REPO_NAME_FILTER=""
+while [ $# -gt 0 ]; do
+
+ case "$1" in
+ --pull|-pull) PULL=1 ;;
+ --cleanup|-cleanup|-c) CLEANUP=1 ;;
+ --no-post|-nop) POST_INFO=0 ;;
+
+ -*help|-h) usage | pod2text --width 250; exit 0 ;;
+ --man) usage | pod2man | man -l -; exit 0 ;;
+ --help2man) usage | pod2man; exit 0 ;;
-filter_name="$@"
+ --verbose|-v) VERBOSE=$(($VERBOSE+1)) ;;
+ --debug|-debug|-d) DEBUG=$(($DEBUG+1)) ;;
+
+ *) REPO_NAME_FILTER="$REPO_NAME_FILTER $1" ;;
+
+ esac
+ shift
+
+done
#####################################################################
#
# args filter on name
- if [ -n "$filter_name" ]; then
- #[ "$DEBUG" = "1" ] && echo "DEBUG: filter_name=$filter_name"
+ if [ -n "$REPO_NAME_FILTER" ]; then
+ #[ "$DEBUG" = "1" ] && echo "DEBUG: filter_name=$REPO_NAME_FILTER"
match=0
- for i in $filter_name; do
- #[ "$DEBUG" = "1" ] && echo "DEBUG: filter_name=$filter_name $i"
+ for i in $REPO_NAME_FILTER; do
+ #[ "$DEBUG" = "1" ] && echo "DEBUG: filter_name=$REPO_NAME_FILTER $i"
case "$name" in
$i) match=1; break ;;
#*) echo ">$i!=$name" ;;
esac
done
- #[ "$DEBUG" = "1" ] && echo "DEBUG: filter_name: match='$match' filter_name='$filter_name' name='$name'"
+ #[ "$DEBUG" = "1" ] && echo "DEBUG: filter_name: match='$match' filter_name='$REPO_NAME_FILTER' name='$name'"
[ "$match" = "1" ] || continue
fi
# preff to post report
preff="git.$dir"
- # include extra scripts
+ # include extra scripts
! [ -r "$NB_ROOT/lib/$NAME/repo.sh" ] || . "$NB_ROOT/lib/$NAME/repo.sh" || bye
+if [ "$PULL" = "1" ]
+then
+ #exec {F_INDENT}> >(sed 's/^/ /')
+ exec_user $user "nb-repo-install --pull" #>&$F_INDENT 2>&1
+ exp_repo=$?
+ [ "$ex_repo" = "0" ] || ex=$ex_repo
+ #exec {F_INDENT}>&-
+else # PULL
#
# Build command
#
ex_repo=$ex_cmd_root
echo ">err $ex_cmd_root"
fi
- # NB 08.10.24 [ -x bin/$name-install ] && \
- # NB 08.10.24 cmd_root="$cmd_root && echo ' >$name-install' && (git-setup-hooks.sh;bin/$name-install)|sed 's/^/ /'"
- # NB 08.10.24 if [ "$cmd_root" != "true" ]; then
- # NB 08.10.24 exec_user $user "$cmd_root"
- # NB 08.10.24 ex_cmd_root=$?
- # NB 08.10.24 if [ "$ex_cmd_root" -gt "0" ]; then
- # NB 08.10.24 ex_repo=$ex_cmd_root
- # NB 08.10.24 echo ">err $ex_cmd_root"
- # NB 08.10.24 fi
- # NB 08.10.24 fi
fi
[ "$ex_repo" = "0" ] && ex_repo="$(exec_user $user git status --short &> /dev/null; echo $?)"
+fi # PULL
[ "$ex_repo" = "0" ] || ex=$ex_repo
- echo
- echo " >Post repo infos"
- (
- nb_api_post_host_info "$preff.name" "$name"
- nb_api_post_host_info "$preff.path" "$dir"
- nb_api_post_host_info "$preff.branch" "$branch"
- nb_api_post_host_info "$preff.url" "$(exec_user $user git remote get-url origin)"
- nb_api_post_host_info "$preff.exit_code" "$ex_repo"
- ) 2>/dev/null | sed -E -e 's/^/ /; s/'$'\t''/: /'
+ if [ "$POST_INFO" = "1" ]
+ then
+ echo
+ echo " >Post repo infos"
+ (
+ nb_api_post_host_info "$preff.name" "$name"
+ nb_api_post_host_info "$preff.path" "$dir"
+ nb_api_post_host_info "$preff.branch" "$branch"
+ nb_api_post_host_info "$preff.url" "$(exec_user $user git remote get-url origin)"
+ nb_api_post_host_info "$preff.exit_code" "$ex_repo"
+ ) 2>/dev/null | sed -E -e 's/^/ /; s/'$'\t''/: /'
+ fi
echo
done
# Update infos
#
# Delete old lock
-sys_info_lock="/run/nb/$NAME-post.lock"
-find $sys_info_lock -mmin +$((60*24*30)) -exec rm {} \; >/dev/null 2>&1
-if [ ! -e $sys_info_lock ]
+if [ "$POST_INFO" = "1" ]
then
- touch $sys_info_lock
+ sys_info_lock="/run/nb/$NAME-post.lock"
+ find $sys_info_lock -mmin +$((60*24*30)) -exec rm {} \; >/dev/null 2>&1
+ if [ ! -e $sys_info_lock ]
+ then
+ touch $sys_info_lock
- echo ">Post sys infos"
- nb_api_post_hosts_infos | tee /run/nb/sys.csv.tmp | sed -e 's/^/ /; s/'$'\t''/: /'
- [ -e /run/nb/sys.csv.tmp ] && sed -e 's/^sys\.//' /run/nb/sys.csv.tmp > /run/nb/sys.csv
- rm -f /run/nb/sys.csv.tmp
- echo
+ echo ">Post sys infos"
+ nb_api_post_hosts_infos | tee /run/nb/sys.csv.tmp | sed -e 's/^/ /; s/'$'\t''/: /'
+ [ -e /run/nb/sys.csv.tmp ] && sed -e 's/^sys\.//' /run/nb/sys.csv.tmp > /run/nb/sys.csv
+ rm -f /run/nb/sys.csv.tmp
+ echo
+ fi
fi
#####################################################################