Update script files

Accept date instead of gdaye if it is actually gnu date
This commit is contained in:
Rob Pearce 2021-12-23 16:28:03 +11:00
parent 6c268c3f3b
commit 4fb75769c3
1 changed files with 23 additions and 13 deletions

View File

@ -163,7 +163,7 @@ function loadcachefile() { # loadcachefile [dc1 dc2 ...]
function uuid_callback() { function uuid_callback() {
nuuids=0 nuuids=0
loadcachefile $curlocs loadcachefile $curlocs
uuidend=$(($(gdate +%s%N)/1000)) uuidend=$(($($GDATE +%s%N)/1000))
uuidsecs=$(echo "scale=2; ($uuidend - $uuidstart) / 1000000;" | bc) uuidsecs=$(echo "scale=2; ($uuidend - $uuidstart) / 1000000;" | bc)
if [[ $nuuids -ge 1 ]]; then if [[ $nuuids -ge 1 ]]; then
@ -193,7 +193,7 @@ function start_recache_if_needed() {
function start_recache() { function start_recache() {
local rv local rv
uuidstart=$(($(gdate +%s%N)/1000)) uuidstart=$(($($GDATE +%s%N)/1000))
if [[ -z $recache_pid ]]; then if [[ -z $recache_pid ]]; then
# setup callback for uuid cache reload handling # setup callback for uuid cache reload handling
trap uuid_callback SIGUSR1 trap uuid_callback SIGUSR1
@ -1157,13 +1157,13 @@ function getbasefilter() { # epidx [regexp_filter]
function profile_start() { function profile_start() {
profile "start profiling" profile "start profiling"
prof_start=$(($(gdate +%s%N)/1000)) prof_start=$(($($GDATE +%s%N)/1000))
prof_last="$prof_start" prof_last="$prof_start"
} }
function profile_mark() { function profile_mark() {
local now secs local now secs
now=$(($(gdate +%s%N)/1000)) now=$(($($GDATE +%s%N)/1000))
secs=$(echo "scale=2; ($now - $prof_last) / 1000000;" | bc) secs=$(echo "scale=2; ($now - $prof_last) / 1000000;" | bc)
profile "[+${secs} secs] $* " profile "[+${secs} secs] $* "
prof_last="$now" prof_last="$now"
@ -1253,7 +1253,7 @@ function runaction() { # runaction <nodes|vms|etc> <actionname> targetlist optio
local jqf_bad='[ "_DC_", "_OB_", .fault.detail, .fault.reason, .status ] | @csv' local jqf_bad='[ "_DC_", "_OB_", .fault.detail, .fault.reason, .status ] | @csv'
local objecttype extrainfo local objecttype extrainfo
start=$(($(gdate +%s%N)/1000)) start=$(($($GDATE +%s%N)/1000))
lastqsecs="" lastqsecs=""
lastprocsecs="" lastprocsecs=""
what="$1" what="$1"
@ -1380,7 +1380,7 @@ debug "extrainfo is: $extrainfo"
rm -f $TMPDIR/run,* rm -f $TMPDIR/run,*
fi fi
end=$(($(gdate +%s%N)/1000)) end=$(($($GDATE +%s%N)/1000))
lastqsecs=$(echo "scale=2; ($end - $start) / 1000000;" | bc) lastqsecs=$(echo "scale=2; ($end - $start) / 1000000;" | bc)
return $rv return $rv
} }
@ -1408,7 +1408,7 @@ function getdata() { # getdata <nodes|vms|etc> <cmd> options
local errordebug=0 local errordebug=0
local quiet=0 ignorecase=0 local quiet=0 ignorecase=0
start=$(($(gdate +%s%N)/1000)) start=$(($($GDATE +%s%N)/1000))
lastqsecs="" lastqsecs=""
lastprocsecs="" lastprocsecs=""
what="$1" what="$1"
@ -1545,9 +1545,9 @@ debug all pids finished
fi fi
debug "combined results: [$all]" debug "combined results: [$all]"
end=$(($(gdate +%s%N)/1000)) end=$(($($GDATE +%s%N)/1000))
lastqsecs=$(echo "scale=2; ($end - $start) / 1000000;" | bc) lastqsecs=$(echo "scale=2; ($end - $start) / 1000000;" | bc)
start=$(($(gdate +%s%N)/1000)) start=$(($($GDATE +%s%N)/1000))
rescount=$(printf %d $(echo -n "$all" | wc -c)) rescount=$(printf %d $(echo -n "$all" | wc -c))
if [[ $rescount -eq 0 ]]; then if [[ $rescount -eq 0 ]]; then
@ -1671,7 +1671,7 @@ debug "wantcols is [$wantcols]"
#end=$(($(gdate +%s%N)/1000)) #end=$(($(gdate +%s%N)/1000))
#lastqsecs=$(echo "scale=2; ($end - $start) / 1000000;" | bc) #lastqsecs=$(echo "scale=2; ($end - $start) / 1000000;" | bc)
end=$(($(gdate +%s%N)/1000)) end=$(($($GDATE +%s%N)/1000))
lastprocsecs=$(echo "scale=2; ($end - $start) / 1000000;" | bc) lastprocsecs=$(echo "scale=2; ($end - $start) / 1000000;" | bc)
} }
@ -2160,10 +2160,20 @@ function setproject() { # setproject [project_name]
function checkfor() { # checkfor name [pkg_name] function checkfor() { # checkfor name [pkg_name]
local what pkgname local what pkgname
local os ok=0 confirm=0 local os ok=0 confirm=0
local alt rv
what=$1 what=$1
pkg_name=${2:-$what} pkg_name=${2:-$what}
os=$(uname -s) os=$(uname -s)
which $what >/dev/null 2>&1 which $what >/dev/null 2>&1
rv=$?
if [[ $rv -ne 0 && $what == "gdate" ]]; then
date --version 2>/dev/null | grep -q GNU 2>/dev/null
if [[ $? -eq 0 ]] then
GDATE=$(which date)
rv=0
fi
fi
if [[ $? -eq 0 ]]; then if [[ $? -eq 0 ]]; then
ok=1 ok=1
else else
@ -2367,6 +2377,7 @@ addcmd -a q "Exit from gnscli" 0
VERBOSE=0 VERBOSE=0
GDATE="gdate"
CONFDIR="$HOME/.gnscli" CONFDIR="$HOME/.gnscli"
HISTFILE="$CONFDIR/history" HISTFILE="$CONFDIR/history"
TMPDIR="$CONFDIR/tmp" TMPDIR="$CONFDIR/tmp"
@ -2569,11 +2580,10 @@ END {
"Model UUID#" + .template_id, "Model UUID#" + .template_id,
"Project UUID#" + .project_id, "Project UUID#" + .project_id,
"Status#" + .status, "Status#" + .status,
"Console port#" + ((.console|tostring) // "n/a"),
"Locked#" + (.locked // "n/a"),
"Port format#" + .port_name_format, "Port format#" + .port_name_format,
"Locked#" + (.locked // "n/a"),
"Console port#" + ((.console|tostring) // "n/a"),
"Port count#" + try (.ports[] | length) catch ("unknown"), "Port count#" + try (.ports[] | length) catch ("unknown"),
"__END__"
#END_INLINE:node.jq #END_INLINE:node.jq
#START_INLINE:link.jq #START_INLINE:link.jq
"UUID#" + .link_id, "UUID#" + .link_id,