[ "$1" = "-cleanup" ] && CLEANUP=1
#####################################################################
-#
-# Functions
-#
-#####################################################################
-run_parts_minutes() {
- local usage="run_parts_minutes MINUTES DIR" \
- local min=${1:?$usage}; min=$(($min-1))
- local dir=${2:?$usage}
- local lock="/run/run_parts_minutes.$min"
- #echo $min $dir
- find "$lock" -mmin +$min -exec rm {} \; >/dev/null 2>&1
- [ -e "$lock" ] && return
- #touch "$lock" || return
- run-parts -v --test --report "$dir"
- echo BYE
-}
-if [ "$1" = "-test" ]; then
- run_parts_minutes 1 /tmp/run/
- exit 0
-fi
-
#
# Requirments
#
+#####################################################################
. $(dirname "$0")/../etc/profile || exit 1; [ -z "$NB_ROOT" ] && exit
+! [ -e "$NB_ROOT/lib/sh/$NAME.sh" ] || . "$NB_ROOT/lib/sh/$NAME.sh" || exit
if ! which git > /dev/null; then
- echo "$NAME: can't find git!" 1>&2
- exit 1
+ echo "$NAME: can't find git!" 1>&2
+ exit 1
fi
ex=0
filter_name="$@"
for repo in $(nb_repos); do
- [ -d "$repo/.git" ] || continue
- [ ! -w "$repo/.git" ] && echo ">No Permission $repo" && echo && continue
- cd "$repo" || continue
+ [ -d "$repo/.git" ] || continue
+ [ ! -w "$repo/.git" ] && echo ">No Permission $repo" && echo && continue
+ cd "$repo" || continue
- # name from git not from path
- name=$(git_name) || continue
- [ -z "$name" ] && continue
+ # name from git not from path
+ name=$(git_name) || continue
+ [ -z "$name" ] && continue
- # args filter on name
- if [ -n "$filter_name" ]; then
- match=0
- for i in $@; do
- case "$name" in
+ # args filter on name
+ if [ -n "$filter_name" ]; then
+ match=0
+ for i in $@; do
+ case "$name" in
$i) match=1; break ;;
#*) echo ">$i!=$name" ;;
- esac
- done
- [ "$match" = "1" ] || continue
- fi
-
- branch=$(git_branch) || continue
- [ -z "$branch" ] && continue
-
- #
- # Get user
- #
- user=`ls -dl "$repo/.git" |awk '{print $3}'`
-
- cmd=""
-
- #
- # Check ssh agent sh file
- #
- agent=$(eval realpath ~$user/.ssh/agent.sh)
- [ -r "$agent" ] && cmd=". $agent && "
- #[ -r "$agent" ] && echo "Found agent $agent"
-
- #
- # Pull
- #
- echo ">Pull $name branch=$branch user=$user path=$repo"
-
- cmd="${cmd}GIT_SSH=$GIT_SSH cd \"$repo\" && git pull"
- [ "$CLEANUP" = "1" ] && cmd="$cmd && git gc"
-
- if [ 1 = 1 ] && ! git_conn_check; then
- echo
- elif [ "$USER" = "$user" ]; then
- sh -c "$cmd"
- elif [ "$USER" = "root" ]; then
- su $user -c "$cmd"
- else
- echo "Wrong user current user=$USER repo user=$user"
- false
- fi
- ret=$?
-
- #
- # *-install
- #
- if [ "$ret" != "0" ]; then
- ex=$ret && echo ">err $ret"
-
- else
- cmd_root="true"
- # NB 23.04.18: TODEL
+ esac
+ done
+ [ "$match" = "1" ] || continue
+ fi
+
+ branch=$(git_branch) || continue
+ [ -z "$branch" ] && continue
+
+ #
+ # Get user
+ #
+ user=`ls -dl "$repo/.git" |awk '{print $3}'`
+
+ cmd=""
+
+ #
+ # Check ssh agent sh file
+ #
+ agent=$(eval realpath ~$user/.ssh/agent.sh)
+ [ -r "$agent" ] && cmd=". $agent && "
+ #[ -r "$agent" ] && echo "Found agent $agent"
+
+ #
+ # Pull
+ #
+ echo ">Pull $name branch=$branch user=$user path=$repo"
+
+ cmd="${cmd}GIT_SSH=$GIT_SSH cd \"$repo\" && git pull"
+ [ "$CLEANUP" = "1" ] && cmd="$cmd && git gc"
+
+ if [ 1 = 1 ] && ! git_conn_check; then
+ echo
+ elif [ "$USER" = "$user" ]; then
+ sh -c "$cmd"
+ elif [ "$USER" = "root" ]; then
+ su $user -c "$cmd"
+ else
+ echo "Wrong user current user=$USER repo user=$user"
+ false
+ fi
+ ret=$?
+
+ #
+ # *-install
+ #
+ if [ "$ret" != "0" ]; then
+ ex=$ret && echo ">err $ret"
+
+ else
+ cmd_root="true"
+ # NB 23.04.18: TODEL
# NB 24.07.18 [ "$(git config --get remote.origin.url)" = "git@git.nbdom.net:root.git" ] && git remote set-url origin git.nbdom.net:/home/git/root.git
# NB 24.07.18 [ "$(git config --get remote.origin.url)" = "git@git.nbdom.net:nbdom.git" ] && git remote set-url origin git.nbdom.net:/home/git/nbdom.git
# NB 24.07.18 [ "$(git config --get remote.origin.url)" = "git@git.nbdom.net:pi.git" ] && git remote set-url origin git.nbdom.net:/home/git/pi.git
- [ -x bin/$name-install ] && cmd_root="$cmd_root && echo ' >$name-install' && bin/$name-install|sed 's/^/ /'"
- if [ "$cmd_root" != "true" ]; then
- eval "$cmd_root"
- ex=$?
- [ "$ex" -gt "0" ] && echo ">err"
- fi
+ [ -x bin/$name-install ] && cmd_root="$cmd_root && echo ' >$name-install' && bin/$name-install|sed 's/^/ /'"
+ if [ "$cmd_root" != "true" ]; then
+ eval "$cmd_root"
+ ex=$?
+ [ "$ex" -gt "0" ] && echo ">err"
+ fi
- fi
+ fi
- echo
- nb_api_post_host_info "key=${NAME}.$repo" "val=name:$name branch:$branch"
-# NB 06.02.18 key="repo.$name.$branch"
-# NB 06.02.18 nb_api_post_host_info "key=${key}.path" "val=$repo"
-# NB 06.02.18 nb_api_post_host_info "key=${key}.exit_code" "val=$ex"
+ echo
+ (
+ nb_api_post_host_info "${NAME}.$repo" "name:$name branch:$branch"
+ # NB 06.02.18 key="repo.$name.$branch"
+ # NB 06.02.18 nb_api_post_host_info "${key}.path" "$repo"
+ # NB 06.02.18 nb_api_post_host_info "${key}.exit_code" "$ex"
+ ) 2>/dev/null
done
#####################################################################
# Update infos
#
-rm -f /tmp/$NAME.infos /tmp/$NAME.check
-find /run/$NAME-nb_post_sys_infos.lock -mmin +60 -exec rm {} \; >/dev/null 2>&1
-if [ ! -e /run/$NAME-nb_post_sys_infos.lock ]; then
- touch /run/$NAME-nb_post_sys_infos.lock
- nb_post_sys_infos
+rm -f /tmp/$NAME.infos /tmp/$NAME.check /run/$NAME-nb_post_sys_infos.lock
+find /run/$NAME-nb_api_post_sys_infos.lock -mmin +60 -exec rm {} \; >/dev/null 2>&1
+if [ ! -e /run/$NAME-nb_api_post_sys_infos.lock ]; then
+ touch /run/$NAME-nb_api_post_sys_infos.lock
+ nb_api_post_sys_infos 2>/dev/null
fi
#####################################################################
#
rm -f "$TMP"
if [ "$ex" = "0" ]; then
- printf ">OK\n"
+ printf ">OK\n"
else
- printf ">ERR\n"
+ printf ">ERR\n"
fi
exit $ex
--- /dev/null
+nb_api_table_post() {
+ local usage="Usage: nb_api_table_post TABLE field1=val1 field2=val2 ..."
+ local debug=0; [ "$1" = "-debug" ] && debug=1 && shift
+ local table="${1:?$usage}"; shift
+
+ local curl="nb_api /data/$table/replace.sh"
+
+ local args="$*"
+ while [ "$#" -gt "0" ]; do
+ curl="$curl -d \"$1\""
+ shift
+ done
+ if [ "$debug" = "1" ]; then
+ echo "$curl"; return
+ fi
+ eval "$(eval "$curl")" #&& echo "$table: $rowCount: $args"
+# NB 15.02.19 (
+# NB 15.02.19 eval "$(eval "$curl")" #&& echo "$table: $rowCount: $args"
+# NB 15.02.19 #eval "$curl" #&& echo "$table: $rowCount: $args"
+# NB 15.02.19 )
+}
+
+nb_api_post_sys_infos() {
+ # To be compatible with other sed that does not support \t
+ sys_infos | while read -ra i; do
+ nb_api_post_host_info "${i[0]}" "${i[1]}"
+ done
+}
+
+nb_api_post_host_info() {
+ local host=$(hostname)
+ [ -z "$*" ] && echo "Usage: nb_api_post_host_info key=? val=?" && return 1
+ [ -z "$host" ] && host=$(hostname -f)
+ nb_api_table_post host_info "host=$host" "key=$1" "val=$2"
+ #nb_api_table_post host_info "host=$host" "$@"
+}