Browse Source

worked-off <prefix>/bin/openpkg frontend in order to provide better tool chain processing

Ralf S. Engelschall 21 years ago
parent
commit
32149fad09
3 changed files with 159 additions and 107 deletions
  1. 1 0
      openpkg/HISTORY
  2. 157 106
      openpkg/openpkg.sh
  3. 1 1
      openpkg/openpkg.spec

+ 1 - 0
openpkg/HISTORY

@@ -2,6 +2,7 @@
 2004
 ====
 
+20040409 worked-off <prefix>/bin/openpkg frontend in order to provide better tool chain processing
 20040408 fixed internal OPENPKG_TOOLS variable processing in <prefix>/bin/openpkg frontend
 20040408 added workaround to BeeCrypt build to make sure /dev/audio and /dev/dsp are not used
 20040407 upgraded to GNU shtool 2.0b2

+ 157 - 106
openpkg/openpkg.sh

@@ -30,26 +30,26 @@
 ##  command line parsing
 ##
 
-#   option defaults
+#   command line options defaults
 opt_prefix=""
 opt_tools=""
 opt_version=no
 opt_help=no
 
-#   iterate over argument line
+#   process command line options by iterating over arguments
 for opt
 do
-    case $opt in
-        -*=*) arg=`echo "$opt" | sed 's/^[-_a-zA-Z0-9]*=//'` ;;
+    case "${opt}" in
+        -*=*) arg=`echo "${opt}" | sed 's/^[-_a-zA-Z0-9]*=//'` ;;
            *) arg='' ;;
     esac
-    case $opt in
-        -v|--version   ) opt_version=yes   ;;
-        -h|--help      ) opt_help=yes      ;;
-        --prefix=*     ) opt_prefix="$arg" ;;
-        --tools=*      ) opt_tools="$arg"  ;;
-        -* ) echo "openpkg:ERROR: Invalid command-line option \"$opt\"." 1>&2
-             echo "openpkg:ERROR: Run \"$0 --help\" for list of valid options" 1>&2; exit 1 ;;
+    case "${opt}" in
+        -v|--version ) opt_version=yes;     shift ;;
+        -h|--help    ) opt_help=yes;        shift ;;
+        --prefix=*   ) opt_prefix="${arg}"; shift ;;
+        --tools=*    ) opt_tools="${arg}";  shift ;;
+        -* ) echo "openpkg:ERROR: Invalid command-line option \"${opt}\"." 1>&2
+             echo "openpkg:ERROR: Run \"${0} --help\" for list of valid options" 1>&2; exit 1 ;;
         *  ) break ;;
     esac
 done
@@ -59,89 +59,88 @@ done
 ##
 
 #   determine path to OpenPKG instance
-if [ ".$opt_prefix" != . ]; then
-    OPENPKG_PREFIX="$opt_prefix"
+openpkg_prefix="@l_prefix@"
+if [ ".${OPENPKG_PREFIX}" != . ]; then
+    openpkg_prefix="${OPENPKG_PREFIX}"
 fi
-if [ ".$OPENPKG_PREFIX" = . ]; then
-    OPENPKG_PREFIX="@l_prefix@"
+if [ ".${opt_prefix}" != . ]; then
+    openpkg_prefix="${opt_prefix}"
 fi
-if [ ! -f "$OPENPKG_PREFIX/bin/openpkg" ]; then
-    echo "openpkg:ERROR: no OpenPKG instance found under \"$OPENPKG_PREFIX\"" 1>&2
+if [ -x "${openpkg_prefix}/bin/openpkg" -a -x "${openpkg_prefix}/libexec/openpkg/rpm" ]; then
+    #   OpenPKG 2.0 and higher
+    true
+elif [ -f "${openpkg_prefix}/bin/rpm" -a -x "${openpkg_prefix}/lib/openpkg/rpm" ]; then
+    #   OpenPKG 1.x
+    echo "openpkg:ERROR: OpenPKG 1.x instance found under \"${openpkg_prefix}\" (not supported)" 1>&2
+    exit 1
+else
+    echo "openpkg:ERROR: no OpenPKG instance found under \"${openpkg_prefix}\"" 1>&2
     exit 1
 fi
 
 #   allow convenient all-in-one specification of OpenPKG Tool Chain locations
