openpkg/openpkg.sh

Wed, 22 Jul 2009 20:00:17 +0200

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 22 Jul 2009 20:00:17 +0200
changeset 207
b9e3f33ba619
child 428
f880f219c566
permissions
-rw-r--r--

Import new package specs for introduction into repository.

michael@13 1 #!@l_prefix@/lib/openpkg/bash
michael@13 2 ##
michael@13 3 ## openpkg -- OpenPKG Tool Chain
michael@13 4 ## Copyright (c) 2000-2007 OpenPKG Foundation e.V. <http://openpkg.net/>
michael@13 5 ## Copyright (c) 2000-2007 Ralf S. Engelschall <http://engelschall.com/>
michael@13 6 ##
michael@13 7 ## Permission to use, copy, modify, and distribute this software for
michael@13 8 ## any purpose with or without fee is hereby granted, provided that
michael@13 9 ## the above copyright notice and this permission notice appear in all
michael@13 10 ## copies.
michael@13 11 ##
michael@13 12 ## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
michael@13 13 ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
michael@13 14 ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
michael@13 15 ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
michael@13 16 ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
michael@13 17 ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
michael@13 18 ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
michael@13 19 ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
michael@13 20 ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
michael@13 21 ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
michael@13 22 ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
michael@13 23 ## SUCH DAMAGE.
michael@13 24 ##
michael@13 25 ## openpkg.sh: Execution Frontend (Language: Bourne-Shell)
michael@13 26 ##
michael@13 27
michael@13 28 ##
michael@13 29 ## command line parsing
michael@13 30 ##
michael@13 31
michael@13 32 # command line options defaults
michael@13 33 opt_prefix=""
michael@13 34 opt_tools=""
michael@13 35 opt_version=no
michael@13 36 opt_help=no
michael@13 37
michael@13 38 # process command line options by iterating over arguments
michael@13 39 for opt
michael@13 40 do
michael@13 41 case "${opt}" in
michael@13 42 -*=*) arg=`echo "${opt}" | sed 's/^[-_a-zA-Z0-9]*=//'` ;;
michael@13 43 *) arg='' ;;
michael@13 44 esac
michael@13 45 case "${opt}" in
michael@13 46 -v|--version ) opt_version=yes; shift ;;
michael@13 47 -h|--help ) opt_help=yes; shift ;;
michael@13 48 --prefix=* ) opt_prefix="${arg}"; shift ;;
michael@13 49 --tools=* ) opt_tools="${arg}"; shift ;;
michael@13 50 -* ) echo "openpkg:ERROR: Invalid command-line option \"${opt}\"." 1>&2
michael@13 51 echo "openpkg:ERROR: Run \"${0} --help\" for list of valid options" 1>&2; exit 1 ;;
michael@13 52 * ) break ;;
michael@13 53 esac
michael@13 54 done
michael@13 55
michael@13 56 ##
michael@13 57 ## determine OpenPKG locations
michael@13 58 ##
michael@13 59
michael@13 60 # determine path to OpenPKG instance
michael@13 61 openpkg_prefix="@l_prefix@"
michael@13 62 if [ ".${OPENPKG_PREFIX}" != . ]; then
michael@13 63 openpkg_prefix="${OPENPKG_PREFIX}"
michael@13 64 fi
michael@13 65 if [ ".${opt_prefix}" != . ]; then
michael@13 66 openpkg_prefix="${opt_prefix}"
michael@13 67 fi
michael@13 68 if [ -x "${openpkg_prefix}/bin/openpkg" -a -x "${openpkg_prefix}/libexec/openpkg/rpm" ]; then
michael@13 69 # OpenPKG 2.0 and higher
michael@13 70 true
michael@13 71 elif [ -f "${openpkg_prefix}/bin/rpm" -a -x "${openpkg_prefix}/lib/openpkg/rpm" ]; then
michael@13 72 # OpenPKG 1.x
michael@13 73 echo "openpkg:ERROR: OpenPKG 1.x instance found under \"${openpkg_prefix}\" (not supported)" 1>&2
michael@13 74 exit 1
michael@13 75 else
michael@13 76 echo "openpkg:ERROR: no OpenPKG instance found under \"${openpkg_prefix}\"" 1>&2
michael@13 77 exit 1
michael@13 78 fi
michael@13 79
michael@13 80 # allow convenient all-in-one specification of OpenPKG Tool Chain locations
michael@13 81 # (assuming the filesystem layout of an uninstalled OpenPKG Tool Chain)
michael@13 82 openpkg_tools="${OPENPKG_TOOLS}"
michael@13 83 openpkg_tools_cmdpath="${OPENPKG_TOOLS_CMDPATH}"
michael@13 84 openpkg_tools_apipath="${OPENPKG_TOOLS_APIPATH}"
michael@13 85 if [ ".${opt_tool}" != . ]; then
michael@13 86 openpkg_tools="${opt_tools}"
michael@13 87 fi
michael@13 88 if [ ".${openpkg_tools}" != . -a ".${openpkg_tools_cmdpath}" = . ]; then
michael@13 89 openpkg_tools_cmdpath="${openpkg_tools}/cmd:@"
michael@13 90 fi
michael@13 91 if [ ".${openpkg_tools}" != . -a ".${openpkg_tools_apipath}" = . ]; then
michael@13 92 openpkg_tools_apipath="${openpkg_tools}/api:@"
michael@13 93 fi
michael@13 94
michael@13 95 # determine path to OpenPKG Tool Chain commands
michael@13 96 cmdpath="${openpkg_prefix}/libexec/openpkg"
michael@13 97 if [ -d "${openpkg_prefix}/libexec/openpkg-tools" ]; then
michael@13 98 # openpkg-tools package overrides
michael@13 99 cmdpath="${openpkg_prefix}/libexec/openpkg-tools:${cmdpath}"
michael@13 100 fi
michael@13 101 if [ -d "${openpkg_prefix}/libexec/openpkg-audit" ]; then
michael@13 102 # openpkg-audit package overrides
michael@13 103 cmdpath="${openpkg_prefix}/libexec/openpkg-audit:${cmdpath}"
michael@13 104 fi
michael@13 105 if [ ".${openpkg_tools_cmdpath}" != . ]; then
michael@13 106 # user supplied path overrides
michael@13 107 cmdpath=`echo "${openpkg_tools_cmdpath}" | sed -e "s;@;${cmdpath};"`
michael@13 108 fi
michael@13 109 openpkg_tools_cmdpath=`echo "${cmdpath}" | sed -e 's/::/:/g' -e 's/^://' -e 's/:$//'`
michael@13 110
michael@13 111 # determine path to OpenPKG Tool Chain API
michael@13 112 apipath=""
michael@13 113 if [ -d "${openpkg_prefix}/lib/openpkg-tools" ]; then
michael@13 114 # openpkg-tools package overrides
michael@13 115 apipath="${openpkg_prefix}/lib/openpkg-tools:${apipath}"
michael@13 116 fi
michael@13 117 if [ ".${openpkg_tools_apipath}" != . ]; then
michael@13 118 # user supplied path overrides
michael@13 119 apipath=`echo "${openpkg_tools_apipath}" | sed -e "s;@;${apipath};"`
michael@13 120 fi
michael@13 121 openpkg_tools_apipath=`echo "${apipath}" | sed -e 's/::/:/g' -e 's/^://' -e 's/:$//'`
michael@13 122
michael@13 123 ##
michael@13 124 ## execute stand-alone option commands in advance
michael@13 125 ##
michael@13 126
michael@13 127 # implement stand-alone "--help" option
michael@13 128 if [ ".${opt_help}" = .yes ]; then
michael@13 129 release=`${openpkg_prefix}/libexec/openpkg/rpm --eval '%{l_openpkg_release}'`
michael@13 130 echo ""
michael@13 131 echo "This is ${release} <http://www.openpkg.org/>"
michael@13 132 echo "Cross-Platform Unix Software Packaging Facility"
michael@13 133 echo ""
michael@13 134 echo "Copyright (c) 2000-2007 OpenPKG Foundation e.V. <http://openpkg.net/>"
michael@13 135 echo "Copyright (c) 2000-2007 Ralf S. Engelschall <http://engelschall.com/>"
michael@13 136 echo ""
michael@13 137 echo "The command \"${openpkg_prefix}/bin/openpkg\" is the official command-line"
michael@13 138 echo "execution frontend of the OpenPKG tool chain. Its usage is:"
michael@13 139 echo ""
michael@13 140 echo " \$ ${openpkg_prefix}/bin/openpkg [<option> ...] \\"
michael@13 141 echo " <command> [<command-option> ...] [<command-argument> ...]"
michael@13 142 echo ""
michael@13 143 echo "where <option> is one of the following global options:"
michael@13 144 echo " -p, --prefix sets the OpenPKG instance prefix (also: \${OPENPKG_PREFIX})"
michael@13 145 echo " -t, --tools sets the OpenPKG tool chain prefix (also: \${OPENPKG_TOOLS})"
michael@13 146 echo " -v, --version display OpenPKG version/release"
michael@13 147 echo " -h, --help display this usage help message"
michael@13 148 echo ""
michael@13 149 echo "where <command> is one of the following commands:"
michael@13 150 echo " rpm (provided by bootstrap package)"
michael@13 151 echo " rpmbuild (provided by bootstrap package)"
michael@13 152 echo " rpm2cpio (provided by bootstrap package)"
michael@13 153 echo " rpm-config (provided by bootstrap package)"
michael@13 154 echo " uuid (provided by bootstrap package)"
michael@13 155 echo " rc (provided by bootstrap package)"
michael@13 156 echo " lsync (provided by bootstrap package)"
michael@13 157 echo " man (provided by bootstrap package)"
michael@13 158 # install command intentionally left out in above display!
michael@13 159
michael@13 160 # dynamically figure out add-on commands
michael@13 161 for cmd in rpm rpmbuild rpm2cpio rpm-config uuid rc lsync man install; do
michael@13 162 id=`echo "${cmd}" | sed -e 's/-/_/g'`
michael@13 163 eval "__cmd_seen_${id}=yes"
michael@13 164 done
michael@13 165 OIFS="${IFS}"; IFS=":"
michael@13 166 for dir in ${openpkg_tools_cmdpath}; do
michael@13 167 IFS="${OIFS}"
michael@13 168 if [ ! -d ${dir} ]; then
michael@13 169 continue
michael@13 170 fi
michael@13 171 for cmd in `cd ${dir} 2>/dev/null && echo *`; do
michael@13 172 name=`echo "${cmd}" | sed -e 's/\.sh$//' -e 's/\.pl$//' \
michael@13 173 -e 's/^/X/' -e 's/^X\([a-z][a-zA-Z0-9_-]*\)$/\1/' -e 's/^X.*$//'`
michael@13 174 if [ ".${name}" != . ]; then
michael@13 175 if [ -f ${dir}/${cmd} ]; then
michael@13 176 id=`echo "${name}" | sed -e 's/-/_/g'`
michael@13 177 eval "seen=\$__cmd_seen_${id}"
michael@13 178 if [ ".${seen}" != .yes ]; then
michael@13 179 echo "${name}" | awk '{ printf(" %-15s (provided by add-on package)\n", $0); }'
michael@13 180 eval "__cmd_seen_${id}=yes"
michael@13 181 fi
michael@13 182 fi
michael@13 183 fi
michael@13 184 done
michael@13 185 done
michael@13 186 IFS="${OIFS}"
michael@13 187 echo ""
michael@13 188 echo "where <command-option> and <command-argument> are <command> specific"
michael@13 189 echo "options and arguments. Run \"${openpkg_prefix}/bin/openpkg <command> --help\""
michael@13 190 echo "and \"${openpkg_prefix}/bin/openpkg man <command>\" for more details."
michael@13 191 echo ""
michael@13 192 exit 0
michael@13 193 fi
michael@13 194
michael@13 195 # implement stand-alone "--version" option
michael@13 196 if [ ".${opt_version}" = .yes ]; then
michael@13 197 release=`${openpkg_prefix}/libexec/openpkg/rpm --eval '%{l_openpkg_release}'`
michael@13 198 version=`${openpkg_prefix}/libexec/openpkg/rpm -q --qf '%{version}' openpkg`
michael@13 199 echo "${release} (${version})"
michael@13 200 exit 0
michael@13 201 fi
michael@13 202
michael@13 203 ##
michael@13 204 ## determine command details and execute command appropriately
michael@13 205 ##
michael@13 206
michael@13 207 # command line sanity check
michael@13 208 if [ ${#} -eq 0 ]; then
michael@13 209 echo "openpkg:ERROR: Invalid command-line arguments." 1>&2
michael@13 210 echo "openpkg:ERROR: Run \"${openpkg_prefix}/bin/openpkg --help\" for list of valid arguments." 1>&2
michael@13 211 exit 1
michael@13 212 fi
michael@13 213
michael@13 214 # search command by iterating over all command directories
michael@13 215 cmd="${1}"
michael@13 216 shift
michael@13 217 cmd_path=""
michael@13 218 cmd_shell=""
michael@13 219 cmd_stack="${OPENPKG_TOOLS_CMDSTACK}"
michael@13 220 OIFS="${IFS}"; IFS=":"
michael@13 221 for dir in ${openpkg_tools_cmdpath}; do
michael@13 222 IFS="${OIFS}"
michael@13 223
michael@13 224 # skip (currently) not existing directory
michael@13 225 if [ ! -d ${dir} ]; then
michael@13 226 continue
michael@13 227 fi
michael@13 228
michael@13 229 # check for various command implementations
michael@13 230 if [ -x ${dir}/${cmd} ]; then
michael@13 231 # found executable stand-alone binary
michael@13 232 cmd_path="${dir}/${cmd}"
michael@13 233 cmd_shell=""
michael@13 234 elif [ -f ${dir}/${cmd}.sh ]; then
michael@13 235 # found non-executable Bourne-Shell script
michael@13 236 cmd_path="${dir}/${cmd}.sh"
michael@13 237 cmd_shell="${openpkg_prefix}/lib/openpkg/bash"
michael@13 238 elif [ -f ${dir}/${cmd}.pl ]; then
michael@13 239 # found non-executable Perl script
michael@13 240 cmd_path="${dir}/${cmd}.pl"
michael@13 241 if [ -x ${openpkg_prefix}/bin/perl ]; then
michael@13 242 cmd_shell="${openpkg_prefix}/bin/perl"
michael@13 243 else
michael@13 244 cmd_shell=`${openpkg_prefix}/lib/openpkg/shtool path -p "$PATH:$openpkg_prefix/lib/openpkg" -m perl 2>&1`
michael@13 245 if [ ".${cmd_shell}" = . ]; then
michael@13 246 echo "openpkg:ERROR: No Perl interpreter found in \${PATH}" 1>&2
michael@13 247 exit 1
michael@13 248 fi
michael@13 249 fi
michael@13 250 # provide Perl module include path(s) to API
michael@13 251 OIFS="${IFS}"; IFS=":"
michael@13 252 for dir2 in ${openpkg_tools_apipath}; do
michael@13 253 IFS="${OIFS}"
michael@13 254 if [ ! -d ${dir2} ]; then
michael@13 255 continue
michael@13 256 fi
michael@13 257 cmd_shell="${cmd_shell} -I${dir2}"
michael@13 258 done
michael@13 259 IFS="${OIFS}"
michael@13 260 else
michael@13 261 # command not found, continue searching
michael@13 262 continue
michael@13 263 fi
michael@13 264
michael@13 265 # check whether to use this found command or to continue searching
michael@13 266 # for next command implementation in sequence (in order to support
michael@13 267 # flexible nested command wrapping)
michael@13 268 cmd_last=`echo "${cmd_stack}" | sed -e 's;:.*$;;'`
michael@13 269 if [ ".${cmd_last}" = ".${cmd}" ]; then
michael@13 270 # we were last command on stack, so pop us from call
michael@13 271 # stack and continue searching for next implementation
michael@13 272 cmd_stack=`echo "${cmd_stack}" | sed -e 's;^[^:][^:]*:*;;'`
michael@13 273 continue
michael@13 274 else
michael@13 275 # last command on stack was different, so stop
michael@13 276 # searching because we found the implementation
michael@13 277 break
michael@13 278 fi
michael@13 279 done
michael@13 280 IFS="${OIFS}"
michael@13 281
michael@13 282 # sanity check search result
michael@13 283 if [ ".${cmd_path}" = . ]; then
michael@13 284 echo "openpkg:ERROR: No such command \"${cmd}\" found in command path" 1>&2
michael@13 285 echo "openpkg:ERROR: (${openpkg_tools_cmdpath})." 1>&2
michael@13 286 echo "openpkg:ERROR: Set \${OPENPKG_TOOLS_CMDPATH} appropriately." 1>&2
michael@13 287 echo "openpkg:ERROR: Run \"${openpkg_prefix}/bin/openpkg --help\" for list of valid commands." 1>&2
michael@13 288 exit 1
michael@13 289 fi
michael@13 290
michael@13 291 # export essential run-time information to command
michael@13 292 export OPENPKG_PREFIX="$openpkg_prefix"
michael@13 293 export OPENPKG_TOOLS_CMDPROG="${0}"
michael@13 294 export OPENPKG_TOOLS_CMDNAME="${cmd}"
michael@13 295 export OPENPKG_TOOLS_CMDSTACK=`echo "${OPENPKG_TOOLS_CMDSTACK}" | sed -e 's;^\(.\);:\1;' -e "s;^;${cmd};"`
michael@13 296
michael@13 297 # execute command
michael@13 298 eval "exec ${cmd_shell} ${cmd_path} \${1+\"\$@\"}"
michael@13 299

mercurial