DEFUSER=alex declare -i TRUE=0 declare -i FALSE=1 # files from 2 hosts considered same time MAXTIMEDIFF=5 if [ "z$(which usleep)" = "z" ] then function usleep () { tutu=`expr $1 / 1000000` sleep $tutu } fi # give opportunity to read output function hit () { echo $* echo "Hit ENTER to continue"; echo -e '\a'; usleep 100000 ; echo -e '\a' # echo -e '\a' read ; } # verbose only version function vhit () { if [[ z"$verbose" = z"true" || z"$verbose" = z"TRUE"|| z"$verbose" = z"OUI" ]]; then echo $* echo "Hit ENTER to continue"; echo -e '\a'; usleep 100000 ; echo -e '\a' # echo -e '\a' read ; fi } # debug only version function debug_hit () { if [ z$BASH_DEBUG != z ] then echo $* echo "Hit ENTER to continue"; echo -e '\a'; usleep 100000 ; echo -e '\a' # echo -e '\a' read ; fi } # question string is given as argument # if a second argument askit equal to false is given returns yes without asking. function y_or_n () { if [[ z$2 = "zfalse" || z$2 = "zFALSE" || z$2 = "zNON" ]]; then return 0 fi REPLY= until [ z$REPLY = "zy" ] || [ z$REPLY = "zn" ] || [ z$REPLY = "zyes" ] || [ z$REPLY = "zno" ] do echo ${1}\?; echo -e '\a'; usleep 200000 ; echo -e '\a'Please answer y or n. read # REPLY=$(echo $REPLY | tr ' ' '_') # REPLY=$(echo $REPLY) REPLY=$(echo $REPLY | tr "[A-Z]" "[a-z]") echo REPLY is $REPLY done if [ z$REPLY = "zy" -o z$REPLY = "zyes" ]; then # echo do it return 0 else # echo don\'t do it return 3 fi } # ask for a string function gimme_a_string () { REPLY= until [ z$REPLY != z ] do echo ${1}\?; echo -e '\a'; usleep 200000 ; echo -e '\a'Please give me a string. read done } # args are a question followed by the allowed answers function gimme_an_answer () { if [ $# -lt 2 ]; then echo "gimme_an_answer: bad args to function."; exit 1; fi question=$1 shift REPLY= accept=0 until [ $accept -eq 1 ] do echo ${question}\?; echo -e '\a'; usleep 200000 ; echo -e '\a'Please give me an answer among: "$@" read for answer in "$@"; do if [ "z$answer" = "z$REPLY" ] then accept=1 fi done done } function debug_echo () # $*=blabla { # echo BASH_DEBUG = $BASH_DEBUG; # if [ z$BASH_DEBUG != z ]; then echo $* 1>&2 ; fi if [ z$BASH_DEBUG != z ]; then echo $* ; fi } function isnumber () # $*=blabla { number=$1; number=${number##0x} number=${number##0X} number=${number##0} #echo number = $number number=`echo $number | sed 's/[0-9]*//g'` number=`echo $number | sed 's/[A-F]*//g'` #echo number = $number if [ -z $number ]; then testnb=true; else testnb=false; fi; } function noroot () { if [ $(whoami) = root ] then if [ "z$1" != "z" ] then echo $1 else echo "Please don't run this as root" fi exit 0 fi } function beroot () { if [ $(whoami) != root ] then echo "You must be root to do this." exit 0 fi } function pourdevrai () { if [[ z"$testing" = "z" || z"$testing" = z"false" || z"$testing" = z"FALSE"|| z"$testing" = z"NON" ]] then return 0 # pourdevrai true else return 1 # pourdevrai false fi } function showdo () { showdocom="$*" echo $showdocom pourdevrai if [ $? = 0 ] then # echo case yes $showdocom return $? else # echo case no return $? fi } function showdo2 () { showdocom="$@" eval "echo $showdocom" pourdevrai if [ $? = 0 ] then eval $showdocom fi } function showdoask () { showdocom="$*" echo $showdocom y_or_n "Do it" if [ $? = 0 ] then # echo Doing it pourdevrai if [ $? = 0 ] then $showdocom ; else echo testing only; fi return 0 else echo Not doing it. return 1 fi } function showdoroot () { showdocom="$*" echo $showdocom vecho "In showdoroot showdocom is $showdocom" pourdevrai if [ $? = 0 ] then if [ $(whoami) = root ] then $showdocom else su -m -c "$showdocom" fi fi } function showdoaskroot () { showdocom="$*" echo $showdocom y_or_n "Do it" if [ $? = 0 ] then # echo Doing it pourdevrai if [ $? = 0 ] then if [ $(whoami) = root ] then $showdocom else su -m -c "$showdocom" fi else echo testing only; fi return 0 else echo Not doing it. return 1 fi } function vecho () { if [[ z"$verbose" = z"true" || z"$verbose" = z"TRUE"|| z"$verbose" = z"OUI" ]]; then echo $* fi } # this one comments its output: function cvecho () { if [[ z"$verbose" = z"true" || z"$verbose" = z"TRUE"|| z"$verbose" = z"OUI" ]]; then echo \# $* fi } # exit from script if the environment variable is not defined. function envassert () { if [ "z${!1}" = "z" ] then echo "Environment variable $1 must be defined for this script to run." exit 1 fi } # exit if cd fails function safecd () { cd $1 if [ $? != 0 ] then echo "Could not change directory, exiting ..." exit 1 fi } caller=$(basename $0) # caller=$0 lastpasswdfile=$HOME/tmp/lastpasswd.txt function logpass () { echo caller is $caller debug_echo "In logpass pass is $pass" if [ z$pass = z ] then logger -t $caller "$caller used no pass." else echo $pass | gpg -e --default-recipient-self | gpg --enarmor > $lastpasswdfile fi # retrieve using # cat $lastpasswdfile | gpg --dearmor | gpg -d }