shtool

来自「监控软件rrdtools」· 代码 · 共 1,047 行 · 第 1/3 页

TXT
1,047 行
字号
        exit 1    fi        #   iterate over all source(s)    for src in $srcs; do        dst=$dstpath            #   if destination is a directory, append the input filename        if [ $dstisdir = 1 ]; then            dstfile=`echo "$src" | sed -e 's;.*/\([^/]*\)$;\1;'`            dst="$dst/$dstfile"        fi            #   check for correct arguments        if [ ".$src" = ".$dst" ]; then            echo "$msgprefix:Warning: source and destination are the same - skipped" 1>&2            continue        fi        if [ -d "$src" ]; then            echo "$msgprefix:Warning: source \`$src' is a directory - skipped" 1>&2            continue        fi            #   make a temp file name in the destination directory        dsttmp=`echo $dst |\                sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;' -e 's;^$;.;' \                    -e "s;\$;/#INST@$$#;"`            #   verbosity        if [ ".$opt_v" = .yes ]; then            echo "$src -> $dst" 1>&2        fi            #   copy or move the file name to the temp name        #   (because we might be not allowed to change the source)        if [ ".$opt_C" = .yes ]; then            opt_c=yes        fi        if [ ".$opt_c" = .yes ]; then            if [ ".$opt_t" = .yes ]; then                echo "cp $src $dsttmp" 1>&2            fi            cp $src $dsttmp || exit $?        else            if [ ".$opt_t" = .yes ]; then                echo "mv $src $dsttmp" 1>&2            fi            mv $src $dsttmp || exit $?        fi            #   adjust the target file        if [ ".$opt_e" != . ]; then            sed='sed'            OIFS="$IFS"; IFS="$ASC_NL"; set -- $opt_e; IFS="$OIFS"            for e            do                sed="$sed -e '$e'"            done            cp $dsttmp $dsttmp.old            eval "$sed <$dsttmp.old >$dsttmp" || exit $?            rm -f $dsttmp.old        fi        if [ ".$opt_s" = .yes ]; then            if [ ".$opt_t" = .yes ]; then                echo "strip $dsttmp" 1>&2            fi            strip $dsttmp || exit $?        fi        if [ ".$opt_o" != . ]; then            if [ ".$opt_t" = .yes ]; then                echo "chown $opt_o $dsttmp" 1>&2            fi            chown $opt_o $dsttmp || exit $?        fi        if [ ".$opt_g" != . ]; then            if [ ".$opt_t" = .yes ]; then                echo "chgrp $opt_g $dsttmp" 1>&2            fi            chgrp $opt_g $dsttmp || exit $?        fi        if [ ".$opt_m" != ".-" ]; then            if [ ".$opt_t" = .yes ]; then                echo "chmod $opt_m $dsttmp" 1>&2            fi            chmod $opt_m $dsttmp || exit $?        fi            #   determine whether to do a quick install        #   (has to be done _after_ the strip was already done)        quick=no        if [ ".$opt_C" = .yes ]; then            if [ -r $dst ]; then                if cmp -s $src $dst; then                    quick=yes                fi            fi        fi            #   finally, install the file to the real destination        if [ $quick = yes ]; then            if [ ".$opt_t" = .yes ]; then                echo "rm -f $dsttmp" 1>&2            fi            rm -f $dsttmp        else            if [ ".$opt_t" = .yes ]; then                echo "rm -f $dst && mv $dsttmp $dst" 1>&2            fi            rm -f $dst && mv $dsttmp $dst        fi    done    ;;mkdir )    ##    ##  mkdir -- Make one or more directories    ##  Copyright (c) 1996-2002 Ralf S. Engelschall <rse@engelschall.com>    ##  Originally written for public domain by Noah Friedman <friedman@prep.ai.mit.edu>    ##  Cleaned up and enhanced for shtool    ##        errstatus=0    for p in ${1+"$@"}; do        #   if the directory already exists...        if [ -d "$p" ]; then            if [ ".$opt_f" = .no -a ".$opt_p" = .no ]; then                echo "$msgprefix:Error: directory already exists: $p" 1>&2                errstatus=1                break            else                continue            fi        fi        #   if the directory has to be created...        if [ ".$opt_p" = .no ]; then            if [ ".$opt_t" = .yes ]; then                echo "mkdir $p" 1>&2            fi            mkdir $p || errstatus=$?            if [ ".$opt_o" != . ]; then                if [ ".$opt_t" = .yes ]; then                    echo "chown $opt_o $p" 1>&2                fi                chown $opt_o $p || errstatus=$?            fi            if [ ".$opt_g" != . ]; then                if [ ".$opt_t" = .yes ]; then                    echo "chgrp $opt_g $p" 1>&2                fi                chgrp $opt_g $p || errstatus=$?            fi            if [ ".$opt_m" != . ]; then                if [ ".$opt_t" = .yes ]; then                    echo "chmod $opt_m $p" 1>&2                fi                chmod $opt_m $p || errstatus=$?            fi        else            #   the smart situation            set fnord `echo ":$p" |\                       sed -e 's/^:\//%/' \                           -e 's/^://' \                           -e 's/\// /g' \                           -e 's/^%/\//'`            shift            pathcomp=''            for d in ${1+"$@"}; do                pathcomp="$pathcomp$d"                case "$pathcomp" in                    -* ) pathcomp="./$pathcomp" ;;                esac                if [ ! -d "$pathcomp" ]; then                    if [ ".$opt_t" = .yes ]; then                        echo "mkdir $pathcomp" 1>&2                    fi                    mkdir $pathcomp || errstatus=$?                    if [ ".$opt_o" != . ]; then                        if [ ".$opt_t" = .yes ]; then                            echo "chown $opt_o $pathcomp" 1>&2                        fi                        chown $opt_o $pathcomp || errstatus=$?                    fi                    if [ ".$opt_g" != . ]; then                        if [ ".$opt_t" = .yes ]; then                            echo "chgrp $opt_g $pathcomp" 1>&2                        fi                        chgrp $opt_g $pathcomp || errstatus=$?                    fi                    if [ ".$opt_m" != . ]; then                        if [ ".$opt_t" = .yes ]; then                            echo "chmod $opt_m $pathcomp" 1>&2                        fi                        chmod $opt_m $pathcomp || errstatus=$?                    fi                fi                pathcomp="$pathcomp/"            done        fi    done    exit $errstatus    ;;path )    ##    ##  path -- Deal with program paths    ##  Copyright (c) 1998-2002 Ralf S. Engelschall <rse@engelschall.com>    ##  Originally written for Apache    ##        namelist="$*"        #   check whether the test command supports the -x option    if [ -x /bin/sh ] 2>/dev/null; then        minusx="-x"    else        minusx="-r"    fi        #   split path string    paths="`echo $opt_p |\            sed -e 's/^:/.:/' \                -e 's/::/:.:/g' \                -e 's/:$/:./' \                -e 's/:/ /g'`"        #   SPECIAL REQUEST    #   translate forward to reverse path    if [ ".$opt_r" = .yes ]; then        if [ "x$namelist" = "x." ]; then            rp='.'        else            rp=''            for pe in `IFS="$IFS/"; echo $namelist`; do                rp="../$rp"            done        fi        echo $rp | sed -e 's:/$::'        exit 0    fi        #   SPECIAL REQUEST    #   strip out directory or base name    if [ ".$opt_d" = .yes ]; then        echo "$namelist" |\        sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;'        exit 0    fi    if [ ".$opt_b" = .yes ]; then        echo "$namelist" |\        sed -e 's;.*/\([^/]*\)$;\1;'        exit 0    fi        #   MAGIC SITUATION    #   Perl Interpreter (perl)    if [ ".$opt_m" = .yes  -a ".$namelist" = .perl ]; then        rm -f $tmpfile >/dev/null 2>&1        touch $tmpfile        found=0        pc=99        for dir in $paths; do            dir=`echo $dir | sed -e 's;/*$;;'`            nc=99            for name in perl perl5 miniperl; do                 if [ $minusx "$dir/$name" -a ! -d "$dir/$name" ]; then                     perl="$dir/$name"                     pv=`$perl -e 'printf("%.3f", $]);'`                     echo "$pv:$pc:$nc:$perl" >>$tmpfile                     found=1                 fi                 nc=`expr $nc - 1`            done            pc=`expr $pc - 1`        done        if [ $found = 1 ]; then            perl="`cat $tmpfile | sort -r -u | sed -e 'q' | cut -d: -f4`"            rm -f $tmpfile >/dev/null 2>&1            echo "$perl"            exit 0        fi        rm -f $tmpfile >/dev/null 2>&1        exit 1    fi        #   MAGIC SITUATION    #   C pre-processor (cpp)    if [ ".$opt_m" = .yes -a ".$namelist" = .cpp ]; then        echo >$tmpfile.c "#include <assert.h>"        echo >>$tmpfile.c "Syntax Error"        #   1. try the standard cc -E approach        cpp="${CC-cc} -E"        (eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out        my_error=`grep -v '^ *+' $tmpfile.out`        if [ ".$my_error" != . ]; then            #   2. try the cc -E approach and GCC's -traditional-ccp option            cpp="${CC-cc} -E -traditional-cpp"            (eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out            my_error=`grep -v '^ *+' $tmpfile.out`            if [ ".$my_error" != . ]; then                #   3. try a standalone cpp command in path and lib dirs                for path in $paths /lib /usr/lib /usr/local/lib; do                    path=`echo $path | sed -e 's;/*$;;'`                    if [ $minusx "$path/cpp" -a ! -d "$path/cpp" ]; then                        cpp="$path/cpp"                        break                    fi                done                if [ ".$cpp" != . ]; then                    (eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out                    my_error=`grep -v '^ *+' $tmpfile.out`                    if [ ".$my_error" != . ]; then                        #   ok, we gave up...                        cpp=''                    fi                fi            fi        fi        rm -f $tmpfile >/dev/null 2>&1        rm -f $tmpfile.c $tmpfile.out >/dev/null 2>&1        if [ ".$cpp" != . ]; then            echo "$cpp"            exit 0        fi        exit 1    fi        #   STANDARD SITUATION    #   iterate over names    for name in $namelist; do        #   iterate over paths        for path in $paths; do            path=`echo $path | sed -e 's;/*$;;'`            if [ $minusx "$path/$name" -a ! -d "$path/$name" ]; then                if [ ".$opt_s" != .yes ]; then                    echo "$path/$name"                fi                exit 0            fi        done    done    exit 1    ;;esacexit 0##EOF##

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?