]> git.nbdom.net Git - nb.git/commitdiff
etc/profile.d/nb.sh
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Sun, 10 Mar 2019 02:28:53 +0000 (02:28 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Sun, 10 Mar 2019 02:28:53 +0000 (02:28 +0000)
bin/nb-update
etc/profile.d/nb.sh

index 4967d5fa114c8cc4686661676a02152eda1ccaac..4c07af56f2c11cf1ff1834e162a90750382ec8bf 100755 (executable)
@@ -137,7 +137,7 @@ 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
+       nb_api_post_hosts_infos 2>/dev/null
 fi
 
 #####################################################################
index 577744fd928dd74dea622f9e192b78c35d5acc77..98f99319eceacb2377aaf12eb10afac90d84c9cc 100644 (file)
@@ -98,34 +98,32 @@ nb_api_table_post() {
        local debug=0; [ "$1" = "-debug" ] && debug=1 && shift
        local table="${1:?$usage}"; shift
 
-       local curl="nb_api /data/$table/replace.sh"
-
-       local args="$*"
+       local args=()
        while [ "$#" -gt "0" ]; do
-               curl="$curl -d \"$1\""
+               args+=(-d)
+               args+=("$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 "sys.${i[0]}" "${i[1]}"
-       done
+       nb_api /data/$table/replace.sh "${args[@]}"
 }
 
 nb_api_post_host_info() {
+       [ $# = 0  ] && echo "Usage: nb_api_post_host_info key=? val=?" && return 1
        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" "$@"
+       nb_api_table_post host_info "host=$host" "key=$1" "val=${i[*]:1}"
+}
+
+nb_api_post_hosts_infos() {
+       sys_infos | while read -ra i; do
+               nb_api_post_host_info "sys.${i[0]}" "${i[*]:1}"
+       done
+
+       which lshw > /dev/null && lshw -quiet -class system \
+               | awk '/^ /{sub("^ *","",$0); sub(": ","\t",$0); print $0}' \
+               | while read -ra i \
+       ; do
+               nb_api_post_host_info "sys.${i[0]}" "${i[*]:1}"
+       done
 }