Преглед изворни кода

OpenPKG bootstrap 0.9-37 which provides: - "rpmtool config" command for editing config files - "rc --query" command for querying particular config variables (This stuff will soon be used for the MTA packages)

Ralf S. Engelschall пре 24 година
родитељ
комит
f70750427d
3 измењених фајлова са 412 додато и 1 уклоњено
  1. 1 1
      openpkg/openpkg.spec
  2. 319 0
      openpkg/rc
  3. 92 0
      openpkg/rpmtool

+ 1 - 1
openpkg/openpkg.spec

@@ -39,7 +39,7 @@
 
 #   the package version and release
 %define       V_openpkg 0.9
-%define       R_openpkg 36
+%define       R_openpkg 37
 
 #   the used software versions
 %define       V_rpm     4.0.2

+ 319 - 0
openpkg/rc

@@ -0,0 +1,319 @@
+#!@l_prefix@/lib/rpm/bash
+##
+##  @l_prefix@/etc/rc -- Run-Command Handling for OpenPKG Hierarchy
+##  Copyright (c) 2000-2001 Cable & Wireless Deutschland GmbH
+##  Copyright (c) 2000-2001 Ralf S. Engelschall <rse@engelschall.com>
+##
+##  Permission to use, copy, modify, and distribute this software for
+##  any purpose with or without fee is hereby granted, provided that
+##  the above copyright notice and this permission notice appear in all
+##  copies.
+##
+##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
+##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+##  SUCH DAMAGE.
+##
+
+#   program name, version and date
+progname="rc"
+progvers="1.0.7"
+progdate="17-Oct-2001"
+
+##
+##  command line option parsing
+##
+
+#   default parameters
+verbose=0
+help=0
+print=0
+eval=0
+config=0
+query=0
+raw=0
+rcdir="@l_prefix@/etc/rc.d"
+
+#   iterate over argument line
+while [ $# -gt 0 ]; do
+    opt=$1
+    case $opt in
+        -*=*) arg=`echo "$opt" | sed 's/^[-_a-zA-Z0-9]*=//'` ;;
+           *) arg='' ;;
+    esac
+    case $opt in
+        -v|--verbose ) verbose=1     ;;
+        -h|--help    ) help=1        ;;
+        -p|--print   ) print=1       ;;
+        -e|--eval    ) eval=1        ;;
+        -c|--config  ) config=1      ;;
+        -q|--query   ) query=1       ;;
+        -r|--raw     ) raw=1         ;;
+        --rcdir=*    ) rcdir=$arg    ;;
+        -*           ) help="Invalid option \`$opt'"; break ;;
+        *            ) break         ;;
+    esac
+    shift
+done
+
+#   determine path to rc.conf
+rcconf="`echo $rcdir | sed -e 's;/rc.d$;/rc.conf;'`"
+rcfunc="`echo $rcdir | sed -e 's;/rc.d$;/rc.func;'`"
+
+#   error or usage message
+if [ ".$help" != .0 ]; then
+    if [ ".$help" != ".Usage" ]; then
+        echo "$progname:ERROR: $help" 1>&2
+    fi
+    echo "Usage: $progname [-v|--verbose] [-h|--help]" 1>&2
+    echo "       [-p|--print] [-e|--eval] [-c|--config] [-q|--query] [-r|--raw]" 1>&2
+    echo "       <package> <command> [<command> ...]"  1>&2
+fi
+
+#   extend run-time environment with our local tools (shtool, rpmtool, etc)
+PATH="@l_prefix@/bin:$PATH"
+PATH="@l_prefix@/sbin:$PATH"
+PATH="@l_prefix@/lib/rpm:$PATH"
+
+#   find a reasonable temporary location
+if [ ".$TMPDIR" != . ]; then
+    tmpdir="$TMPDIR"
+elif [ ".$TEMPDIR" != . ]; then
+    tmpdir="$TEMPDIR"
+else
+    tmpdir="/tmp"
+fi
+tmpfile="$tmpdir/rc.$$.tmp"
+
+#   handle --query option
+if [ ".$query" = .1 ]; then
+    var="$1"
+    scripts=`ls $rcdir/rc.* | sed -e "s;^$rcdir/rc\.;;"`
+    rm -f $tmpfile
+    touch $tmpfile
+    for s_name in $scripts; do
+        sed <$rcdir/rc.$s_name >>$tmpfile -e "1,/^%config/d" -e '/^%.*/,$d'
+    done
+    . $tmpfile
+    . $rcconf
+    eval "echo \${$var}"
+    exit 0
+fi
+
+#   handle --config option
+if [ ".$config" = .1 ]; then
+    scripts=`ls $rcdir/rc.* | sed -e "s;^$rcdir/rc\.;;"`
+    rm -f $tmpfile
+    touch $tmpfile
+    for s_name in $scripts; do
+        sed <$rcdir/rc.$s_name >>$tmpfile -e "1,/^%config/d" -e '/^%.*/,$d'
+    done
+    vars=""
+    . $tmpfile
+    for assign in . `egrep '[ 	]*[a-zA-Z_][a-zA-Z_0-9]*=' $tmpfile | sort`; do
+        test ".$assign" = .. && continue
+        var=`echo "$assign" | sed -e 's;^[ 	]*\([a-zA-Z_][a-zA-Z_0-9]*\)=.*;\1;'`
+        vars="$vars $var"
+        eval "${var}_def=\"\$$var\""
+    done
+    . $rcconf
+    if [ ".$raw" = ".0" ]; then
+        begin_bold=`@l_prefix@/lib/rpm/shtool echo -e '%B'`
+        end_bold=`@l_prefix@/lib/rpm/shtool echo -e '%b'`
+    else
+        begin_bold=""
+        end_bold=""
+    fi
+    echo "${begin_bold}Configuration Variable   Effective Value              Default Value${end_bold}"
+    echo "------------------------ ------------------------- -- -------------------------"
+    for var in . $vars; do
+        test ".$var" = .. && continue
+        eval "val=\"\$$var\""
+        eval "def=\"\$${var}_def\""
+        tag="!="
+        begin="$begin_bold"
+        end="$end_bold"
+        if [ ".$val" = ".$def" ]; then
+            tag="=="
+            begin=""
+            end=""
+        fi
+        echo dummy | awk '{ printf("%s%-24s %-25s %s %-25s%s\n", begin, var, val, tag, def, end); }' \
+            begin="$begin" var="$var" tag="$tag" val="\"$val\"" def="\"$def\"" end="$end"
+    done
+    exit 0
+fi
+
+#   determine script(s) to use
+if [ $# -lt 2 ]; then
+    echo "$0:ERROR: no package and command(s) specified" 1>&2
+    exit 1
+fi
+scripts=`echo "$1" | sed -e 's;^.*rc\.;;'`
+shift
+if [ ".$scripts" = ".all" ]; then
+    scripts=`ls $rcdir/rc.* | sed -e "s;^$rcdir/rc\.;;"`
+else
+    if [ ! -f "$rcdir/rc.$scripts" ]; then
+        echo "$0:ERROR: script \`$rcdir/rc.$scripts' not found" 1>&2
+        exit 1
+    fi
+fi
+
+#   determine current run-time user
+user="$LOGNAME"
+if [ ".$user" = . ]; then
+    user="$USER"
+    if [ ".$user" = . ]; then
+        user="`(whoami) 2>/dev/null | awk '{ printf("%s", $1); }'`"
+        if [ ".$user" = . ]; then
+            user="`(who am i) 2>/dev/null | awk '{ printf("%s", $1); }'`"
+            if [ ".$user" = . ]; then
+                echo "$0:ERROR: unable to determine current username" 1>&2
+                exit 1
+            fi
+        fi
+    fi
+fi
+
+#   iterate over the commands
+cmds="$*"
+for cmd in $cmds; do
+
+    #   find scripts which contain the command and determine
+    #   their individual user/prio settings
+    list=''
+    for s_name in $scripts; do
+        enable=yes
+
+        #   check script options
+        shebangline=`head -1 $rcdir/rc.$s_name | grep "^#!rc"`
+        if [ ".$shebangline" != . ]; then
+            shebangopts=`echo "$shebangline" | sed -e "s;^#!rc *;;"`
+            set -- $shebangopts;
+            prev=''
+            for opt
+            do
+                if [ ".$prev" != . ]; then
+                    opt="$prev$opt"
+                    prev=''
+                fi
+                case $opt in
+                    -*=*       ) arg=`echo "$opt" | sed 's/^[-_a-zA-Z0-9]*=//'` ;;
+                    -[a-zA-Z]* ) arg=`echo "$opt" | sed 's/^-[a-zA-Z0-9]//'`    ;;
+                              *) arg='' ;;
+                esac
+                case $opt in
+                    -e|--enable  ) enable=yes ;;
+                    -d|--disable ) enable=no  ;;
+                    *          ) echo "$0:ERROR: invalid option \`$opt' in \`$rcdir/rc.$s_name:#!rc'"; break ;;
+                esac
+                shift
+            done
+        fi
+
+        #   check whether command exists in script
+        cmdline=`grep "^%$cmd" $rcdir/rc.$s_name`
+        if [ ".$cmdline" != . ]; then
+            cmdopts=`echo "$cmdline" | sed -e "s;^%$cmd *;;"`
+            s_user=$user
+            s_prio=500
+            set -- $cmdopts;
+            prev=''
+            for opt
+            do
+                if [ ".$prev" != . ]; then
+                    opt="$prev$opt"
+                    prev=''
+                fi
+                case $opt in
+                    -*=*       ) arg=`echo "$opt" | sed 's/^[-_a-zA-Z0-9]*=//'` ;;
+                    -[a-zA-Z]* ) arg=`echo "$opt" | sed 's/^-[a-zA-Z0-9]//'`    ;;
+                              *) arg='' ;;
+                esac
+                case $opt in
+                    -u|-p         ) prev=$opt    ;;
+                    -e|--enable   ) enable=yes   ;;
+                    -d|--disable  ) enable=no    ;;
+                    -u*|--user=*  ) s_user=$arg  ;;
+                    -p*|--prio=*  ) s_prio=$arg  ;;
+                    *             ) echo "$0:ERROR: invalid option \`$opt' in \`$rcdir/rc.$s_name'"; break ;;
+                esac
+                shift
+            done
+            if [ ".$s_user" != ".$user" -a ".$user" != ".root" ]; then
+                echo "$0:ERROR: require root priviledges to run \`$rcdir/rc.$s_name:$cmd' as user \`$s_user'" 1>&2
+                exit 1
+            fi
+            #   skip script if disabled
+            if [ ".$enable" != .yes ]; then
+                continue
+            fi
+            list="$list,$s_prio:$s_name:$s_user"
+        fi
+    done
+
+    #   execute/print the scripts in order
+    if [ ".$print" = .1 -o ".$eval" = .1 ]; then
+        rm -f $tmpfile
+        touch $tmpfile
+        if [ ".$verbose" = .1 ]; then
+            echo "set -x" >>$tmpfile
+        fi
+    fi
+    for entry in `echo $list | tr ',' '\012' | sort`; do
+        test ".$entry" = . && continue
+        eval `echo $entry | sed -e 's%^[0-9]*:\(.*\):\(.*\)$%s_name="\1"; s_user="\2"%'`
+        if [ ".$verbose" = .1 ]; then
+            echo "$0: executing $rcdir/rc.$s_name [%$cmd] as user $s_user" 1>&2
+        fi
+        if [ ".$print" = .1 -o ".$eval" = .1 ]; then
+            echo ". $rcfunc" >>$tmpfile
+            sed <$rcdir/rc.$s_name >>$tmpfile -e "1,/^%config/d" -e '/^%.*/,$d'
+            echo ". $rcconf" >>$tmpfile
+            sed <$rcdir/rc.$s_name >>$tmpfile -e "1,/^%common/d" -e '/^%.*/,$d'
+            sed <$rcdir/rc.$s_name >>$tmpfile -e "1,/^%$cmd/d" -e '/^%.*/,$d'
+            continue
+        fi
+        rm -f $tmpfile
+        touch $tmpfile
+        if [ ".$verbose" = .1 ]; then
+            echo "set -x" >>$tmpfile
+        fi
+        echo ". $rcfunc" >>$tmpfile
+        sed <$rcdir/rc.$s_name >>$tmpfile -e "1,/^%config/d" -e '/^%.*/,$d'
+        echo ". $rcconf" >>$tmpfile
+        sed <$rcdir/rc.$s_name >>$tmpfile -e "1,/^%common/d" -e '/^%.*/,$d'
+        sed <$rcdir/rc.$s_name >>$tmpfile -e "1,/^%$cmd/d" -e '/^%.*/,$d'
+        sh='sh'
+        if [ ".$user" != ".$s_user" ]; then
+            su $s_user -c "sh $tmpfile"
+            rc=$?
+        else
+            sh $tmpfile
+            rc=$?
+        fi
+        if [ $rc -ne 0 ]; then
+            echo "$0:WARNING: script \`$rcdir/rc.$s_name:$cmd' returned non-null ($#) return code" 1>&2
+        fi
+    done
+    if [ ".$print" = .1 ]; then
+        cat $tmpfile
+    elif [ ".$eval" = .1 ]; then
+        echo "source $tmpfile; rm -f $tmpfile 2>/dev/null || true"
+    fi
+done
+
+#   cleanup
+if [ ".$eval" = .0 ]; then
+    rm -f $tmpfile >/dev/null 2>&1 || true
+fi
+

