]> git.nbdom.net Git - nb.git/commitdiff
etc/profile.d/nb.sh
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 18 Feb 2019 04:43:55 +0000 (04:43 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 18 Feb 2019 04:43:55 +0000 (04:43 +0000)
bin/nb-install
etc/profile.d/functions
etc/profile.d/nb.sh
lib/sh/nb-update.sh

index 373f1effd68e4f901dc794ec62a78c941ed609d1..80beed0f95546c4f406e6767de095ac3eaee89da 100755 (executable)
@@ -123,108 +123,4 @@ main() {
 
 }
 
-cron_d_install() {
-       local usage fname file exp cron tmp test
-       usage="Usage: $FUNCNAME [-t|--test] [CRON_D_FILE] [IGNORE_REGEXP] or [NAME] [CRON_D_CONTENT] [IGNORE_REGEXP]"
-       #shell_help_noarg "$usage" "$@" && return 1
-       #shell_help "$usage" "$@" && return 1
-       [ -z "$*" ] && echo "$usage" && return 1
-       if ! perl -e '' 2>/dev/null; then
-               echo "$FUNCNAME: please install perl" 1>&2
-               return 1
-       fi
-
-       if [ "$#" -gt 0 ]; then
-               case "$1" in -t|--test) test=1; shift ;; esac
-       fi
-
-       #echo "$#"; return
-       if [ $# -gt 4 -o $# = 0 ]; then
-               shell_help_noarg "$usage" "--help" && return 1
-
-       #elif [ $# -eq 3 ]; then
-       elif [ ! -e "$1" ]; then
-               fname=$1; shift
-               tmp="/tmp/$FUNCNAME.$$"
-               trap "rm -f $tmp*" EXIT
-               file="$tmp.cron"
-# NB 31.08.16     cat <<< "$1" > "$file"; shift
-               echo "$1" > "$file"; shift
-               exp=$1; shift
-
-       else
-               file=$1; shift
-               exp=$1; shift
-               fname=$(basename "$file")
-
-       fi
-
-       #
-       # Case 1 - /etc/cron.d
-       #
-       if [ -d /etc/cron.d ]; then
-
-               if [ "$test" = "1" ]; then
-                       printf '%s' "$FUNCNAME: /etc/cron.d: $fname"
-                       [ "$(cat $file 2>/dev/null)" != "$(cat /etc/cron.d/$fname 2>/dev/null)" ] && echo ': Changed' && return
-                       echo ': Not changed'
-                       return 1
-               fi
-
-               [ "$(cat $file 2>/dev/null)" != "$(cat /etc/cron.d/$fname 2>/dev/null)" ] && cp "$file" "/etc/cron.d/$fname"
-               return
-       fi
-
-       #
-       # Case 2 - crontab
-       #
-
-       cron=$(perl -e '
-$diff = 0;
-$e = shift @ARGV;
-
-@f = map {chomp; $_} grep {!/^(#|\s*$)/} <>;
-for ($i=0;$i<@f;$i++) {
-       @F = split(" ",$f[$i]);
-       next if $f[$i] !~ /^[\*\d]/ or @F<6;
-       if ($F[5] ne "root"){
-        $_ = join(" ",@F[6..$#F]);
-        s/"/\\"/g;
-        @_=qq|su -l "$F[5]" -c "$_"|;
-        @F = (@F[0..4],"",@_);
-       };
-       $f[$i] = join(" ",@F[0..4,6..$#F]);
-}
-%f = map {$_=>1} @f;
-
-@ARGV = ("crontab -l|");
-@c = map {chomp; $_} <>;
-%c = map {$_=>1} @c;
-
-for (@c) {
-       0 and print STDERR "-$_\n" if $e and !$f{$_} and /$e/;
-       $diff=1 and next if $e and !$f{$_} and /$e/;
-       print "$_\n";
-}
-
-for (@f) {
-       $diff=2 and print "$_\n" if !$c{$_};
-}
-
-exit $diff ? 0 : 1;
-' "$exp" "$file"
-)
-
-       if [ "$test" = "1" ]; then
-               printf '%s' "$FUNCNAME: crontab: $fname"
-               #echo -e "\n<\n$(crontab -l)\n>\n<\n$cron\n>\n"
-               [ "$cron" != "$(crontab -l)" ] && echo ': Changed' && return
-               echo ": Not changed; return 1"
-       fi
-
-# NB 31.08.16   [ "$cron" != "$(crontab -l)" ] && crontab <<< "$cron"
-       [ "$cron" != "$(crontab -l)" ] && echo "$cron" | crontab
-
-}
-
 main
index 39303c5cc4bbfed761663d8232493ed49c0d8309..58bcf33ab42f8429560be9d3af07218af4876a20 100755 (executable)
@@ -875,3 +875,106 @@ xml2csv() {
 # NB 16.01.18 ' $noheader
 # NB 16.01.18 }
 
+cron_d_install() {
+       local usage fname file exp cron tmp test
+       usage="Usage: $FUNCNAME [-t|--test] [CRON_D_FILE] [IGNORE_REGEXP] or [NAME] [CRON_D_CONTENT] [IGNORE_REGEXP]"
+       #shell_help_noarg "$usage" "$@" && return 1
+       #shell_help "$usage" "$@" && return 1
+       [ -z "$*" ] && echo "$usage" && return 1
+       if ! perl -e '' 2>/dev/null; then
+               echo "$FUNCNAME: please install perl" 1>&2
+               return 1
+       fi
+
+       if [ "$#" -gt 0 ]; then
+               case "$1" in -t|--test) test=1; shift ;; esac
+       fi
+
+       #echo "$#"; return
+       if [ $# -gt 4 -o $# = 0 ]; then
+               shell_help_noarg "$usage" "--help" && return 1
+
+       #elif [ $# -eq 3 ]; then
+       elif [ ! -e "$1" ]; then
+               fname=$1; shift
+               tmp="/tmp/$FUNCNAME.$$"
+               trap "rm -f $tmp*" EXIT
+               file="$tmp.cron"
+# NB 31.08.16     cat <<< "$1" > "$file"; shift
+               echo "$1" > "$file"; shift
+               exp=$1; shift
+
+       else
+               file=$1; shift
+               exp=$1; shift
+               fname=$(basename "$file")
+
+       fi
+
+       #
+       # Case 1 - /etc/cron.d
+       #
+       if [ -d /etc/cron.d ]; then
+
+               if [ "$test" = "1" ]; then
+                       printf '%s' "$FUNCNAME: /etc/cron.d: $fname"
+                       [ "$(cat $file 2>/dev/null)" != "$(cat /etc/cron.d/$fname 2>/dev/null)" ] && echo ': Changed' && return
+                       echo ': Not changed'
+                       return 1
+               fi
+
+               [ "$(cat $file 2>/dev/null)" != "$(cat /etc/cron.d/$fname 2>/dev/null)" ] && cp "$file" "/etc/cron.d/$fname"
+               return
+       fi
+
+       #
+       # Case 2 - crontab
+       #
+
+       cron=$(perl -e '
+$diff = 0;
+$e = shift @ARGV;
+
+@f = map {chomp; $_} grep {!/^(#|\s*$)/} <>;
+for ($i=0;$i<@f;$i++) {
+       @F = split(" ",$f[$i]);
+       next if $f[$i] !~ /^[\*\d]/ or @F<6;
+       if ($F[5] ne "root"){
+        $_ = join(" ",@F[6..$#F]);
+        s/"/\\"/g;
+        @_=qq|su -l "$F[5]" -c "$_"|;
+        @F = (@F[0..4],"",@_);
+       };
+       $f[$i] = join(" ",@F[0..4,6..$#F]);
+}
+%f = map {$_=>1} @f;
+
+@ARGV = ("crontab -l|");
+@c = map {chomp; $_} <>;
+%c = map {$_=>1} @c;
+
+for (@c) {
+       0 and print STDERR "-$_\n" if $e and !$f{$_} and /$e/;
+       $diff=1 and next if $e and !$f{$_} and /$e/;
+       print "$_\n";
+}
+
+for (@f) {
+       $diff=2 and print "$_\n" if !$c{$_};
+}
+
+exit $diff ? 0 : 1;
+' "$exp" "$file"
+)
+
+       if [ "$test" = "1" ]; then
+               printf '%s' "$FUNCNAME: crontab: $fname"
+               #echo -e "\n<\n$(crontab -l)\n>\n<\n$cron\n>\n"
+               [ "$cron" != "$(crontab -l)" ] && echo ': Changed' && return
+               echo ": Not changed; return 1"
+       fi
+
+# NB 31.08.16   [ "$cron" != "$(crontab -l)" ] && crontab <<< "$cron"
+       [ "$cron" != "$(crontab -l)" ] && echo "$cron" | crontab
+
+}
index c01d7b720bc543b85662b2eab81cc0241952a39f..f94b03fc39b47adbcec41f420672f74f843f460e 100644 (file)
@@ -85,6 +85,7 @@ nb_api() {
        local uri="$1"; shift
 
        if [ -n "$NB_AUTH" -a x = x$(awk '/^machine api.nbdom.net / { print $4":"$6}' $HOME/.netrc 2> /dev/null) ]; then
+#echo $NB_AUTH 1>&2
 # NB 16.01.19  if [ -z "$NB_AUTH" -o x = x$(awk '/^machine api.nbdom.net / { print $4":"$6}' $HOME/.netrc 2> /dev/null) ]; then
                curl -sfS -u "$NB_AUTH" "https://api.nbdom.net$uri" "$@"
        else
@@ -92,3 +93,39 @@ nb_api() {
        fi
 }
 
+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" "$@"
+}
index 3bd7977121a979ff1e7a098254b7975f29bb168d..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 (file)
@@ -1,36 +0,0 @@
-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" "$@"
-}