-if [ ".$opt_tool" != . ]; then
-    OPENPKG_TOOLS="$opt_tools"
+#   (assuming the filesystem layout of an uninstalled OpenPKG Tool Chain)
+openpkg_tools="${OPENPKG_TOOLS}"
+openpkg_tools_cmdpath="${OPENPKG_TOOLS_CMDPATH}"
+openpkg_tools_apipath="${OPENPKG_TOOLS_APIPATH}"
+if [ ".${opt_tool}" != . ]; then
+    openpkg_tools="${opt_tools}"
 fi
-if [ ".$OPENPKG_TOOLS" != . -a ".$OPENPKG_TOOLS_CMDPATH" = . ]; then
-    OPENPKG_TOOLS_CMDPATH="$OPENPKG_TOOLS/cmd:@"
+if [ ".${openpkg_tools}" != . -a ".${openpkg_tools_cmdpath}" = . ]; then
+    openpkg_tools_cmdpath="${openpkg_tools}/cmd:@"
 fi
-if [ ".$OPENPKG_TOOLS" != . -a ".$OPENPKG_TOOLS_APIPATH" = . ]; then
-    OPENPKG_TOOLS_APIPATH="$OPENPKG_TOOLS/api:@"
+if [ ".${openpkg_tools}" != . -a ".${openpkg_tools_apipath}" = . ]; then
+    openpkg_tools_apipath="${openpkg_tools}/api:@"
 fi
 
 #   determine path to OpenPKG Tool Chain commands
-cmdpath="$OPENPKG_PREFIX/libexec/openpkg"
-if [ -d "$OPENPKG_PREFIX/libexec/openpkg-tools" ]; then
+cmdpath="${openpkg_prefix}/libexec/openpkg"
+if [ -d "${openpkg_prefix}/libexec/openpkg-tools" ]; then
     #   openpkg-tools package overrides
-    cmdpath="$OPENPKG_PREFIX/libexec/openpkg-tools:$cmdpath"
+    cmdpath="${openpkg_prefix}/libexec/openpkg-tools:${cmdpath}"
 fi
-if [ ".$OPENPKG_TOOLS_CMDPATH" != . ]; then
+if [ ".${openpkg_tools_cmdpath}" != . ]; then
     #   user supplied path overrides
-    cmdpath=`echo "$OPENPKG_TOOLS_CMDPATH" | sed -e "s;@;$cmdpath;"`
+    cmdpath=`echo "${openpkg_tools_cmdpath}" | sed -e "s;@;${cmdpath};"`
 fi
-OPENPKG_TOOLS_CMDPATH=`echo "$cmdpath" | sed -e 's/::/:/g' -e 's/^://' -e 's/:$//'`
+openpkg_tools_cmdpath=`echo "${cmdpath}" | sed -e 's/::/:/g' -e 's/^://' -e 's/:$//'`
 
 #   determine path to OpenPKG Tool Chain API
 apipath=""
-if [ -d "$OPENPKG_PREFIX/lib/openpkg-tools" ]; then
+if [ -d "${openpkg_prefix}/lib/openpkg-tools" ]; then
     #   openpkg-tools package overrides
-    apipath="$OPENPKG_PREFIX/lib/openpkg-tools:$apipath"
+    apipath="${openpkg_prefix}/lib/openpkg-tools:${apipath}"
 fi
-if [ ".$OPENPKG_TOOLS_APIPATH" != . ]; then
+if [ ".${openpkg_tools_apipath}" != . ]; then
     #   user supplied path overrides
-    apipath=`echo "$OPENPKG_TOOLS_APIPATH" | sed -e "s;@;$apipath;"`
+    apipath=`echo "${openpkg_tools_apipath}" | sed -e "s;@;${apipath};"`
 fi
-OPENPKG_TOOLS_APIPATH=`echo "$apipath" | sed -e 's/::/:/g' -e 's/^://' -e 's/:$//'`
-
-#   export variables into environment
-export OPENPKG_PREFIX
-export OPENPKG_TOOLS
-export OPENPKG_TOOLS_CMDPATH
-export OPENPKG_TOOLS_APIPATH
+openpkg_tools_apipath=`echo "${apipath}" | sed -e 's/::/:/g' -e 's/^://' -e 's/:$//'`
 
 ##