+ 92 - 0
openpkg/rpmtool

@@ -51,6 +51,7 @@ if [ ".$1" = ".-h" -o ".$1" = ".--help" ]; then
     echo '         [-s <shell>] [-u <min-uid>] <username>'
     echo '  group  [-c] [-d] <groupname> <min-gid> [<username> ...]'
     echo '  signal [-v] [-t] [-n] [-c] [-d <delay>] [-p <pid>] [-m <pattern>] <sig> [<sig> ...]'
+    echo '  config [-v] [-a] [-r] [-b <ext>] [-p <tagprefix>] [-t <tagname>] [-i <tagid>] <file>'
     echo ''
     exit 0
 fi
@@ -134,6 +135,20 @@ case $tool in
         opt_p=""
         opt_m=""
         ;;
+    config )
+        str_usage="[-v] [-a] [-r] [-b <ext>] [-p <tagprefix>] [-t <tagname>] [-i <tagid>] <file>"
+        arg_spec="1="
+        opt_spec="v.a.r.b:p:t:i:c:"
+        opt_v=no
+        opt_a=no
+        opt_r=no
+        opt_b=""
+        opt_p="#"
+        opt_t="OpenPKG"
+        opt_i=""
+        gen_tmpfile=yes
+        ;;
+
     -* )
         echo "$prog_name:Error: unknown option \`$tool'" 2>&1
         echo "$prog_name:Hint:  run \`$0 -h' for usage" 2>&1
