#!/bin/bash # #This is network lib for confignetwork to configure bond/vlan/bridge awk="awk" sed="sed" cut="cut" sleep="sleep" sort="sort" ps="ps" head="head" readlink="readlink" basename="basename" udevadm="udevadm" touch="touch" tail="tail" dmesg="dmesg" grep="grep" lspci="lspci" ifup="ifup" ifdown="ifdown" nmcli="nmcli" dirname="dirname" ip="ip" ifconfig="ifconfig" brctl="brctl" uniq="uniq" xargs="xargs" modprobe="modprobe" if [ -n "$LOGLABEL" ]; then log_label=$LOGLABEL else log_label="xcat" fi ######################################################################### # ifdown/ifup will not be executed in diskful provision postscripts stage ######################################################################### reboot_nic_bool=1 if [ -z "$UPDATENODE" ] || [ $UPDATENODE -ne 1 ] ; then if [ "$NODESETSTATE" = "install" ] && ! grep "REBOOT=TRUE" /opt/xcat/xcatinfo >/dev/null 2>&1; then reboot_nic_bool=0 fi fi ###################################################### # # log lines # # input : info or warn or error or status # # output : multiple lines of string # ###################################################### function log_lines { local pcnt=$# local __level=$1 shift local cmd=log_${__level} local hit=0 local OIFS=$IFS local NIFS=$'\n' IFS=$NIFS local __msg for __msg in $* do IFS=$OIFS $cmd "$__msg" hit=1 IFS=$NIFS done IFS=$OIFS [ $hit -eq 0 -a $pcnt -le 1 ] && \ while read __msg; do $cmd "$__msg" done } ###################################################### # # error information # # input : string # # output : [E]: message # return : 0 # ###################################################### function log_error { local __msg="$*" $log_print_cmd $log_print_arg "[E]:Error: $__msg" logger -t $log_label -p local4.err "$__msg" return 1 } ###################################################### # # warning information # # input : string # # output : [W]: message # return : 0 # ###################################################### function log_warn { local __msg="$*" $log_print_cmd $log_print_arg "[W]: $__msg" logger -t $log_label -p local4.info "$__msg" return 0 } ###################################################### # # log information # # input : string # # output : [I]: message # return : 0 # ###################################################### function log_info { local __msg="$*" $log_print_cmd $log_print_arg "[I]: $__msg" logger -t $log_label -p local4.info "$__msg" return 0 } #################################################### # # print command status # # input : message # # output : [S]: message # ################################################### __my_log_status= function log_status { local __msg="$*" $log_print_cmd $log_print_arg "[S]: $__msg" # call my_log_status hook to triger more processing for status messages. if [ -n "$__my_log_status" ]; then $__my_log_status "$__msg" fi return 0 } #################################################### # # print output # ################################################### function log_print_default { printf "%s\n" "$*" } #################################################### # # handle command # ################################################### function set_log_print { local cmd="$1" if [ -z "$cmd" ]; then return 1 fi shift local args="$*" eval "log_print_cmd=\"$cmd\"" eval "log_print_arg=\"$args\"" } # let log work [ -z "$log_print" ] && set_log_print "log_print_default" ##################################################### # # uniq line in cfg files # # input : -t"str_for_FS" -k"num" # # output : text have no duplicate linkes # ##################################################### function uniq_per_key { local fs="" local keyno=0 local opt while getopts "t:k:" opt; do case $opt in t) fs="$OPTARG";; k) keyno="$OPTARG";; esac done shift $(($OPTIND - 1)) $awk ${fs:+"-F"}"$fs" -v keyno=$keyno ' BEGIN { cnt=0; } { if(!($keyno in keya)) { keya[$keyno]=cnt; cnt+=1; }; idx=keya[$keyno]; vala[idx]=$0; } END { for(i = 0; i < cnt; i++) { print vala[i]; }; }' } ################################################################################## # # load kernel module # # input : module= retry= interval=