shtool

来自「lzo-1.08-src.zip 高效的压缩解压代码」· 代码 · 共 1,936 行 · 第 1/5 页

TXT
1,936 行
字号
    #   type check for destination    dstisdir=0    if [ -d $dstpath ]; then        dstpath=`echo "$dstpath" | sed -e 's:/$::'`        dstisdir=1    fi    #   consistency check for destination    if [ $argc -gt 2 -a $dstisdir = 0 ]; then        echo "$msgprefix:Error: multiple sources require destination to be directory" 1>&2        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_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_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    ;;mkln )    ##    ##  mkln -- Make link with calculation of relative paths    ##  Copyright (c) 1999-2002 Ralf S. Engelschall <rse@engelschall.com>    ##  Originally written for shtool    ##    args=$?    srcs=""    while [ $# -gt 1 ]; do        srcs="$srcs $1"        shift    done    dst="$1"    if [ ! -d $dst ]; then        if [ $args -gt 2 ]; then            echo "$msgprefix:Error: multiple sources not allowed when target isn't a directory" 1>&2            exit 1        fi    fi    #   determine link options    lnopt=""    if [ ".$opt_f" = .yes ]; then        lnopt="$lnopt -f"    fi    if [ ".$opt_s" = .yes ]; then        lnopt="$lnopt -s"    fi    #   iterate over sources    for src in $srcs; do        #   determine if one of the paths is an absolute path,        #   because then we _have_ to use an absolute symlink        oneisabs=0        srcisabs=0        dstisabs=0        case $src in            /* ) oneisabs=1; srcisabs=1 ;;        esac        case $dst in            /* ) oneisabs=1; dstisabs=1 ;;        esac        #   split source and destination into dir and base name        if [ -d $src ]; then            srcdir=`echo $src | sed -e 's;/*$;;'`            srcbase=""        else            srcdir=`echo  $src | sed -e 's;^[^/]*$;;' -e 's;^\(.*/\)[^/]*$;\1;' -e 's;\(.\)/$;\1;'`            srcbase=`echo $src | sed -e 's;.*/\([^/]*\)$;\1;'`        fi        if [ -d $dst ]; then            dstdir=`echo $dst | sed -e 's;/*$;;'`            dstbase=""        else            dstdir=`echo  $dst | sed -e 's;^[^/]*$;;' -e 's;^\(.*/\)[^/]*$;\1;' -e 's;\(.\)/$;\1;'`            dstbase=`echo $dst | sed -e 's;.*/\([^/]*\)$;\1;'`        fi        #   consistency check        if [ ".$dstdir" != . ]; then            if [ ! -d $dstdir ]; then                echo "$msgprefix:Error: destination directory not found: $dstdir" 1>&2                exit 1            fi        fi        #   make sure the source is reachable from the destination        if [ $dstisabs = 1 ]; then            if [ $srcisabs = 0 ]; then                if [ -d $srcdir ]; then                    srcdir="`cd $srcdir; pwd | sed -e 's;/*$;;'`"                    srcisabs=1                    oneisabs=1                fi            fi        fi        #   split away a common prefix        prefix=""        if [ ".$srcdir" = ".$dstdir" -a ".$srcdir" != . ]; then            prefix="$srcdir/"            srcdir=""            dstdir=""        else            while [ ".$srcdir" != . -a ".$dstdir" != . ]; do                presrc=`echo $srcdir | sed -e 's;^\([^/]*\)/.*;\1;'`                predst=`echo $dstdir | sed -e 's;^\([^/]*\)/.*;\1;'`                if [ ".$presrc" != ".$predst" ]; then                    break                fi                prefix="$prefix$presrc/"                srcdir=`echo $srcdir | sed -e 's;^[^/]*/*;;'`                dstdir=`echo $dstdir | sed -e 's;^[^/]*/*;;'`            done        fi        #   destination prefix is just the common prefix        dstpre="$prefix"        #   determine source prefix which is the reverse directory        #   step-up corresponding to the destination directory        srcpre=""        if [ $oneisabs = 0 ] || [ ".$prefix" != . -a ".$prefix" != ./ ]; then            pl="$dstdir/"            OIFS="$IFS"; IFS='/'            for pe in $pl; do                [ ".$pe" = . ] && continue                srcpre="../$srcpre"            done            IFS="$OIFS"        else            if [ $srcisabs = 1 ]; then                srcpre="$prefix"            fi        fi        #   determine destination symlink name        if [ ".$dstbase" = . ]; then            if [ ".$srcbase" != . ]; then                dstbase="$srcbase"            else                dstbase=`echo "$prefix$srcdir" | sed -e 's;/*$;;' -e 's;.*/\([^/]*\)$;\1;'`            fi        fi        #   now finalize source and destination directory paths        srcdir=`echo $srcdir | sed -e 's;\([^/]\)$;\1/;'`        dstdir=`echo $dstdir | sed -e 's;\([^/]\)$;\1/;'`        #   run the final link command        if [ ".$opt_t" = .yes ]; then            echo "ln$lnopt $srcpre$srcdir$srcbase $dstpre$dstdir$dstbase"        fi        eval ln$lnopt $srcpre$srcdir$srcbase $dstpre$dstdir$dstbase    done    ;;mkshadow )    ##    ##  mkshadow -- Make a shadow tree through symbolic links    ##  Copyright (c) 1998-2002 Ralf S. Engelschall <rse@engelschall.com>    ##  Originally written for Apache    ##    #   source and destination directory    src=`echo "$1" | sed -e 's:/$::' -e 's:^\./\(.\):\1:'`    dst=`echo "$2" | sed -e 's:/$::' -e 's:^\./\(.\):\1:'`    #   check whether source exists    if [ ! -d $src ]; then        echo "$msgprefix:Error: source directory not found: \`$src'" 1>&2        exit 1    fi    #   determine if one of the paths is an absolute path,    #   because then we have to use an absolute symlink    oneisabs=0    case $src in        /* ) oneisabs=1 ;;    esac    case $dst in        /* ) oneisabs=1 ;;    esac    #   determine reverse directory for destination directory    dstrevdir=''    if [ $oneisabs = 0 ]; then        #   derive reverse path from forward path        pwd=`pwd`        OIFS="$IFS"; IFS='/'        for pe in $dst; do            if [ "x$pe" = "x.." ]; then                OIFS2="$IFS"; IFS="$DIFS"                eval `echo "$pwd" |\                      sed -e 's:\([^/]*\)$:; dir="\1":' \                          -e 's:^\(.*\)/[^/]*;:pwd="\1";:'\                          -e 's:^;:pwd="";:'`                dstrevdir="$dir/$dstrevdir"                IFS="$OIFS2"            else                dstrevdir="../$dstrevdir"            fi        done        IFS="$OIFS"    else        src="`cd $src; pwd`";    fi    #   create directory tree at destination    if [ ! -d $dst ]; then        if [ ".$opt_t" = .yes ]; then            echo "mkdir $dst" 1>&2        fi        mkdir $dst    fi    if [ ".$opt_a" = .yes ]; then        DIRS=`cd $src; find . -type d -print |\

⌨️ 快捷键说明

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