@@ -1042,6 +1057,83 @@ EOT
             fi
         done
         ;;
+
+    config )
+        #   usage consistency
+        if [ ".$opt_a" = .no -a ".$opt_r" = .no ]; then
+            echo "$msgprefix:Error: either option -a or -r has to be specified" 1>&2
+            exit 1
+        fi
+        configfile="$1"
+
+        #   determine block markers
+        block_start="${opt_p}<${opt_t}"
+        if [ ".$opt_i" != . ]; then
+            block_start="${block_start} id=\"${opt_i}\""
+        fi
+        block_start="${block_start}>"
+        block_end="${opt_p}</${opt_t}>"
+
+        #   slash-escaped versions of block markers (for sed(3) call)
+        block_start_esc=`echo "$block_start" | sed -e 's;/;\\\\/;g'`
+        block_end_esc=`echo "$block_end" | sed -e 's;/;\\\\/;g'`
+
+        #   determine backup extension
+        case "X$opt_b" in
+            X   ) ext=".bak"    ;;
+            X.* ) ext="$opt_b"  ;;
+            X*  ) ext=".$opt_b" ;;
+        esac
+
+        #   check for block in config file
+        if [ -f $configfile ]; then
+            check=`grep "^${block_start}" $configfile`
+        else
+            touch $configfile
+            check=""
+        fi
+
+        #   add entry
+        if [ ".$opt_a" = .yes ]; then
+            if [ ".$check" != . ]; then
+                echo "$msgprefix:Error: config entry already exists" 1>&2
+                exit 1
+            fi
+            cp $configfile $configfile$ext
+            echo "${block_start}" >$tmpfile
+            cat >>$tmpfile
+            echo "${block_end}" >>$tmpfile
+            cat $tmpfile >>$configfile
+
+        #   remove entry
+        elif [ ".$opt_r" = .yes ]; then
+            if [ ".$check" = . ]; then
+                echo "$msgprefix:Error: config entry does not exist" 1>&2
+                exit 1
+            fi
+            cp $configfile $configfile$ext
+            sed -e "/^${block_start_esc}/,/^${block_end_esc}/d" \
+                <$configfile$ext >$configfile
+        fi
+
+        #   verbosity
+        if [ ".$opt_v" = .yes ]; then
+            (diff -u1 $configfile$ext $configfile >$tmpfile) 2>/dev/null
+            if [ ".`cat $tmpfile`" = . ]; then
+                (diff -C1 $configfile$ext $configfile >$tmpfile) 2>/dev/null
+                if [ ".`cat $tmpfile`" = . ]; then
+                    echo "$msgprefix:Warning: unable to show difference for config file \`$configfile'" 1>&2
+                fi
+            fi
+            echo "editing $configfile:"
+            cat $tmpfile
+        fi
+
+        #   optionally remove backup file
+        if [ ".$opt_b" = . ]; then
+            rm -f $configfile$ext
+        fi
+        ;;
 esac
 
 #   cleanup