-##  determine command details and execute command appropriately
+##  execute stand-alone option commands in advance
 ##
 
-#   command line sanity check
-if [ $# -eq 0 ]; then
-    echo "openpkg:ERROR: Invalid command-line arguments." 1>&2
-    echo "openpkg:ERROR: Run \"$0 --help\" for list of valid arguments." 1>&2
-    exit 1
-fi
-
 #   implement stand-alone "--help" option
-if [ ".$opt_help" = .yes ]; then
-    release=`$OPENPKG_PREFIX/libexec/openpkg/rpm --eval '%{l_openpkg_release}'`
+if [ ".${opt_help}" = .yes ]; then
+    release=`${openpkg_prefix}/libexec/openpkg/rpm --eval '%{l_openpkg_release}'`
     echo ""
-    echo "This is $release <http://www.openpkg.org/>"
+    echo "This is ${release} <http://www.openpkg.org/>"
     echo "Cross-Platform Unix Software Packaging Facility"
     echo ""
     echo "Copyright (c) 2000-2004 The OpenPKG Project <http://www.openpkg.org/>"
     echo "Copyright (c) 2000-2004 Ralf S. Engelschall <rse@engelschall.com>"
     echo "Copyright (c) 2000-2004 Cable & Wireless <http://www.cw.com/>"
     echo ""
-    echo "The command \"@l_prefix@/bin/openpkg\" is the official command-line"
+    echo "The command \"${openpkg_prefix}/bin/openpkg\" is the official command-line"
     echo "execution frontend of the OpenPKG tool chain. Its usage is:"
     echo ""
-    echo "  \$ @l_prefix@/bin/openpkg [<option> ...] \\"
+    echo "  \$ ${openpkg_prefix}/bin/openpkg [<option> ...] \\"
     echo "     <command> [<command-option> ...] [<command-argument> ...]"
     echo ""
     echo "where <option> is one of the following global options:"
-    echo "  -p, --prefix    sets the OpenPKG instance prefix   (also: \$OPENPKG_PREFIX)"
-    echo "  -t, --tools     sets the OpenPKG tool chain prefix (also: \$OPENPKG_TOOLS)"
+    echo "  -p, --prefix    sets the OpenPKG instance prefix   (also: \${OPENPKG_PREFIX})"
+    echo "  -t, --tools     sets the OpenPKG tool chain prefix (also: \${OPENPKG_TOOLS})"
     echo "  -v, --version   display OpenPKG version/release"
     echo "  -h, --help      display this usage help message"
     echo ""
@@ -155,90 +154,142 @@ if [ ".$opt_help" = .yes ]; then
     echo "  lsync           (provided by bootstrap package)"
     echo "  man             (provided by bootstrap package)"
     #   install command intentionally left out in above display!
+
+    #   dynamically figure out add-on commands
     for cmd in rpm rpmbuild rpm2cpio rpm-config uuid rc lsync man install; do
-        id=`echo "$cmd" | sed -e 's/-/_/g'`
-        eval "__cmd_seen_$id=yes"
+        id=`echo "${cmd}" | sed -e 's/-/_/g'`
+        eval "__cmd_seen_${id}=yes"
     done
-    OIFS="$IFS"; IFS=":"
-    for dir in $OPENPKG_TOOLS_CMDPATH; do
-        IFS="$OIFS"
-        for cmd in `cd $dir 2>&1 && echo *`; do
-            cmd=`echo "$cmd" | sed -e 's/\.sh$//' -e 's/\.pl$//' -e 's;^;X;' -e 's;^X\([a-zA-Z][a-zA-Z0-9_-]*\)$;\1;' -e 's;^X.*$;;'`
-            if [ ".$cmd" != . ]; then
-                id=`echo "$cmd" | sed -e 's/-/_/g' -e 's/\.sh$//' -e 's/\.pl$//'`
-                eval "seen=\$__cmd_seen_$id"
-                if [ ".$seen" != .yes ]; then
-                    echo "$cmd" | awk '{ printf("  %-15s (provided by addon package)\n", $0); }'
+    OIFS="${IFS}"; IFS=":"
+    for dir in ${openpkg_tools_cmdpath}; do
+        IFS="${OIFS}"
+        if [ ! -d ${dir} ]; then
+            continue
+        fi
+        for cmd in `cd ${dir} 2>/dev/null && echo *`; do
+            is_cmd=`echo "${cmd}" | sed -e 's/\.sh$//' -e 's/\.pl$//' \
+                 -e 's/^/X/' -e 's/^X\([a-z][a-zA-Z0-9_-]*\)$/\1/' -e 's/^X.*$//'`
+            if [ ".${is_cmd}" != . ]; then
+                if [ -f ${dir}/${cmd} ]; then
+                    id=`echo "${cmd}" | sed -e 's/-/_/g' -e 's/\.sh$//' -e 's/\.pl$//'`
+                    eval "seen=\$__cmd_seen_${id}"
+                    if [ ".${seen}" != .yes ]; then
+                        echo "${cmd}" | awk '{ printf("  %-15s (provided by add-on package)\n", $0); }'
+                    fi
                 fi
             fi
         done
     done
-    IFS="$OIFS"
+    IFS="${OIFS}"
     echo ""
     echo "where <command-option> and <command-argument> are <command> specific"
-    echo "options and arguments. Run \"@l_prefix@/bin/openpkg <command> --help\""
-    echo "and \"@l_prefix@/bin/openpkg man <command>\" for more details."
+    echo "options and arguments. Run \"${openpkg_prefix}/bin/openpkg <command> --help\""
+    echo "and \"${openpkg_prefix}/bin/openpkg man <command>\" for more details."
     echo ""
     exit 0
 fi
 
 #   implement stand-alone "--version" option
-if [ ".$opt_version" = .yes ]; then
-    release=`$OPENPKG_PREFIX/libexec/openpkg/rpm --eval '%{l_openpkg_release}'`
-    version=`$OPENPKG_PREFIX/libexec/openpkg/rpm -q --qf '%{version}' openpkg`
-    echo "$release ($version)"
+if [ ".${opt_version}" = .yes ]; then
+    release=`${openpkg_prefix}/libexec/openpkg/rpm --eval '%{l_openpkg_release}'`
+    version=`${openpkg_prefix}/libexec/openpkg/rpm -q --qf '%{version}' openpkg`
+    echo "${release} (${version})"
     exit 0
 fi
 
-#   iterate over all command directories
-cmd="$1"
+##
+##  determine command details and execute command appropriately
+##
+
+#   command line sanity check
+if [ ${#} -eq 0 ]; then
+    echo "openpkg:ERROR: Invalid command-line arguments." 1>&2
+    echo "openpkg:ERROR: Run \"${openpkg_prefix}/bin/openpkg --help\" for list of valid arguments." 1>&2
+    exit 1
+fi
+
+#   search command by iterating over all command directories
+cmd="${1}"
 shift
 cmd_path=""
 cmd_shell=""
-OIFS="$IFS"; IFS=":"
-for dir in $OPENPKG_TOOLS_CMDPATH; do
-    IFS="$OIFS"
-    if [ -x "$dir/$cmd" ]; then
+cmd_stack="${OPENPKG_TOOLS_CMDSTACK}"
+OIFS="${IFS}"; IFS=":"
+for dir in ${openpkg_tools_cmdpath}; do
+    IFS="${OIFS}"
+
+    #   skip (currently) not existing directory
+    if [ ! -d ${dir} ]; then
+        continue
+    fi
+
+    #   check for various command implementations
+    if [ -x ${dir}/${cmd} ]; then
         #   found executable stand-alone binary
-        cmd_path="$dir/$cmd"
+        cmd_path="${dir}/${cmd}"
         cmd_shell=""
-        break
-    elif [ -f "$dir/$cmd.sh" ]; then
+    elif [ -f ${dir}/${cmd}.sh ]; then
         #   found non-executable Bourne-Shell script
-        cmd_path="$dir/$cmd.sh"
-        cmd_shell="$OPENPKG_PREFIX/lib/openpkg/bash"
-        break
-    elif [ -f "$dir/$cmd.pl" ]; then
+        cmd_path="${dir}/${cmd}.sh"
+        cmd_shell="${openpkg_prefix}/lib/openpkg/bash"
+    elif [ -f ${dir}/${cmd}.pl ]; then
         #   found non-executable Perl script
-        cmd_path="$dir/$cmd.pl"
-        if [ -x "$OPENPKG_PREFIX/bin/perl" ]; then
-            cmd_shell="$OPENPKG_PREFIX/bin/perl"
+        cmd_path="${dir}/${cmd}.pl"
+        if [ -x ${openpkg_prefix}/bin/perl ]; then
+            cmd_shell="${openpkg_prefix}/bin/perl"
         else
-            cmd_shell=`$OPENPKG_PREFIX/lib/openpkg/shtool path -m perl 2>&1`
-            if [ ".$cmd_shell" = . ]; then
-                echo "openpkg:ERROR: No Perl interpreter found in \$PATH" 1>&2
+            cmd_shell=`${openpkg_prefix}/lib/openpkg/shtool path -m perl 2>&1`
+            if [ ".${cmd_shell}" = . ]; then
+                echo "openpkg:ERROR: No Perl interpreter found in \${PATH}" 1>&2
                 exit 1
             fi
         fi
-        #   provide module include path(s) to API
-        OIFS="$IFS"; IFS=":"
-        for dir2 in $OPENPKG_TOOLS_APIPATH; do
-            IFS="$OIFS"
-            cmd_shell="$cmd_shell -I$dir2"
+        #   provide Perl module include path(s) to API
+        OIFS="${IFS}"; IFS=":"
+        for dir2 in ${openpkg_tools_apipath}; do
+            IFS="${OIFS}"
+            if [ ! -d ${dir2} ]; then
+                continue
+            fi
+            cmd_shell="${cmd_shell} -I${dir2}"
         done
-        IFS="$OIFS"
+        IFS="${OIFS}"
+    else
+        #   command not found, continue searching
+        continue
+    fi
+
+    #   check whether to use this found command or to continue searching
+    #   for next command implementation in sequence (in order to support
+    #   flexible nested command wrapping)
+    cmd_last=`echo "${cmd_stack}" | sed -e 's;:.*$;;'`
+    if [ ".${cmd_last}" = ".${cmd}" ]; then
+        #   we were last command on stack, so pop us from call
+        #   stack and continue searching for next implementation
+        cmd_stack=`echo "${cmd_stack}" | sed -e 's;^[^:][^:]*:*;;'`
+        continue
+    else
+        #   last command on stack was different, so stop
+        #   searching because we found the implementation
         break
     fi
 done
-IFS="$OIFS"
-if [ ".$cmd_path" = . ]; then
-    echo "openpkg:ERROR: No such command \"$cmd\" found in command path" 1>&2
-    echo "openpkg:ERROR: ($OPENPKG_TOOLS_CMDPATH)." 1>&2
-    echo "openpkg:ERROR: Set \$OPENPKG_TOOLS_CMDPATH appropriately." 1>&2
-    echo "openpkg:ERROR: Run \"$0 --help\" for list of valid commands." 1>&2
+IFS="${OIFS}"
+
+#   sanity check search result
+if [ ".${cmd_path}" = . ]; then
+    echo "openpkg:ERROR: No such command \"${cmd}\" found in command path" 1>&2
+    echo "openpkg:ERROR: (${openpkg_tools_cmdpath})." 1>&2
+    echo "openpkg:ERROR: Set \${OPENPKG_TOOLS_CMDPATH} appropriately." 1>&2
+    echo "openpkg:ERROR: Run \"${openpkg_prefix}/bin/openpkg --help\" for list of valid commands." 1>&2
     exit 1
 fi
 
+#   export essential run-time information to command
+export OPENPKG_TOOLS_CMDPROG="${0}"
+export OPENPKG_TOOLS_CMDNAME="${cmd}"
+export OPENPKG_TOOLS_CMDSTACK=`echo "${OPENPKG_TOOLS_CMDSTACK}" | sed -e 's;^\(.\);:\1;' -e "s;^;${cmd};"`
+
 #   execute command
-eval "exec $cmd_shell $cmd_path \${1+\"\$@\"}"
+eval "exec ${cmd_shell} ${cmd_path} \${1+\"\$@\"}"
 

+ 1 - 1
openpkg/openpkg.spec

@@ -39,7 +39,7 @@
 #   o any cc(1)
 
 #   the package version/release
-%define       V_openpkg  20040408
+%define       V_openpkg  20040409
 
 #   the used software versions
 %define       V_rpm      4.2.1