Thu, 04 Oct 2012 20:30:05 +0200
Correct out of date build configuration, porting to Solaris 11 network
link infrastructure and new libpcap logic. This additionally allows for
device drivers in subdirectories of /dev. Correct packaged nmap
personalities and signatures to work out of the box. Finally, hack
arpd logic to properly close sockets and quit on TERM by repeating
signaling in the run command script. Sadly, all this fails to correct
the run time behaviour of honeyd which fails to bind to the IP layer.
michael@13 | 1 | #!@l_prefix@/lib/openpkg/bash |
michael@13 | 2 | ## |
michael@13 | 3 | ## rpmtool -- OpenPKG RPM Auxiliary Tool |
michael@428 | 4 | ## Copyright (c) 2000-2012 OpenPKG GmbH <http://openpkg.com/> |
michael@13 | 5 | ## |
michael@428 | 6 | ## This software is property of the OpenPKG GmbH, DE MUC HRB 160208. |
michael@428 | 7 | ## All rights reserved. Licenses which grant limited permission to use, |
michael@428 | 8 | ## copy, modify and distribute this software are available from the |
michael@428 | 9 | ## OpenPKG GmbH. |
michael@13 | 10 | ## |
michael@428 | 11 | ## THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED |
michael@13 | 12 | ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
michael@13 | 13 | ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
michael@13 | 14 | ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR |
michael@13 | 15 | ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
michael@13 | 16 | ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
michael@13 | 17 | ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
michael@13 | 18 | ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
michael@13 | 19 | ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
michael@13 | 20 | ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
michael@13 | 21 | ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
michael@13 | 22 | ## SUCH DAMAGE. |
michael@13 | 23 | ## |
michael@13 | 24 | |
michael@13 | 25 | prog_path="$0" |
michael@13 | 26 | prog_name="rpmtool" |
michael@13 | 27 | prog_vers="1.1.0" |
michael@13 | 28 | prog_date="05-Mar-2007" |
michael@13 | 29 | |
michael@13 | 30 | if [ $# -eq 0 ]; then |
michael@13 | 31 | echo "$0:Error: invalid command line" 1>&2 |
michael@13 | 32 | echo "$0:Hint: run \`$0 -h' for usage" 1>&2 |
michael@13 | 33 | exit 1 |
michael@13 | 34 | fi |
michael@13 | 35 | if [ ".$1" = ".-h" -o ".$1" = ".--help" ]; then |
michael@13 | 36 | echo "This is $prog_name, version $prog_vers ($prog_date)" |
michael@428 | 37 | echo "Copyright (c) 2000-2012 OpenPKG GmbH <http://openpkg.com/>" |
michael@13 | 38 | echo '' |
michael@13 | 39 | echo "Usage: $prog_name [<options>] [<cmd-name> [<cmd-options>] [<cmd-args>]]" |
michael@13 | 40 | echo '' |
michael@13 | 41 | echo 'Available global <options>:' |
michael@13 | 42 | echo ' -d, --debug enable internal debugging' |
michael@13 | 43 | echo ' -v, --version display version information' |
michael@13 | 44 | echo ' -h, --help display usage help page (this one)' |
michael@13 | 45 | echo '' |
michael@13 | 46 | echo 'Available <cmd-name> [<cmd-options>] [<cmd-args>]:' |
michael@13 | 47 | echo ' platform' |
michael@13 | 48 | echo ' mflags [-O] <tool>' |
michael@13 | 49 | echo ' cflags [-O] <tool>' |
michael@13 | 50 | echo ' cppflags [-p <prefix>] [<subdir> ...]' |
michael@13 | 51 | echo ' ldflags [-p <prefix>] [<subdir> ...]' |
michael@13 | 52 | echo ' files [-v] [-o <outfile>] [-r <buildroot>] [<filelist>]' |
michael@13 | 53 | echo ' signal [-v] [-t] [-n] [-c] [-d <delay>] [-p <pid>] [-m <pattern>] <sig> [<sig> ...]' |
michael@13 | 54 | echo ' config [-v] [-s] [-a] [-r] [-b <ext>] [-p <tagprefix>] [-t <tagname>] [-i <tagid>] <file>' |
michael@13 | 55 | echo ' msg [-b] [-r] [-t <type>]' |
michael@13 | 56 | echo '' |
michael@13 | 57 | exit 0 |
michael@13 | 58 | fi |
michael@13 | 59 | if [ ".$1" = ".-v" -o ".$1" = ."--version" ]; then |
michael@13 | 60 | echo "$prog_name $prog_vers ($prog_date)" |
michael@13 | 61 | exit 0 |
michael@13 | 62 | fi |
michael@13 | 63 | if [ ".$1" = ".-d" -o ".$1" = ."--debug" ]; then |
michael@13 | 64 | shift |
michael@13 | 65 | set -x |
michael@13 | 66 | fi |
michael@13 | 67 | |
michael@13 | 68 | tool="$1" |
michael@13 | 69 | shift |
michael@13 | 70 | arg_spec="" |
michael@13 | 71 | opt_spec="" |
michael@13 | 72 | gen_tmpfile=no |
michael@13 | 73 | |
michael@13 | 74 | # configure tool specific option parsing |
michael@13 | 75 | case $tool in |
michael@13 | 76 | platform ) |
michael@13 | 77 | str_usage="" |
michael@13 | 78 | arg_spec="0=" |
michael@13 | 79 | opt_spec="" |
michael@13 | 80 | ;; |
michael@13 | 81 | mflags ) |
michael@13 | 82 | str_usage="[-O] <tool>" |
michael@13 | 83 | arg_spec="1=" |
michael@13 | 84 | opt_spec="O." |
michael@13 | 85 | opt_O=no |
michael@13 | 86 | ;; |
michael@13 | 87 | cflags ) |
michael@13 | 88 | str_usage="[-O] <tool>" |
michael@13 | 89 | arg_spec="1=" |
michael@13 | 90 | opt_spec="O." |
michael@13 | 91 | opt_O=no |
michael@13 | 92 | ;; |
michael@13 | 93 | cppflags ) |
michael@13 | 94 | str_usage="[-p <prefix>] [-i] [<subdir> ...]" |
michael@13 | 95 | arg_spec="0+" |
michael@13 | 96 | opt_spec="p:i." |
michael@13 | 97 | opt_p="/" |
michael@13 | 98 | ;; |
michael@13 | 99 | ldflags ) |
michael@13 | 100 | str_usage="[-p <prefix>] [<subdir> ...]" |
michael@13 | 101 | arg_spec="0+" |
michael@13 | 102 | opt_spec="p:" |
michael@13 | 103 | opt_p="/" |
michael@13 | 104 | ;; |
michael@13 | 105 | files ) |
michael@13 | 106 | gen_tmpfile=yes |
michael@13 | 107 | str_usage="[-v] [-o <outfile>] [-r <buildroot>] [<filelist>]" |
michael@13 | 108 | arg_spec="0+" |
michael@13 | 109 | opt_spec="v.o:r:" |
michael@13 | 110 | opt_v=no |
michael@13 | 111 | opt_o='' |
michael@13 | 112 | opt_r='' |
michael@13 | 113 | ;; |
michael@13 | 114 | signal ) |
michael@13 | 115 | str_usage="[-v] [-t] [-n] [-c] [-d <delay>] [-p <pid>] [-m <pattern>] <sig> [<sig> ...]" |
michael@13 | 116 | arg_spec="1+" |
michael@13 | 117 | opt_spec="v.t.n.c.d:p:m:" |
michael@13 | 118 | opt_v=no |
michael@13 | 119 | opt_t=no |
michael@13 | 120 | opt_n=no |
michael@13 | 121 | opt_c=no |
michael@13 | 122 | opt_d=1 |
michael@13 | 123 | opt_p="" |
michael@13 | 124 | opt_m="" |
michael@13 | 125 | ;; |
michael@13 | 126 | config ) |
michael@13 | 127 | str_usage="[-v] [-s] [-a] [-r] [-b <ext>] [-p <tagprefix>] [-t <tagname>] [-i <tagid>] <file>" |
michael@13 | 128 | arg_spec="1=" |
michael@13 | 129 | opt_spec="v.s.a.r.b:p:t:i:c:" |
michael@13 | 130 | opt_v=no |
michael@13 | 131 | opt_s=no |
michael@13 | 132 | opt_a=no |
michael@13 | 133 | opt_r=no |
michael@13 | 134 | opt_b="" |
michael@13 | 135 | opt_p="#" |
michael@13 | 136 | opt_t="OpenPKG" |
michael@13 | 137 | opt_i="" |
michael@13 | 138 | gen_tmpfile=yes |
michael@13 | 139 | ;; |
michael@13 | 140 | msg ) |
michael@13 | 141 | str_usage="[-b] [-r] [-t <type>]" |
michael@13 | 142 | arg_spec="0=" |
michael@13 | 143 | opt_spec="b.r.t:" |
michael@13 | 144 | opt_b=no |
michael@13 | 145 | opt_r=no |
michael@13 | 146 | opt_t=info |
michael@13 | 147 | ;; |
michael@13 | 148 | check-class ) |
michael@13 | 149 | str_usage="" |
michael@13 | 150 | arg_spec="1=" |
michael@13 | 151 | opt_spec="" |
michael@13 | 152 | ;; |
michael@13 | 153 | -* ) |
michael@13 | 154 | echo "$prog_name:Error: unknown option \`$tool'" 2>&1 |
michael@13 | 155 | echo "$prog_name:Hint: run \`$0 -h' for usage" 2>&1 |
michael@13 | 156 | exit 1 |
michael@13 | 157 | ;; |
michael@13 | 158 | * ) |
michael@13 | 159 | echo "$prog_name:Error: unknown command \`$tool'" 2>&1 |
michael@13 | 160 | echo "$prog_name:Hint: run \`$0 -h' for usage" 2>&1 |
michael@13 | 161 | exit 1 |
michael@13 | 162 | ;; |
michael@13 | 163 | esac |
michael@13 | 164 | |
michael@13 | 165 | # tool information |
michael@13 | 166 | toolcmd="$0 $tool" |
michael@13 | 167 | toolcmdhelp="$prog_name $tool" |
michael@13 | 168 | msgprefix="$prog_name:$tool" |
michael@13 | 169 | |
michael@13 | 170 | # parse argument specification string |
michael@13 | 171 | eval `echo $arg_spec |\ |
michael@13 | 172 | sed -e 's/^\([0-9]*\)\([+=]\)/arg_NUMS=\1; arg_MODE=\2/'` |
michael@13 | 173 | |
michael@13 | 174 | # parse option specification string |
michael@13 | 175 | eval `echo h.$opt_spec |\ |
michael@13 | 176 | sed -e 's/\([a-zA-Z0-9]\)\([.:+]\)/opt_MODE_\1=\2;/g'` |
michael@13 | 177 | |
michael@13 | 178 | # iterate over argument line |
michael@13 | 179 | opt_PREV='' |
michael@13 | 180 | while [ $# -gt 0 ]; do |
michael@13 | 181 | # special option stops processing |
michael@13 | 182 | if [ ".$1" = ".--" ]; then |
michael@13 | 183 | shift |
michael@13 | 184 | break |
michael@13 | 185 | fi |
michael@13 | 186 | |
michael@13 | 187 | # determine option and argument |
michael@13 | 188 | opt_ARG_OK=no |
michael@13 | 189 | if [ ".$opt_PREV" != . ]; then |
michael@13 | 190 | # merge previous seen option with argument |
michael@13 | 191 | opt_OPT="$opt_PREV" |
michael@13 | 192 | opt_ARG="$1" |
michael@13 | 193 | opt_ARG_OK=yes |
michael@13 | 194 | opt_PREV='' |
michael@13 | 195 | else |
michael@13 | 196 | # split argument into option and argument |
michael@13 | 197 | case "$1" in |
michael@13 | 198 | -[a-zA-Z0-9]*) |
michael@13 | 199 | eval `echo "x$1" |\ |
michael@13 | 200 | sed -e 's/^x-\([a-zA-Z0-9]\)/opt_OPT="\1";/' \ |
michael@13 | 201 | -e 's/";\(.*\)$/"; opt_ARG="\1"/'` |
michael@13 | 202 | ;; |
michael@13 | 203 | -[a-zA-Z0-9]) |
michael@13 | 204 | opt_OPT=`echo "x$1" | cut -c3-` |
michael@13 | 205 | opt_ARG='' |
michael@13 | 206 | ;; |
michael@13 | 207 | *) |
michael@13 | 208 | break |
michael@13 | 209 | ;; |
michael@13 | 210 | esac |
michael@13 | 211 | fi |
michael@13 | 212 | |
michael@13 | 213 | # eat up option |
michael@13 | 214 | shift |
michael@13 | 215 | |
michael@13 | 216 | # determine whether option needs an argument |
michael@13 | 217 | eval "opt_MODE=\$opt_MODE_${opt_OPT}" |
michael@13 | 218 | if [ ".$opt_ARG" = . -a ".$opt_ARG_OK" != .yes ]; then |
michael@13 | 219 | if [ ".$opt_MODE" = ".:" -o ".$opt_MODE" = ".+" ]; then |
michael@13 | 220 | opt_PREV="$opt_OPT" |
michael@13 | 221 | continue |
michael@13 | 222 | fi |
michael@13 | 223 | fi |
michael@13 | 224 | |
michael@13 | 225 | # process option |
michael@13 | 226 | case $opt_MODE in |
michael@13 | 227 | '.' ) |
michael@13 | 228 | # boolean option |
michael@13 | 229 | eval "opt_${opt_OPT}=yes" |
michael@13 | 230 | ;; |
michael@13 | 231 | ':' ) |
michael@13 | 232 | # option with argument (multiple occurances override) |
michael@13 | 233 | eval "opt_${opt_OPT}=\"\$opt_ARG\"" |
michael@13 | 234 | ;; |
michael@13 | 235 | '+' ) |
michael@13 | 236 | # option with argument (multiple occurances append) |
michael@13 | 237 | eval "opt_${opt_OPT}=\"\$opt_${opt_OPT} \$opt_ARG\"" |
michael@13 | 238 | ;; |
michael@13 | 239 | * ) |
michael@13 | 240 | echo "$msgprefix:Error: unknown option: \`-$opt_OPT'" 1>&2 |
michael@13 | 241 | echo "$msgprefix:Hint: run \`$toolcmdhelp -h' or \`man $prog_name' for details" 1>&2 |
michael@13 | 242 | exit 1 |
michael@13 | 243 | ;; |
michael@13 | 244 | esac |
michael@13 | 245 | done |
michael@13 | 246 | if [ ".$opt_PREV" != . ]; then |
michael@13 | 247 | echo "$msgprefix:Error: missing argument to option \`-$opt_PREV'" 1>&2 |
michael@13 | 248 | echo "$msgprefix:Hint: run \`$toolcmdhelp -h' or \`man $prog_name' for details" 1>&2 |
michael@13 | 249 | exit 1 |
michael@13 | 250 | fi |
michael@13 | 251 | |
michael@13 | 252 | # process help option |
michael@13 | 253 | if [ ".$opt_h" = .yes ]; then |
michael@13 | 254 | echo "Usage: $toolcmdhelp $str_usage" |
michael@13 | 255 | exit 0 |
michael@13 | 256 | fi |
michael@13 | 257 | |
michael@13 | 258 | # complain about incorrect number of arguments |
michael@13 | 259 | case $arg_MODE in |
michael@13 | 260 | '=' ) |
michael@13 | 261 | if [ $# -ne $arg_NUMS ]; then |
michael@13 | 262 | echo "$msgprefix:Error: invalid number of arguments (exactly $arg_NUMS expected)" 1>&2 |
michael@13 | 263 | echo "$msgprefix:Hint: run \`$toolcmd -h' or \`man $prog_name' for details" 1>&2 |
michael@13 | 264 | exit 1 |
michael@13 | 265 | fi |
michael@13 | 266 | ;; |
michael@13 | 267 | '+' ) |
michael@13 | 268 | if [ $# -lt $arg_NUMS ]; then |
michael@13 | 269 | echo "$msgprefix:Error: invalid number of arguments (at least $arg_NUMS expected)" 1>&2 |
michael@13 | 270 | echo "$msgprefix:Hint: run \`$toolcmd -h' or \`man $prog_name' for details" 1>&2 |
michael@13 | 271 | exit 1 |
michael@13 | 272 | fi |
michael@13 | 273 | ;; |
michael@13 | 274 | esac |
michael@13 | 275 | |
michael@13 | 276 | # establish a temporary file on request |
michael@13 | 277 | if [ ".$gen_tmpfile" = .yes ]; then |
michael@13 | 278 | if [ ".$TMPDIR" != . ]; then |
michael@13 | 279 | tmpdir="$TMPDIR" |
michael@13 | 280 | else |
michael@13 | 281 | tmpdir="/tmp" |
michael@13 | 282 | fi |
michael@13 | 283 | tmpfile="$tmpdir/.$prog_name.$$" |
michael@13 | 284 | rm -f $tmpfile >/dev/null 2>&1 |
michael@13 | 285 | touch $tmpfile |
michael@13 | 286 | fi |
michael@13 | 287 | |
michael@13 | 288 | # provide a few useful variables |
michael@13 | 289 | NL=" |
michael@13 | 290 | " |
michael@13 | 291 | TAB=" " |
michael@13 | 292 | DIFS=" ${TAB}${NL}" |
michael@13 | 293 | |
michael@13 | 294 | # determine platform information |
michael@13 | 295 | platform_machine=`(uname -m) 2>/dev/null` ||\ |
michael@13 | 296 | platform_machine=`(uname -p) 2>/dev/null` ||\ |
michael@13 | 297 | platform_machine='unknown' |
michael@13 | 298 | if [ ".$platform_machine" = ".Power Macintosh" ]; then |
michael@13 | 299 | platform_machine=`(uname -p) 2>/dev/null` |
michael@13 | 300 | fi |
michael@13 | 301 | platform_release=`(uname -r) 2>/dev/null` ||\ |
michael@13 | 302 | platform_release='unknown' |
michael@13 | 303 | platform_system=`(uname -s) 2>/dev/null` ||\ |
michael@13 | 304 | platform_system='unknown' |
michael@13 | 305 | platform_version=`(uname -v) 2>/dev/null` ||\ |
michael@13 | 306 | platform_version='unknown' |
michael@13 | 307 | platform="${platform_machine}:${platform_system}:${platform_release}:${platform_version}" |
michael@13 | 308 | |
michael@13 | 309 | # dispatch into tools |
michael@13 | 310 | case $tool in |
michael@13 | 311 | platform ) |
michael@13 | 312 | # provide unique platform id |
michael@13 | 313 | m=`echo "$platform_machine" | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` |
michael@13 | 314 | s=`echo "$platform_system" | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` |
michael@13 | 315 | r=`echo "$platform_release" | sed -e 's;-.*$;;'` |
michael@13 | 316 | echo "${m}-${s}${r}" |
michael@13 | 317 | ;; |
michael@13 | 318 | |
michael@13 | 319 | mflags ) |
michael@13 | 320 | tool="$1" |
michael@13 | 321 | isgmake=no |
michael@13 | 322 | if [ ".`$tool -v -f /dev/null 2>/dev/null | grep 'GNU Make'`" != . ]; then |
michael@13 | 323 | isgmake=yes |
michael@13 | 324 | fi |
michael@13 | 325 | mflags='' |
michael@13 | 326 | if [ ".$isgmake" = .yes ]; then |
michael@13 | 327 | mflags="--no-print-directory" |
michael@13 | 328 | fi |
michael@13 | 329 | if [ ".$opt_O" = .yes ]; then |
michael@13 | 330 | case $platform in |
michael@13 | 331 | *:SunOS:5.*:* | *:OSF1:*:* ) |
michael@13 | 332 | if [ ".$isgmake" = .yes ]; then |
michael@13 | 333 | n=`(/bin/uname -X) 2>/dev/null | grep -i NumCPU | awk '{ print $3; }'` |
michael@13 | 334 | if [ ".$n" != . ]; then |
michael@13 | 335 | if [ $n -gt 1 ]; then |
michael@13 | 336 | n=`expr $n \* 2` |
michael@13 | 337 | mflags="$mflags -j$n" |
michael@13 | 338 | fi |
michael@13 | 339 | fi |
michael@13 | 340 | fi |
michael@13 | 341 | ;; |
michael@13 | 342 | *:FreeBSD:[4-8].*:* ) |
michael@13 | 343 | n=`/sbin/sysctl -n hw.ncpu` |
michael@13 | 344 | if [ ".$n" != . ]; then |
michael@13 | 345 | if [ $n -gt 1 ]; then |
michael@13 | 346 | n=`expr $n \* 2` |
michael@13 | 347 | mflags="$mflags -j$n" |
michael@13 | 348 | if [ ".$isgmake" = .no ]; then |
michael@13 | 349 | mflags="$mflags -B" |
michael@13 | 350 | fi |
michael@13 | 351 | fi |
michael@13 | 352 | fi |
michael@13 | 353 | ;; |
michael@13 | 354 | *:NetBSD:1.[56]*:* | *:NetBSD:[2345].*:* ) |
michael@13 | 355 | n=`/sbin/sysctl -n hw.ncpu` |
michael@13 | 356 | if [ ".$n" != . ]; then |
michael@13 | 357 | if [ $n -gt 1 ]; then |
michael@13 | 358 | n=`expr $n \* 2` |
michael@13 | 359 | mflags="$mflags -j$n" |
michael@13 | 360 | if [ ".$isgmake" = .no ]; then |
michael@13 | 361 | mflags="$mflags -B" |
michael@13 | 362 | fi |
michael@13 | 363 | fi |
michael@13 | 364 | fi |
michael@13 | 365 | ;; |
michael@13 | 366 | *:Linux:*:* ) |
michael@13 | 367 | n=`grep ^processor /proc/cpuinfo | wc -l | awk '{ print $1; }'` |
michael@13 | 368 | if [ ".$n" != . ]; then |
michael@13 | 369 | if [ $n -gt 1 ]; then |
michael@13 | 370 | n=`expr $n \* 2` |
michael@13 | 371 | mflags="$mflags -j$n" |
michael@13 | 372 | fi |
michael@13 | 373 | fi |
michael@13 | 374 | ;; |
michael@13 | 375 | *:HP-UX:*:* ) |
michael@13 | 376 | if [ ".$isgmake" = .yes ]; then |
michael@13 | 377 | n=`ioscan -d processor -k -F | wc -l` |
michael@13 | 378 | if [ ".$n" != . ]; then |
michael@13 | 379 | if [ $n -gt 1 ]; then |
michael@13 | 380 | n=`expr $n \* 2` |
michael@13 | 381 | mflags="$mflags -j$n" |
michael@13 | 382 | fi |
michael@13 | 383 | fi |
michael@13 | 384 | fi |
michael@13 | 385 | ;; |
michael@13 | 386 | *:IRIX64:6.*:* ) |
michael@13 | 387 | if [ ".$isgmake" = .yes ]; then |
michael@13 | 388 | n=`/usr/sbin/sysconf | awk '/NUM_PROCESSORS/ { print $2; }'` |
michael@13 | 389 | if [ ".$n" != . ]; then |
michael@13 | 390 | if [ $n -gt 1 ]; then |
michael@13 | 391 | n=`expr $n \* 2` |
michael@13 | 392 | mflags="$mflags -j$n" |
michael@13 | 393 | fi |
michael@13 | 394 | fi |
michael@13 | 395 | fi |
michael@13 | 396 | ;; |
michael@13 | 397 | *:Darwin:*:* ) |
michael@13 | 398 | n=`/usr/sbin/sysctl hw.ncpu | awk '{ print $3; }'` |
michael@13 | 399 | if [ ".$n" != . ]; then |
michael@13 | 400 | if [ $n -gt 1 ]; then |
michael@13 | 401 | n=`expr $n \* 2` |
michael@13 | 402 | mflags="$mflags -j$n" |
michael@13 | 403 | if [ ".$isgmake" = .no ]; then |
michael@13 | 404 | mflags="$mflags -B" |
michael@13 | 405 | fi |
michael@13 | 406 | fi |
michael@13 | 407 | fi |
michael@13 | 408 | ;; |
michael@13 | 409 | *:AIX:*:* ) |
michael@13 | 410 | if [ ".$isgmake" = .yes ]; then |
michael@13 | 411 | if [ -x /usr/sbin/lsdev ]; then |
michael@13 | 412 | n=`/usr/sbin/lsdev -C -c processor -S available | wc -l | awk '{ print $1; }'` |
michael@13 | 413 | if [ ".$n" != . ]; then |
michael@13 | 414 | if [ $n -gt 1 ]; then |
michael@13 | 415 | n=`expr $n \* 2` |
michael@13 | 416 | mflags="$mflags -j$n" |
michael@13 | 417 | fi |
michael@13 | 418 | fi |
michael@13 | 419 | fi |
michael@13 | 420 | fi |
michael@13 | 421 | ;; |
michael@13 | 422 | esac |
michael@13 | 423 | fi |
michael@13 | 424 | echo "x$mflags" | sed -e 's;^x;;' |
michael@13 | 425 | ;; |
michael@13 | 426 | |
michael@13 | 427 | cflags ) |
michael@13 | 428 | tool="$1" |
michael@13 | 429 | echo $tool | grep ^/ >/dev/null |
michael@13 | 430 | if [ $? -eq 0 ]; then |
michael@13 | 431 | if [ ! -x "$tool" -o -d "$tool" ]; then |
michael@13 | 432 | echo "$msgprefix:Error: specified tool \`$tool' not found or not executable" 1>&2 |
michael@13 | 433 | exit 1 |
michael@13 | 434 | fi |
michael@13 | 435 | else |
michael@13 | 436 | shtool=`echo $prog_path | sed -e 's;/[^/]*$;/shtool;'` |
michael@13 | 437 | sh $shtool path --suppress $tool |
michael@13 | 438 | if [ $? -ne 0 ]; then |
michael@13 | 439 | echo "$msgprefix:Error: specified tool \`$tool' not found in PATH" 1>&2 |
michael@13 | 440 | exit 1 |
michael@13 | 441 | fi |
michael@13 | 442 | fi |
michael@13 | 443 | isgcc=no |
michael@13 | 444 | if [ ".`($tool -v; $tool --version) </dev/null 2>&1 | grep -i 'gcc'`" != . ]; then |
michael@13 | 445 | isgcc=yes |
michael@13 | 446 | fi |
michael@13 | 447 | cflags='' |
michael@13 | 448 | if [ ".$opt_O" = .yes ]; then |
michael@13 | 449 | if [ ".$isgcc" = .yes ]; then |
michael@13 | 450 | case "$platform:`$tool -dumpversion 2>/dev/null`" in |
michael@13 | 451 | *:NetBSD:1.6*:*:2.* ) |
michael@13 | 452 | # NetBSD 1.6.x with GCC 2.95.x suffers from memory |
michael@13 | 453 | # exhaustion problems under GCC optimizations. |
michael@13 | 454 | ;; |
michael@13 | 455 | * ) |
michael@13 | 456 | cflags="-O2" |
michael@13 | 457 | ;; |
michael@13 | 458 | esac |
michael@13 | 459 | if [ ".`$tool -v 2>/dev/null | grep 'with-gnu-as'`" != . ] || \ |
michael@13 | 460 | [ ".`(as --version </dev/null) 2>/dev/null | grep 'GNU'`" != . ]; then |
michael@13 | 461 | cflags="$cflags -pipe" |
michael@13 | 462 | fi |
michael@13 | 463 | else |
michael@13 | 464 | cflags="-O" |
michael@13 | 465 | fi |
michael@13 | 466 | fi |
michael@13 | 467 | case "$platform" in |
michael@13 | 468 | amd64:FreeBSD:*:* | ia64:FreeBSD:*:* | sparc64:FreeBSD:*:* | x86_64:Linux:*:* ) |
michael@13 | 469 | # at least under FreeBSD on amd64, ia64 and sparc64 |
michael@13 | 470 | # the GNU binutils strictly require Position In- |
michael@13 | 471 | # dependent Code (PIC) when Dynamic Shared Objects |
michael@13 | 472 | # (DSO) are involved. As an ugly workaround we |
michael@13 | 473 | # build everything with PIC there, although this is |
michael@13 | 474 | # more than required. We also can assume that the C |
michael@13 | 475 | # compiler is always GCC, either the OpenPKG one or |
michael@13 | 476 | # the FreeBSD one. |
michael@13 | 477 | cflags="-fPIC" |
michael@13 | 478 | ;; |
michael@13 | 479 | esac |
michael@13 | 480 | echo "x$cflags" | sed -e 's;^x;;' |
michael@13 | 481 | ;; |
michael@13 | 482 | |
michael@13 | 483 | cppflags ) |
michael@13 | 484 | std=0 |
michael@13 | 485 | cppflags="" |
michael@13 | 486 | for pkg in .. $*; do |
michael@13 | 487 | [ ".$pkg" = ... ] && continue |
michael@13 | 488 | if [ ".$pkg" = .. ]; then |
michael@13 | 489 | cppflags="$cppflags -I${opt_p}/include" |
michael@13 | 490 | std=1 |
michael@13 | 491 | else |
michael@13 | 492 | cppflags="$cppflags -I${opt_p}/include/$pkg" |
michael@13 | 493 | fi |
michael@13 | 494 | done |
michael@13 | 495 | if [ $std -eq 0 ]; then |
michael@13 | 496 | cppflags="-I${opt_p}/include$cppflags" |
michael@13 | 497 | fi |
michael@13 | 498 | if [ ".$opt_i" = .yes ]; then |
michael@13 | 499 | arch="unknown"; os_name="unknown"; os_vers="0" |
michael@13 | 500 | shtool=`echo $prog_path | sed -e 's;/[^/]*$;/shtool;'` |
michael@13 | 501 | eval `sh $shtool platform -U -S ":" -C "" -F "%<ac>:%<st>" |\ |
michael@13 | 502 | sed -e 's/^\(.*\):\(.*\):\(.*\)$/arch="\1"; os_name="\2"; os_vers="\3";/'` |
michael@13 | 503 | V=0; R=0; L=0 |
michael@13 | 504 | eval `echo "$os_vers" |\ |
michael@13 | 505 | sed -e 's/^/X/' \ |
michael@13 | 506 | -e 's/^X[^0-9]*\([0-9][0-9]*\)[^0-9][^0-9]*\([0-9][0-9]*\)[^0-9][^0-9]*\([0-9][0-9]*\).*$/V="\1"; R="\2"; L="\3";/' \ |
michael@13 | 507 | -e 's/^X[^0-9]*\([0-9][0-9]*\)[^0-9][^0-9]*\([0-9][0-9]*\).*$/V="\1"; R="\2";/' \ |
michael@13 | 508 | -e 's/^X[^0-9]*\([0-9][0-9]*\).*$/V="\1";/' \ |
michael@13 | 509 | -e 's/^X.*$/:/'` |
michael@13 | 510 | os_vers=`echo . | awk '{ printf("%02d%02d%02d", V, R, L); }' V="$V" R="$R" L="$L"` |
michael@13 | 511 | cppflags="$cppflags -D__OPENPKG_${arch} -D__OPENPKG_${os_name}=${os_vers}" |
michael@13 | 512 | fi |
michael@13 | 513 | echo "x$cppflags" | sed -e 's;^x;;' -e 's;^ *;;' |
michael@13 | 514 | ;; |
michael@13 | 515 | |
michael@13 | 516 | ldflags ) |
michael@13 | 517 | std=0 |
michael@13 | 518 | ldflags="" |
michael@13 | 519 | for pkg in .. $*; do |
michael@13 | 520 | [ ".$pkg" = ... ] && continue |
michael@13 | 521 | if [ ".$pkg" = .. ]; then |
michael@13 | 522 | ldflags="$ldflags -L${opt_p}/lib" |
michael@13 | 523 | std=1 |
michael@13 | 524 | else |
michael@13 | 525 | ldflags="$ldflags -L${opt_p}/lib/$pkg" |
michael@13 | 526 | fi |
michael@13 | 527 | done |
michael@13 | 528 | if [ $std -eq 0 ]; then |
michael@13 | 529 | ldflags="-L${opt_p}/lib$ldflags" |
michael@13 | 530 | fi |
michael@13 | 531 | echo "x$ldflags" | sed -e 's;^x;;' -e 's;^ *;;' |
michael@13 | 532 | ;; |
michael@13 | 533 | |
michael@13 | 534 | files ) |
michael@13 | 535 | # if a Perl interpreter is available, we perform the operation |
michael@13 | 536 | # with it because Perl is a magnitude (factor 10!) faster than |
michael@13 | 537 | # what we can do here in Bourne-Shell. |
michael@13 | 538 | perl='' |
michael@13 | 539 | for dir in `echo "$PATH:@l_prefix@/lib/openpkg" | sed -e 's/:/ /g'` .; do |
michael@13 | 540 | [ ".$dir" = .. -o ".$dir" = . ] && continue |
michael@13 | 541 | for tool in perl5 perl miniperl; do |
michael@13 | 542 | if [ -f "$dir/$tool" ]; then |
michael@13 | 543 | perl="$dir/$tool" |
michael@13 | 544 | break |
michael@13 | 545 | fi |
michael@13 | 546 | done |
michael@13 | 547 | if [ ".$perl" != . ]; then |
michael@13 | 548 | break |
michael@13 | 549 | fi |
michael@13 | 550 | done |
michael@13 | 551 | if [ ".$perl" != . ]; then |
michael@13 | 552 | cat >$tmpfile <<'EOT' |
michael@13 | 553 | ## |
michael@13 | 554 | ## PERL IMPLEMENTATION (FAST) |
michael@13 | 555 | ## |
michael@13 | 556 | |
michael@13 | 557 | my $opt_v = 0; |
michael@13 | 558 | my $opt_o = ''; |
michael@13 | 559 | my $opt_r = ''; |
michael@13 | 560 | while ($ARGV[0] =~ m|^-(.)(.*)$|) { |
michael@13 | 561 | my ($opt, $arg) = ($1, $2); |
michael@13 | 562 | shift(@ARGV); |
michael@13 | 563 | unshift(@ARGV, $arg) if ($arg ne ''); |
michael@13 | 564 | $opt_v = 1 if ($opt eq 'v'); |
michael@13 | 565 | $opt_o = shift(@ARGV) if ($opt eq 'o'); |
michael@13 | 566 | $opt_r = shift(@ARGV) if ($opt eq 'r'); |
michael@13 | 567 | } |
michael@13 | 568 | |
michael@13 | 569 | # remember the build root in a reasonable short variable ;) |
michael@13 | 570 | my $br = "$opt_r"; |
michael@13 | 571 | |
michael@13 | 572 | # read input file list |
michael@13 | 573 | my @L = (); |
michael@13 | 574 | if ($#ARGV == -1 or ($#ARGV == 0 and $ARGV[0] eq "-")) { |
michael@13 | 575 | # read file list from stdin |
michael@13 | 576 | while (<STDIN>) { |
michael@13 | 577 | s/\n$//s; |
michael@13 | 578 | push(@L, $_); |
michael@13 | 579 | } |
michael@13 | 580 | } |
michael@13 | 581 | else { |
michael@13 | 582 | # read file list from argument line |
michael@13 | 583 | @L = @ARGV; |
michael@13 | 584 | } |
michael@13 | 585 | |
michael@13 | 586 | # PASS 1: PREPARATION AND SYNTACTICAL EXPANSION |
michael@13 | 587 | if ($opt_v == 1) { |
michael@13 | 588 | print STDERR "rpmtool:files: pass 1 (preparation and syntactical expansions)\n"; |
michael@13 | 589 | } |
michael@13 | 590 | my @T = (); |
michael@13 | 591 | my $l; |
michael@13 | 592 | foreach $l (@L) { |
michael@13 | 593 | # replace tabs with spaces, reduce multiple spaces to single |
michael@13 | 594 | # spaces, and remove leading and trailing spaces |
michael@13 | 595 | $l =~ s|[ \t\n]+| |sg; |
michael@13 | 596 | $l =~ s|^[ \t]+||sg; |
michael@13 | 597 | $l =~ s|[ \t]+$||sg; |
michael@13 | 598 | |
michael@13 | 599 | # move tags to end of entry for easier parsing |
michael@13 | 600 | 1 while ($l =~ s|^(%\S+) (.+)|$2 $1|); |
michael@13 | 601 | |
michael@13 | 602 | # use `:' as a dummy path for tag-only entries (like `%defattr') |
michael@13 | 603 | # to avoid special cases in the later processing |
michael@13 | 604 | if ($l =~ m|^%.+|) { |
michael@13 | 605 | $l = ": $l"; |
michael@13 | 606 | } |
michael@13 | 607 | |
michael@13 | 608 | # split entry into path and optional tags |
michael@13 | 609 | my ($p, $t) = ($l =~ m|^(\S+)(.*)$|); |
michael@13 | 610 | |
michael@13 | 611 | # expand `{foo,bar,quux}' constructs in path (silent |
michael@13 | 612 | # assumtion to make life easier is that the constructs |
michael@13 | 613 | # occurs only once in a path!) |
michael@13 | 614 | if ($p =~ m|^(.*)\{([^\}]+)\}(.*)$|) { |
michael@13 | 615 | # split path into prolog, the set construct, and the epilog |
michael@13 | 616 | my ($pro, $set, $epi) = ($1, $2, $3); |
michael@13 | 617 | |
michael@13 | 618 | # repeat prolog and epilog for all elements in set |
michael@13 | 619 | my $x; |
michael@13 | 620 | foreach $x (split(/,/, $set)) { |
michael@13 | 621 | push(@T, "${pro}${x}${epi}${t}"); |
michael@13 | 622 | } |
michael@13 | 623 | } |
michael@13 | 624 | else { |
michael@13 | 625 | # else just take over the entry as is |
michael@13 | 626 | push(@T, $l); |
michael@13 | 627 | } |
michael@13 | 628 | } |
michael@13 | 629 | @L = @T; |
michael@13 | 630 | |
michael@13 | 631 | # PASS 2: FILESYSTEM-BASED EXPANSIONS |
michael@13 | 632 | if ($opt_v == 1) { |
michael@13 | 633 | print STDERR "rpmtool:files: pass 2 (filesystem-based expansions)\n"; |
michael@13 | 634 | } |
michael@13 | 635 | @T = (); |
michael@13 | 636 | foreach $l (@L) { |
michael@13 | 637 | # split entry into path and optional tags |
michael@13 | 638 | my ($p, $t) = ($l =~ m|^(\S*)(.*)$|); |
michael@13 | 639 | |
michael@13 | 640 | # expand... |
michael@13 | 641 | if (-d "$br$p" and $t !~ m|.*%dir.*|) { |
michael@13 | 642 | # expand path because it is not tagged with %dir |
michael@13 | 643 | my @X = `cd "$br$p" && find . -print`; |
michael@13 | 644 | my $x; |
michael@13 | 645 | foreach $x (@X) { |
michael@13 | 646 | $x =~ s|\n$||s; |
michael@13 | 647 | $x =~ s|^\.|$p|s; |
michael@13 | 648 | push(@T, "${x}${t}"); |
michael@13 | 649 | } |
michael@13 | 650 | } |
michael@13 | 651 | else { |
michael@13 | 652 | # expand path wildcards (`*' and `[..]') |
michael@13 | 653 | # (if not wildcards are present, this doesn't harm) |
michael@13 | 654 | my @X = glob("$br$p"); |
michael@13 | 655 | my $x; |
michael@13 | 656 | foreach $x (@X) { |
michael@13 | 657 | my $brqm = quotemeta($br); |
michael@13 | 658 | $x =~ s|^$brqm||s; |
michael@13 | 659 | push(@T, "${x}${t}"); |
michael@13 | 660 | } |
michael@13 | 661 | } |
michael@13 | 662 | } |
michael@13 | 663 | @L = @T; |
michael@13 | 664 | |
michael@13 | 665 | # PASS 3: DUPLICATION REMOVAL AND CLEANUP |
michael@13 | 666 | if ($opt_v == 1) { |
michael@13 | 667 | print STDERR "rpmtool:files: pass 3 (duplication removal and cleanup)\n"; |
michael@13 | 668 | } |
michael@13 | 669 | @T = (); |
michael@13 | 670 | foreach $l (@L) { |
michael@13 | 671 | # split entry into path and optional tags |
michael@13 | 672 | my ($p, $t) = ($l =~ m|^(\S*)(.*)$|); |
michael@13 | 673 | |
michael@13 | 674 | # add %dir tag if entry is a directory, but still not |
michael@13 | 675 | # tagged as such (else RPM would again expand it recursively) |
michael@13 | 676 | if (-d "$br$p") { |
michael@13 | 677 | if ($t !~ m|%dir|) { |
michael@13 | 678 | $t .= " %dir"; |
michael@13 | 679 | } |
michael@13 | 680 | } |
michael@13 | 681 | |
michael@13 | 682 | # remove duplicate entries in already processed part |
michael@13 | 683 | # (but make sure we keep the entries with the dummy tags) |
michael@13 | 684 | if ($p ne ":") { |
michael@13 | 685 | my @T2 = (); |
michael@13 | 686 | foreach $t (@T) { |
michael@13 | 687 | my $pqm = quotemeta($p); |
michael@13 | 688 | next if ($t =~ m|^$pqm | or $t eq $p); |
michael@13 | 689 | push(@T2, $t); |
michael@13 | 690 | } |
michael@13 | 691 | @T = @T2; |
michael@13 | 692 | } |
michael@13 | 693 | |
michael@13 | 694 | # keep entry only if no %not tag is present |
michael@13 | 695 | # (else all entries are removed) |
michael@13 | 696 | if ($t !~ m|.*%not.*|) { |
michael@13 | 697 | push(@T, "${p}${t}"); |
michael@13 | 698 | } |
michael@13 | 699 | } |
michael@13 | 700 | @L = @T; |
michael@13 | 701 | |
michael@13 | 702 | # write out new file list |
michael@13 | 703 | @T = (); |
michael@13 | 704 | foreach $l (@L) { |
michael@13 | 705 | $l =~ s|^(\S+) (.*)$|$2 $1|sg; |
michael@13 | 706 | $l =~ s|^\s+||s; |
michael@13 | 707 | $l =~ s|\s+$||s; |
michael@13 | 708 | $l =~ s|\s+:$||s; |
michael@13 | 709 | push(@T, $l); |
michael@13 | 710 | } |
michael@13 | 711 | @L = @T; |
michael@13 | 712 | if ($opt_o eq '' or $opt_o eq '-') { |
michael@13 | 713 | print STDOUT join("\n", @L)."\n"; |
michael@13 | 714 | } |
michael@13 | 715 | else { |
michael@13 | 716 | open(FP, ">$opt_o"); |
michael@13 | 717 | print FP join("\n", @L)."\n"; |
michael@13 | 718 | close(FP); |
michael@13 | 719 | } |
michael@13 | 720 | EOT |
michael@13 | 721 | cmd="$perl $tmpfile"; |
michael@13 | 722 | if [ ".$opt_v" = .yes ]; then |
michael@13 | 723 | cmd="$cmd -v" |
michael@13 | 724 | fi |
michael@13 | 725 | if [ ".$opt_o" != . ]; then |
michael@13 | 726 | cmd="$cmd -o \"$opt_o\"" |
michael@13 | 727 | fi |
michael@13 | 728 | if [ ".$opt_r" != . ]; then |
michael@13 | 729 | cmd="$cmd -r \"$opt_r\"" |
michael@13 | 730 | fi |
michael@13 | 731 | for arg |
michael@13 | 732 | do |
michael@13 | 733 | cmd="$cmd \"$arg\"" |
michael@13 | 734 | done |
michael@13 | 735 | eval "$cmd" |
michael@13 | 736 | else |
michael@13 | 737 | ## |
michael@13 | 738 | ## BOURNE-SHELL IMPLEMENTATION (PORTABLE) |
michael@13 | 739 | ## |
michael@13 | 740 | |
michael@13 | 741 | # remember the build root in a reasonable short variable ;) |
michael@13 | 742 | br="$opt_r" |
michael@13 | 743 | |
michael@13 | 744 | # make sure filename expansion is disabled per default |
michael@13 | 745 | set -f |
michael@13 | 746 | |
michael@13 | 747 | # read input file list |
michael@13 | 748 | L='' |
michael@13 | 749 | if [ $# -eq 0 ] || [ $# -eq 1 -a ".$1" = ".-" ]; then |
michael@13 | 750 | # read file list from stdin |
michael@13 | 751 | L=`cat` |
michael@13 | 752 | else |
michael@13 | 753 | # read file list from argument line |
michael@13 | 754 | for arg |
michael@13 | 755 | do |
michael@13 | 756 | L="$L$NL$arg" |
michael@13 | 757 | done |
michael@13 | 758 | fi |
michael@13 | 759 | |
michael@13 | 760 | # PASS 1: PREPARATION AND SYNTACTICAL EXPANSION |
michael@13 | 761 | if [ ".$opt_v" = .yes ]; then |
michael@13 | 762 | echo "rpmtool:files: pass 1 (preparation and syntactical expansions)" 1>&2 |
michael@13 | 763 | fi |
michael@13 | 764 | T='' |
michael@13 | 765 | OIFS="$IFS"; IFS="$NL" |
michael@13 | 766 | for l in $L; do |
michael@13 | 767 | [ ".$l" = . ] && continue |
michael@13 | 768 | |
michael@13 | 769 | # replace tabs with spaces, reduce multiple spaces to single |
michael@13 | 770 | # spaces, and remove leading and trailing spaces |
michael@13 | 771 | l=`echo "$l" | sed -e "s;${TAB}; ;g" -e 's; *; ;g' -e 's;^ *;;' -e 's; *$;;'` |
michael@13 | 772 | |
michael@13 | 773 | # move tags to end of entry for easier parsing |
michael@13 | 774 | while [ ".`echo \"$l\" | grep '^%[^ ]* .*'`" != . ]; do |
michael@13 | 775 | l=`echo "$l" | sed -e 's;^\(%[^ ]*\) \(.*\);\2 \1;'` |
michael@13 | 776 | done |
michael@13 | 777 | |
michael@13 | 778 | # use `:' as a dummy path for tag-only entries (like `%defattr') |
michael@13 | 779 | # to avoid special cases in the later processing |
michael@13 | 780 | if [ ".`echo \"$l\" | grep '^%.*'`" != . ]; then |
michael@13 | 781 | l=": $l" |
michael@13 | 782 | fi |
michael@13 | 783 | |
michael@13 | 784 | # split entry into path and optional tags |
michael@13 | 785 | eval `echo ".$l" | sed -e 's;^\.\([^ ]*\)\(.*\)$;p="\1" t="\2";'` |
michael@13 | 786 | |
michael@13 | 787 | # expand `{foo,bar,quux}' constructs in path (silent |
michael@13 | 788 | # assumtion to make life easier is that the constructs |
michael@13 | 789 | # occurs only once in a path!) |
michael@13 | 790 | if [ ".`echo \".$p\" | grep '^\..*{[^}]*}.*$'`" != . ]; then |
michael@13 | 791 | |
michael@13 | 792 | # split path into prolog, the set construct, and the epilog |
michael@13 | 793 | eval `echo ".$p" | sed -e 's;^\.\(.*\){\([^}]*\)}\(.*\)$;pro="\1" set="\2" epi="\3";'` |
michael@13 | 794 | |
michael@13 | 795 | # repeat prolog and epilog for all elements in set |
michael@13 | 796 | OIFS2="$IFS"; IFS="," |
michael@13 | 797 | for x in $set; do |
michael@13 | 798 | T="$T$NL${pro}${x}${epi}${t}" |
michael@13 | 799 | done |
michael@13 | 800 | IFS="$OIFS2" |
michael@13 | 801 | else |
michael@13 | 802 | # else just take over the entry as is |
michael@13 | 803 | T="$T$NL$l" |
michael@13 | 804 | fi |
michael@13 | 805 | done |
michael@13 | 806 | L="$T" |
michael@13 | 807 | IFS="$OIFS" |
michael@13 | 808 | |
michael@13 | 809 | # PASS 2: FILESYSTEM-BASED EXPANSIONS |
michael@13 | 810 | if [ ".$opt_v" = .yes ]; then |
michael@13 | 811 | echo "rpmtool:files: pass 2 (filesystem-based expansions)" 1>&2 |
michael@13 | 812 | fi |
michael@13 | 813 | T='' |
michael@13 | 814 | OIFS="$IFS"; IFS="$NL" |
michael@13 | 815 | for l in $L; do |
michael@13 | 816 | [ ".$l" = . ] && continue |
michael@13 | 817 | |
michael@13 | 818 | # split entry into path and optional tags |
michael@13 | 819 | eval `echo ".$l" | sed -e 's;^\.\([^ ]*\)\(.*\)$;p="\1" t="\2";'` |
michael@13 | 820 | |
michael@13 | 821 | # expand... |
michael@13 | 822 | if [ -d "$br$p" -a ".`expr \".$t\" : '\..*%dir.*'`" = .0 ]; then |
michael@13 | 823 | # expand path because it is not tagged with %dir |
michael@13 | 824 | OIFS2="$IFS"; IFS="$DIFS" |
michael@13 | 825 | for x in `cd "$br$p" && find . -print | sed -e "s;^\\.;$p;"`; do |
michael@13 | 826 | T="$T$NL${x}${t}" |
michael@13 | 827 | done |
michael@13 | 828 | IFS="$OIFS2" |
michael@13 | 829 | else |
michael@13 | 830 | # expand path wildcards (`*' and `[..]') |
michael@13 | 831 | # (if not wildcards are present, this doesn't harm) |
michael@13 | 832 | OIFS2="$IFS"; IFS="$DIFS" |
michael@13 | 833 | for x in `(set +f; echo $br$p) | sed -e "s;^$br;;" -e "s; $br; ;g"`; do |
michael@13 | 834 | T="$T$NL${x}${t}" |
michael@13 | 835 | done |
michael@13 | 836 | IFS="$OIFS2" |
michael@13 | 837 | fi |
michael@13 | 838 | done |
michael@13 | 839 | IFS="$OIFS" |
michael@13 | 840 | L="$T" |
michael@13 | 841 | |
michael@13 | 842 | # PASS 3: DUPLICATION REMOVAL AND CLEANUP |
michael@13 | 843 | if [ ".$opt_v" = .yes ]; then |
michael@13 | 844 | echo "rpmtool:files: pass 3 (duplication removal and cleanup)" 1>&2 |
michael@13 | 845 | fi |
michael@13 | 846 | T='' |
michael@13 | 847 | OIFS="$IFS"; IFS="$NL" |
michael@13 | 848 | for l in $L; do |
michael@13 | 849 | [ ".$l" = . ] && continue |
michael@13 | 850 | |
michael@13 | 851 | # split entry into path and optional tags |
michael@13 | 852 | eval `echo ".$l" | sed -e 's;^\.\([^ ]*\)\(.*\)$;p="\1" t="\2";'` |
michael@13 | 853 | |
michael@13 | 854 | # add %dir tag if entry is a directory, but still not |
michael@13 | 855 | # tagged as such (else RPM would again expand it recursively) |
michael@13 | 856 | if [ -d "$br$p" ]; then |
michael@13 | 857 | if [ ".`expr \".$t\" : '\..*%dir.*'`" = .0 ]; then |
michael@13 | 858 | t="$t %dir" |
michael@13 | 859 | fi |
michael@13 | 860 | fi |
michael@13 | 861 | |
michael@13 | 862 | # remove duplicate entries in already processed part |
michael@13 | 863 | # (but make sure we keep the entries with the dummy tags) |
michael@13 | 864 | if [ ".$p" != ".:" ]; then |
michael@13 | 865 | T=`echo "$T" | grep -v "^$p " | grep -v "^$p\$"` |
michael@13 | 866 | fi |
michael@13 | 867 | |
michael@13 | 868 | # keep entry only if no %not tag is present |
michael@13 | 869 | # (else all entries are removed) |
michael@13 | 870 | if [ ".`expr \".$t\" : '\..*%not.*'`" = .0 ]; then |
michael@13 | 871 | T="$T$NL${p}${t}" |
michael@13 | 872 | fi |
michael@13 | 873 | done |
michael@13 | 874 | IFS="$OIFS" |
michael@13 | 875 | L="$T" |
michael@13 | 876 | |
michael@13 | 877 | # write out new file list |
michael@13 | 878 | if [ ".$opt_o" = . -o ".$opt_o" = ".-" ]; then |
michael@13 | 879 | outcmd="cat" |
michael@13 | 880 | else |
michael@13 | 881 | outcmd="cat > $opt_o" |
michael@13 | 882 | fi |
michael@13 | 883 | echo "$L" |\ |
michael@13 | 884 | sed -e '/^$/d' \ |
michael@13 | 885 | -e 's;^\([^ ]*\) *\(.*\)$;\2 \1;g' \ |
michael@13 | 886 | -e 's;^ *;;' \ |
michael@13 | 887 | -e 's; *$;;' \ |
michael@13 | 888 | -e 's; *:$;;' | eval $outcmd |
michael@13 | 889 | fi |
michael@13 | 890 | ;; |
michael@13 | 891 | |
michael@13 | 892 | signal ) |
michael@13 | 893 | if [ ".$opt_p" = . -a ".$opt_m" = . ]; then |
michael@13 | 894 | echo "$msgprefix:Error: either option -p or -m has to be specified" 1>&2 |
michael@13 | 895 | exit 1 |
michael@13 | 896 | fi |
michael@13 | 897 | case "$platform" in |
michael@13 | 898 | *:FreeBSD:*:* | *:NetBSD:*:* ) |
michael@13 | 899 | cmd0="ps -ax -o pid" |
michael@13 | 900 | cmd1="ps -ax -o command" |
michael@13 | 901 | cmd2="ps -ax -o pid,command" |
michael@13 | 902 | cmd3="ps -ax -o pid,ppid" |
michael@13 | 903 | ;; |
michael@13 | 904 | *:Linux:*:* | *:OSF1:5.*:* ) |
michael@13 | 905 | cmd0="ps axo pid" |
michael@13 | 906 | cmd1="ps axo cmd" |
michael@13 | 907 | cmd2="ps axo pid,cmd" |
michael@13 | 908 | cmd3="ps axo pid,ppid" |
michael@13 | 909 | ;; |
michael@13 | 910 | *:SunOS:5.*:* ) |
michael@13 | 911 | cmd0="ps -ef -o pid" |
michael@13 | 912 | cmd1="ps -ef -o args" |
michael@13 | 913 | cmd2="ps -ef -o pid,args" |
michael@13 | 914 | cmd3="ps -ef -o pid,ppid" |
michael@13 | 915 | ;; |
michael@13 | 916 | *:HP-UX:*:* ) |
michael@13 | 917 | cmd0="ps -ef" # FIXME |
michael@13 | 918 | cmd1="ps -ef" # FIXME |
michael@13 | 919 | cmd2="ps -ef" # FIXME |
michael@13 | 920 | cmd3="ps -ef" # FIXME |
michael@13 | 921 | ;; |
michael@13 | 922 | *:IRIX64:6.*:* ) |
michael@13 | 923 | cmd0="ps -ef -o pid" |
michael@13 | 924 | cmd1="ps -ef -o args" |
michael@13 | 925 | cmd2="ps -ef -o pid,args" |
michael@13 | 926 | cmd3="ps -ef -o pid,ppid" |
michael@13 | 927 | ;; |
michael@13 | 928 | *:Darwin:*:* ) |
michael@13 | 929 | cmd0="ps -ax -opid" |
michael@13 | 930 | cmd1="ps -ax -ocommand" |
michael@13 | 931 | cmd2="ps -ax -opid,command" |
michael@13 | 932 | cmd3="ps -ax -opid,ppid" |
michael@13 | 933 | esac |
michael@13 | 934 | # try all signals in order |
michael@13 | 935 | i=$# |
michael@13 | 936 | for sig in "$@"; do |
michael@13 | 937 | # check whether program is still running/active |
michael@13 | 938 | active="" |
michael@13 | 939 | if [ ".$opt_p" != . ]; then |
michael@13 | 940 | active=`$cmd0 | grep "$opt_p" | grep -v grep | grep -v rpmtool` |
michael@13 | 941 | elif [ ".$opt_m" != . ]; then |
michael@13 | 942 | active=`$cmd1 | grep "$opt_m" | grep -v grep | grep -v rpmtool` |
michael@13 | 943 | fi |
michael@13 | 944 | if [ ".$active" = . ]; then |
michael@13 | 945 | break |
michael@13 | 946 | fi |
michael@13 | 947 | |
michael@13 | 948 | # send signal to program |
michael@13 | 949 | if [ ".$opt_p" != . ]; then |
michael@13 | 950 | pids="$opt_p" |
michael@13 | 951 | elif [ ".$opt_m" != . ]; then |
michael@13 | 952 | pids=`$cmd2 | sed -e "s;^[ ${TAB}]*;;" | egrep "[0-9]* .*$opt_m" |\ |
michael@13 | 953 | grep -v grep | grep -v rpmtool |\ |
michael@13 | 954 | awk '{ printf("%s\n", $1); }'` |
michael@13 | 955 | fi |
michael@13 | 956 | for pid in $pids; do |
michael@13 | 957 | if [ ".$opt_v" = .yes ]; then |
michael@13 | 958 | echo "sending $sig signal to process $pid" |
michael@13 | 959 | fi |
michael@13 | 960 | if [ ".$opt_t" = .yes ]; then |
michael@13 | 961 | echo "kill -$sig $pid" |
michael@13 | 962 | fi |
michael@13 | 963 | if [ ".$opt_n" = .no ]; then |
michael@13 | 964 | eval "kill -$sig $pid" |
michael@13 | 965 | fi |
michael@13 | 966 | done |
michael@13 | 967 | |
michael@13 | 968 | # optionally send signal to childs of program |
michael@13 | 969 | if [ ".$opt_c" = .yes ]; then |
michael@13 | 970 | for pid in $pids; do |
michael@13 | 971 | cpids=`$cmd3 | sed -e "s;^[ ${TAB}]*;;" | egrep "[0-9]* $pid" |\ |
michael@13 | 972 | grep -v grep | grep -v rpmtool |\ |
michael@13 | 973 | awk '{ printf("%s\n", $1); }'` |
michael@13 | 974 | for cpid in $cpids; do |
michael@13 | 975 | if [ ".$opt_v" = .yes ]; then |
michael@13 | 976 | echo "sending $sig signal to child process $cpid" |
michael@13 | 977 | fi |
michael@13 | 978 | if [ ".$opt_t" = .yes ]; then |
michael@13 | 979 | echo "kill -$sig $cpid" |
michael@13 | 980 | fi |
michael@13 | 981 | if [ ".$opt_n" = .no ]; then |
michael@13 | 982 | eval "kill -$sig $cpid >/dev/null 2>&1" |
michael@13 | 983 | fi |
michael@13 | 984 | done |
michael@13 | 985 | done |
michael@13 | 986 | fi |
michael@13 | 987 | |
michael@13 | 988 | # perform optional delay |
michael@13 | 989 | i=`expr $i - 1` |
michael@13 | 990 | if [ $i -gt 0 ]; then |
michael@13 | 991 | if [ ".$opt_d" != . -a ".$opt_d" != . ]; then |
michael@13 | 992 | sleep $opt_d |
michael@13 | 993 | fi |
michael@13 | 994 | fi |
michael@13 | 995 | done |
michael@13 | 996 | ;; |
michael@13 | 997 | |
michael@13 | 998 | config ) |
michael@13 | 999 | # usage consistency |
michael@13 | 1000 | if [ ".$opt_a" = .no -a ".$opt_r" = .no ]; then |
michael@13 | 1001 | echo "$msgprefix:Error: either option -a or -r has to be specified" 1>&2 |
michael@13 | 1002 | exit 1 |
michael@13 | 1003 | fi |
michael@13 | 1004 | configfile="$1" |
michael@13 | 1005 | |
michael@13 | 1006 | # determine block markers |
michael@13 | 1007 | block_start="${opt_p}<${opt_t}" |
michael@13 | 1008 | if [ ".$opt_i" != . ]; then |
michael@13 | 1009 | block_start="${block_start} id=\"${opt_i}\"" |
michael@13 | 1010 | fi |
michael@13 | 1011 | block_start="${block_start}>" |
michael@13 | 1012 | block_end="${opt_p}</${opt_t}>" |
michael@13 | 1013 | |
michael@13 | 1014 | # slash-escaped versions of block markers (for sed(3) call) |
michael@13 | 1015 | block_start_esc=`echo "$block_start" | sed -e 's;/;\\\\/;g'` |
michael@13 | 1016 | block_end_esc=`echo "$block_end" | sed -e 's;/;\\\\/;g'` |
michael@13 | 1017 | |
michael@13 | 1018 | # determine backup extension |
michael@13 | 1019 | case "X$opt_b" in |
michael@13 | 1020 | X ) ext=".bak" ;; |
michael@13 | 1021 | X.* ) ext="$opt_b" ;; |
michael@13 | 1022 | X* ) ext=".$opt_b" ;; |
michael@13 | 1023 | esac |
michael@13 | 1024 | |
michael@13 | 1025 | # check for block in config file |
michael@13 | 1026 | if [ -f $configfile ]; then |
michael@13 | 1027 | check=`grep "^${block_start}" $configfile` |
michael@13 | 1028 | else |
michael@13 | 1029 | touch $configfile |
michael@13 | 1030 | check="" |
michael@13 | 1031 | fi |
michael@13 | 1032 | |
michael@13 | 1033 | # add entry |
michael@13 | 1034 | if [ ".$opt_a" = .yes ]; then |
michael@13 | 1035 | if [ ".$check" != . ]; then |
michael@13 | 1036 | if [ ".$opt_s" = .yes ]; then |
michael@13 | 1037 | exit 0 |
michael@13 | 1038 | else |
michael@13 | 1039 | echo "$msgprefix:Error: config entry already exists" 1>&2 |
michael@13 | 1040 | exit 1 |
michael@13 | 1041 | fi |
michael@13 | 1042 | fi |
michael@13 | 1043 | cp $configfile $configfile$ext |
michael@13 | 1044 | echo "${block_start}" >$tmpfile |
michael@13 | 1045 | cat >>$tmpfile |
michael@13 | 1046 | echo "${block_end}" >>$tmpfile |
michael@13 | 1047 | cat $tmpfile >>$configfile |
michael@13 | 1048 | |
michael@13 | 1049 | # remove entry |
michael@13 | 1050 | elif [ ".$opt_r" = .yes ]; then |
michael@13 | 1051 | if [ ".$check" = . ]; then |
michael@13 | 1052 | if [ ".$opt_s" = .yes ]; then |
michael@13 | 1053 | exit 0 |
michael@13 | 1054 | else |
michael@13 | 1055 | echo "$msgprefix:Error: config entry does not exist" 1>&2 |
michael@13 | 1056 | exit 1 |
michael@13 | 1057 | fi |
michael@13 | 1058 | fi |
michael@13 | 1059 | cp $configfile $configfile$ext |
michael@13 | 1060 | sed -e "/^${block_start_esc}/,/^${block_end_esc}/d" \ |
michael@13 | 1061 | <$configfile$ext >$configfile |
michael@13 | 1062 | fi |
michael@13 | 1063 | |
michael@13 | 1064 | # verbosity |
michael@13 | 1065 | if [ ".$opt_v" = .yes ]; then |
michael@13 | 1066 | (diff -u1 $configfile$ext $configfile >$tmpfile) 2>/dev/null |
michael@13 | 1067 | if [ ".`cat $tmpfile`" = . ]; then |
michael@13 | 1068 | (diff -C1 $configfile$ext $configfile >$tmpfile) 2>/dev/null |
michael@13 | 1069 | if [ ".`cat $tmpfile`" = . ]; then |
michael@13 | 1070 | if [ ".$opt_s" = .no ]; then |
michael@13 | 1071 | echo "$msgprefix:Warning: unable to show difference for config file \`$configfile'" 1>&2 |
michael@13 | 1072 | fi |
michael@13 | 1073 | fi |
michael@13 | 1074 | fi |
michael@13 | 1075 | echo "editing $configfile:" |
michael@13 | 1076 | cat $tmpfile |
michael@13 | 1077 | fi |
michael@13 | 1078 | |
michael@13 | 1079 | # optionally remove backup file |
michael@13 | 1080 | if [ ".$opt_b" = . ]; then |
michael@13 | 1081 | rm -f $configfile$ext |
michael@13 | 1082 | fi |
michael@13 | 1083 | ;; |
michael@13 | 1084 | |
michael@13 | 1085 | msg ) |
michael@13 | 1086 | # optionally beep before message |
michael@13 | 1087 | if [ ".$opt_b" = .yes ]; then |
michael@13 | 1088 | echo . | awk '{ printf("%c", 7); }' |
michael@13 | 1089 | fi |
michael@428 | 1090 | |
michael@428 | 1091 | # determine title of message |
michael@13 | 1092 | title="" |
michael@13 | 1093 | case $opt_t in |
michael@13 | 1094 | info ) title="-------" ;; |
michael@13 | 1095 | notice ) title="Notice-" ;; |
michael@13 | 1096 | warn ) title="Warning" ;; |
michael@13 | 1097 | error ) title="Error--" ;; |
michael@13 | 1098 | * ) echo "$msgprefix:Error: invalid message type \`$opt_t'" 1>&2; exit 1 ;; |
michael@13 | 1099 | esac |
michael@13 | 1100 | |
michael@13 | 1101 | # display message |
michael@13 | 1102 | if [ ".$opt_r" != .yes ]; then |
michael@13 | 1103 | echo . | awk '{ printf("\r"); }' |
michael@13 | 1104 | fi |
michael@13 | 1105 | echo "+----------------------------------${title}------------------------------------+" |
michael@13 | 1106 | expand -t 8 | sed -e 's; *$;;' | awk '{ printf("| %-75s |\n", substr($0, 0, 75)); }' |
michael@13 | 1107 | echo "+-----------------------------------------------------------------------------+" |
michael@13 | 1108 | ;; |
michael@13 | 1109 | check-class ) |
michael@13 | 1110 | # check package class from within .spec file macro expansion for %prep section |
michael@13 | 1111 | class="$1"; shift |
michael@13 | 1112 | case "$class" in |
michael@13 | 1113 | CORE|BASE ) |
michael@13 | 1114 | ;; |
michael@13 | 1115 | PLUS ) |
michael@13 | 1116 | echo "set +x" |
michael@13 | 1117 | ( echo "This OpenPKG package is of class PLUS." |
michael@433 | 1118 | echo "It is still in a QUALITY ASSURANCE state," |
michael@433 | 1119 | echo "therefore it is NOT ready for careless use." |
michael@13 | 1120 | echo "Do not use it in critical production environments." |
michael@433 | 1121 | echo "This software might still be unstable at runtime." |
michael@13 | 1122 | ) | sh $prog_path msg -r -t notice | sed -e 's;^;echo ";' -e 's;$;";' |
michael@13 | 1123 | echo "set -x" |
michael@13 | 1124 | ;; |
michael@13 | 1125 | EVAL ) |
michael@13 | 1126 | echo "set +x" |
michael@13 | 1127 | ( echo "This OpenPKG package is of class EVAL." |
michael@433 | 1128 | echo "It is still in a EVALUATION and QA state," |
michael@433 | 1129 | echo "therefore it is NOT ready for general use." |
michael@13 | 1130 | echo "Do not use it in production environments." |
michael@433 | 1131 | echo "It might be unstable or incompletely packaged." |
michael@13 | 1132 | ) | sh $prog_path msg -r -t warn | sed -e 's;^;echo ";' -e 's;$;";' |
michael@13 | 1133 | echo "set -x" |
michael@13 | 1134 | ;; |
michael@13 | 1135 | JUNK ) |
michael@13 | 1136 | echo "set +x" |
michael@13 | 1137 | ( echo "This OpenPKG package is of class JUNK." |
michael@433 | 1138 | echo "It is still in DEVELOPMENT state," |
michael@433 | 1139 | echo "therefore it is NOT ready to be used." |
michael@13 | 1140 | echo "Do not use it at all, except in development environments!" |
michael@433 | 1141 | echo "This software is either unstable or incompletely packaged." |
michael@13 | 1142 | ) | sh $prog_path msg -r -t warn | sed -e 's;^;echo ";' -e 's;$;";' |
michael@13 | 1143 | echo "set -x" |
michael@13 | 1144 | ;; |
michael@13 | 1145 | esac |
michael@13 | 1146 | ;; |
michael@13 | 1147 | esac |
michael@13 | 1148 | |
michael@13 | 1149 | # cleanup |
michael@13 | 1150 | if [ ".$gen_tmpfile" = .yes ]; then |
michael@13 | 1151 | rm -f $tmpfile >/dev/null 2>&1 |
michael@13 | 1152 | fi |
michael@13 | 1153 | |
michael@13 | 1154 | # die gracefully ;) |
michael@13 | 1155 | exit 0 |
michael@13 | 1156 |