]> git.nbdom.net Git - nb.git/commitdiff
bin/nb-repo-install
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 9 Oct 2024 11:10:31 +0000 (13:10 +0200)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 9 Oct 2024 11:10:31 +0000 (13:10 +0200)
bin/git-setup-hooks.sh
bin/nb-repo-install
bin/nb-update

index 405b288a8ef2c95fc2b5877247e170519027bd52..2653732a3f802b5af25e3f2419681b8692e3300e 100755 (executable)
@@ -10,7 +10,7 @@ GIT_HOOKS_DIR="$REPO_ROOT/.git/hooks"
 
 # Copy or symlink the pre-commit hook
 #echo "Setting up Git hooks..."
-[ -d "$HOOKS_DIR" ] || exit
+[ -d "$HOOKS_DIR" ] || exit 0
 
 for hook in "$HOOKS_DIR"/*; do
   hook_name=$(basename "$hook")
index 63a6f121349e67e9d33cf52387acd497648695e0..c25683e549ba7d04935c24d62ec259cda3d872b0 100755 (executable)
@@ -31,17 +31,113 @@ REPO_ROOT="$(git rev-parse --show-toplevel)"
 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
index 40802a8ec977553cecb4b26fc37ea7b87ab6e174..1263a9bbd9e023f13e27434a18fc58844b2eb60d 100755 (executable)
@@ -11,13 +11,61 @@ TMP="/tmp/$NAME.$$"
 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
 
 #####################################################################
 #
@@ -101,17 +149,17 @@ for dir in $(nb_repos); do
 
 
        # 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
 
@@ -124,9 +172,17 @@ for dir in $(nb_repos); do
        # 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
        #
@@ -179,31 +235,25 @@ for dir in $(nb_repos); do
                        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
@@ -224,17 +274,20 @@ fi
 # 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
 
 #####################################################################