openpkg/shtool

Tue, 29 Nov 2011 18:44:37 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 29 Nov 2011 18:44:37 +0100
changeset 395
41738a0e98d1
child 428
f880f219c566
permissions
-rw-r--r--

Reduce private memory allocation after observing stable operation.

michael@13 1 #!/bin/sh
michael@13 2 ##
michael@13 3 ## GNU shtool -- The GNU Portable Shell Tool
michael@13 4 ## Copyright (c) 1994-2007 Ralf S. Engelschall <rse@engelschall.com>
michael@13 5 ##
michael@13 6 ## See http://www.gnu.org/software/shtool/ for more information.
michael@13 7 ## See ftp://ftp.gnu.org/gnu/shtool/ for latest version.
michael@13 8 ##
michael@13 9 ## Version: 2.0.7 (19-May-2007)
michael@13 10 ## Contents: all available modules
michael@13 11 ##
michael@13 12
michael@13 13 ##
michael@13 14 ## This program is free software; you can redistribute it and/or modify
michael@13 15 ## it under the terms of the GNU General Public License as published by
michael@13 16 ## the Free Software Foundation; either version 2 of the License, or
michael@13 17 ## (at your option) any later version.
michael@13 18 ##
michael@13 19 ## This program is distributed in the hope that it will be useful,
michael@13 20 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
michael@13 21 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
michael@13 22 ## General Public License for more details.
michael@13 23 ##
michael@13 24 ## You should have received a copy of the GNU General Public License
michael@13 25 ## along with this program; if not, write to the Free Software
michael@13 26 ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
michael@13 27 ## USA, or contact Ralf S. Engelschall <rse@engelschall.com>.
michael@13 28 ##
michael@13 29 ## NOTICE: Given that you include this file verbatim into your own
michael@13 30 ## source tree, you are justified in saying that it remains separate
michael@13 31 ## from your package, and that this way you are simply just using GNU
michael@13 32 ## shtool. So, in this situation, there is no requirement that your
michael@13 33 ## package itself is licensed under the GNU General Public License in
michael@13 34 ## order to take advantage of GNU shtool.
michael@13 35 ##
michael@13 36
michael@13 37 ##
michael@13 38 ## Usage: shtool [<options>] [<cmd-name> [<cmd-options>] [<cmd-args>]]
michael@13 39 ##
michael@13 40 ## Available commands:
michael@13 41 ## echo Print string with optional construct expansion
michael@13 42 ## mdate Pretty-print modification time of a file or dir
michael@13 43 ## table Pretty-print a field-separated list as a table
michael@13 44 ## prop Display progress with a running propeller
michael@13 45 ## move Move files with simultaneous substitution
michael@13 46 ## install Install a program, script or datafile
michael@13 47 ## mkdir Make one or more directories
michael@13 48 ## mkln Make link with calculation of relative paths
michael@13 49 ## mkshadow Make a shadow tree through symbolic links
michael@13 50 ## fixperm Fix file permissions inside a source tree
michael@13 51 ## rotate Logfile rotation
michael@13 52 ## tarball Roll distribution tarballs
michael@13 53 ## subst Apply sed(1) substitution operations
michael@13 54 ## platform Platform Identification Utility
michael@13 55 ## arx Extended archive command
michael@13 56 ## slo Separate linker options by library class
michael@13 57 ## scpp Sharing C Pre-Processor
michael@13 58 ## version Maintain a version information file
michael@13 59 ## path Deal with program paths
michael@13 60 ##
michael@13 61
michael@13 62 # maximum Bourne-Shell compatibility
michael@13 63 if [ ".$ZSH_VERSION" != . ] && (emulate sh) >/dev/null 2>&1; then
michael@13 64 # reconfigure zsh(1)
michael@13 65 emulate sh
michael@13 66 NULLCMD=:
michael@13 67 alias -g '${1+"$@"}'='"$@"'
michael@13 68 elif [ ".$BASH_VERSION" != . ] && (set -o posix) >/dev/null 2>&1; then
michael@13 69 # reconfigure bash(1)
michael@13 70 set -o posix
michael@13 71 fi
michael@13 72
michael@13 73 # maximum independence of NLS nuisances
michael@13 74 for var in \
michael@13 75 LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \
michael@13 76 LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \
michael@13 77 LC_TELEPHONE LC_TIME
michael@13 78 do
michael@13 79 if (set +x; test -z "`(eval $var=C; export $var) 2>&1`"); then
michael@13 80 eval $var=C; export $var
michael@13 81 else
michael@13 82 unset $var
michael@13 83 fi
michael@13 84 done
michael@13 85
michael@13 86 # initial command line handling
michael@13 87 if [ $# -eq 0 ]; then
michael@13 88 echo "$0:Error: invalid command line" 1>&2
michael@13 89 echo "$0:Hint: run \`$0 -h' for usage" 1>&2
michael@13 90 exit 1
michael@13 91 fi
michael@13 92 if [ ".$1" = ".-h" ] || [ ".$1" = ".--help" ]; then
michael@13 93 echo "This is GNU shtool, version 2.0.7 (19-May-2007)"
michael@13 94 echo 'Copyright (c) 1994-2007 Ralf S. Engelschall <rse@engelschall.com>'
michael@13 95 echo 'Report bugs to <bug-shtool@gnu.org>'
michael@13 96 echo ''
michael@13 97 echo 'Usage: shtool [<options>] [<cmd-name> [<cmd-options>] [<cmd-args>]]'
michael@13 98 echo ''
michael@13 99 echo 'Available global <options>:'
michael@13 100 echo ' -v, --version display shtool version information'
michael@13 101 echo ' -h, --help display shtool usage help page (this one)'
michael@13 102 echo ' -d, --debug display shell trace information'
michael@13 103 echo ' -r, --recreate recreate this shtool script via shtoolize'
michael@13 104 echo ''
michael@13 105 echo 'Available <cmd-name> [<cmd-options>] [<cmd-args>]:'
michael@13 106 echo ' echo [-n|--newline] [-e|--expand] [<string> ...]'
michael@13 107 echo ' mdate [-n|--newline] [-z|--zero] [-s|--shorten] [-d|--digits]'
michael@13 108 echo ' [-f|--field-sep <str>] [-o|--order <spec>] <path>'
michael@13 109 echo ' table [-F|--field-sep <sep>] [-w|--width <width>] [-c|--columns'
michael@13 110 echo ' <cols>] [-s|--strip <strip>] <str><sep><str>...'
michael@13 111 echo ' prop [-p|--prefix <str>]'
michael@13 112 echo ' move [-v|--verbose] [-t|--trace] [-e|--expand] [-p|--preserve]'
michael@13 113 echo ' <src-file> <dst-file>'
michael@13 114 echo ' install [-v|--verbose] [-t|--trace] [-d|--mkdir] [-c|--copy]'
michael@13 115 echo ' [-C|--compare-copy] [-s|--strip] [-m|--mode <mode>]'
michael@13 116 echo ' [-o|--owner <owner>] [-g|--group <group>] [-e|--exec'
michael@13 117 echo ' <sed-cmd>] <file> [<file> ...] <path>'
michael@13 118 echo ' mkdir [-t|--trace] [-f|--force] [-p|--parents] [-m|--mode'
michael@13 119 echo ' <mode>] [-o|--owner <owner>] [-g|--group <group>] <dir>'
michael@13 120 echo ' [<dir> ...]'
michael@13 121 echo ' mkln [-t|--trace] [-f|--force] [-s|--symbolic] <src-path>'
michael@13 122 echo ' [<src-path> ...] <dst-path>'
michael@13 123 echo ' mkshadow [-v|--verbose] [-t|--trace] [-a|--all] <src-dir> <dst-dir>'
michael@13 124 echo ' fixperm [-v|--verbose] [-t|--trace] <path> [<path> ...]'
michael@13 125 echo ' rotate [-v|--verbose] [-t|--trace] [-f|--force] [-n|--num-files'
michael@13 126 echo ' <count>] [-s|--size <size>] [-c|--copy] [-r|--remove]'
michael@13 127 echo ' [-a|--archive-dir <dir>] [-z|--compress [<tool>:]<level>]'
michael@13 128 echo ' [-b|--background] [-d|--delay] [-p|--pad <len>] [-m|--mode'
michael@13 129 echo ' <mode>] [-o|--owner <owner>] [-g|--group <group>] [-M|--migrate'
michael@13 130 echo ' <cmd>] [-P|--prolog <cmd>] [-E|--epilog <cmd>] <file> [...]'
michael@13 131 echo ' tarball [-t|--trace] [-v|--verbose] [-o|--output <tarball>]'
michael@13 132 echo ' [-c|--compress <prog>] [-d|--directory <dir>] [-u|--user'
michael@13 133 echo ' <user>] [-g|--group <group>] [-e|--exclude <pattern>]'
michael@13 134 echo ' <path> [<path> ...]'
michael@13 135 echo ' subst [-v|--verbose] [-t|--trace] [-n|--nop] [-w|--warning]'
michael@13 136 echo ' [-q|--quiet] [-s|--stealth] [-i|--interactive] [-b|--backup'
michael@13 137 echo ' <ext>] [-e|--exec <cmd>] [-f|--file <cmd-file>] [<file>]'
michael@13 138 echo ' [...]'
michael@13 139 echo ' platform [-F|--format <format>] [-S|--sep <string>] [-C|--conc'
michael@13 140 echo ' <string>] [-L|--lower] [-U|--upper] [-v|--verbose]'
michael@13 141 echo ' [-c|--concise] [-n|--no-newline] [-t|--type <type>]'
michael@13 142 echo ' [-V|--version] [-h|--help]'
michael@13 143 echo ' arx [-t|--trace] [-C|--command <cmd>] <op> <archive> [<file>'
michael@13 144 echo ' ...]'
michael@13 145 echo ' slo [-p|--prefix <str>] -- -L<dir> -l<lib> [-L<dir> -l<lib>'
michael@13 146 echo ' ...]'
michael@13 147 echo ' scpp [-v|--verbose] [-p|--preserve] [-f|--filter <filter>]'
michael@13 148 echo ' [-o|--output <ofile>] [-t|--template <tfile>] [-M|--mark'
michael@13 149 echo ' <mark>] [-D|--define <dname>] [-C|--class <cname>]'
michael@13 150 echo ' <file> [<file> ...]'
michael@13 151 echo ' version [-l|--language <lang>] [-n|--name <name>] [-p|--prefix'
michael@13 152 echo ' <prefix>] [-s|--set <version>] [-e|--edit] [-i|--increase'
michael@13 153 echo ' <knob>] [-d|--display <type>] <file>'
michael@13 154 echo ' path [-s|--suppress] [-r|--reverse] [-d|--dirname] [-b|--basename]'
michael@13 155 echo ' [-m|--magic] [-p|--path <path>] <str> [<str> ...]'
michael@13 156 echo ''
michael@13 157 exit 0
michael@13 158 fi
michael@13 159 if [ ".$1" = ".-v" ] || [ ".$1" = ".--version" ]; then
michael@13 160 echo "GNU shtool 2.0.7 (19-May-2007)"
michael@13 161 exit 0
michael@13 162 fi
michael@13 163 if [ ".$1" = ".-r" ] || [ ".$1" = ".--recreate" ]; then
michael@13 164 shtoolize -oshtool all
michael@13 165 exit 0
michael@13 166 fi
michael@13 167 if [ ".$1" = ".-d" ] || [ ".$1" = ".--debug" ]; then
michael@13 168 shift
michael@13 169 set -x
michael@13 170 fi
michael@13 171 name=`echo "$0" | sed -e 's;.*/\([^/]*\)$;\1;' -e 's;-sh$;;' -e 's;\.sh$;;'`
michael@13 172 case "$name" in
michael@13 173 echo|mdate|table|prop|move|install|mkdir|mkln|mkshadow|fixperm|rotate|tarball|subst|platform|arx|slo|scpp|version|path )
michael@13 174 # implicit tool command selection
michael@13 175 tool="$name"
michael@13 176 ;;
michael@13 177 * )
michael@13 178 # explicit tool command selection
michael@13 179 tool="$1"
michael@13 180 shift
michael@13 181 ;;
michael@13 182 esac
michael@13 183 arg_spec=""
michael@13 184 opt_spec=""
michael@13 185 gen_tmpfile=no
michael@13 186
michael@13 187 ##
michael@13 188 ## DISPATCH INTO SCRIPT PROLOG
michael@13 189 ##
michael@13 190
michael@13 191 case $tool in
michael@13 192 echo )
michael@13 193 str_tool="echo"
michael@13 194 str_usage="[-n|--newline] [-e|--expand] [<string> ...]"
michael@13 195 arg_spec="0+"
michael@13 196 opt_spec="n.e."
michael@13 197 opt_alias="n:newline,e:expand"
michael@13 198 opt_n=no
michael@13 199 opt_e=no
michael@13 200 ;;
michael@13 201 mdate )
michael@13 202 str_tool="mdate"
michael@13 203 str_usage="[-n|--newline] [-z|--zero] [-s|--shorten] [-d|--digits] [-f|--field-sep <str>] [-o|--order <spec>] <path>"
michael@13 204 arg_spec="1="
michael@13 205 opt_spec="n.z.s.d.f:o:"
michael@13 206 opt_alias="n:newline,z:zero,s:shorten,d:digits,f:field-sep,o:order"
michael@13 207 opt_n=no
michael@13 208 opt_z=no
michael@13 209 opt_s=no
michael@13 210 opt_d=no
michael@13 211 opt_f=" "
michael@13 212 opt_o="dmy"
michael@13 213 ;;
michael@13 214 table )
michael@13 215 str_tool="table"
michael@13 216 str_usage="[-F|--field-sep <sep>] [-w|--width <width>] [-c|--columns <cols>] [-s|--strip <strip>] <str><sep><str>..."
michael@13 217 arg_spec="1+"
michael@13 218 opt_spec="F:w:c:s:"
michael@13 219 opt_alias="F:field-sep,w:width,c:columns,s:strip"
michael@13 220 opt_F=":"
michael@13 221 opt_w=15
michael@13 222 opt_c=3
michael@13 223 opt_s=79
michael@13 224 ;;
michael@13 225 prop )
michael@13 226 str_tool="prop"
michael@13 227 str_usage="[-p|--prefix <str>]"
michael@13 228 arg_spec="0="
michael@13 229 opt_spec="p:"
michael@13 230 opt_alias="p:prefix"
michael@13 231 opt_p=""
michael@13 232 ;;
michael@13 233 move )
michael@13 234 str_tool="move"
michael@13 235 str_usage="[-v|--verbose] [-t|--trace] [-e|--expand] [-p|--preserve] <src-file> <dst-file>"
michael@13 236 arg_spec="2="
michael@13 237 opt_spec="v.t.e.p."
michael@13 238 opt_alias="v:verbose,t:trace,e:expand,p:preserve"
michael@13 239 opt_v=no
michael@13 240 opt_t=no
michael@13 241 opt_e=no
michael@13 242 opt_p=no
michael@13 243 ;;
michael@13 244 install )
michael@13 245 str_tool="install"
michael@13 246 str_usage="[-v|--verbose] [-t|--trace] [-d|--mkdir] [-c|--copy] [-C|--compare-copy] [-s|--strip] [-m|--mode <mode>] [-o|--owner <owner>] [-g|--group <group>] [-e|--exec <sed-cmd>] <file> [<file> ...] <path>"
michael@13 247 arg_spec="1+"
michael@13 248 opt_spec="v.t.d.c.C.s.m:o:g:e+"
michael@13 249 opt_alias="v:verbose,t:trace,d:mkdir,c:copy,C:compare-copy,s:strip,m:mode,o:owner,g:group,e:exec"
michael@13 250 opt_v=no
michael@13 251 opt_t=no
michael@13 252 opt_d=no
michael@13 253 opt_c=no
michael@13 254 opt_C=no
michael@13 255 opt_s=no
michael@13 256 opt_m="0755"
michael@13 257 opt_o=""
michael@13 258 opt_g=""
michael@13 259 opt_e=""
michael@13 260 ;;
michael@13 261 mkdir )
michael@13 262 str_tool="mkdir"
michael@13 263 str_usage="[-t|--trace] [-f|--force] [-p|--parents] [-m|--mode <mode>] [-o|--owner <owner>] [-g|--group <group>] <dir> [<dir> ...]"
michael@13 264 arg_spec="1+"
michael@13 265 opt_spec="t.f.p.m:o:g:"
michael@13 266 opt_alias="t:trace,f:force,p:parents,m:mode,o:owner,g:group"
michael@13 267 opt_t=no
michael@13 268 opt_f=no
michael@13 269 opt_p=no
michael@13 270 opt_m=""
michael@13 271 opt_o=""
michael@13 272 opt_g=""
michael@13 273 ;;
michael@13 274 mkln )
michael@13 275 str_tool="mkln"
michael@13 276 str_usage="[-t|--trace] [-f|--force] [-s|--symbolic] <src-path> [<src-path> ...] <dst-path>"
michael@13 277 arg_spec="2+"
michael@13 278 opt_spec="t.f.s."
michael@13 279 opt_alias="t:trace,f:force,s:symbolic"
michael@13 280 opt_t=no
michael@13 281 opt_f=no
michael@13 282 opt_s=no
michael@13 283 ;;
michael@13 284 mkshadow )
michael@13 285 str_tool="mkshadow"
michael@13 286 str_usage="[-v|--verbose] [-t|--trace] [-a|--all] <src-dir> <dst-dir>"
michael@13 287 arg_spec="2="
michael@13 288 opt_spec="v.t.a."
michael@13 289 opt_alias="v:verbose,t:trace,a:all"
michael@13 290 opt_v=no
michael@13 291 opt_t=no
michael@13 292 opt_a=no
michael@13 293 ;;
michael@13 294 fixperm )
michael@13 295 str_tool="fixperm"
michael@13 296 str_usage="[-v|--verbose] [-t|--trace] <path> [<path> ...]"
michael@13 297 arg_spec="1+"
michael@13 298 opt_spec="v.t."
michael@13 299 opt_alias="v:verbose,t:trace"
michael@13 300 opt_v=no
michael@13 301 opt_t=no
michael@13 302 ;;
michael@13 303 rotate )
michael@13 304 str_tool="rotate"
michael@13 305 str_usage="[-v|--verbose] [-t|--trace] [-f|--force] [-n|--num-files <count>] [-s|--size <size>] [-c|--copy] [-r|--remove] [-a|--archive-dir <dir>] [-z|--compress [<tool>:]<level>] [-b|--background] [-d|--delay] [-p|--pad <len>] [-m|--mode <mode>] [-o|--owner <owner>] [-g|--group <group>] [-M|--migrate <cmd>] [-P|--prolog <cmd>] [-E|--epilog <cmd>] <file> [...]"
michael@13 306 arg_spec="1+"
michael@13 307 opt_spec="v.t.f.n:s:c.r.a:z:b.d.p:o:g:m:M:P:E:"
michael@13 308 opt_alias="v:verbose,t:trace,f:force,n:num-files,s:size,c:copy,r:remove,a:archive-dir,z:compress,b:background,d:delay,p:pad,o:owner,g:group,m:mode,M:migrate,P:prolog,E:epilog"
michael@13 309 opt_v=no
michael@13 310 opt_t=no
michael@13 311 opt_f=no
michael@13 312 opt_n=10
michael@13 313 opt_s=""
michael@13 314 opt_c=no
michael@13 315 opt_r=no
michael@13 316 opt_a=""
michael@13 317 opt_z=""
michael@13 318 opt_b=no
michael@13 319 opt_d=no
michael@13 320 opt_p=1
michael@13 321 opt_o=""
michael@13 322 opt_g=""
michael@13 323 opt_m=""
michael@13 324 opt_M=""
michael@13 325 opt_P=""
michael@13 326 opt_E=""
michael@13 327 ;;
michael@13 328 tarball )
michael@13 329 str_tool="tarball"
michael@13 330 str_usage="[-t|--trace] [-v|--verbose] [-o|--output <tarball>] [-c|--compress <prog>] [-d|--directory <dir>] [-u|--user <user>] [-g|--group <group>] [-e|--exclude <pattern>] <path> [<path> ...]"
michael@13 331 gen_tmpfile=yes
michael@13 332 arg_spec="1+"
michael@13 333 opt_spec="t.v.o:c:d:u:g:e:"
michael@13 334 opt_alias="t:trace,v:verbose,o:output,c:compress,d:directory,u:user,g:group,e:exclude"
michael@13 335 opt_t=no
michael@13 336 opt_v=no
michael@13 337 opt_o=""
michael@13 338 opt_c=""
michael@13 339 opt_d=""
michael@13 340 opt_u=""
michael@13 341 opt_g=""
michael@13 342 opt_e="CVS,\\.cvsignore,\\.svn,\\.[oa]\$"
michael@13 343 ;;
michael@13 344 subst )
michael@13 345 str_tool="subst"
michael@13 346 str_usage="[-v|--verbose] [-t|--trace] [-n|--nop] [-w|--warning] [-q|--quiet] [-s|--stealth] [-i|--interactive] [-b|--backup <ext>] [-e|--exec <cmd>] [-f|--file <cmd-file>] [<file>] [...]"
michael@13 347 gen_tmpfile=yes
michael@13 348 arg_spec="0+"
michael@13 349 opt_spec="v.t.n.w.q.s.i.b:e+f:"
michael@13 350 opt_alias="v:verbose,t:trace,n:nop,w:warning,q:quiet,s:stealth,i:interactive,b:backup,e:exec,f:file"
michael@13 351 opt_v=no
michael@13 352 opt_t=no
michael@13 353 opt_n=no
michael@13 354 opt_w=no
michael@13 355 opt_q=no
michael@13 356 opt_s=no
michael@13 357 opt_i=no
michael@13 358 opt_b=""
michael@13 359 opt_e=""
michael@13 360 opt_f=""
michael@13 361 ;;
michael@13 362 platform )
michael@13 363 str_tool="platform"
michael@13 364 str_usage="[-F|--format <format>] [-S|--sep <string>] [-C|--conc <string>] [-L|--lower] [-U|--upper] [-v|--verbose] [-c|--concise] [-n|--no-newline] [-t|--type <type>] [-V|--version] [-h|--help]"
michael@13 365 arg_spec="0="
michael@13 366 opt_spec="F:S:C:L.U.v.c.n.t:d.V.h."
michael@13 367 opt_alias="F:format,S:sep,C:conc,L:lower,U:upper,v:verbose,c:consise,t:type,n:no-newline,V:version,h:help"
michael@13 368 opt_F="%{sp} (%{ap})"
michael@13 369 opt_S=" "
michael@13 370 opt_C="/"
michael@13 371 opt_L=no
michael@13 372 opt_U=no
michael@13 373 opt_t=""
michael@13 374 opt_v=no
michael@13 375 opt_c=no
michael@13 376 opt_n=no
michael@13 377 opt_V=no
michael@13 378 opt_h=no
michael@13 379 ;;
michael@13 380 arx )
michael@13 381 str_tool="arx"
michael@13 382 str_usage="[-t|--trace] [-C|--command <cmd>] <op> <archive> [<file> ...]"
michael@13 383 arg_spec="2+"
michael@13 384 opt_spec="t.C:"
michael@13 385 opt_alias="t:trace,C:command"
michael@13 386 opt_t=no
michael@13 387 opt_C="ar"
michael@13 388 ;;
michael@13 389 slo )
michael@13 390 str_tool="slo"
michael@13 391 str_usage="[-p|--prefix <str>] -- -L<dir> -l<lib> [-L<dir> -l<lib> ...]"
michael@13 392 arg_spec="1+"
michael@13 393 opt_spec="p:"
michael@13 394 opt_alias="p:prefix"
michael@13 395 opt_p="SLO_"
michael@13 396 ;;
michael@13 397 scpp )
michael@13 398 str_tool="scpp"
michael@13 399 str_usage="[-v|--verbose] [-p|--preserve] [-f|--filter <filter>] [-o|--output <ofile>] [-t|--template <tfile>] [-M|--mark <mark>] [-D|--define <dname>] [-C|--class <cname>] <file> [<file> ...]"
michael@13 400 gen_tmpfile=yes
michael@13 401 arg_spec="1+"
michael@13 402 opt_spec="v.p.f+o:t:M:D:C:"
michael@13 403 opt_alias="v:verbose,p:preserve,f:filter,o:output,t:template,M:mark,D:define,C:class"
michael@13 404 opt_v=no
michael@13 405 opt_p=no
michael@13 406 opt_f=""
michael@13 407 opt_o="lib.h"
michael@13 408 opt_t="lib.h.in"
michael@13 409 opt_M="%%MARK%%"
michael@13 410 opt_D="cpp"
michael@13 411 opt_C="intern"
michael@13 412 ;;
michael@13 413 version )
michael@13 414 str_tool="version"
michael@13 415 str_usage="[-l|--language <lang>] [-n|--name <name>] [-p|--prefix <prefix>] [-s|--set <version>] [-e|--edit] [-i|--increase <knob>] [-d|--display <type>] <file>"
michael@13 416 arg_spec="1="
michael@13 417 opt_spec="l:n:p:s:i:e.d:"
michael@13 418 opt_alias="l:language,n:name,p:prefix,s:set,e:edit,i:increase,d:display"
michael@13 419 opt_l="txt"
michael@13 420 opt_n="unknown"
michael@13 421 opt_p=""
michael@13 422 opt_s=""
michael@13 423 opt_e="no"
michael@13 424 opt_i=""
michael@13 425 opt_d="short"
michael@13 426 ;;
michael@13 427 path )
michael@13 428 str_tool="path"
michael@13 429 str_usage="[-s|--suppress] [-r|--reverse] [-d|--dirname] [-b|--basename] [-m|--magic] [-p|--path <path>] <str> [<str> ...]"
michael@13 430 gen_tmpfile=yes
michael@13 431 arg_spec="1+"
michael@13 432 opt_spec="s.r.d.b.m.p:"
michael@13 433 opt_alias="s:suppress,r:reverse,d:dirname,b:basename,m:magic,p:path"
michael@13 434 opt_s=no
michael@13 435 opt_r=no
michael@13 436 opt_d=no
michael@13 437 opt_b=no
michael@13 438 opt_m=no
michael@13 439 opt_p="$PATH"
michael@13 440 ;;
michael@13 441 -* )
michael@13 442 echo "$0:Error: unknown option \`$tool'" 2>&1
michael@13 443 echo "$0:Hint: run \`$0 -h' for usage" 2>&1
michael@13 444 exit 1
michael@13 445 ;;
michael@13 446 * )
michael@13 447 echo "$0:Error: unknown command \`$tool'" 2>&1
michael@13 448 echo "$0:Hint: run \`$0 -h' for usage" 2>&1
michael@13 449 exit 1
michael@13 450 ;;
michael@13 451 esac
michael@13 452
michael@13 453 ##
michael@13 454 ## COMMON UTILITY CODE
michael@13 455 ##
michael@13 456
michael@13 457 # commonly used ASCII values
michael@13 458 ASC_TAB=" "
michael@13 459 ASC_NL="
michael@13 460 "
michael@13 461
michael@13 462 # determine name of tool
michael@13 463 if [ ".$tool" != . ]; then
michael@13 464 # used inside shtool script
michael@13 465 toolcmd="$0 $tool"
michael@13 466 toolcmdhelp="shtool $tool"
michael@13 467 msgprefix="shtool:$tool"
michael@13 468 else
michael@13 469 # used as standalone script
michael@13 470 toolcmd="$0"
michael@13 471 toolcmdhelp="sh $0"
michael@13 472 msgprefix="$str_tool"
michael@13 473 fi
michael@13 474
michael@13 475 # parse argument specification string
michael@13 476 eval `echo $arg_spec |\
michael@13 477 sed -e 's/^\([0-9]*\)\([+=]\)/arg_NUMS=\1; arg_MODE=\2/'`
michael@13 478
michael@13 479 # parse option specification string
michael@13 480 eval `echo h.$opt_spec |\
michael@13 481 sed -e 's/\([a-zA-Z0-9]\)\([.:+]\)/opt_MODE_\1=\2;/g'`
michael@13 482
michael@13 483 # parse option alias string
michael@13 484 eval `echo h:help,$opt_alias |\
michael@13 485 sed -e 's/-/_/g' -e 's/\([a-zA-Z0-9]\):\([^,]*\),*/opt_ALIAS_\2=\1;/g'`
michael@13 486
michael@13 487 # interate over argument line
michael@13 488 opt_PREV=''
michael@13 489 while [ $# -gt 0 ]; do
michael@13 490 # special option stops processing
michael@13 491 if [ ".$1" = ".--" ]; then
michael@13 492 shift
michael@13 493 break
michael@13 494 fi
michael@13 495
michael@13 496 # determine option and argument
michael@13 497 opt_ARG_OK=no
michael@13 498 if [ ".$opt_PREV" != . ]; then
michael@13 499 # merge previous seen option with argument
michael@13 500 opt_OPT="$opt_PREV"
michael@13 501 opt_ARG="$1"
michael@13 502 opt_ARG_OK=yes
michael@13 503 opt_PREV=''
michael@13 504 else
michael@13 505 # split argument into option and argument
michael@13 506 case "$1" in
michael@13 507 --[a-zA-Z0-9]*=*)
michael@13 508 eval `echo "x$1" |\
michael@13 509 sed -e 's/^x--\([a-zA-Z0-9-]*\)=\(.*\)$/opt_OPT="\1";opt_ARG="\2"/'`
michael@13 510 opt_STR=`echo $opt_OPT | sed -e 's/-/_/g'`
michael@13 511 eval "opt_OPT=\${opt_ALIAS_${opt_STR}-${opt_OPT}}"
michael@13 512 ;;
michael@13 513 --[a-zA-Z0-9]*)
michael@13 514 opt_OPT=`echo "x$1" | cut -c4-`
michael@13 515 opt_STR=`echo $opt_OPT | sed -e 's/-/_/g'`
michael@13 516 eval "opt_OPT=\${opt_ALIAS_${opt_STR}-${opt_OPT}}"
michael@13 517 opt_ARG=''
michael@13 518 ;;
michael@13 519 -[a-zA-Z0-9]*)
michael@13 520 eval `echo "x$1" |\
michael@13 521 sed -e 's/^x-\([a-zA-Z0-9]\)/opt_OPT="\1";/' \
michael@13 522 -e 's/";\(.*\)$/"; opt_ARG="\1"/'`
michael@13 523 ;;
michael@13 524 -[a-zA-Z0-9])
michael@13 525 opt_OPT=`echo "x$1" | cut -c3-`
michael@13 526 opt_ARG=''
michael@13 527 ;;
michael@13 528 *)
michael@13 529 break
michael@13 530 ;;
michael@13 531 esac
michael@13 532 fi
michael@13 533
michael@13 534 # eat up option
michael@13 535 shift
michael@13 536
michael@13 537 # determine whether option needs an argument
michael@13 538 eval "opt_MODE=\$opt_MODE_${opt_OPT}"
michael@13 539 if [ ".$opt_ARG" = . ] && [ ".$opt_ARG_OK" != .yes ]; then
michael@13 540 if [ ".$opt_MODE" = ".:" ] || [ ".$opt_MODE" = ".+" ]; then
michael@13 541 opt_PREV="$opt_OPT"
michael@13 542 continue
michael@13 543 fi
michael@13 544 fi
michael@13 545
michael@13 546 # process option
michael@13 547 case $opt_MODE in
michael@13 548 '.' )
michael@13 549 # boolean option
michael@13 550 eval "opt_${opt_OPT}=yes"
michael@13 551 ;;
michael@13 552 ':' )
michael@13 553 # option with argument (multiple occurances override)
michael@13 554 eval "opt_${opt_OPT}=\"\$opt_ARG\""
michael@13 555 ;;
michael@13 556 '+' )
michael@13 557 # option with argument (multiple occurances append)
michael@13 558 eval "opt_${opt_OPT}=\"\$opt_${opt_OPT}\${ASC_NL}\$opt_ARG\""
michael@13 559 ;;
michael@13 560 * )
michael@13 561 echo "$msgprefix:Error: unknown option: \`$opt_OPT'" 1>&2
michael@13 562 echo "$msgprefix:Hint: run \`$toolcmdhelp -h' or \`man shtool' for details" 1>&2
michael@13 563 exit 1
michael@13 564 ;;
michael@13 565 esac
michael@13 566 done
michael@13 567 if [ ".$opt_PREV" != . ]; then
michael@13 568 echo "$msgprefix:Error: missing argument to option \`$opt_PREV'" 1>&2
michael@13 569 echo "$msgprefix:Hint: run \`$toolcmdhelp -h' or \`man shtool' for details" 1>&2
michael@13 570 exit 1
michael@13 571 fi
michael@13 572
michael@13 573 # process help option
michael@13 574 if [ ".$opt_h" = .yes ]; then
michael@13 575 echo "Usage: $toolcmdhelp $str_usage"
michael@13 576 exit 0
michael@13 577 fi
michael@13 578
michael@13 579 # complain about incorrect number of arguments
michael@13 580 case $arg_MODE in
michael@13 581 '=' )
michael@13 582 if [ $# -ne $arg_NUMS ]; then
michael@13 583 echo "$msgprefix:Error: invalid number of arguments (exactly $arg_NUMS expected)" 1>&2
michael@13 584 echo "$msgprefix:Hint: run \`$toolcmd -h' or \`man shtool' for details" 1>&2
michael@13 585 exit 1
michael@13 586 fi
michael@13 587 ;;
michael@13 588 '+' )
michael@13 589 if [ $# -lt $arg_NUMS ]; then
michael@13 590 echo "$msgprefix:Error: invalid number of arguments (at least $arg_NUMS expected)" 1>&2
michael@13 591 echo "$msgprefix:Hint: run \`$toolcmd -h' or \`man shtool' for details" 1>&2
michael@13 592 exit 1
michael@13 593 fi
michael@13 594 ;;
michael@13 595 esac
michael@13 596
michael@13 597 # establish a temporary file on request
michael@13 598 if [ ".$gen_tmpfile" = .yes ]; then
michael@13 599 # create (explicitly) secure temporary directory
michael@13 600 if [ ".$TMPDIR" != . ]; then
michael@13 601 tmpdir="$TMPDIR"
michael@13 602 elif [ ".$TEMPDIR" != . ]; then
michael@13 603 tmpdir="$TEMPDIR"
michael@13 604 else
michael@13 605 tmpdir="/tmp"
michael@13 606 fi
michael@13 607 tmpdir="$tmpdir/.shtool.$$"
michael@13 608 ( umask 077
michael@13 609 rm -rf "$tmpdir" >/dev/null 2>&1 || true
michael@13 610 mkdir "$tmpdir" >/dev/null 2>&1
michael@13 611 if [ $? -ne 0 ]; then
michael@13 612 echo "$msgprefix:Error: failed to create temporary directory \`$tmpdir'" 1>&2
michael@13 613 exit 1
michael@13 614 fi
michael@13 615 )
michael@13 616
michael@13 617 # create (implicitly) secure temporary file
michael@13 618 tmpfile="$tmpdir/shtool.tmp"
michael@13 619 touch "$tmpfile"
michael@13 620 fi
michael@13 621
michael@13 622 # utility function: map string to lower case
michael@13 623 util_lower () {
michael@13 624 echo "$1" | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'
michael@13 625 }
michael@13 626
michael@13 627 # utility function: map string to upper case
michael@13 628 util_upper () {
michael@13 629 echo "$1" | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
michael@13 630 }
michael@13 631
michael@13 632 # cleanup procedure
michael@13 633 shtool_exit () {
michael@13 634 rc="$1"
michael@13 635 if [ ".$gen_tmpfile" = .yes ]; then
michael@13 636 rm -rf "$tmpdir" >/dev/null 2>&1 || true
michael@13 637 fi
michael@13 638 exit $rc
michael@13 639 }
michael@13 640
michael@13 641 ##
michael@13 642 ## DISPATCH INTO SCRIPT BODY
michael@13 643 ##
michael@13 644
michael@13 645 case $tool in
michael@13 646
michael@13 647 echo )
michael@13 648 ##
michael@13 649 ## echo -- Print string with optional construct expansion
michael@13 650 ## Copyright (c) 1998-2007 Ralf S. Engelschall <rse@engelschall.com>
michael@13 651 ##
michael@13 652
michael@13 653 text="$*"
michael@13 654
michael@13 655 # check for broken escape sequence expansion
michael@13 656 seo=''
michael@13 657 bytes=`echo '\1' | wc -c | awk '{ printf("%s", $1); }'`
michael@13 658 if [ ".$bytes" != .3 ]; then
michael@13 659 bytes=`echo -E '\1' | wc -c | awk '{ printf("%s", $1); }'`
michael@13 660 if [ ".$bytes" = .3 ]; then
michael@13 661 seo='-E'
michael@13 662 fi
michael@13 663 fi
michael@13 664
michael@13 665 # check for existing -n option (to suppress newline)
michael@13 666 minusn=''
michael@13 667 bytes=`echo -n 123 2>/dev/null | wc -c | awk '{ printf("%s", $1); }'`
michael@13 668 if [ ".$bytes" = .3 ]; then
michael@13 669 minusn='-n'
michael@13 670 fi
michael@13 671
michael@13 672 # determine terminal bold sequence
michael@13 673 term_bold=''
michael@13 674 term_norm=''
michael@13 675 if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%[Bb]'`" != . ]; then
michael@13 676 case $TERM in
michael@13 677 # for the most important terminal types we directly know the sequences
michael@13 678 xterm|xterm*|vt220|vt220*)
michael@13 679 term_bold=`awk 'BEGIN { printf("%c%c%c%c", 27, 91, 49, 109); }' </dev/null 2>/dev/null`
michael@13 680 term_norm=`awk 'BEGIN { printf("%c%c%c", 27, 91, 109); }' </dev/null 2>/dev/null`
michael@13 681 ;;
michael@13 682 vt100|vt100*|cygwin)
michael@13 683 term_bold=`awk 'BEGIN { printf("%c%c%c%c%c%c", 27, 91, 49, 109, 0, 0); }' </dev/null 2>/dev/null`
michael@13 684 term_norm=`awk 'BEGIN { printf("%c%c%c%c%c", 27, 91, 109, 0, 0); }' </dev/null 2>/dev/null`
michael@13 685 ;;
michael@13 686 # for all others, we try to use a possibly existing `tput' or `tcout' utility
michael@13 687 * )
michael@13 688 paths=`echo $PATH | sed -e 's/:/ /g'`
michael@13 689 for tool in tput tcout; do
michael@13 690 for dir in $paths; do
michael@13 691 if [ -r "$dir/$tool" ]; then
michael@13 692 for seq in bold md smso; do # 'smso' is last
michael@13 693 bold="`$dir/$tool $seq 2>/dev/null`"
michael@13 694 if [ ".$bold" != . ]; then
michael@13 695 term_bold="$bold"
michael@13 696 break
michael@13 697 fi
michael@13 698 done
michael@13 699 if [ ".$term_bold" != . ]; then
michael@13 700 for seq in sgr0 me rmso init reset; do # 'reset' is last
michael@13 701 norm="`$dir/$tool $seq 2>/dev/null`"
michael@13 702 if [ ".$norm" != . ]; then
michael@13 703 term_norm="$norm"
michael@13 704 break
michael@13 705 fi
michael@13 706 done
michael@13 707 fi
michael@13 708 break
michael@13 709 fi
michael@13 710 done
michael@13 711 if [ ".$term_bold" != . ] && [ ".$term_norm" != . ]; then
michael@13 712 break;
michael@13 713 fi
michael@13 714 done
michael@13 715 ;;
michael@13 716 esac
michael@13 717 if [ ".$term_bold" = . ] || [ ".$term_norm" = . ]; then
michael@13 718 echo "$msgprefix:Warning: unable to determine terminal sequence for bold mode" 1>&2
michael@13 719 term_bold=''
michael@13 720 term_norm=''
michael@13 721 fi
michael@13 722 fi
michael@13 723
michael@13 724 # determine user name
michael@13 725 username=''
michael@13 726 if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%[uUgG]'`" != . ]; then
michael@13 727 username="`(id -un) 2>/dev/null`"
michael@13 728 if [ ".$username" = . ]; then
michael@13 729 str="`(id) 2>/dev/null`"
michael@13 730 if [ ".`echo $str | grep '^uid[ ]*=[ ]*[0-9]*('`" != . ]; then
michael@13 731 username=`echo $str | sed -e 's/^uid[ ]*=[ ]*[0-9]*(//' -e 's/).*$//'`
michael@13 732 fi
michael@13 733 if [ ".$username" = . ]; then
michael@13 734 username="$LOGNAME"
michael@13 735 if [ ".$username" = . ]; then
michael@13 736 username="$USER"
michael@13 737 if [ ".$username" = . ]; then
michael@13 738 username="`(whoami) 2>/dev/null |\
michael@13 739 awk '{ printf("%s", $1); }'`"
michael@13 740 if [ ".$username" = . ]; then
michael@13 741 username="`(who am i) 2>/dev/null |\
michael@13 742 awk '{ printf("%s", $1); }'`"
michael@13 743 if [ ".$username" = . ]; then
michael@13 744 username='unknown'
michael@13 745 fi
michael@13 746 fi
michael@13 747 fi
michael@13 748 fi
michael@13 749 fi
michael@13 750 fi
michael@13 751 fi
michael@13 752
michael@13 753 # determine user id
michael@13 754 userid=''
michael@13 755 if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%U'`" != . ]; then
michael@13 756 userid="`(id -u) 2>/dev/null`"
michael@13 757 if [ ".$userid" = . ]; then
michael@13 758 userid="`(id -u ${username}) 2>/dev/null`"
michael@13 759 if [ ".$userid" = . ]; then
michael@13 760 str="`(id) 2>/dev/null`"
michael@13 761 if [ ".`echo $str | grep '^uid[ ]*=[ ]*[0-9]*('`" != . ]; then
michael@13 762 userid=`echo $str | sed -e 's/^uid[ ]*=[ ]*//' -e 's/(.*$//'`
michael@13 763 fi
michael@13 764 if [ ".$userid" = . ]; then
michael@13 765 userid=`(getent passwd ${username}) 2>/dev/null | \
michael@13 766 sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'`
michael@13 767 if [ ".$userid" = . ]; then
michael@13 768 userid=`grep "^${username}:" /etc/passwd 2>/dev/null | \
michael@13 769 sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'`
michael@13 770 if [ ".$userid" = . ]; then
michael@13 771 userid=`(ypmatch "${username}" passwd; nismatch "${username}" passwd) 2>/dev/null | \
michael@13 772 sed -e 'q' | sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'`
michael@13 773 if [ ".$userid" = . ]; then
michael@13 774 userid=`(nidump passwd . | grep "^${username}:") 2>/dev/null | \
michael@13 775 sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'`
michael@13 776 if [ ".$userid" = . ]; then
michael@13 777 userid='?'
michael@13 778 fi
michael@13 779 fi
michael@13 780 fi
michael@13 781 fi
michael@13 782 fi
michael@13 783 fi
michael@13 784 fi
michael@13 785 fi
michael@13 786
michael@13 787 # determine (primary) group id
michael@13 788 groupid=''
michael@13 789 if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%[gG]'`" != . ]; then
michael@13 790 groupid="`(id -g ${username}) 2>/dev/null`"
michael@13 791 if [ ".$groupid" = . ]; then
michael@13 792 str="`(id) 2>/dev/null`"
michael@13 793 if [ ".`echo $str | grep 'gid[ ]*=[ ]*[0-9]*('`" != . ]; then
michael@13 794 groupid=`echo $str | sed -e 's/^.*gid[ ]*=[ ]*//' -e 's/(.*$//'`
michael@13 795 fi
michael@13 796 if [ ".$groupid" = . ]; then
michael@13 797 groupid=`(getent passwd ${username}) 2>/dev/null | \
michael@13 798 sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'`
michael@13 799 if [ ".$groupid" = . ]; then
michael@13 800 groupid=`grep "^${username}:" /etc/passwd 2>/dev/null | \
michael@13 801 sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'`
michael@13 802 if [ ".$groupid" = . ]; then
michael@13 803 groupid=`(ypmatch "${username}" passwd; nismatch "${username}" passwd) 2>/dev/null | \
michael@13 804 sed -e 'q' | sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'`
michael@13 805 if [ ".$groupid" = . ]; then
michael@13 806 groupid=`(nidump passwd . | grep "^${username}:") 2>/dev/null | \
michael@13 807 sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'`
michael@13 808 if [ ".$groupid" = . ]; then
michael@13 809 groupid='?'
michael@13 810 fi
michael@13 811 fi
michael@13 812 fi
michael@13 813 fi
michael@13 814 fi
michael@13 815 fi
michael@13 816 fi
michael@13 817
michael@13 818 # determine (primary) group name
michael@13 819 groupname=''
michael@13 820 if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%g'`" != . ]; then
michael@13 821 groupname="`(id -gn ${username}) 2>/dev/null`"
michael@13 822 if [ ".$groupname" = . ]; then
michael@13 823 str="`(id) 2>/dev/null`"
michael@13 824 if [ ".`echo $str | grep 'gid[ ]*=[ ]*[0-9]*('`" != . ]; then
michael@13 825 groupname=`echo $str | sed -e 's/^.*gid[ ]*=[ ]*[0-9]*(//' -e 's/).*$//'`
michael@13 826 fi
michael@13 827 if [ ".$groupname" = . ]; then
michael@13 828 groupname=`(getent group) 2>/dev/null | \
michael@13 829 grep "^[^:]*:[^:]*:${groupid}:" | \
michael@13 830 sed -e 's/:.*$//'`
michael@13 831 if [ ".$groupname" = . ]; then
michael@13 832 groupname=`grep "^[^:]*:[^:]*:${groupid}:" /etc/group 2>/dev/null | \
michael@13 833 sed -e 's/:.*$//'`
michael@13 834 if [ ".$groupname" = . ]; then
michael@13 835 groupname=`(ypcat group; niscat group) 2>/dev/null | \
michael@13 836 sed -e 'q' | grep "^[^:]*:[^:]*:${groupid}:" | \
michael@13 837 sed -e 's/:.*$//'`
michael@13 838 if [ ".$groupname" = . ]; then
michael@13 839 groupname=`(nidump group .) 2>/dev/null | \
michael@13 840 grep "^[^:]*:[^:]*:${groupid}:" | \
michael@13 841 sed -e 's/:.*$//'`
michael@13 842 if [ ".$groupname" = . ]; then
michael@13 843 groupname='?'
michael@13 844 fi
michael@13 845 fi
michael@13 846 fi
michael@13 847 fi
michael@13 848 fi
michael@13 849 fi
michael@13 850 fi
michael@13 851
michael@13 852 # determine host and domain name
michael@13 853 hostname=''
michael@13 854 domainname=''
michael@13 855 if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%h'`" != . ]; then
michael@13 856 hostname="`(uname -n) 2>/dev/null |\
michael@13 857 awk '{ printf("%s", $1); }'`"
michael@13 858 if [ ".$hostname" = . ]; then
michael@13 859 hostname="`(hostname) 2>/dev/null |\
michael@13 860 awk '{ printf("%s", $1); }'`"
michael@13 861 if [ ".$hostname" = . ]; then
michael@13 862 hostname='unknown'
michael@13 863 fi
michael@13 864 fi
michael@13 865 case $hostname in
michael@13 866 *.* )
michael@13 867 domainname=".`echo $hostname | cut -d. -f2-`"
michael@13 868 hostname="`echo $hostname | cut -d. -f1`"
michael@13 869 ;;
michael@13 870 esac
michael@13 871 fi
michael@13 872 if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%d'`" != . ]; then
michael@13 873 if [ ".$domainname" = . ]; then
michael@13 874 if [ -f /etc/resolv.conf ]; then
michael@13 875 domainname="`grep '^[ ]*domain' /etc/resolv.conf | sed -e 'q' |\
michael@13 876 sed -e 's/.*domain//' \
michael@13 877 -e 's/^[ ]*//' -e 's/^ *//' -e 's/^ *//' \
michael@13 878 -e 's/^\.//' -e 's/^/./' |\
michael@13 879 awk '{ printf("%s", $1); }'`"
michael@13 880 if [ ".$domainname" = . ]; then
michael@13 881 domainname="`grep '^[ ]*search' /etc/resolv.conf | sed -e 'q' |\
michael@13 882 sed -e 's/.*search//' \
michael@13 883 -e 's/^[ ]*//' -e 's/^ *//' -e 's/^ *//' \
michael@13 884 -e 's/ .*//' -e 's/ .*//' \
michael@13 885 -e 's/^\.//' -e 's/^/./' |\
michael@13 886 awk '{ printf("%s", $1); }'`"
michael@13 887 fi
michael@13 888 fi
michael@13 889 fi
michael@13 890 fi
michael@13 891
michael@13 892 # determine current time
michael@13 893 time_day=''
michael@13 894 time_month=''
michael@13 895 time_year=''
michael@13 896 time_monthname=''
michael@13 897 if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%[DMYm]'`" != . ]; then
michael@13 898 time_day=`date '+%d'`
michael@13 899 time_month=`date '+%m'`
michael@13 900 time_year=`date '+%Y' 2>/dev/null`
michael@13 901 if [ ".$time_year" = . ]; then
michael@13 902 time_year=`date '+%y'`
michael@13 903 case $time_year in
michael@13 904 [5-9][0-9]) time_year="19$time_year" ;;
michael@13 905 [0-4][0-9]) time_year="20$time_year" ;;
michael@13 906 esac
michael@13 907 fi
michael@13 908 case $time_month in
michael@13 909 1|01) time_monthname='Jan' ;;
michael@13 910 2|02) time_monthname='Feb' ;;
michael@13 911 3|03) time_monthname='Mar' ;;
michael@13 912 4|04) time_monthname='Apr' ;;
michael@13 913 5|05) time_monthname='May' ;;
michael@13 914 6|06) time_monthname='Jun' ;;
michael@13 915 7|07) time_monthname='Jul' ;;
michael@13 916 8|08) time_monthname='Aug' ;;
michael@13 917 9|09) time_monthname='Sep' ;;
michael@13 918 10) time_monthname='Oct' ;;
michael@13 919 11) time_monthname='Nov' ;;
michael@13 920 12) time_monthname='Dec' ;;
michael@13 921 esac
michael@13 922 fi
michael@13 923
michael@13 924 # expand special ``%x'' constructs
michael@13 925 if [ ".$opt_e" = .yes ]; then
michael@13 926 text=`echo $seo "$text" |\
michael@13 927 sed -e "s/%B/${term_bold}/g" \
michael@13 928 -e "s/%b/${term_norm}/g" \
michael@13 929 -e "s/%u/${username}/g" \
michael@13 930 -e "s/%U/${userid}/g" \
michael@13 931 -e "s/%g/${groupname}/g" \
michael@13 932 -e "s/%G/${groupid}/g" \
michael@13 933 -e "s/%h/${hostname}/g" \
michael@13 934 -e "s/%d/${domainname}/g" \
michael@13 935 -e "s/%D/${time_day}/g" \
michael@13 936 -e "s/%M/${time_month}/g" \
michael@13 937 -e "s/%Y/${time_year}/g" \
michael@13 938 -e "s/%m/${time_monthname}/g" 2>/dev/null`
michael@13 939 fi
michael@13 940
michael@13 941 # create output
michael@13 942 if [ .$opt_n = .no ]; then
michael@13 943 echo $seo "$text"
michael@13 944 else
michael@13 945 # the harder part: echo -n is best, because
michael@13 946 # awk may complain about some \xx sequences.
michael@13 947 if [ ".$minusn" != . ]; then
michael@13 948 echo $seo $minusn "$text"
michael@13 949 else
michael@13 950 echo dummy | awk '{ printf("%s", TEXT); }' TEXT="$text"
michael@13 951 fi
michael@13 952 fi
michael@13 953
michael@13 954 shtool_exit 0
michael@13 955 ;;
michael@13 956
michael@13 957 mdate )
michael@13 958 ##
michael@13 959 ## mdate -- Pretty-print modification time of a file or dir
michael@13 960 ## Copyright (c) 1995-1997 Free Software Foundation, Inc.
michael@13 961 ## Copyright (c) 1998-2007 Ralf S. Engelschall <rse@engelschall.com>
michael@13 962 ##
michael@13 963
michael@13 964 fod="$1"
michael@13 965 case "$opt_o" in
michael@13 966 [dmy][dmy][dmy] )
michael@13 967 ;;
michael@13 968 * ) echo "$msgprefix:Error: invalid argument to option \`-o': $opt_o" 1>&2
michael@13 969 shtool_exit 1
michael@13 970 ;;
michael@13 971 esac
michael@13 972 if [ ! -r "$fod" ]; then
michael@13 973 echo "$msgprefix:Error: file or directory not found: $fod" 1>&2
michael@13 974 shtool_exit 1
michael@13 975 fi
michael@13 976
michael@13 977 # GNU ls changes its time format in response to the TIME_STYLE
michael@13 978 # variable. Since we cannot assume "unset" works, revert this
michael@13 979 # variable to its documented default.
michael@13 980 if [ ".$TIME_STYLE" != . ]; then
michael@13 981 TIME_STYLE=posix-long-iso
michael@13 982 export TIME_STYLE
michael@13 983 fi
michael@13 984
michael@13 985 # get the extended ls output of the file or directory.
michael@13 986 if /bin/ls -L /dev/null >/dev/null 2>&1; then
michael@13 987 set - x`/bin/ls -L -l -d $fod`
michael@13 988 else
michael@13 989 set - x`/bin/ls -l -d $fod`
michael@13 990 fi
michael@13 991
michael@13 992 # The month is at least the fourth argument
michael@13 993 # (3 shifts here, the next inside the loop).
michael@13 994 shift; shift; shift
michael@13 995
michael@13 996 # Find the month. Next argument is day, followed by the year or time.
michael@13 997 month=""
michael@13 998 while [ ".$month" = . ]; do
michael@13 999 shift
michael@13 1000 case $1 in
michael@13 1001 Jan) month=January; nummonth=1 ;;
michael@13 1002 Feb) month=February; nummonth=2 ;;
michael@13 1003 Mar) month=March; nummonth=3 ;;
michael@13 1004 Apr) month=April; nummonth=4 ;;
michael@13 1005 May) month=May; nummonth=5 ;;
michael@13 1006 Jun) month=June; nummonth=6 ;;
michael@13 1007 Jul) month=July; nummonth=7 ;;
michael@13 1008 Aug) month=August; nummonth=8 ;;
michael@13 1009 Sep) month=September; nummonth=9 ;;
michael@13 1010 Oct) month=October; nummonth=10 ;;
michael@13 1011 Nov) month=November; nummonth=11 ;;
michael@13 1012 Dec) month=December; nummonth=12 ;;
michael@13 1013 esac
michael@13 1014 done
michael@13 1015 day="$2"
michael@13 1016 year="$3"
michael@13 1017
michael@13 1018 # We finally have to deal with the problem that the "ls" output
michael@13 1019 # gives either the time of the day or the year.
michael@13 1020 case $year in
michael@13 1021 *:*)
michael@13 1022 this_year=`date '+%Y' 2>/dev/null`
michael@13 1023 if [ ".$this_year" = . ]; then
michael@13 1024 this_year=`date '+%y'`
michael@13 1025 case $this_year in
michael@13 1026 [5-9][0-9]) this_year="19$this_year" ;;
michael@13 1027 [0-4][0-9]) this_year="20$this_year" ;;
michael@13 1028 esac
michael@13 1029 fi
michael@13 1030 # for the following months of the last year the time notation
michael@13 1031 # is usually also used for files modified in the last year.
michael@13 1032 this_month=`date '+%m'`
michael@13 1033 if (expr $nummonth \> $this_month) >/dev/null; then
michael@13 1034 this_year=`expr $this_year - 1`
michael@13 1035 fi
michael@13 1036 year="$this_year"
michael@13 1037 ;;
michael@13 1038 esac
michael@13 1039
michael@13 1040 # Optionally fill day and month with leeding zeros
michael@13 1041 if [ ".$opt_z" = .yes ]; then
michael@13 1042 case $day in
michael@13 1043 [0-9][0-9] ) ;;
michael@13 1044 [0-9] ) day="0$day" ;;
michael@13 1045 esac
michael@13 1046 case $nummonth in
michael@13 1047 [0-9][0-9] ) ;;
michael@13 1048 [0-9] ) nummonth="0$nummonth" ;;
michael@13 1049 esac
michael@13 1050 fi
michael@13 1051
michael@13 1052 # Optionally use digits for month
michael@13 1053 if [ ".$opt_d" = .yes ]; then
michael@13 1054 month="$nummonth"
michael@13 1055 fi
michael@13 1056
michael@13 1057 # Optionally shorten the month name to three characters
michael@13 1058 if [ ".$opt_s" = .yes ]; then
michael@13 1059 month=`echo $month | cut -c1-3`
michael@13 1060 fi
michael@13 1061
michael@13 1062 # Output the resulting date string
michael@13 1063 echo dummy | awk '{
michael@13 1064 for (i = 0; i < 3; i++) {
michael@13 1065 now = substr(order, 1, 1);
michael@13 1066 order = substr(order, 2);
michael@13 1067 if (now == "d")
michael@13 1068 out = day;
michael@13 1069 else if (now == "m")
michael@13 1070 out = month;
michael@13 1071 else if (now == "y")
michael@13 1072 out = year;
michael@13 1073 if (i < 2)
michael@13 1074 printf("%s%s", out, field);
michael@13 1075 else
michael@13 1076 printf("%s", out);
michael@13 1077 }
michael@13 1078 if (newline != "yes")
michael@13 1079 printf("\n");
michael@13 1080 }' "day=$day" "month=$month" "year=$year" \
michael@13 1081 "field=$opt_f" "order=$opt_o" "newline=$opt_n"
michael@13 1082
michael@13 1083 shtool_exit 0
michael@13 1084 ;;
michael@13 1085
michael@13 1086 table )
michael@13 1087 ##
michael@13 1088 ## table -- Pretty-print a field-separated list as a table
michael@13 1089 ## Copyright (c) 1998-2007 Ralf S. Engelschall <rse@engelschall.com>
michael@13 1090 ##
michael@13 1091
michael@13 1092 if [ $opt_c -gt 4 ]; then
michael@13 1093 echo "$msgprefix:Error: Invalid number of colums (1..4 allowed only)" 1>&2
michael@13 1094 shtool_exit 1
michael@13 1095 fi
michael@13 1096 case "x$opt_F" in
michael@13 1097 x? ) ;;
michael@13 1098 * ) echo "$msgprefix:Error: Invalid separator (one char allowed only)" 1>&2; shtool_exit 1 ;;
michael@13 1099 esac
michael@13 1100
michael@13 1101 # split the list into a table
michael@13 1102 list=`
michael@13 1103 IFS="$opt_F"
michael@13 1104 for entry in $*; do
michael@13 1105 if [ ".$entry" != . ]; then
michael@13 1106 echo "$entry"
michael@13 1107 fi
michael@13 1108 done |\
michael@13 1109 awk "
michael@13 1110 BEGIN { list = \"\"; n = 0; }
michael@13 1111 {
michael@13 1112 list = list \\$1;
michael@13 1113 n = n + 1;
michael@13 1114 if (n < $opt_c) {
michael@13 1115 list = list \":\";
michael@13 1116 }
michael@13 1117 if (n == $opt_c) {
michael@13 1118 list = list \"\\n\";
michael@13 1119 n = 0;
michael@13 1120 }
michael@13 1121 }
michael@13 1122 END { print list; }
michael@13 1123 "
michael@13 1124 `
michael@13 1125
michael@13 1126 # format table cells and make sure table
michael@13 1127 # doesn't exceed maximum width
michael@13 1128 OIFS="$IFS"
michael@13 1129 IFS='
michael@13 1130 '
michael@13 1131 for entry in $list; do
michael@13 1132 case $opt_c in
michael@13 1133 1 ) eval "echo \"\${entry}\" | awk -F: '{ printf(\"%-${opt_w}s\\n\", \$1); }'" ;;
michael@13 1134 2 ) eval "echo \"\${entry}\" | awk -F: '{ printf(\"%-${opt_w}s %-${opt_w}s\\n\", \$1, \$2); }'" ;;
michael@13 1135 3 ) eval "echo \"\${entry}\" | awk -F: '{ printf(\"%-${opt_w}s %-${opt_w}s %-${opt_w}s\\n\", \$1, \$2, \$3); }'" ;;
michael@13 1136 4 ) eval "echo \"\${entry}\" | awk -F: '{ printf(\"%-${opt_w}s %-${opt_w}s %-${opt_w}s %-${opt_w}s\\n\", \$1, \$2, \$3, \$4); }'" ;;
michael@13 1137 esac
michael@13 1138 done |\
michael@13 1139 awk "{
michael@13 1140 if (length(\$0) > $opt_s) {
michael@13 1141 printf(\"%s\\n\", substr(\$0, 0, $opt_s-1));
michael@13 1142 } else {
michael@13 1143 print \$0;
michael@13 1144 }
michael@13 1145 }"
michael@13 1146 IFS="$OIFS"
michael@13 1147
michael@13 1148 shtool_exit 0
michael@13 1149 ;;
michael@13 1150
michael@13 1151 prop )
michael@13 1152 ##
michael@13 1153 ## prop -- Display progress with a running propeller
michael@13 1154 ## Copyright (c) 1998-2007 Ralf S. Engelschall <rse@engelschall.com>
michael@13 1155 ##
michael@13 1156
michael@13 1157 perl=''
michael@13 1158 for dir in `echo $PATH | sed -e 's/:/ /g'` .; do
michael@13 1159 if [ -f "$dir/perl" ]; then
michael@13 1160 perl="$dir/perl"
michael@13 1161 break
michael@13 1162 fi
michael@13 1163 done
michael@13 1164 if [ ".$perl" != . ]; then
michael@13 1165 # Perl is preferred because writing to STDERR in
michael@13 1166 # Perl really writes immediately as one would expect
michael@13 1167 $perl -e '
michael@13 1168 @p = ("|","/","-","\\");
michael@13 1169 $i = 0;
michael@13 1170 while (<STDIN>) {
michael@13 1171 printf(STDERR "\r%s...%s\b", $ARGV[0], $p[$i++]);
michael@13 1172 $i = 0 if ($i > 3);
michael@13 1173 }
michael@13 1174 printf(STDERR "\r%s \n", $ARGV[0]);
michael@13 1175 ' "$opt_p"
michael@13 1176 else
michael@13 1177 # But if Perl doesn't exists we use Awk even
michael@13 1178 # some Awk's buffer even the /dev/stderr writing :-(
michael@13 1179 awk '
michael@13 1180 BEGIN {
michael@13 1181 split("|#/#-#\\", p, "#");
michael@13 1182 i = 1;
michael@13 1183 }
michael@13 1184 {
michael@13 1185 printf("\r%s%c\b", prefix, p[i++]) > "/dev/stderr";
michael@13 1186 if (i > 4) { i = 1; }
michael@13 1187 }
michael@13 1188 END {
michael@13 1189 printf("\r%s \n", prefix) > "/dev/stderr";
michael@13 1190 }
michael@13 1191 ' "prefix=$opt_p"
michael@13 1192 fi
michael@13 1193
michael@13 1194 shtool_exit 0
michael@13 1195 ;;
michael@13 1196
michael@13 1197 move )
michael@13 1198 ##
michael@13 1199 ## move -- Move files with simultaneous substitution
michael@13 1200 ## Copyright (c) 1999-2007 Ralf S. Engelschall <rse@engelschall.com>
michael@13 1201 ##
michael@13 1202
michael@13 1203 src="$1"
michael@13 1204 dst="$2"
michael@13 1205
michael@13 1206 # consistency checks
michael@13 1207 if [ ".$src" = . ] || [ ".$dst" = . ]; then
michael@13 1208 echo "$msgprefix:Error: Invalid arguments" 1>&2
michael@13 1209 shtool_exit 1
michael@13 1210 fi
michael@13 1211 if [ ".$src" = ".$dst" ]; then
michael@13 1212 echo "$msgprefix:Error: Source and destination files are the same" 1>&2
michael@13 1213 shtool_exit 1
michael@13 1214 fi
michael@13 1215 expsrc="$src"
michael@13 1216 if [ ".$opt_e" = .yes ]; then
michael@13 1217 expsrc="`echo $expsrc`"
michael@13 1218 fi
michael@13 1219 if [ ".$opt_e" = .yes ]; then
michael@13 1220 if [ ".`echo "$src" | sed -e 's;^.*\\*.*$;;'`" = ".$src" ]; then
michael@13 1221 echo "$msgprefix:Error: Source doesn't contain wildcard ('*'): $dst" 1>&2
michael@13 1222 shtool_exit 1
michael@13 1223 fi
michael@13 1224 if [ ".`echo "$dst" | sed -e 's;^.*%[1-9].*$;;'`" = ".$dst" ]; then
michael@13 1225 echo "$msgprefix:Error: Destination doesn't contain substitution ('%N'): $dst" 1>&2
michael@13 1226 shtool_exit 1
michael@13 1227 fi
michael@13 1228 if [ ".$expsrc" = ".$src" ]; then
michael@13 1229 echo "$msgprefix:Error: Sources not found or no asterisk : $src" 1>&2
michael@13 1230 shtool_exit 1
michael@13 1231 fi
michael@13 1232 else
michael@13 1233 if [ ! -r "$src" ]; then
michael@13 1234 echo "$msgprefix:Error: Source not found: $src" 1>&2
michael@13 1235 shtool_exit 1
michael@13 1236 fi
michael@13 1237 fi
michael@13 1238
michael@13 1239 # determine substitution patterns
michael@13 1240 if [ ".$opt_e" = .yes ]; then
michael@13 1241 srcpat=`echo "$src" | sed -e 's/\\./\\\\./g' -e 's/;/\\;/g' -e 's;\\*;\\\\(.*\\\\);g'`
michael@13 1242 dstpat=`echo "$dst" | sed -e 's;%\([1-9]\);\\\\\1;g'`
michael@13 1243 fi
michael@13 1244
michael@13 1245 # iterate over source(s)
michael@13 1246 for onesrc in $expsrc; do
michael@13 1247 if [ .$opt_e = .yes ]; then
michael@13 1248 onedst=`echo $onesrc | sed -e "s;$srcpat;$dstpat;"`
michael@13 1249 else
michael@13 1250 onedst="$dst"
michael@13 1251 fi
michael@13 1252 errorstatus=0
michael@13 1253 if [ ".$opt_v" = .yes ]; then
michael@13 1254 echo "$onesrc -> $onedst"
michael@13 1255 fi
michael@13 1256 if [ ".$opt_p" = .yes ]; then
michael@13 1257 if [ -r $onedst ]; then
michael@13 1258 if cmp -s $onesrc $onedst; then
michael@13 1259 if [ ".$opt_t" = .yes ]; then
michael@13 1260 echo "rm -f $onesrc" 1>&2
michael@13 1261 fi
michael@13 1262 rm -f $onesrc || errorstatus=$?
michael@13 1263 else
michael@13 1264 if [ ".$opt_t" = .yes ]; then
michael@13 1265 echo "mv -f $onesrc $onedst" 1>&2
michael@13 1266 fi
michael@13 1267 mv -f $onesrc $onedst || errorstatus=$?
michael@13 1268 fi
michael@13 1269 else
michael@13 1270 if [ ".$opt_t" = .yes ]; then
michael@13 1271 echo "mv -f $onesrc $onedst" 1>&2
michael@13 1272 fi
michael@13 1273 mv -f $onesrc $onedst || errorstatus=$?
michael@13 1274 fi
michael@13 1275 else
michael@13 1276 if [ ".$opt_t" = .yes ]; then
michael@13 1277 echo "mv -f $onesrc $onedst" 1>&2
michael@13 1278 fi
michael@13 1279 mv -f $onesrc $onedst || errorstatus=$?
michael@13 1280 fi
michael@13 1281 if [ $errorstatus -ne 0 ]; then
michael@13 1282 break;
michael@13 1283 fi
michael@13 1284 done
michael@13 1285
michael@13 1286 shtool_exit $errorstatus
michael@13 1287 ;;
michael@13 1288
michael@13 1289 install )
michael@13 1290 ##
michael@13 1291 ## install -- Install a program, script or datafile
michael@13 1292 ## Copyright (c) 1997-2007 Ralf S. Engelschall <rse@engelschall.com>
michael@13 1293 ##
michael@13 1294
michael@13 1295 # special case: "shtool install -d <dir> [...]" internally
michael@13 1296 # maps to "shtool mkdir -f -p -m 755 <dir> [...]"
michael@13 1297 if [ "$opt_d" = yes ]; then
michael@13 1298 cmd="$0 mkdir -f -p -m 755"
michael@13 1299 if [ ".$opt_o" != . ]; then
michael@13 1300 cmd="$cmd -o '$opt_o'"
michael@13 1301 fi
michael@13 1302 if [ ".$opt_g" != . ]; then
michael@13 1303 cmd="$cmd -g '$opt_g'"
michael@13 1304 fi
michael@13 1305 if [ ".$opt_v" = .yes ]; then
michael@13 1306 cmd="$cmd -v"
michael@13 1307 fi
michael@13 1308 if [ ".$opt_t" = .yes ]; then
michael@13 1309 cmd="$cmd -t"
michael@13 1310 fi
michael@13 1311 for dir in "$@"; do
michael@13 1312 eval "$cmd $dir" || shtool_exit $?
michael@13 1313 done
michael@13 1314 shtool_exit 0
michael@13 1315 fi
michael@13 1316
michael@13 1317 # determine source(s) and destination
michael@13 1318 argc=$#
michael@13 1319 srcs=""
michael@13 1320 while [ $# -gt 1 ]; do
michael@13 1321 srcs="$srcs $1"
michael@13 1322 shift
michael@13 1323 done
michael@13 1324 dstpath="$1"
michael@13 1325
michael@13 1326 # type check for destination
michael@13 1327 dstisdir=0
michael@13 1328 if [ -d $dstpath ]; then
michael@13 1329 dstpath=`echo "$dstpath" | sed -e 's:/$::'`
michael@13 1330 dstisdir=1
michael@13 1331 fi
michael@13 1332
michael@13 1333 # consistency check for destination
michael@13 1334 if [ $argc -gt 2 ] && [ $dstisdir = 0 ]; then
michael@13 1335 echo "$msgprefix:Error: multiple sources require destination to be directory" 1>&2
michael@13 1336 shtool_exit 1
michael@13 1337 fi
michael@13 1338
michael@13 1339 # iterate over all source(s)
michael@13 1340 for src in $srcs; do
michael@13 1341 dst=$dstpath
michael@13 1342
michael@13 1343 # if destination is a directory, append the input filename
michael@13 1344 if [ $dstisdir = 1 ]; then
michael@13 1345 dstfile=`echo "$src" | sed -e 's;.*/\([^/]*\)$;\1;'`
michael@13 1346 dst="$dst/$dstfile"
michael@13 1347 fi
michael@13 1348
michael@13 1349 # check for correct arguments
michael@13 1350 if [ ".$src" = ".$dst" ]; then
michael@13 1351 echo "$msgprefix:Warning: source and destination are the same - skipped" 1>&2
michael@13 1352 continue
michael@13 1353 fi
michael@13 1354 if [ -d "$src" ]; then
michael@13 1355 echo "$msgprefix:Warning: source \`$src' is a directory - skipped" 1>&2
michael@13 1356 continue
michael@13 1357 fi
michael@13 1358
michael@13 1359 # make a temp file name in the destination directory
michael@13 1360 dsttmp=`echo $dst |\
michael@13 1361 sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;' -e 's;^$;.;' \
michael@13 1362 -e "s;\$;/#INST@$$#;"`
michael@13 1363
michael@13 1364 # verbosity
michael@13 1365 if [ ".$opt_v" = .yes ]; then
michael@13 1366 echo "$src -> $dst" 1>&2
michael@13 1367 fi
michael@13 1368
michael@13 1369 # copy or move the file name to the temp name
michael@13 1370 # (because we might be not allowed to change the source)
michael@13 1371 if [ ".$opt_C" = .yes ]; then
michael@13 1372 opt_c=yes
michael@13 1373 fi
michael@13 1374 if [ ".$opt_c" = .yes ]; then
michael@13 1375 if [ ".$opt_t" = .yes ]; then
michael@13 1376 echo "cp $src $dsttmp" 1>&2
michael@13 1377 fi
michael@13 1378 cp "$src" "$dsttmp" || shtool_exit $?
michael@13 1379 else
michael@13 1380 if [ ".$opt_t" = .yes ]; then
michael@13 1381 echo "mv $src $dsttmp" 1>&2
michael@13 1382 fi
michael@13 1383 mv "$src" "$dsttmp" || shtool_exit $?
michael@13 1384 fi
michael@13 1385
michael@13 1386 # adjust the target file
michael@13 1387 if [ ".$opt_e" != . ]; then
michael@13 1388 sed='sed'
michael@13 1389 OIFS="$IFS"; IFS="$ASC_NL"; set -- $opt_e; IFS="$OIFS"
michael@13 1390 for e
michael@13 1391 do
michael@13 1392 sed="$sed -e '$e'"
michael@13 1393 done
michael@13 1394 cp "$dsttmp" "$dsttmp.old"
michael@13 1395 chmod u+w $dsttmp
michael@13 1396 eval "$sed <$dsttmp.old >$dsttmp" || shtool_exit $?
michael@13 1397 rm -f $dsttmp.old
michael@13 1398 fi
michael@13 1399 if [ ".$opt_s" = .yes ]; then
michael@13 1400 if [ ".$opt_t" = .yes ]; then
michael@13 1401 echo "strip $dsttmp" 1>&2
michael@13 1402 fi
michael@13 1403 strip $dsttmp || shtool_exit $?
michael@13 1404 fi
michael@13 1405 if [ ".$opt_o" != . ]; then
michael@13 1406 if [ ".$opt_t" = .yes ]; then
michael@13 1407 echo "chown $opt_o $dsttmp" 1>&2
michael@13 1408 fi
michael@13 1409 chown $opt_o $dsttmp || shtool_exit $?
michael@13 1410 fi
michael@13 1411 if [ ".$opt_g" != . ]; then
michael@13 1412 if [ ".$opt_t" = .yes ]; then
michael@13 1413 echo "chgrp $opt_g $dsttmp" 1>&2
michael@13 1414 fi
michael@13 1415 chgrp $opt_g $dsttmp || shtool_exit $?
michael@13 1416 fi
michael@13 1417 if [ ".$opt_m" != ".-" ]; then
michael@13 1418 if [ ".$opt_t" = .yes ]; then
michael@13 1419 echo "chmod $opt_m $dsttmp" 1>&2
michael@13 1420 fi
michael@13 1421 chmod $opt_m $dsttmp || shtool_exit $?
michael@13 1422 fi
michael@13 1423
michael@13 1424 # determine whether to do a quick install
michael@13 1425 # (has to be done _after_ the strip was already done)
michael@13 1426 quick=no
michael@13 1427 if [ ".$opt_C" = .yes ]; then
michael@13 1428 if [ -r $dst ]; then
michael@13 1429 if cmp -s "$src" "$dst"; then
michael@13 1430 quick=yes
michael@13 1431 fi
michael@13 1432 fi
michael@13 1433 fi
michael@13 1434
michael@13 1435 # finally, install the file to the real destination
michael@13 1436 if [ $quick = yes ]; then
michael@13 1437 if [ ".$opt_t" = .yes ]; then
michael@13 1438 echo "rm -f $dsttmp" 1>&2
michael@13 1439 fi
michael@13 1440 rm -f $dsttmp
michael@13 1441 else
michael@13 1442 if [ ".$opt_t" = .yes ]; then
michael@13 1443 echo "rm -f $dst && mv $dsttmp $dst" 1>&2
michael@13 1444 fi
michael@13 1445 rm -f $dst && mv $dsttmp $dst
michael@13 1446 fi
michael@13 1447 done
michael@13 1448
michael@13 1449 shtool_exit 0
michael@13 1450 ;;
michael@13 1451
michael@13 1452 mkdir )
michael@13 1453 ##
michael@13 1454 ## mkdir -- Make one or more directories
michael@13 1455 ## Copyright (c) 1996-2007 Ralf S. Engelschall <rse@engelschall.com>
michael@13 1456 ##
michael@13 1457
michael@13 1458 errstatus=0
michael@13 1459 for p in ${1+"$@"}; do
michael@13 1460 # if the directory already exists...
michael@13 1461 if [ -d "$p" ]; then
michael@13 1462 if [ ".$opt_f" = .no ] && [ ".$opt_p" = .no ]; then
michael@13 1463 echo "$msgprefix:Error: directory already exists: $p" 1>&2
michael@13 1464 errstatus=1
michael@13 1465 break
michael@13 1466 else
michael@13 1467 continue
michael@13 1468 fi
michael@13 1469 fi
michael@13 1470 # if the directory has to be created...
michael@13 1471 if [ ".$opt_p" = .no ]; then
michael@13 1472 if [ ".$opt_t" = .yes ]; then
michael@13 1473 echo "mkdir $p" 1>&2
michael@13 1474 fi
michael@13 1475 mkdir $p || errstatus=$?
michael@13 1476 if [ ".$opt_o" != . ]; then
michael@13 1477 if [ ".$opt_t" = .yes ]; then
michael@13 1478 echo "chown $opt_o $p" 1>&2
michael@13 1479 fi
michael@13 1480 chown $opt_o $p || errstatus=$?
michael@13 1481 fi
michael@13 1482 if [ ".$opt_g" != . ]; then
michael@13 1483 if [ ".$opt_t" = .yes ]; then
michael@13 1484 echo "chgrp $opt_g $p" 1>&2
michael@13 1485 fi
michael@13 1486 chgrp $opt_g $p || errstatus=$?
michael@13 1487 fi
michael@13 1488 if [ ".$opt_m" != . ]; then
michael@13 1489 if [ ".$opt_t" = .yes ]; then
michael@13 1490 echo "chmod $opt_m $p" 1>&2
michael@13 1491 fi
michael@13 1492 chmod $opt_m $p || errstatus=$?
michael@13 1493 fi
michael@13 1494 else
michael@13 1495 # the smart situation
michael@13 1496 set fnord `echo ":$p" |\
michael@13 1497 sed -e 's/^:\//%/' \
michael@13 1498 -e 's/^://' \
michael@13 1499 -e 's/\// /g' \
michael@13 1500 -e 's/^%/\//'`
michael@13 1501 shift
michael@13 1502 pathcomp=''
michael@13 1503 for d in ${1+"$@"}; do
michael@13 1504 pathcomp="$pathcomp$d"
michael@13 1505 case "$pathcomp" in
michael@13 1506 -* ) pathcomp="./$pathcomp" ;;
michael@13 1507 esac
michael@13 1508 if [ ! -d "$pathcomp" ]; then
michael@13 1509 if [ ".$opt_t" = .yes ]; then
michael@13 1510 echo "mkdir $pathcomp" 1>&2
michael@13 1511 fi
michael@13 1512 mkdir $pathcomp || errstatus=$?
michael@13 1513 if [ ".$opt_o" != . ]; then
michael@13 1514 if [ ".$opt_t" = .yes ]; then
michael@13 1515 echo "chown $opt_o $pathcomp" 1>&2
michael@13 1516 fi
michael@13 1517 chown $opt_o $pathcomp || errstatus=$?
michael@13 1518 fi
michael@13 1519 if [ ".$opt_g" != . ]; then
michael@13 1520 if [ ".$opt_t" = .yes ]; then
michael@13 1521 echo "chgrp $opt_g $pathcomp" 1>&2
michael@13 1522 fi
michael@13 1523 chgrp $opt_g $pathcomp || errstatus=$?
michael@13 1524 fi
michael@13 1525 if [ ".$opt_m" != . ]; then
michael@13 1526 if [ ".$opt_t" = .yes ]; then
michael@13 1527 echo "chmod $opt_m $pathcomp" 1>&2
michael@13 1528 fi
michael@13 1529 chmod $opt_m $pathcomp || errstatus=$?
michael@13 1530 fi
michael@13 1531 fi
michael@13 1532 pathcomp="$pathcomp/"
michael@13 1533 done
michael@13 1534 fi
michael@13 1535 done
michael@13 1536
michael@13 1537 shtool_exit $errstatus
michael@13 1538 ;;
michael@13 1539
michael@13 1540 mkln )
michael@13 1541 ##
michael@13 1542 ## mkln -- Make link with calculation of relative paths
michael@13 1543 ## Copyright (c) 1998-2007 Ralf S. Engelschall <rse@engelschall.com>
michael@13 1544 ##
michael@13 1545
michael@13 1546 # determine source(s) and destination
michael@13 1547 args=$?
michael@13 1548 srcs=""
michael@13 1549 while [ $# -gt 1 ]; do
michael@13 1550 srcs="$srcs $1"
michael@13 1551 shift
michael@13 1552 done
michael@13 1553 dst="$1"
michael@13 1554 if [ ! -d $dst ]; then
michael@13 1555 if [ $args -gt 2 ]; then
michael@13 1556 echo "$msgprefix:Error: multiple sources not allowed when target isn't a directory" 1>&2
michael@13 1557 shtool_exit 1
michael@13 1558 fi
michael@13 1559 fi
michael@13 1560
michael@13 1561 # determine link options
michael@13 1562 lnopt=""
michael@13 1563 if [ ".$opt_f" = .yes ]; then
michael@13 1564 lnopt="$lnopt -f"
michael@13 1565 fi
michael@13 1566 if [ ".$opt_s" = .yes ]; then
michael@13 1567 lnopt="$lnopt -s"
michael@13 1568 fi
michael@13 1569
michael@13 1570 # iterate over sources
michael@13 1571 for src in $srcs; do
michael@13 1572 # determine if one of the paths is an absolute path,
michael@13 1573 # because then we _have_ to use an absolute symlink
michael@13 1574 oneisabs=0
michael@13 1575 srcisabs=0
michael@13 1576 dstisabs=0
michael@13 1577 case $src in
michael@13 1578 /* ) oneisabs=1; srcisabs=1 ;;
michael@13 1579 esac
michael@13 1580 case $dst in
michael@13 1581 /* ) oneisabs=1; dstisabs=1 ;;
michael@13 1582 esac
michael@13 1583
michael@13 1584 # split source and destination into dir and base name
michael@13 1585 if [ -d $src ]; then
michael@13 1586 srcdir=`echo $src | sed -e 's;/*$;;'`
michael@13 1587 srcbase=""
michael@13 1588 else
michael@13 1589 srcdir=`echo $src | sed -e 's;^[^/]*$;;' -e 's;^\(.*/\)[^/]*$;\1;' -e 's;\(.\)/$;\1;'`
michael@13 1590 srcbase=`echo $src | sed -e 's;.*/\([^/]*\)$;\1;'`
michael@13 1591 fi
michael@13 1592 if [ -d $dst ]; then
michael@13 1593 dstdir=`echo $dst | sed -e 's;/*$;;'`
michael@13 1594 dstbase=""
michael@13 1595 else
michael@13 1596 dstdir=`echo $dst | sed -e 's;^[^/]*$;;' -e 's;^\(.*/\)[^/]*$;\1;' -e 's;\(.\)/$;\1;'`
michael@13 1597 dstbase=`echo $dst | sed -e 's;.*/\([^/]*\)$;\1;'`
michael@13 1598 fi
michael@13 1599
michael@13 1600 # consistency check
michael@13 1601 if [ ".$dstdir" != . ]; then
michael@13 1602 if [ ! -d $dstdir ]; then
michael@13 1603 echo "$msgprefix:Error: destination directory not found: $dstdir" 1>&2
michael@13 1604 shtool_exit 1
michael@13 1605 fi
michael@13 1606 fi
michael@13 1607
michael@13 1608 # make sure the source is reachable from the destination
michael@13 1609 if [ $dstisabs = 1 ]; then
michael@13 1610 if [ $srcisabs = 0 ]; then
michael@13 1611 if [ ".$srcdir" = . ]; then
michael@13 1612 srcdir="`pwd | sed -e 's;/*$;;'`"
michael@13 1613 srcisabs=1
michael@13 1614 oneisabs=1
michael@13 1615 elif [ -d $srcdir ]; then
michael@13 1616 srcdir="`cd $srcdir; pwd | sed -e 's;/*$;;'`"
michael@13 1617 srcisabs=1
michael@13 1618 oneisabs=1
michael@13 1619 fi
michael@13 1620 fi
michael@13 1621 fi
michael@13 1622
michael@13 1623 # split away a common prefix
michael@13 1624 prefix=""
michael@13 1625 if [ ".$srcdir" = ".$dstdir" ] && [ ".$srcdir" != . ]; then
michael@13 1626 prefix="$srcdir/"
michael@13 1627 srcdir=""
michael@13 1628 dstdir=""
michael@13 1629 else
michael@13 1630 while [ ".$srcdir" != . ] && [ ".$dstdir" != . ]; do
michael@13 1631 presrc=`echo $srcdir | sed -e 's;^\([^/]*\)/.*;\1;'`
michael@13 1632 predst=`echo $dstdir | sed -e 's;^\([^/]*\)/.*;\1;'`
michael@13 1633 if [ ".$presrc" != ".$predst" ]; then
michael@13 1634 break
michael@13 1635 fi
michael@13 1636 prefix="$prefix$presrc/"
michael@13 1637 srcdir=`echo $srcdir | sed -e 's;^[^/]*/*;;'`
michael@13 1638 dstdir=`echo $dstdir | sed -e 's;^[^/]*/*;;'`
michael@13 1639 done
michael@13 1640 fi
michael@13 1641
michael@13 1642 # destination prefix is just the common prefix
michael@13 1643 dstpre="$prefix"
michael@13 1644
michael@13 1645 # determine source prefix which is the reverse directory
michael@13 1646 # step-up corresponding to the destination directory
michael@13 1647 srcpre=""
michael@13 1648 allow_relative_srcpre=no
michael@13 1649 if [ ".$prefix" != . ] && [ ".$prefix" != ./ ]; then
michael@13 1650 allow_relative_srcpre=yes
michael@13 1651 fi
michael@13 1652 if [ $oneisabs = 0 ]; then
michael@13 1653 allow_relative_srcpre=yes
michael@13 1654 fi
michael@13 1655 if [ ".$opt_s" != .yes ]; then
michael@13 1656 allow_relative_srcpre=no
michael@13 1657 fi
michael@13 1658 if [ ".$allow_relative_srcpre" = .yes ]; then
michael@13 1659 pl="$dstdir/"
michael@13 1660 OIFS="$IFS"; IFS='/'
michael@13 1661 for pe in $pl; do
michael@13 1662 [ ".$pe" = . ] && continue
michael@13 1663 [ ".$pe" = .. ] && continue
michael@13 1664 srcpre="../$srcpre"
michael@13 1665 done
michael@13 1666 IFS="$OIFS"
michael@13 1667 else
michael@13 1668 if [ $srcisabs = 1 ]; then
michael@13 1669 srcpre="$prefix"
michael@13 1670 fi
michael@13 1671 fi
michael@13 1672
michael@13 1673 # determine destination symlink name
michael@13 1674 if [ ".$dstbase" = . ]; then
michael@13 1675 if [ ".$srcbase" != . ]; then
michael@13 1676 dstbase="$srcbase"
michael@13 1677 else
michael@13 1678 dstbase=`echo "$prefix$srcdir" | sed -e 's;/*$;;' -e 's;.*/\([^/]*\)$;\1;'`
michael@13 1679 fi
michael@13 1680 fi
michael@13 1681
michael@13 1682 # now finalize source and destination directory paths
michael@13 1683 srcdir=`echo $srcdir | sed -e 's;\([^/]\)$;\1/;'`
michael@13 1684 dstdir=`echo $dstdir | sed -e 's;\([^/]\)$;\1/;'`
michael@13 1685
michael@13 1686 # run the final link command
michael@13 1687 if [ ".$opt_t" = .yes ]; then
michael@13 1688 echo "ln$lnopt $srcpre$srcdir$srcbase $dstpre$dstdir$dstbase"
michael@13 1689 fi
michael@13 1690 eval ln$lnopt $srcpre$srcdir$srcbase $dstpre$dstdir$dstbase
michael@13 1691 done
michael@13 1692
michael@13 1693 shtool_exit 0
michael@13 1694 ;;
michael@13 1695
michael@13 1696 mkshadow )
michael@13 1697 ##
michael@13 1698 ## mkshadow -- Make a shadow tree through symbolic links
michael@13 1699 ## Copyright (c) 1998-2007 Ralf S. Engelschall <rse@engelschall.com>
michael@13 1700 ##
michael@13 1701
michael@13 1702 # source and destination directory
michael@13 1703 src=`echo "$1" | sed -e 's:/$::' -e 's:^\./\(.\):\1:'`
michael@13 1704 dst=`echo "$2" | sed -e 's:/$::' -e 's:^\./\(.\):\1:'`
michael@13 1705
michael@13 1706 # check whether source exists
michael@13 1707 if [ ! -d $src ]; then
michael@13 1708 echo "$msgprefix:Error: source directory not found: \`$src'" 1>&2
michael@13 1709 shtool_exit 1
michael@13 1710 fi
michael@13 1711
michael@13 1712 # determine if one of the paths is an absolute path,
michael@13 1713 # because then we have to use an absolute symlink
michael@13 1714 oneisabs=0
michael@13 1715 case $src in
michael@13 1716 /* ) oneisabs=1 ;;
michael@13 1717 esac
michael@13 1718 case $dst in
michael@13 1719 /* ) oneisabs=1 ;;
michael@13 1720 esac
michael@13 1721
michael@13 1722 # determine reverse directory for destination directory
michael@13 1723 dstrevdir=''
michael@13 1724 if [ $oneisabs = 0 ]; then
michael@13 1725 # derive reverse path from forward path
michael@13 1726 pwd=`pwd`
michael@13 1727 OIFS="$IFS"; IFS='/'
michael@13 1728 for pe in $dst; do
michael@13 1729 if [ "x$pe" = "x.." ]; then
michael@13 1730 OIFS2="$IFS"; IFS="$DIFS"
michael@13 1731 eval `echo "$pwd" |\
michael@13 1732 sed -e 's:\([^/]*\)$:; dir="\1":' \
michael@13 1733 -e 's:^\(.*\)/[^/]*;:pwd="\1";:'\
michael@13 1734 -e 's:^;:pwd="";:'`
michael@13 1735 dstrevdir="$dir/$dstrevdir"
michael@13 1736 IFS="$OIFS2"
michael@13 1737 else
michael@13 1738 dstrevdir="../$dstrevdir"
michael@13 1739 fi
michael@13 1740 done
michael@13 1741 IFS="$OIFS"
michael@13 1742 else
michael@13 1743 src="`cd $src; pwd`";
michael@13 1744 fi
michael@13 1745
michael@13 1746 # create directory tree at destination
michael@13 1747 if [ ! -d $dst ]; then
michael@13 1748 if [ ".$opt_t" = .yes ]; then
michael@13 1749 echo "mkdir $dst" 1>&2
michael@13 1750 fi
michael@13 1751 mkdir $dst
michael@13 1752 fi
michael@13 1753 if [ ".$opt_a" = .yes ]; then
michael@13 1754 DIRS=`cd $src; find . -type d -print |\
michael@13 1755 sed -e '/^\.$/d' -e 's:^\./::'`
michael@13 1756 else
michael@13 1757 DIRS=`cd $src; find . -type d -print |\
michael@13 1758 sed -e '/\/CVS/d' -e '/^\.$/d' -e 's:^\./::'`
michael@13 1759 fi
michael@13 1760 for dir in $DIRS; do
michael@13 1761 if [ ".$opt_t" = .yes ]; then
michael@13 1762 echo "mkdir $dst/$dir" 1>&2
michael@13 1763 fi
michael@13 1764 mkdir $dst/$dir
michael@13 1765 done
michael@13 1766
michael@13 1767 # fill directory tree with symlinks to files
michael@13 1768 if [ ".$opt_a" = .yes ]; then
michael@13 1769 FILES="`cd $src; find . -depth -print |\
michael@13 1770 sed -e 's/^\.\///'`"
michael@13 1771 else
michael@13 1772 FILES="`cd $src; find . -depth -print |\
michael@13 1773 sed -e '/\.o$/d' -e '/\.a$/d' -e '/\.so$/d' \
michael@13 1774 -e '/\.cvsignore$/d' -e '/\/CVS/d' \
michael@13 1775 -e '/\/\.#/d' -e '/\.orig$/d' \
michael@13 1776 -e 's/^\.\///'`"
michael@13 1777 fi
michael@13 1778 for file in $FILES; do
michael@13 1779 # don't use `-type f' above for find because of symlinks
michael@13 1780 if [ -d "$src/$file" ]; then
michael@13 1781 continue
michael@13 1782 fi
michael@13 1783 basename=`echo $file | sed -e 's:^.*/::'`
michael@13 1784 dir=`echo $file | sed -e 's:[^/]*$::' -e 's:/$::' -e 's:$:/:' -e 's:^/$::'`
michael@13 1785 from=`echo "$src/$file" | sed -e 's/^\.\///'`
michael@13 1786 to="$dst/$dir$basename"
michael@13 1787 if [ $oneisabs = 0 ]; then
michael@13 1788 if [ ".$dir" != . ]; then
michael@13 1789 subdir=`echo $dir | sed -e 's:/$::'`
michael@13 1790 # derive reverse path from forward path
michael@13 1791 revdir=''
michael@13 1792 OIFS="$IFS"; IFS='/'
michael@13 1793 for pe in $subdir; do
michael@13 1794 revdir="../$revdir"
michael@13 1795 done
michael@13 1796 IFS="$OIFS"
michael@13 1797 # finalize from
michael@13 1798 from="$revdir$from"
michael@13 1799 fi
michael@13 1800 from="$dstrevdir$from"
michael@13 1801 fi
michael@13 1802 if [ ".$opt_v" = .yes ]; then
michael@13 1803 echo " $to" 1>&2
michael@13 1804 fi
michael@13 1805 if [ ".$opt_t" = .yes ]; then
michael@13 1806 echo "ln -s $from $to" 1>&2
michael@13 1807 fi
michael@13 1808 ln -s $from $to
michael@13 1809 done
michael@13 1810
michael@13 1811 shtool_exit 0
michael@13 1812 ;;
michael@13 1813
michael@13 1814 fixperm )
michael@13 1815 ##
michael@13 1816 ## fixperm -- Fix file permissions inside a source tree
michael@13 1817 ## Copyright (c) 1996-2007 Ralf S. Engelschall <rse@engelschall.com>
michael@13 1818 ##
michael@13 1819
michael@13 1820 paths="$*"
michael@13 1821
michael@13 1822 # check whether the test command supports the -x option
michael@13 1823 if [ -x /bin/sh ] 2>/dev/null; then
michael@13 1824 minusx="-x"
michael@13 1825 else
michael@13 1826 minusx="-r"
michael@13 1827 fi
michael@13 1828
michael@13 1829 # iterate over paths
michael@13 1830 for p in $paths; do
michael@13 1831 for file in `find $p -depth -print`; do
michael@13 1832 if [ -f $file ]; then
michael@13 1833 if [ $minusx $file ]; then
michael@13 1834 if [ ".$opt_v" = .yes ]; then
michael@13 1835 echo "-rwxr-xr-x $file" 2>&1
michael@13 1836 fi
michael@13 1837 if [ ".$opt_t" = .yes ]; then
michael@13 1838 echo "chmod 755 $file" 2>&1
michael@13 1839 fi
michael@13 1840 chmod 755 $file
michael@13 1841 else
michael@13 1842 if [ ".$opt_v" = .yes ]; then
michael@13 1843 echo "-rw-r--r-- $file" 2>&1
michael@13 1844 fi
michael@13 1845 if [ ".$opt_t" = .yes ]; then
michael@13 1846 echo "chmod 644 $file" 2>&1
michael@13 1847 fi
michael@13 1848 chmod 644 $file
michael@13 1849 fi
michael@13 1850 continue
michael@13 1851 fi
michael@13 1852 if [ -d $file ]; then
michael@13 1853 if [ ".$opt_v" = .yes ]; then
michael@13 1854 echo "drwxr-xr-x $file" 2>&1
michael@13 1855 fi
michael@13 1856 if [ ".$opt_t" = .yes ]; then
michael@13 1857 echo "chmod 755 $file" 2>&1
michael@13 1858 fi
michael@13 1859 chmod 755 $file
michael@13 1860 continue
michael@13 1861 fi
michael@13 1862 if [ ".$opt_v" = .yes ]; then
michael@13 1863 echo "?????????? $file" 2>&1
michael@13 1864 fi
michael@13 1865 done
michael@13 1866 done
michael@13 1867
michael@13 1868 shtool_exit 0
michael@13 1869 ;;
michael@13 1870
michael@13 1871 rotate )
michael@13 1872 ##
michael@13 1873 ## rotate -- Logfile rotation
michael@13 1874 ## Copyright (c) 2001-2007 Ralf S. Engelschall <rse@engelschall.com>
michael@13 1875 ##
michael@13 1876
michael@13 1877 # make sure we have at least one file to rotate
michael@13 1878 if [ ".$opt_n" = .0 ]; then
michael@13 1879 echo "$msgprefix:Error: invalid argument \`$opt_n' to option -n." 1>&2
michael@13 1880 shtool_exit 1
michael@13 1881 fi
michael@13 1882
michael@13 1883 # canonicalize -s option argument
michael@13 1884 if [ ".$opt_s" != . ]; then
michael@13 1885 if [ ".`expr $opt_s : '[0-9]*$'`" != .0 ]; then
michael@13 1886 :
michael@13 1887 elif [ ".`expr $opt_s : '[0-9]*[Kk]$'`" != .0 ]; then
michael@13 1888 opt_s=`expr $opt_s : '\([0-9]*\)[Kk]$'`
michael@13 1889 opt_s=`expr $opt_s \* 1024`
michael@13 1890 elif [ ".`expr $opt_s : '[0-9]*[Mm]$'`" != .0 ]; then
michael@13 1891 opt_s=`expr $opt_s : '\([0-9]*\)[Mm]$'`
michael@13 1892 opt_s=`expr $opt_s \* 1048576` # 1024*1024
michael@13 1893 elif [ ".`expr $opt_s : '[0-9]*[Gg]$'`" != .0 ]; then
michael@13 1894 opt_s=`expr $opt_s : '\([0-9]*\)[Gg]$'`
michael@13 1895 opt_s=`expr $opt_s \* 1073741824` # 1024*1024*1024
michael@13 1896 else
michael@13 1897 echo "$msgprefix:Error: invalid argument \`$opt_s' to option -s." 1>&2
michael@13 1898 shtool_exit 1
michael@13 1899 fi
michael@13 1900 fi
michael@13 1901
michael@13 1902 # option -d/-z consistency
michael@13 1903 if [ ".$opt_d" = .yes ] && [ ".$opt_z" = . ]; then
michael@13 1904 echo "$msgprefix:Error: option -d requires option -z." 1>&2
michael@13 1905 shtool_exit 1
michael@13 1906 fi
michael@13 1907
michael@13 1908 # make sure target directory exists
michael@13 1909 if [ ".$opt_a" != . ]; then
michael@13 1910 if [ ! -d $opt_a ]; then
michael@13 1911 if [ ".$opt_f" = .no ]; then
michael@13 1912 echo "$msgprefix:Error: archive directory \`$opt_a' does not exist." 1>&2
michael@13 1913 shtool_exit 1
michael@13 1914 fi
michael@13 1915 mkdir $opt_a || shtool_exit $?
michael@13 1916 chmod 755 $opt_a
michael@13 1917 fi
michael@13 1918 if [ ! -w $opt_a ]; then
michael@13 1919 echo "$msgprefix:Error: archive directory \`$opt_a' not writable." 1>&2
michael@13 1920 shtool_exit 1
michael@13 1921 fi
michael@13 1922 fi
michael@13 1923
michael@13 1924 # determine compression approach
michael@13 1925 if [ ".$opt_z" != . ]; then
michael@13 1926 comp_lvl="$opt_z"
michael@13 1927 comp_prg=""
michael@13 1928 case $comp_lvl in
michael@13 1929 *:* ) eval `echo $comp_lvl |\
michael@13 1930 sed -e 's%^\(.*\):\(.*\)$%comp_prg="\1"; comp_lvl="\2"%'` ;;
michael@13 1931 esac
michael@13 1932
michael@13 1933 # compression level consistency
michael@13 1934 case $comp_lvl in
michael@13 1935 [0-9] )
michael@13 1936 ;;
michael@13 1937 * ) echo "$msgprefix:Error: invalid compression level \`$comp_lvl'" 1>&2
michael@13 1938 shtool_exit 1
michael@13 1939 ;;
michael@13 1940 esac
michael@13 1941
michael@13 1942 # determine a suitable compression tool
michael@13 1943 if [ ".$comp_prg" = . ]; then
michael@13 1944 # check whether the test command supports the -x option
michael@13 1945 if [ -x /bin/sh ] 2>/dev/null; then
michael@13 1946 minusx="-x"
michael@13 1947 else
michael@13 1948 minusx="-r"
michael@13 1949 fi
michael@13 1950 # search for tools in $PATH
michael@13 1951 paths="`echo $PATH |\
michael@13 1952 sed -e 's%/*:%:%g' -e 's%/*$%%' \
michael@13 1953 -e 's/^:/.:/' -e 's/::/:.:/g' -e 's/:$/:./' \
michael@13 1954 -e 's/:/ /g'`"
michael@13 1955 for prg in bzip2 gzip compress; do
michael@13 1956 for path in $paths; do
michael@13 1957 if [ $minusx "$path/$prg" ] && [ ! -d "$path/$prg" ]; then
michael@13 1958 comp_prg="$prg"
michael@13 1959 break
michael@13 1960 fi
michael@13 1961 done
michael@13 1962 if [ ".$comp_prg" != . ]; then
michael@13 1963 break
michael@13 1964 fi
michael@13 1965 done
michael@13 1966 if [ ".$comp_prg" = . ]; then
michael@13 1967 echo "$msgprefix:Error: no suitable compression tool found in \$PATH" 1>&2
michael@13 1968 shtool_exit 1
michael@13 1969 fi
michael@13 1970 fi
michael@13 1971
michael@13 1972 # determine standard compression extension
michael@13 1973 # and make sure it is a known tool
michael@13 1974 case $comp_prg in
michael@13 1975 */bzip2 | bzip2 ) comp_ext="bz2" comp_lvl="-$comp_lvl" ;;
michael@13 1976 */gzip | gzip ) comp_ext="gz" comp_lvl="-$comp_lvl" ;;
michael@13 1977 */compress | compress ) comp_ext="Z"; comp_lvl="" ;;
michael@13 1978 * ) echo "$msgprefix:Error: tool \`$comp_prg' is not a known compression tool" 1>&2
michael@13 1979 shtool_exit 1
michael@13 1980 ;;
michael@13 1981 esac
michael@13 1982 comp_suf=".$comp_ext"
michael@13 1983 fi
michael@13 1984
michael@13 1985 # iterate over all given logfile arguments
michael@13 1986 for file in $*; do
michael@13 1987 # make sure the logfile exists
michael@13 1988 if [ ! -f $file ]; then
michael@13 1989 if [ ".$opt_f" = .yes ]; then
michael@13 1990 continue
michael@13 1991 fi
michael@13 1992 echo "$msgprefix:Error: logfile \`$file' not found" 1>&2
michael@13 1993 shtool_exit 1
michael@13 1994 fi
michael@13 1995
michael@13 1996 # determine log directory (where original logfile is placed)
michael@13 1997 ldir="."
michael@13 1998 case $file in
michael@13 1999 */* ) eval `echo $file | sed -e 's%^\(.*\)/\([^/]*\)$%ldir="\1"; file="\2";%'` ;;
michael@13 2000 esac
michael@13 2001
michael@13 2002 # determine archive directory (where rotated logfiles are placed)
michael@13 2003 adir="$ldir"
michael@13 2004 if [ ".$opt_a" != . ]; then
michael@13 2005 case "$opt_a" in
michael@13 2006 /* | ./* ) adir="$opt_a" ;;
michael@13 2007 * ) adir="$ldir/$opt_a" ;;
michael@13 2008 esac
michael@13 2009 fi
michael@13 2010
michael@13 2011 # optionally take logfile size into account
michael@13 2012 if [ ".$opt_s" != . ]; then
michael@13 2013 # determine size of logfile
michael@13 2014 set -- `env -i /bin/ls -l "$ldir/$file" | sed -e "s;$ldir/$file;;" |\
michael@13 2015 sed -e 's; -> .*$;;' -e 's;[ ][ ]*; ;g'`
michael@13 2016 n=`expr $# - 3`
michael@13 2017 eval "size=\`echo \${$n}\`"
michael@13 2018
michael@13 2019 # skip logfile if size is still too small
michael@13 2020 if [ $size -lt $opt_s ]; then
michael@13 2021 if [ ".$opt_v" = .yes ]; then
michael@13 2022 echo "$ldir/$file: still too small in size -- skipping"
michael@13 2023 fi
michael@13 2024 continue
michael@13 2025 fi
michael@13 2026 fi
michael@13 2027
michael@13 2028 # verbosity
michael@13 2029 if [ ".$opt_v" = .yes ]; then
michael@13 2030 echo "rotating $ldir/$file"
michael@13 2031 fi
michael@13 2032
michael@13 2033 # execute prolog
michael@13 2034 if [ ".$opt_P" != . ]; then
michael@13 2035 if [ ".$opt_t" = .yes ]; then
michael@13 2036 echo "$opt_P"
michael@13 2037 fi
michael@13 2038 eval $opt_P
michael@13 2039 [ $? -ne 0 ] && shtool_exit $?
michael@13 2040 fi
michael@13 2041
michael@13 2042 # kick away out-rotated logfile
michael@13 2043 n=`expr $opt_n - 1`
michael@13 2044 n=`echo dummy | awk "{ printf(\"%0${opt_p}d\", n); }" n=$n`
michael@13 2045 if [ -f "${adir}/${file}.${n}${comp_suf}" ]; then
michael@13 2046 # optionally migrate away the out-rotated logfile
michael@13 2047 if [ ".$opt_M" != . ]; then
michael@13 2048 if [ ".$opt_t" = .yes ]; then
michael@13 2049 echo "$opt_M ${adir}/${file}.${n}${comp_suf}"
michael@13 2050 fi
michael@13 2051 eval "$opt_M ${adir}/${file}.${n}${comp_suf}"
michael@13 2052 [ $? -ne 0 ] && shtool_exit $?
michael@13 2053 fi
michael@13 2054 # finally get rid of the out-rotated logfile
michael@13 2055 if [ ".$opt_t" = .yes ]; then
michael@13 2056 echo "rm -f ${adir}/${file}.${n}${comp_suf}"
michael@13 2057 fi
michael@13 2058 rm -f ${adir}/${file}.${n}${comp_suf} || shtool_exit $?
michael@13 2059 fi
michael@13 2060
michael@13 2061 # rotate already archived logfiles
michael@13 2062 while [ $n -gt 0 ]; do
michael@13 2063 m=$n
michael@13 2064 n=`expr $n - 1`
michael@13 2065 n=`echo dummy | awk "{ printf(\"%0${opt_p}d\", n); }" n=$n`
michael@13 2066 if [ $n -eq 0 ] && [ ".$opt_d" = .yes ]; then
michael@13 2067 # special case: first rotation file under delayed compression situation
michael@13 2068 if [ ! -f "${adir}/${file}.${n}" ]; then
michael@13 2069 continue
michael@13 2070 fi
michael@13 2071
michael@13 2072 # compress file (delayed)
michael@13 2073 if [ ".$opt_b" = .yes ]; then
michael@13 2074 if [ ".$opt_t" = .yes ]; then
michael@13 2075 echo "mv ${adir}/${file}.${n} ${adir}/${file}.${m}"
michael@13 2076 fi
michael@13 2077 mv ${adir}/${file}.${n} ${adir}/${file}.${m} || shtool_exit $?
michael@13 2078 if [ ".$opt_t" = .yes ]; then
michael@13 2079 echo "(${comp_prg} ${comp_lvl} <${adir}/${file}.${m} >${adir}/${file}.${m}${comp_suf}; rm -f ${adir}/${file}.${m}) &"
michael@13 2080 fi
michael@13 2081 ( ${comp_prg} ${comp_lvl} \
michael@13 2082 <${adir}/${file}.${m} \
michael@13 2083 >${adir}/${file}.${m}${comp_suf} || shtool_exit $?
michael@13 2084 rm -f ${adir}/${file}.${m} || shtool_exit $?
michael@13 2085 ) </dev/null >/dev/null 2>&1 &
michael@13 2086 else
michael@13 2087 if [ ".$opt_t" = .yes ]; then
michael@13 2088 echo "${comp_prg} ${comp_lvl} <${adir}/${file}.${n} >${adir}/${file}.${m}${comp_suf}"
michael@13 2089 fi
michael@13 2090 ${comp_prg} ${comp_lvl} \
michael@13 2091 <${adir}/${file}.${n} \
michael@13 2092 >${adir}/${file}.${m}${comp_suf} || shtool_exit $?
michael@13 2093 if [ ".$opt_t" = .yes ]; then
michael@13 2094 echo "rm -f ${adir}/${file}.${n}"
michael@13 2095 fi
michael@13 2096 rm -f ${adir}/${file}.${n} || shtool_exit $?
michael@13 2097 fi
michael@13 2098
michael@13 2099 # fix file attributes
michael@13 2100 if [ ".$opt_o" != . ]; then
michael@13 2101 if [ ".$opt_t" = .yes ]; then
michael@13 2102 echo "chown $opt_o ${adir}/${file}.${m}${comp_suf}"
michael@13 2103 fi
michael@13 2104 chown $opt_o ${adir}/${file}.${m}${comp_suf} || shtool_exit $?
michael@13 2105 fi
michael@13 2106 if [ ".$opt_g" != . ]; then
michael@13 2107 if [ ".$opt_t" = .yes ]; then
michael@13 2108 echo "chgrp $opt_g ${adir}/${file}.${m}${comp_suf}"
michael@13 2109 fi
michael@13 2110 chgrp $opt_g ${adir}/${file}.${m}${comp_suf} || shtool_exit $?
michael@13 2111 fi
michael@13 2112 if [ ".$opt_m" != . ]; then
michael@13 2113 if [ ".$opt_t" = .yes ]; then
michael@13 2114 echo "chmod $opt_m ${adir}/${file}.${m}${comp_suf}"
michael@13 2115 fi
michael@13 2116 chmod $opt_m ${adir}/${file}.${m}${comp_suf} || shtool_exit $?
michael@13 2117 fi
michael@13 2118 else
michael@13 2119 # standard case: second and following rotation file
michael@13 2120 if [ ! -f "${adir}/${file}.${n}${comp_suf}" ]; then
michael@13 2121 continue
michael@13 2122 fi
michael@13 2123 if [ ".$opt_t" = .yes ]; then
michael@13 2124 echo "mv ${adir}/${file}.${n}${comp_suf} ${adir}/${file}.${m}${comp_suf}"
michael@13 2125 fi
michael@13 2126 mv ${adir}/${file}.${n}${comp_suf} ${adir}/${file}.${m}${comp_suf} || shtool_exit $?
michael@13 2127 fi
michael@13 2128 done
michael@13 2129
michael@13 2130 # move away current logfile
michael@13 2131 if [ ".$opt_c" = .yes ]; then
michael@13 2132 # approach: copy[+truncate]
michael@13 2133 if [ ".$opt_t" = .yes ]; then
michael@13 2134 echo "cp -p ${ldir}/${file} ${adir}/${file}.${n}"
michael@13 2135 fi
michael@13 2136 cp -p ${ldir}/${file} ${adir}/${file}.${n} || shtool_exit $?
michael@13 2137 if [ ".$opt_r" = .no ]; then
michael@13 2138 if [ ".$opt_t" = .yes ]; then
michael@13 2139 echo "cp /dev/null ${ldir}/${file}"
michael@13 2140 fi
michael@13 2141 cp /dev/null ${ldir}/${file} || shtool_exit $?
michael@13 2142 fi
michael@13 2143 else
michael@13 2144 # approach: move[+touch]
michael@13 2145 if [ ".$opt_t" = .yes ]; then
michael@13 2146 echo "mv ${ldir}/${file} ${adir}/${file}.${n}"
michael@13 2147 fi
michael@13 2148 mv ${ldir}/${file} ${adir}/${file}.${n} || shtool_exit $?
michael@13 2149 if [ ".$opt_r" = .no ]; then
michael@13 2150 if [ ".$opt_t" = .yes ]; then
michael@13 2151 echo "touch ${ldir}/${file}"
michael@13 2152 fi
michael@13 2153 touch ${ldir}/${file} || shtool_exit $?
michael@13 2154 # fix file attributes
michael@13 2155 if [ ".$opt_o" != . ]; then
michael@13 2156 if [ ".$opt_t" = .yes ]; then
michael@13 2157 echo "chown $opt_o ${ldir}/${file}"
michael@13 2158 fi
michael@13 2159 chown $opt_o ${ldir}/${file} || shtool_exit $?
michael@13 2160 fi
michael@13 2161 if [ ".$opt_g" != . ]; then
michael@13 2162 if [ ".$opt_t" = .yes ]; then
michael@13 2163 echo "chgrp $opt_g ${ldir}/${file}"
michael@13 2164 fi
michael@13 2165 chgrp $opt_g ${ldir}/${file} || shtool_exit $?
michael@13 2166 fi
michael@13 2167 if [ ".$opt_m" != . ]; then
michael@13 2168 if [ ".$opt_t" = .yes ]; then
michael@13 2169 echo "chmod $opt_m ${ldir}/${file}"
michael@13 2170 fi
michael@13 2171 chmod $opt_m ${ldir}/${file} || shtool_exit $?
michael@13 2172 fi
michael@13 2173 fi
michael@13 2174 fi
michael@13 2175
michael@13 2176 # regular compression step
michael@13 2177 if [ ".$opt_z" != . ] && [ ".$opt_d" = .no ]; then
michael@13 2178 # compress file
michael@13 2179 if [ ".$opt_b" = .yes ]; then
michael@13 2180 if [ ".$opt_t" = .yes ]; then
michael@13 2181 echo "(${comp_prg} ${comp_lvl} <${adir}/${file}.${n} >${adir}/${file}.${n}${comp_suf}; rm -f ${adir}/${file}.${n}) &"
michael@13 2182 fi
michael@13 2183 ( ${comp_prg} ${comp_lvl} \
michael@13 2184 <${adir}/${file}.${n} \
michael@13 2185 >${adir}/${file}.${n}${comp_suf} || shtool_exit $?
michael@13 2186 rm -f ${adir}/${file}.${n} || shtool_exit $?
michael@13 2187 ) </dev/null >/dev/null 2>&1 &
michael@13 2188 else
michael@13 2189 if [ ".$opt_t" = .yes ]; then
michael@13 2190 echo "${comp_prg} ${comp_lvl} <${adir}/${file}.${n} >${adir}/${file}.${n}${comp_suf}"
michael@13 2191 fi
michael@13 2192 ${comp_prg} ${comp_lvl} \
michael@13 2193 <${adir}/${file}.${n} \
michael@13 2194 >${adir}/${file}.${n}${comp_suf} || shtool_exit $?
michael@13 2195 if [ ".$opt_t" = .yes ]; then
michael@13 2196 echo "rm -f ${opt_a}${file}.${n}"
michael@13 2197 fi
michael@13 2198 rm -f ${adir}/${file}.${n} || shtool_exit $?
michael@13 2199 fi
michael@13 2200
michael@13 2201 # fix file attributes
michael@13 2202 if [ ".$opt_o" != . ]; then
michael@13 2203 if [ ".$opt_t" = .yes ]; then
michael@13 2204 echo "chown $opt_o ${adir}/${file}.${n}${comp_suf}"
michael@13 2205 fi
michael@13 2206 chown $opt_o ${adir}/${file}.${n}${comp_suf} || shtool_exit $?
michael@13 2207 fi
michael@13 2208 if [ ".$opt_g" != . ]; then
michael@13 2209 if [ ".$opt_t" = .yes ]; then
michael@13 2210 echo "chgrp $opt_g ${adir}/${file}.${n}${comp_suf}"
michael@13 2211 fi
michael@13 2212 chgrp $opt_g ${adir}/${file}.${n}${comp_suf} || shtool_exit $?
michael@13 2213 fi
michael@13 2214 if [ ".$opt_m" != . ]; then
michael@13 2215 if [ ".$opt_t" = .yes ]; then
michael@13 2216 echo "chmod $opt_m ${adir}/${file}.${n}${comp_suf}"
michael@13 2217 fi
michael@13 2218 chmod $opt_m ${adir}/${file}.${n}${comp_suf} || shtool_exit $?
michael@13 2219 fi
michael@13 2220 fi
michael@13 2221
michael@13 2222 # execute epilog
michael@13 2223 if [ ".$opt_E" != . ]; then
michael@13 2224 if [ ".$opt_t" = .yes ]; then
michael@13 2225 echo "$opt_E"
michael@13 2226 fi
michael@13 2227 eval $opt_E
michael@13 2228 [ $? -ne 0 ] && shtool_exit $?
michael@13 2229 fi
michael@13 2230 done
michael@13 2231
michael@13 2232 shtool_exit 0
michael@13 2233 ;;
michael@13 2234
michael@13 2235 tarball )
michael@13 2236 ##
michael@13 2237 ## tarball -- Roll distribution tarballs
michael@13 2238 ## Copyright (c) 1999-2007 Ralf S. Engelschall <rse@engelschall.com>
michael@13 2239 ##
michael@13 2240
michael@13 2241 srcs="$*"
michael@13 2242
michael@13 2243 # check whether the test command supports the -x option
michael@13 2244 if [ -x /bin/sh ] 2>/dev/null; then
michael@13 2245 minusx="-x"
michael@13 2246 else
michael@13 2247 minusx="-r"
michael@13 2248 fi
michael@13 2249
michael@13 2250 # find the tools
michael@13 2251 paths="`echo $PATH |\
michael@13 2252 sed -e 's%/*:%:%g' -e 's%/*$%%' \
michael@13 2253 -e 's/^:/.:/' -e 's/::/:.:/g' -e 's/:$/:./' \
michael@13 2254 -e 's/:/ /g'`"
michael@13 2255 for spec in find:gfind,find tar:gtar,tar tardy:tardy,tarcust; do
michael@13 2256 prg=`echo $spec | sed -e 's/:.*$//'`
michael@13 2257 tools=`echo $spec | sed -e 's/^.*://'`
michael@13 2258 eval "prg_${prg}=''"
michael@13 2259 # iterate over tools
michael@13 2260 for tool in `echo $tools | sed -e 's/,/ /g'`; do
michael@13 2261 # iterate over paths
michael@13 2262 for path in $paths; do
michael@13 2263 if [ $minusx "$path/$tool" ] && [ ! -d "$path/$tool" ]; then
michael@13 2264 eval "prg_${prg}=\"$path/$tool\""
michael@13 2265 break
michael@13 2266 fi
michael@13 2267 done
michael@13 2268 eval "val=\$prg_${prg}"
michael@13 2269 if [ ".$val" != . ]; then
michael@13 2270 break
michael@13 2271 fi
michael@13 2272 done
michael@13 2273 done
michael@13 2274
michael@13 2275 # expand source paths
michael@13 2276 exclude=''
michael@13 2277 for pat in `echo $opt_e | sed 's/,/ /g'`; do
michael@13 2278 exclude="$exclude | grep -v '$pat'"
michael@13 2279 done
michael@13 2280 if [ ".$opt_t" = .yes ]; then
michael@13 2281 echo "cp /dev/null $tmpfile.lst" 1>&2
michael@13 2282 fi
michael@13 2283 cp /dev/null $tmpfile.lst
michael@13 2284 for src in $srcs; do
michael@13 2285 if [ -d $src ]; then
michael@13 2286 if [ ".$opt_t" = .yes ]; then
michael@13 2287 echo "(cd $src && $prg_find . -type f -depth -print) | sed -e 's:^\\.\$::' -e 's:^\\./::' | cat $exclude >>$tmpfile.lst" 1>&2
michael@13 2288 fi
michael@13 2289 (cd $src && $prg_find . -type f -depth -print) |\
michael@13 2290 sed -e 's:^\.$::' -e 's:^\./::' | eval cat $exclude >>$tmpfile.lst
michael@13 2291 else
michael@13 2292 if [ ".$opt_t" = .yes ]; then
michael@13 2293 echo "echo $src >>$tmpfile.lst" 1>&2
michael@13 2294 fi
michael@13 2295 echo $src >>$tmpfile.lst
michael@13 2296 fi
michael@13 2297 done
michael@13 2298 sort <$tmpfile.lst >$tmpfile.lst.n
michael@13 2299 mv $tmpfile.lst.n $tmpfile.lst
michael@13 2300 if [ ".$opt_v" = .yes ]; then
michael@13 2301 cat $tmpfile.lst | sed -e 's/^/ /' 1>&2
michael@13 2302 fi
michael@13 2303
michael@13 2304 # determine tarball file and directory name
michael@13 2305 if [ ".$opt_o" != . ]; then
michael@13 2306 tarfile="$opt_o"
michael@13 2307 if [ ".$opt_d" != . ]; then
michael@13 2308 tarname="$opt_d"
michael@13 2309 else
michael@13 2310 tarname=`echo $tarfile | sed -e 's/\.tar.*$//' -e 's;.*/\([^/]*\)$;\1;'`
michael@13 2311 fi
michael@13 2312 else
michael@13 2313 if [ ".$opt_d" != . ]; then
michael@13 2314 tarname="$opt_d"
michael@13 2315 elif [ -d "$from" ]; then
michael@13 2316 tarname=`echo $from | sed -e 's;.*/\([^/]*\)$;\1;'`
michael@13 2317 else
michael@13 2318 tarname="out"
michael@13 2319 fi
michael@13 2320 tarfile="$tarname.tar"
michael@13 2321 fi
michael@13 2322
michael@13 2323 # roll the tarball
michael@13 2324 compress=''
michael@13 2325 if [ ".$opt_c" != . ]; then
michael@13 2326 compress="| $opt_c"
michael@13 2327 fi
michael@13 2328 if [ ".$prg_tardy" != . ]; then
michael@13 2329 # the elegant hackers way
michael@13 2330 tardy_opt="--prefix=$tarname"
michael@13 2331 tardy_opt="$tardy_opt --user_number=0 --group_number=0" # security!
michael@13 2332 if [ ".$opt_u" != . ]; then
michael@13 2333 tardy_opt="$tardy_opt --user_name=$opt_u"
michael@13 2334 fi
michael@13 2335 if [ ".$opt_g" != . ]; then
michael@13 2336 tardy_opt="$tardy_opt --group_name=$opt_g"
michael@13 2337 fi
michael@13 2338 if [ ".$opt_t" = .yes ]; then
michael@13 2339 echo "cat $tmpfile.lst | xargs $prg_tar cf - | $prg_tardy $tardy_opt | cat $compress >$tmpfile.out" 1>&2
michael@13 2340 fi
michael@13 2341 cat $tmpfile.lst |\
michael@13 2342 xargs $prg_tar cf - |\
michael@13 2343 $prg_tardy $tardy_opt |\
michael@13 2344 eval cat $compress >$tmpfile.out
michael@13 2345 if [ ".$opt_t" = .yes ]; then
michael@13 2346 echo "cp $tmpfile.out $tarfile" 1>&2
michael@13 2347 fi
michael@13 2348 cp $tmpfile.out $tarfile
michael@13 2349 else
michael@13 2350 # the portable standard way
michael@13 2351 if [ ".$opt_t" = .yes ]; then
michael@13 2352 echo "mkdir $tmpdir/$tarname" 1>&2
michael@13 2353 fi
michael@13 2354 mkdir $tmpdir/$tarname || shtool_exit 1
michael@13 2355 if [ ".$opt_t" = .yes ]; then
michael@13 2356 echo "cat $tmpfile.lst | xargs $prg_tar cf - | (cd $tmpdir/$tarname && $prg_tar xf -)" 1>&2
michael@13 2357 fi
michael@13 2358 cat $tmpfile.lst |\
michael@13 2359 xargs $prg_tar cf - |\
michael@13 2360 (cd $tmpdir/$tarname && $prg_tar xf -)
michael@13 2361 if [ ".$opt_u" != . ]; then
michael@13 2362 if [ ".$opt_t" = .yes ]; then
michael@13 2363 echo "chown -R $opt_u $tmpdir/$tarname >/dev/null 2>&1" 2>&1
michael@13 2364 fi
michael@13 2365 chown -R $opt_u $tmpdir/$tarname >/dev/null 2>&1 ||\
michael@13 2366 echo "$msgprefix:Warning: cannot set user name \`$opt_u' (would require root privileges)"
michael@13 2367 fi
michael@13 2368 if [ ".$opt_g" != . ]; then
michael@13 2369 if [ ".$opt_t" = .yes ]; then
michael@13 2370 echo "chgrp -R $opt_g $tmpdir/$tarname >/dev/null 2>&1" 2>&1
michael@13 2371 fi
michael@13 2372 chgrp -R $opt_g $tmpdir/$tarname >/dev/null 2>&1 ||\
michael@13 2373 echo "$msgprefix:Warning: cannot set group name \`$opt_g' (would require root privileges)"
michael@13 2374 fi
michael@13 2375 if [ ".$opt_t" = .yes ]; then
michael@13 2376 echo "(cd $tmpdir && $prg_find $tarname -type f -depth -print | sort | xargs $prg_tar cf -) | cat $compress >$tmpfile.out" 1>&2
michael@13 2377 fi
michael@13 2378 (cd $tmpdir && $prg_find $tarname -type f -depth -print | sort | xargs $prg_tar cf -) |\
michael@13 2379 eval cat $compress >$tmpfile.out
michael@13 2380 if [ ".$opt_t" = .yes ]; then
michael@13 2381 echo "cp $tmpfile.out $tarfile" 1>&2
michael@13 2382 fi
michael@13 2383 cp $tmpfile.out $tarfile
michael@13 2384 if [ ".$opt_t" = .yes ]; then
michael@13 2385 echo "rm -rf $tmpdir/$tarname" 1>&2
michael@13 2386 fi
michael@13 2387 rm -rf $tmpdir/$tarname
michael@13 2388 fi
michael@13 2389
michael@13 2390 # cleanup
michael@13 2391 if [ ".$opt_t" = .yes ]; then
michael@13 2392 echo "rm -f $tmpfile.lst $tmpfile.out" 1>&2
michael@13 2393 fi
michael@13 2394 rm -f $tmpfile.lst $tmpfile.out
michael@13 2395
michael@13 2396 shtool_exit 0
michael@13 2397 ;;
michael@13 2398
michael@13 2399 subst )
michael@13 2400 ##
michael@13 2401 ## subst -- Apply sed(1) substitution operations
michael@13 2402 ## Copyright (c) 2001-2007 Ralf S. Engelschall <rse@engelschall.com>
michael@13 2403 ##
michael@13 2404
michael@13 2405 # remember optional list of file(s)
michael@13 2406 files="$*"
michael@13 2407 files_num="$#"
michael@13 2408
michael@13 2409 # parameter consistency check
michael@13 2410 if [ $# -eq 0 ] && [ ".$opt_b" != . ]; then
michael@13 2411 echo "$msgprefix:Error: option -b cannot be applied to stdin" 1>&2
michael@13 2412 shtool_exit 1
michael@13 2413 fi
michael@13 2414 if [ $# -eq 0 ] && [ ".$opt_s" = .yes ]; then
michael@13 2415 echo "$msgprefix:Error: option -s cannot be applied to stdin" 1>&2
michael@13 2416 shtool_exit 1
michael@13 2417 fi
michael@13 2418
michael@13 2419 # build underlying sed(1) command
michael@13 2420 sedcmd='sed'
michael@13 2421 if [ ".$opt_e" != . ]; then
michael@13 2422 OIFS="$IFS"; IFS="$ASC_NL"; set -- $opt_e; IFS="$OIFS"
michael@13 2423 for e
michael@13 2424 do
michael@13 2425 sedcmd="$sedcmd -e '$e'"
michael@13 2426 done
michael@13 2427 elif [ ".$opt_f" != . ]; then
michael@13 2428 if [ ! -f $opt_f ]; then
michael@13 2429 echo "$msgprefix:Error: command file \`$opt_f' not found or not a regular file" 1>&2
michael@13 2430 shtool_exit 1
michael@13 2431 fi
michael@13 2432 sedcmd="$sedcmd -f '$opt_f'"
michael@13 2433 else
michael@13 2434 echo "$msgprefix:Error: either -e option(s) or -f option required" 1>&2
michael@13 2435 shtool_exit 1
michael@13 2436 fi
michael@13 2437
michael@13 2438 # determine extension for original file
michael@13 2439 orig=".orig"
michael@13 2440 if [ ".$opt_b" != . ]; then
michael@13 2441 orig="$opt_b"
michael@13 2442 fi
michael@13 2443
michael@13 2444 # apply sed(1) operation(s)
michael@13 2445 if [ ".$files" != . ]; then
michael@13 2446 # apply operation(s) to files
michael@13 2447 substdone=no
michael@13 2448 for file in $files; do
michael@13 2449 test ".$file" = . && continue
michael@13 2450 if [ ! -f $file ]; then
michael@13 2451 echo "$msgprefix:Warning: file \`$file' not found or not a regular file" 1>&2
michael@13 2452 continue
michael@13 2453 fi
michael@13 2454
michael@13 2455 # handle interactive mode
michael@13 2456 if [ ".$opt_i" = .yes ]; then
michael@13 2457 eval "$sedcmd <$file >$file.new"
michael@13 2458 skip=no
michael@13 2459 if cmp $file $file.new >/dev/null 2>&1; then
michael@13 2460 rm -f $file.new
michael@13 2461 skip=yes
michael@13 2462 else
michael@13 2463 (diff -U1 $file $file.new >$tmpfile) 2>/dev/null
michael@13 2464 if [ ".`cat $tmpfile`" = . ]; then
michael@13 2465 (diff -C1 $file $file.new >$tmpfile) 2>/dev/null
michael@13 2466 if [ ".`cat $tmpfile`" = . ]; then
michael@13 2467 echo "$msgprefix:Warning: unable to show difference for file \`$file'" 1>&2
michael@13 2468 cp /dev/null $tmpfile
michael@13 2469 fi
michael@13 2470 fi
michael@13 2471 rm -f $file.new
michael@13 2472 cat $tmpfile
michael@13 2473 echo dummy | awk '{ printf("%s", TEXT); }' TEXT=">>> Apply [Y/n]: "
michael@13 2474 read input
michael@13 2475 if [ ".$input" != .Y ] &&\
michael@13 2476 [ ".$input" != .y ] &&\
michael@13 2477 [ ".$input" != . ]; then
michael@13 2478 skip=yes
michael@13 2479 fi
michael@13 2480 fi
michael@13 2481 if [ ".$skip" = .yes ]; then
michael@13 2482 if [ ".$opt_v" = .yes ]; then
michael@13 2483 echo "file \`$file' -- skipped" 1>&2
michael@13 2484 fi
michael@13 2485 continue
michael@13 2486 fi
michael@13 2487 fi
michael@13 2488
michael@13 2489 # apply sed(1) operation(s)
michael@13 2490 if [ ".$opt_v" = .yes ]; then
michael@13 2491 echo "patching \`$file'" 1>&2
michael@13 2492 fi
michael@13 2493 if [ ".$opt_t" = .yes ]; then
michael@13 2494 echo "\$ cp -p $file $file$orig"
michael@13 2495 echo "\$ chmod u+w $file"
michael@13 2496 echo "\$ $sedcmd <$file$orig >$file"
michael@13 2497 fi
michael@13 2498 if [ ".$opt_n" = .no ]; then
michael@13 2499 cp -p $file $file$orig
michael@13 2500 chmod u+w $file >/dev/null 2>&1 || true
michael@13 2501 eval "$sedcmd <$file$orig >$file"
michael@13 2502 fi
michael@13 2503
michael@13 2504 # optionally fix timestamp
michael@13 2505 if [ ".$opt_s" = .yes ]; then
michael@13 2506 if [ ".$opt_t" = .yes ]; then
michael@13 2507 echo "\$ touch -r $file$orig $file"
michael@13 2508 fi
michael@13 2509 if [ ".$opt_n" = .no ]; then
michael@13 2510 touch -r $file$orig $file
michael@13 2511 fi
michael@13 2512 fi
michael@13 2513
michael@13 2514 # optionally check whether any content change actually occurred
michael@13 2515 if [ ".$opt_q" = .no ]; then
michael@13 2516 if cmp $file$orig $file >/dev/null 2>&1; then
michael@13 2517 if [ ".$opt_w" = .yes ]; then
michael@13 2518 echo "$msgprefix:Warning: substitution resulted in no content change on file \"$file\"" 1>&2
michael@13 2519 fi
michael@13 2520 else
michael@13 2521 substdone=yes
michael@13 2522 fi
michael@13 2523 fi
michael@13 2524
michael@13 2525 # optionally remove preserved original file
michael@13 2526 if [ ".$opt_b" = . ]; then
michael@13 2527 if [ ".$opt_t" = .yes ]; then
michael@13 2528 echo "\$ rm -f $file$orig"
michael@13 2529 fi
michael@13 2530 if [ ".$opt_n" = .no ]; then
michael@13 2531 rm -f $file$orig
michael@13 2532 fi
michael@13 2533 fi
michael@13 2534 done
michael@13 2535 if [ ".$opt_q" = .no ] && [ ".$opt_w" = .no ]; then
michael@13 2536 if [ ".$substdone" = .no ]; then
michael@13 2537 if [ ".$files_num" = .1 ]; then
michael@13 2538 echo "$msgprefix:Warning: substitution resulted in no content change on file \"$file\"" 1>&2
michael@13 2539 else
michael@13 2540 echo "$msgprefix:Warning: substitution resulted in no content change on any file" 1>&2
michael@13 2541 fi
michael@13 2542 fi
michael@13 2543 fi
michael@13 2544 else
michael@13 2545 # apply operation(s) to stdin/stdout
michael@13 2546 if [ ".$opt_v" = .yes ]; then
michael@13 2547 echo "patching <stdin>" 1>&2
michael@13 2548 fi
michael@13 2549 if [ ".$opt_t" = .yes ]; then
michael@13 2550 echo "\$ $sedcmd"
michael@13 2551 fi
michael@13 2552 if [ ".$opt_n" = .no ]; then
michael@13 2553 eval "$sedcmd"
michael@13 2554 fi
michael@13 2555 fi
michael@13 2556
michael@13 2557 shtool_exit 0
michael@13 2558 ;;
michael@13 2559
michael@13 2560 platform )
michael@13 2561 ##
michael@13 2562 ## platform -- Platform Identification Utility
michael@13 2563 ## Copyright (c) 2003-2007 Ralf S. Engelschall <rse@engelschall.com>
michael@13 2564 ##
michael@13 2565
michael@13 2566 # option post-processing
michael@13 2567 if [ ".$opt_t" != . ]; then
michael@13 2568 case "$opt_t" in
michael@13 2569 binary )
michael@13 2570 # binary package id (OpenPKG RPM)
michael@13 2571 opt_F="%<ap>-%<sp>"
michael@13 2572 opt_L=yes
michael@13 2573 opt_S=""
michael@13 2574 opt_C="+"
michael@13 2575 ;;
michael@13 2576 build )
michael@13 2577 # build time checking (OpenPKG RPM)
michael@13 2578 opt_F="%<at>-%<st>"
michael@13 2579 opt_L=yes
michael@13 2580 opt_S=""
michael@13 2581 opt_C="+"
michael@13 2582 ;;
michael@13 2583 gnu )
michael@13 2584 # GNU config.guess style <arch>-<vendor>-<os><osversion>
michael@13 2585 opt_F="%<at>-unknown-%<st>"
michael@13 2586 opt_L=yes
michael@13 2587 opt_S=""
michael@13 2588 opt_C="+"
michael@13 2589 ;;
michael@13 2590 web )
michael@13 2591 # non-whitespace HTTP Server-header id
michael@13 2592 opt_F="%<sp>-%<ap>"
michael@13 2593 opt_S="/"
michael@13 2594 opt_C="+"
michael@13 2595 ;;
michael@13 2596 summary)
michael@13 2597 # human readable verbose summary information
michael@13 2598 opt_F="Class: %[sc] (%[ac])\\nProduct: %[sp] (%[ap])\\nTechnology: %[st] (%[at])"
michael@13 2599 opt_S=" "
michael@13 2600 opt_C="/"
michael@13 2601 ;;
michael@13 2602 all-in-one )
michael@13 2603 # full-table all-in-one information
michael@13 2604 opt_F=""
michael@13 2605 opt_F="${opt_F}concise architecture class: %<ac>\\n"
michael@13 2606 opt_F="${opt_F}regular architecture class: %{ac}\\n"
michael@13 2607 opt_F="${opt_F}verbose architecture class: %[ac]\\n"
michael@13 2608 opt_F="${opt_F}concise architecture product: %<ap>\\n"
michael@13 2609 opt_F="${opt_F}regular architecture product: %{ap}\\n"
michael@13 2610 opt_F="${opt_F}verbose architecture product: %[ap]\\n"
michael@13 2611 opt_F="${opt_F}concise architecture technology: %<at>\\n"
michael@13 2612 opt_F="${opt_F}regular architecture technology: %{at}\\n"
michael@13 2613 opt_F="${opt_F}verbose architecture technology: %[at]\\n"
michael@13 2614 opt_F="${opt_F}concise system class: %<sc>\\n"
michael@13 2615 opt_F="${opt_F}regular system class: %{sc}\\n"
michael@13 2616 opt_F="${opt_F}verbose system class: %[sc]\\n"
michael@13 2617 opt_F="${opt_F}concise system product: %<sp>\\n"
michael@13 2618 opt_F="${opt_F}regular system product: %{sp}\\n"
michael@13 2619 opt_F="${opt_F}verbose system product: %[sp]\\n"
michael@13 2620 opt_F="${opt_F}concise system technology: %<st>\\n"
michael@13 2621 opt_F="${opt_F}regular system technology: %{st}\\n"
michael@13 2622 opt_F="${opt_F}verbose system technology: %[st]"
michael@13 2623 ;;
michael@13 2624 * )
michael@13 2625 echo "$msgprefix:Error: invalid type \`$opt_t'" 1>&2
michael@13 2626 exit 1
michael@13 2627 ;;
michael@13 2628 esac
michael@13 2629 fi
michael@13 2630
michael@13 2631 # assemble initial platform information
michael@13 2632 UNAME_MACHINE=`(uname -m) 2>/dev/null` ||\
michael@13 2633 UNAME_MACHINE=`(uname -p) 2>/dev/null` ||\
michael@13 2634 UNAME_MACHINE='unknown'
michael@13 2635 UNAME_SYSTEM=`(uname -s) 2>/dev/null` ||\
michael@13 2636 UNAME_SYSTEM='unknown'
michael@13 2637 UNAME_RELEASE=`(uname -r) 2>/dev/null` ||\
michael@13 2638 UNAME_RELEASE=`(uname -v) 2>/dev/null` ||\
michael@13 2639 UNAME_RELEASE='unknown'
michael@13 2640
michael@13 2641 UNAME="${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}"
michael@13 2642
michael@13 2643 AC=""; AP=""; AT=""
michael@13 2644 SC=""; SP=""; ST=""
michael@13 2645
michael@13 2646 # dispatch into platform specific sections
michael@13 2647 case "${UNAME}" in
michael@13 2648
michael@13 2649 # FreeBSD
michael@13 2650 *:FreeBSD:* )
michael@13 2651 # determine architecture
michael@13 2652 AC="${UNAME_MACHINE}"
michael@13 2653 case "${AC}" in
michael@13 2654 i386 ) AC="iX86" ;;
michael@13 2655 esac
michael@13 2656 AP="${AC}"
michael@13 2657 AT="${AP}"
michael@13 2658 if [ ".${AT}" = ".iX86" ]; then
michael@13 2659 case "`(/sbin/sysctl -n hw.model) 2>&1`" in
michael@13 2660 *"Xeon"* | *"Pentium Pro"* | *"Cyrix 6x86MX"* | *"Pentium II"* | *"Pentium III"* | *"Pentium 4"* | *"Celeron"* ) AT="i686" ;;
michael@13 2661 *"Pentium"* ) AT="i586" ;; *"i486[SD]X"* | *"Cyrix 486"* | *"Cyrix [56]x86"* | *"Blue Lightning" | *"Cyrix 486S/DX" ) AT="i486" ;;
michael@13 2662 *"i386[SD]X"* | *"NexGen 586"* ) AT="i386" ;;
michael@13 2663 esac
michael@13 2664 fi
michael@13 2665 # determine system
michael@13 2666 r=`echo "${UNAME_RELEASE}" |\
michael@13 2667 sed -e 's;[()];;' -e 's/\(-.*\)$/[\1]/'`
michael@13 2668 ST="FreeBSD ${r}"
michael@13 2669 SP="${ST}"
michael@13 2670 case "${r}" in
michael@13 2671 1.* ) SC="4.3BSD" ;;
michael@13 2672 * ) SC="4.4BSD" ;;
michael@13 2673 esac
michael@13 2674 ;;
michael@13 2675
michael@13 2676 # NetBSD
michael@13 2677 *:NetBSD:* )
michael@13 2678 # determine architecture
michael@13 2679 AT="${UNAME_MACHINE}"
michael@13 2680 AP="${AT}"
michael@13 2681 case "${AP}" in
michael@13 2682 i[3-6]86 ) AP="iX86" ;;
michael@13 2683 esac
michael@13 2684 AC="${AP}"
michael@13 2685 # determine system
michael@13 2686 r=`echo "${UNAME_RELEASE}" | sed -e 's/\([-_].*\)$/[\1]/'`
michael@13 2687 ST="NetBSD ${r}"
michael@13 2688 SP="${ST}"
michael@13 2689 case "${r}" in
michael@13 2690 0.* ) SC="4.3BSD" ;;
michael@13 2691 * ) SC="4.4BSD" ;;
michael@13 2692 esac
michael@13 2693 ;;
michael@13 2694
michael@13 2695 # OpenBSD
michael@13 2696 *:OpenBSD:* )
michael@13 2697 # determine architecture
michael@13 2698 AT="${UNAME_MACHINE}"
michael@13 2699 AP="${AT}"
michael@13 2700 case "${AP}" in
michael@13 2701 i[3-6]86 ) AP="iX86" ;;
michael@13 2702 esac
michael@13 2703 AC="${AP}"
michael@13 2704 # determine system
michael@13 2705 r=`echo "${UNAME_RELEASE}" | sed -e 's/\([-_].*\)$/[\1]/'`
michael@13 2706 ST="OpenBSD ${r}"
michael@13 2707 SP="${ST}"
michael@13 2708 SC="4.4BSD"
michael@13 2709 ;;
michael@13 2710
michael@13 2711 # GNU/Linux
michael@13 2712 *:Linux:* )
michael@13 2713 # determine architecture
michael@13 2714 AT="${UNAME_MACHINE}"
michael@13 2715 case "${AT}" in
michael@13 2716 ia64 ) AT="IA64" ;;
michael@13 2717 x86_64 ) AT='AMD64' ;;
michael@13 2718 parisc ) AT="HPPA32" ;;
michael@13 2719 parisc64 ) AT="HPPA64" ;;
michael@13 2720 esac
michael@13 2721 AP="${AT}"
michael@13 2722 case "${AP}" in
michael@13 2723 i[3-6]86 ) AP='iX86' ;;
michael@13 2724 esac
michael@13 2725 AC="${AP}"
michael@13 2726 # determine system
michael@13 2727 v_kern=`echo "${UNAME_RELEASE}" |\
michael@13 2728 sed -e 's/^\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/'`
michael@13 2729 v_libc=`(strings /lib/libc.so.* | grep '^GLIBC_' | sed -e 's/^GLIBC_//' |\
michael@13 2730 env -i sort -n | sed -n -e '$p' | sed -e 's/^\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/') 2>/dev/null`
michael@13 2731 ST="GNU/<Linux >${v_libc}/<${v_kern}>"
michael@13 2732 if [ -f /etc/lsb-release ]; then
michael@13 2733 eval `( . /etc/lsb-release
michael@13 2734 echo "SC=\"LSB${LSB_VERSION}\""
michael@13 2735 if [ ".${DISTRIB_ID}" != . -a ".${DISTRIB_RELEASE}" != . ]; then
michael@13 2736 echo "SP=\"${DISTRIB_ID} ${DISTRIB_RELEASE}\""
michael@13 2737 fi
michael@13 2738 ) 2>/dev/null`
michael@13 2739 fi
michael@13 2740 if [ ".$SP" = . ]; then
michael@13 2741 for tagfile in x \
michael@13 2742 `cd /etc && \
michael@13 2743 /bin/ls *[_-]release *[_-]version 2>/dev/null | env -i sort | \
michael@13 2744 sed -e '/^redhat-release$/d' -e '/^lsb-release$/d'; \
michael@13 2745 echo redhat-release lsb-release`
michael@13 2746 do
michael@13 2747 [ ".${tagfile}" = .x ] && continue
michael@13 2748 [ ! -f "/etc/${tagfile}" ] && continue
michael@13 2749 n=`echo ${tagfile} | sed -e 's/[_-]release$//' -e 's/[_-]version$//'`
michael@13 2750 v=`(grep VERSION /etc/${tagfile}; cat /etc/${tagfile}) | grep '[0-9]' | sed -e 'q' |\
michael@13 2751 sed -e 's/^/#/' \
michael@13 2752 -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' \
michael@13 2753 -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' \
michael@13 2754 -e 's/^#[^0-9]*\([0-9][0-9]*\).*$/\1/' \
michael@13 2755 -e 's/^#.*$//'`
michael@13 2756 case "`util_lower ${n}`" in
michael@13 2757 redhat )
michael@13 2758 if [ ".`egrep '(Red Hat Enterprise Linux|CentOS)' /etc/${tagfile}`" != . ]; then
michael@13 2759 n="<R>ed <H>at <E>nterprise <L>inux"
michael@13 2760 else
michael@13 2761 n="<R>ed <H>at <L>inux"
michael@13 2762 fi
michael@13 2763 ;;
michael@13 2764 debian ) n="Debian[ GNU/Linux]" ;;
michael@13 2765 ubuntu ) n="Ubuntu[ GNU/Linux]" ;;
michael@13 2766 fedora ) n="<Fedora> Core[ GNU/Linux]" ;;
michael@13 2767 suse ) n="[Novell ]SUSE[ Linux]" ;;
michael@13 2768 mandrake*|mandriva ) n="Mandriva[ Linux]" ;;
michael@13 2769 gentoo ) n="Gentoo[ GNU/Linux]" ;;
michael@13 2770 slackware ) n="Slackware[ Linux]" ;;
michael@13 2771 turbolinux ) n="TurboLinux" ;;
michael@13 2772 unitedlinux ) n="UnitedLinux" ;;
michael@13 2773 * ) n="${n}[ GNU/Linux]" ;;
michael@13 2774 esac
michael@13 2775 case "$n" in
michael@13 2776 *"<"*">"* ) SP="$n <$v>" ;;
michael@13 2777 * ) SP="$n $v" ;;
michael@13 2778 esac
michael@13 2779 break
michael@13 2780 done
michael@13 2781 fi
michael@13 2782 [ ".$SP" = . ] && SP="${ST}"
michael@13 2783 [ ".$SC" = . ] && SC="LSB"
michael@13 2784 ;;
michael@13 2785
michael@13 2786 # Sun Solaris
michael@13 2787 *:SunOS:* )
michael@13 2788 # determine architecture
michael@13 2789 AT="${UNAME_MACHINE}"
michael@13 2790 case "${AT}" in
michael@13 2791 i86pc )
michael@13 2792 AT="iX86"
michael@13 2793 case "`(/bin/isainfo -k) 2>&1`" in
michael@13 2794 amd64 ) AT="AMD64" ;;
michael@13 2795 esac
michael@13 2796 ;;
michael@13 2797 esac
michael@13 2798 AP="${AT}"
michael@13 2799 case "${AP}" in
michael@13 2800 sun4[cdm] ) AP="SPARC32" ;;
michael@13 2801 sun4[uv] ) AP="SPARC64" ;;
michael@13 2802 sun4* ) AP="SPARC" ;;
michael@13 2803 esac
michael@13 2804 AC="${AP}"
michael@13 2805 case "${AC}" in
michael@13 2806 SPARC* ) AC="SPARC" ;;
michael@13 2807 esac
michael@13 2808 # determine system
michael@13 2809 ST="[Sun ]SunOS ${UNAME_RELEASE}"
michael@13 2810 v=`echo "${UNAME_RELEASE}" |\
michael@13 2811 sed -e 's;^4\.;1.;' \
michael@13 2812 -e 's;^5\.\([0-6]\)[^0-9]*$;2.\1;' \
michael@13 2813 -e 's;^5\.\([0-9][0-9]*\).*;\1;'`
michael@13 2814 SP="[Sun ]Solaris $v"
michael@13 2815 case "${UNAME_RELEASE}" in
michael@13 2816 4.* ) SC="4.3BSD" ;;
michael@13 2817 5.* ) SC="SVR4" ;;
michael@13 2818 esac
michael@13 2819 ;;
michael@13 2820
michael@13 2821 # SCO UnixWare
michael@13 2822 *:UnixWare:* )
michael@13 2823 # determine architecture
michael@13 2824 AT="${UNAME_MACHINE}"
michael@13 2825 case "${AT}" in
michael@13 2826 i[3-6]86 | ix86at ) AT="iX86" ;;
michael@13 2827 esac
michael@13 2828 AP="${AT}"
michael@13 2829 # determine system
michael@13 2830 v=`/sbin/uname -v`
michael@13 2831 ST="[SCO ]UnixWare ${v}"
michael@13 2832 SP="${ST}"
michael@13 2833 SC="SVR${UNAME_RELEASE}"
michael@13 2834 ;;
michael@13 2835
michael@13 2836 # QNX
michael@13 2837 *:QNX:* )
michael@13 2838 # determine architecture
michael@13 2839 AT="${UNAME_MACHINE}"
michael@13 2840 case "${AT}" in
michael@13 2841 x86pc ) AT="iX86" ;;
michael@13 2842 esac
michael@13 2843 AP="${AT}"
michael@13 2844 # determine system
michael@13 2845 v="${UNAME_RELEASE}"
michael@13 2846 ST="QNX[ Neutrino RTOS] ${v}"
michael@13 2847 v=`echo "${v}" | sed -e 's;^\([0-9][0-9]*\.[0-9][0-9]*\).*$;\1;'`
michael@13 2848 SP="QNX[ Neutrino RTOS] ${v}"
michael@13 2849 SC="QNX"
michael@13 2850 ;;
michael@13 2851
michael@13 2852 # SGI IRIX
michael@13 2853 *:IRIX*:* )
michael@13 2854 # determine architecture
michael@13 2855 AT="${UNAME_MACHINE}"
michael@13 2856 AP="${AT}"
michael@13 2857 case "${AP}:${UNAME_SYSTEM}" in
michael@13 2858 IP*:IRIX64 ) AP="MIPS64" ;;
michael@13 2859 IP*:* ) AP="MIPS" ;;
michael@13 2860 esac
michael@13 2861 AC="${AP}"
michael@13 2862 # determine system
michael@13 2863 v=`(/bin/uname -R || /bin/uname -r) 2>/dev/null | sed -e 's;[0-9.]* ;;'`
michael@13 2864 ST="[SGI ]IRIX ${v}"
michael@13 2865 v="${UNAME_RELEASE}"
michael@13 2866 SP="[SGI ]IRIX ${v}"
michael@13 2867 SC="4.2BSD/SVR3"
michael@13 2868 ;;
michael@13 2869
michael@13 2870 # HP HP-UX
michael@13 2871 *:HP-UX:* )
michael@13 2872 # determine architecture
michael@13 2873 AT="${UNAME_MACHINE}"
michael@13 2874 case "${AT}" in
michael@13 2875 ia64 ) AT="IA64" ;;
michael@13 2876 9000/[34]?? ) AT=M68K ;;
michael@13 2877 9000/[678][0-9][0-9])
michael@13 2878 sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null`
michael@13 2879 sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`
michael@13 2880 case "${sc_cpu_version}" in
michael@13 2881 523 ) AT="HPPA1.0" ;;
michael@13 2882 528 ) AT="HPPA1.1" ;;
michael@13 2883 532 ) AT="HPPA2.0"
michael@13 2884 case "${sc_kernel_bits}" in
michael@13 2885 32 ) AT="${AT}n" ;;
michael@13 2886 64 ) AT="${AT}w" ;;
michael@13 2887 esac
michael@13 2888 ;;
michael@13 2889 esac
michael@13 2890 ;;
michael@13 2891 esac
michael@13 2892 AP="${AT}"
michael@13 2893 case "${AP}" in
michael@13 2894 HPPA* ) AP="HPPA" ;;
michael@13 2895 esac
michael@13 2896 AC="${AP}"
michael@13 2897 # determine system
michael@13 2898 v=`echo "${UNAME_RELEASE}" | sed -e 's;^[^0-9]*;;'`
michael@13 2899 ST="[HP ]<HP>-<UX ${v}>"
michael@13 2900 SP="${ST}"
michael@13 2901 case "${v}" in
michael@13 2902 10.* ) SC="SVR4.2" ;;
michael@13 2903 [7-9]* ) SC="SVR4" ;;
michael@13 2904 esac
michael@13 2905 ;;
michael@13 2906
michael@13 2907 # HP Tru64 (OSF1)
michael@13 2908 *:OSF1:* )
michael@13 2909 # determine architecture
michael@13 2910 AP="${UNAME_MACHINE}"
michael@13 2911 case "${AP}" in
michael@13 2912 alpha ) AP="Alpha" ;;
michael@13 2913 esac
michael@13 2914 alpha_type=`(/usr/sbin/psrinfo -v) 2>/dev/null |\
michael@13 2915 sed -n -e 's/^.*The alpha \([^ ][^ ]*\).*processor.*$/\1/p' | sed -e 'q'`
michael@13 2916 AT="${AP}${alpha_type}"
michael@13 2917 AC="${AP}"
michael@13 2918 # determine system
michael@13 2919 v=`echo "${UNAME_RELEASE}" | sed -e 's;^[VTX];;'`
michael@13 2920 ST="[HP ]Tru64 ${v}"
michael@13 2921 SP="${ST}"
michael@13 2922 SC="OSF1"
michael@13 2923 ;;
michael@13 2924
michael@13 2925 # IBM AIX
michael@13 2926 *:AIX:* )
michael@13 2927 # determine architecture
michael@13 2928 cpu_arch=rs6000
michael@13 2929 if [ -x /usr/sbin/lsdev -a -x /usr/sbin/lsattr ]; then
michael@13 2930 cpu_id=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`
michael@13 2931 if [ ".`/usr/sbin/lsattr -El ${cpu_id} | grep -i powerpc`" != . ]; then
michael@13 2932 cpu_arch=powerpc
michael@13 2933 fi
michael@13 2934 elif [ -d /QOpenSys ]; then
michael@13 2935 # IBM i5/OS (aka OS/400) with PASE (Portable Application Solutions Environment)
michael@13 2936 cpu_arch=powerpc
michael@13 2937 fi
michael@13 2938 if [ -x /usr/bin/oslevel ]; then
michael@13 2939 os_level=`/usr/bin/oslevel`
michael@13 2940 else
michael@13 2941 os_level="`uname -v`.`uname -r`"
michael@13 2942 fi
michael@13 2943 os_level=`echo "${os_level}" |\
michael@13 2944 sed -e 's;^\([0-9][0-9]*\.[0-9][0-9]*\)\(\.[0-9][0-9]*\)\(.*\)$;<\1>\2[\3];' \
michael@13 2945 -e 's;^\([0-9][0-9]*\.[0-9][0-9]*\)\(.*\)$;<\1>\2;'`
michael@13 2946 AT="${cpu_arch}"
michael@13 2947 AP="${AT}"
michael@13 2948 AC="${AP}"
michael@13 2949 # determine system
michael@13 2950 ST="[IBM ]<AIX >${os_level}"
michael@13 2951 SP="${ST}"
michael@13 2952 case "${os_level}" in
michael@13 2953 [12]* ) SC="SVR2" ;;
michael@13 2954 * ) SC="SVR4" ;;
michael@13 2955 esac
michael@13 2956 ;;
michael@13 2957
michael@13 2958 # Apple Mac OS X (Darwin)
michael@13 2959 *:Darwin:* )
michael@13 2960 # determine architecture
michael@13 2961 AT="`uname -p`"
michael@13 2962 case "${AT}" in
michael@13 2963 powerpc ) AT="PPC" ;;
michael@13 2964 esac
michael@13 2965 AP="${AT}"
michael@13 2966 case "${AP}" in
michael@13 2967 i?86 ) AP="iX86" ;;
michael@13 2968 esac
michael@13 2969 AC="${AP}"
michael@13 2970 # determine system
michael@13 2971 unset v1; unset v2; unset v3
michael@13 2972 eval `echo "${UNAME_RELEASE}" |\
michael@13 2973 sed -e 's/^/#/' \
michael@13 2974 -e 's/^#\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/v1="\1"; v2="\2"; v3="\3"/' \
michael@13 2975 -e 's/^#\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/v1="\1"; v2="\2"/' \
michael@13 2976 -e 's/^#\([0-9][0-9]*\).*$/v1="\1"/' \
michael@13 2977 -e 's/^#.*$/v1="0"/'`
michael@13 2978 ST="[Apple ]<${UNAME_SYSTEM} ${v1}>${v2+.$v2}${v3+[.$v3]}"
michael@13 2979 SP="$ST"
michael@13 2980 v="`(sw_vers) 2>/dev/null | grep 'ProductVersion:' | sed -e 's/^ProductVersion:[^0-9]*\([0-9][0-9.]*\).*$/\1/'`"
michael@13 2981 if [ ".$v" = . ]; then
michael@13 2982 for name in System Server; do
michael@13 2983 if [ -f /System/Library/CoreServices/${name}Version.plist ]; then
michael@13 2984 v=`(defaults read "/System/Library/CoreServices/${name}Version" "ProductVersion") 2>/dev/null`
michael@13 2985 [ ".$v" != . ] && break
michael@13 2986 fi
michael@13 2987 done
michael@13 2988 fi
michael@13 2989 if [ ".$v" != . ]; then
michael@13 2990 unset v1; unset v2; unset v3
michael@13 2991 eval `echo "${v}" |\
michael@13 2992 sed -e 's/^/#/' \
michael@13 2993 -e 's/^#\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/v1="\1"; v2="\2"; v3="\3"/' \
michael@13 2994 -e 's/^#\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/v1="\1"; v2="\2"/' \
michael@13 2995 -e 's/^#\([0-9][0-9]*\).*$/v1="\1"/' \
michael@13 2996 -e 's/^#.*$/v1="0"/'`
michael@13 2997 SP="[Apple ]Mac OS X ${v1}${v2+.$v2}${v3+[.$v3]}"
michael@13 2998 fi
michael@13 2999 SC="4.4BSD/Mach3.0"
michael@13 3000 ;;
michael@13 3001
michael@13 3002 # TODO ...ADD YOUR NEW PLATFORM CHECK HERE... TODO
michael@13 3003 # *:XXX:* )
michael@13 3004 # ...
michael@13 3005 # ;;
michael@13 3006
michael@13 3007 # ...A STILL UNKNOWN PLATFORM...
michael@13 3008 * )
michael@13 3009 AT=`echo "${UNAME_MACHINE}" | sed -e "s; ;${opt_C};g"`
michael@13 3010 AP="${AT}"
michael@13 3011 AC="${AP}"
michael@13 3012 v=`echo "${UNAME_RELEASE}" |\
michael@13 3013 sed -e 's/^/#/' \
michael@13 3014 -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' \
michael@13 3015 -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' \
michael@13 3016 -e 's/^#[^0-9]*\([0-9][0-9]*\).*$/\1/' \
michael@13 3017 -e 's/^#.*$/?/'`
michael@13 3018 ST="${UNAME_SYSTEM} ${v}"
michael@13 3019 SP="${ST}"
michael@13 3020 SC="${SP}"
michael@13 3021 ;;
michael@13 3022
michael@13 3023 esac
michael@13 3024
michael@13 3025 # provide fallback values
michael@13 3026 [ ".$AT" = . ] && AT="${AP:-${AC}}"
michael@13 3027 [ ".$AP" = . ] && AP="${AT:-${AC}}"
michael@13 3028 [ ".$AC" = . ] && AC="${AP:-${AT}}"
michael@13 3029 [ ".$ST" = . ] && ST="${SP:-${SC}}"
michael@13 3030 [ ".$SP" = . ] && SP="${ST:-${SC}}"
michael@13 3031 [ ".$SC" = . ] && SC="${SP:-${ST}}"
michael@13 3032
michael@13 3033 # support explicit enforced verbose/concise output
michael@13 3034 if [ ".$opt_v" = .yes ]; then
michael@13 3035 opt_F=`echo ":$opt_F" | sed -e 's/^://' -e 's/%\([as][cpt]\)/%[\1]/g'`
michael@13 3036 elif [ ".$opt_c" = .yes ]; then
michael@13 3037 opt_F=`echo ":$opt_F" | sed -e 's/^://' -e 's/%\([as][cpt]\)/%<\1>/g'`
michael@13 3038 fi
michael@13 3039
michael@13 3040 # provide verbose and concise variants
michael@13 3041 AC_V=""; AC_N=""; AC_C=""
michael@13 3042 AP_V=""; AP_N=""; AP_C=""
michael@13 3043 AT_V=""; AT_N=""; AT_C=""
michael@13 3044 SC_V=""; SC_N=""; SC_C=""
michael@13 3045 SP_V=""; SP_N=""; SP_C=""
michael@13 3046 ST_V=""; ST_N=""; ST_C=""
michael@13 3047 for var_lc in at ap ac st sp sc; do
michael@13 3048 case "$opt_F" in
michael@13 3049 *"%[${val_lc}]"* | *"%{${val_lc}}"* | *"%${val_lc}"* | *"%<${val_lc}>"* )
michael@13 3050 var_uc=`util_upper "$var_lc"`
michael@13 3051 eval "val=\"\$${var_uc}\""
michael@13 3052 val_V=""; val_N=""; val_C=""
michael@13 3053 case "$opt_F" in
michael@13 3054 *"%[${var_lc}]"* )
michael@13 3055 val_V=`echo ":$val" | \
michael@13 3056 sed -e 's/^://' \
michael@13 3057 -e 's;\[\([^]]*\)\];\1;g' \
michael@13 3058 -e 's;<\([^>]*\)>;\1;g' \
michael@13 3059 -e "s; ;§§;g" \
michael@13 3060 -e "s;/;%%;g" \
michael@13 3061 -e "s;§§;${opt_S};g" \
michael@13 3062 -e "s;%%;${opt_C};g"`
michael@13 3063 eval "${var_uc}_V=\"\${val_V}\""
michael@13 3064 ;;
michael@13 3065 esac
michael@13 3066 case "$opt_F" in
michael@13 3067 *"%{${var_lc}}"* | *"%${var_lc}"* )
michael@13 3068 val_N=`echo ":$val" | \
michael@13 3069 sed -e 's/^://' \
michael@13 3070 -e 's;\[\([^]]*\)\];;g' \
michael@13 3071 -e 's;<\([^>]*\)>;\1;g' \
michael@13 3072 -e "s; ;§§;g" \
michael@13 3073 -e "s;/;%%;g" \
michael@13 3074 -e "s;§§;${opt_S};g" \
michael@13 3075 -e "s;%%;${opt_C};g"`
michael@13 3076 eval "${var_uc}_N=\"\${val_N}\""
michael@13 3077 ;;
michael@13 3078 esac
michael@13 3079 case "$opt_F" in
michael@13 3080 *"%<${var_lc}>"* )
michael@13 3081 val_C=`echo ":$val" | \
michael@13 3082 sed -e 's/^://' \
michael@13 3083 -e 's;\[\([^]]*\)\];;g' \
michael@13 3084 -e 's;[^<]*<\([^>]*\)>[^<]*;\1;g' \
michael@13 3085 -e "s; ;§§;g" \
michael@13 3086 -e "s;/;%%;g" \
michael@13 3087 -e "s;§§;${opt_S};g" \
michael@13 3088 -e "s;%%;${opt_C};g"`
michael@13 3089 eval "${var_uc}_C=\"\${val_C}\""
michael@13 3090 ;;
michael@13 3091 esac
michael@13 3092 ;;
michael@13 3093 esac
michael@13 3094 done
michael@13 3095
michael@13 3096 # create output string
michael@13 3097 output=`echo ":$opt_F" |\
michael@13 3098 sed -e "s/^://" \
michael@13 3099 -e "s;%\\[ac\\];${AC_V};g" \
michael@13 3100 -e "s;%{ac};${AC_N};g" \
michael@13 3101 -e "s;%ac;${AC_N};g" \
michael@13 3102 -e "s;%<ac>;${AC_C};g" \
michael@13 3103 -e "s;%\\[ap\\];${AP_V};g" \
michael@13 3104 -e "s;%{ap};${AP_N};g" \
michael@13 3105 -e "s;%ap;${AP_N};g" \
michael@13 3106 -e "s;%<ap>;${AP_C};g" \
michael@13 3107 -e "s;%\\[at\\];${AT_V};g" \
michael@13 3108 -e "s;%{at};${AT_N};g" \
michael@13 3109 -e "s;%at;${AT_N};g" \
michael@13 3110 -e "s;%<at>;${AT_C};g" \
michael@13 3111 -e "s;%\\[sc\\];${SC_V};g" \
michael@13 3112 -e "s;%{sc};${SC_N};g" \
michael@13 3113 -e "s;%sc;${SC_N};g" \
michael@13 3114 -e "s;%<sc>;${SC_C};g" \
michael@13 3115 -e "s;%\\[sp\\];${SP_V};g" \
michael@13 3116 -e "s;%{sp};${SP_N};g" \
michael@13 3117 -e "s;%sp;${SP_N};g" \
michael@13 3118 -e "s;%<sp>;${SP_C};g" \
michael@13 3119 -e "s;%\\[st\\];${ST_V};g" \
michael@13 3120 -e "s;%{st};${ST_N};g" \
michael@13 3121 -e "s;%st;${ST_N};g" \
michael@13 3122 -e "s;%<st>;${ST_C};g" \
michael@13 3123 -e 's/\\\\n/^/g' |\
michael@13 3124 tr '^' '\012'`
michael@13 3125
michael@13 3126 # support lower/upper-case mapping
michael@13 3127 if [ ".$opt_L" = .yes ]; then
michael@13 3128 output=`util_lower "$output"`
michael@13 3129 elif [ ".$opt_U" = .yes ]; then
michael@13 3130 output=`util_upper "$output"`
michael@13 3131 fi
michael@13 3132
michael@13 3133 # display output string
michael@13 3134 if [ ".$opt_n" = .yes ]; then
michael@13 3135 echo . | awk '{ printf("%s", output); }' output="$output"
michael@13 3136 else
michael@13 3137 echo "$output"
michael@13 3138 fi
michael@13 3139
michael@13 3140 shtool_exit 0
michael@13 3141 ;;
michael@13 3142
michael@13 3143 arx )
michael@13 3144 ##
michael@13 3145 ## arx -- Extended archive command
michael@13 3146 ## Copyright (c) 1999-2007 Ralf S. Engelschall <rse@engelschall.com>
michael@13 3147 ##
michael@13 3148
michael@13 3149 ar_prg="$opt_C"
michael@13 3150 ar_cmd="$1"; shift
michael@13 3151 archive="$1"; shift
michael@13 3152 files="$*"
michael@13 3153
michael@13 3154 # walk through the file list and expand archives members
michael@13 3155 ar_tmpdir=`echo $archive | sed -e 's;[^/]*$;.arx;'`
michael@13 3156 nfiles=''
michael@13 3157 if [ ".$files" != . ]; then
michael@13 3158 for file in $files; do
michael@13 3159 if [ ! -f $file ]; then
michael@13 3160 echo "$msgprefix:Error: input file not found: $file" 1>&2
michael@13 3161 shtool_exit 1
michael@13 3162 fi
michael@13 3163 case $file in
michael@13 3164 *.a )
michael@13 3165 if [ ! -d $ar_tmpdir ]; then
michael@13 3166 if [ ".$opt_t" = .yes ]; then
michael@13 3167 echo "mkdir $ar_tmpdir" 1>&2
michael@13 3168 fi
michael@13 3169 mkdir $ar_tmpdir
michael@13 3170 fi
michael@13 3171 case $ar_tmpdir in
michael@13 3172 .arx )
michael@13 3173 from="../$file"
michael@13 3174 ;;
michael@13 3175 * )
michael@13 3176 dir=`echo $file | sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;' -e 's;^$;.;'`
michael@13 3177 base=`echo $file | sed -e 's;.*/\([^/]*\)$;\1;'`
michael@13 3178 from="`cd $dir; pwd`/$base"
michael@13 3179 ;;
michael@13 3180 esac
michael@13 3181 if [ ".$opt_t" = .yes ]; then
michael@13 3182 echo "(cd $ar_tmpdir && $ar_prg x $from)" 1>&2
michael@13 3183 fi
michael@13 3184 (cd $ar_tmpdir && eval $ar_prg x $from)
michael@13 3185 if [ $? -ne 0 ]; then
michael@13 3186 echo "$msgprefix:Error: member extraction failed for archive: $file" 1>&2
michael@13 3187 shtool_exit 1
michael@13 3188 fi
michael@13 3189 for member in - `eval $ar_prg t $file | sed -e '/_\.SYMDEF/d'`; do
michael@13 3190 [ ".$member" = .- ] && continue
michael@13 3191 nfiles="$nfiles $ar_tmpdir/$member"
michael@13 3192 done
michael@13 3193 ;;
michael@13 3194 * )
michael@13 3195 nfiles="$nfiles $file"
michael@13 3196 ;;
michael@13 3197 esac
michael@13 3198 done
michael@13 3199 fi
michael@13 3200
michael@13 3201 # run the final archive command
michael@13 3202 if [ ".$opt_t" = .yes ]; then
michael@13 3203 echo "$ar_prg $ar_cmd $archive $nfiles" 1>&2
michael@13 3204 fi
michael@13 3205 eval $ar_prg $ar_cmd $archive $nfiles
michael@13 3206 if [ $? -ne 0 ]; then
michael@13 3207 echo "$msgprefix:Error: archive command failed" 1>&2
michael@13 3208 shtool_exit $?
michael@13 3209 fi
michael@13 3210
michael@13 3211 # cleanup and die gracefully
michael@13 3212 if [ -d $ar_tmpdir ]; then
michael@13 3213 if [ ".$opt_t" = .yes ]; then
michael@13 3214 echo "rm -rf $ar_tmpdir" 1>&2
michael@13 3215 fi
michael@13 3216 rm -rf $ar_tmpdir
michael@13 3217 fi
michael@13 3218
michael@13 3219 shtool_exit 0
michael@13 3220 ;;
michael@13 3221
michael@13 3222 slo )
michael@13 3223 ##
michael@13 3224 ## slo -- Separate linker options by library class
michael@13 3225 ## Copyright (c) 1998-2007 Ralf S. Engelschall <rse@engelschall.com>
michael@13 3226 ##
michael@13 3227
michael@13 3228 DIFS="$IFS"
michael@13 3229
michael@13 3230 # parse out -L and -l options from command line
michael@13 3231 DIRS=''
michael@13 3232 LIBS=''
michael@13 3233 ARGV=''
michael@13 3234 optprev=''
michael@13 3235 for opt
michael@13 3236 do
michael@13 3237 # concatenate with previous option if exists
michael@13 3238 if [ ".$optprev" != . ]; then
michael@13 3239 opt="${optprev}${opt}";
michael@13 3240 optprev=''
michael@13 3241 fi
michael@13 3242 # remember options for arg if used stand-alone
michael@13 3243 if [ ".$opt" = ".-L" ] || [ ".$opt" = ".-l" ]; then
michael@13 3244 optprev="$opt"
michael@13 3245 continue;
michael@13 3246 fi
michael@13 3247 # split argument into option plus option argument
michael@13 3248 arg="`echo $opt | cut -c3-`"
michael@13 3249 opt="`echo $opt | cut -c1-2`"
michael@13 3250 # store into containers
michael@13 3251 case $opt in
michael@13 3252 -L) DIRS="$DIRS:$arg" ;;
michael@13 3253 -l) LIBS="$LIBS:$arg" ;;
michael@13 3254 *) ARGV="$ARGV $opt" ;;
michael@13 3255 esac
michael@13 3256 done
michael@13 3257
michael@13 3258 # set linker default directories
michael@13 3259 DIRS_DEFAULT='/lib:/usr/lib'
michael@13 3260 if [ ".$LD_LIBRARY_PATH" != . ]; then
michael@13 3261 DIRS_DEFAULT="$DIRS_DEFAULT:$LD_LIBRARY_PATH"
michael@13 3262 fi
michael@13 3263
michael@13 3264 # sort options by class
michael@13 3265 DIRS_OBJ=''
michael@13 3266 LIBS_OBJ=''
michael@13 3267 DIRS_PIC=''
michael@13 3268 LIBS_PIC=''
michael@13 3269 DIRS_DSO=''
michael@13 3270 LIBS_DSO=''
michael@13 3271
michael@13 3272 # for each library...
michael@13 3273 OIFS="$IFS"; IFS=':'
michael@13 3274 for lib in $LIBS; do
michael@13 3275 [ ".$lib" = . ] && continue
michael@13 3276
michael@13 3277 found='no'
michael@13 3278 found_indefdir='no'
michael@13 3279 found_type=''
michael@13 3280 found_dir=''
michael@13 3281
michael@13 3282 # for each directory...
michael@13 3283 OIFS2="$IFS"; IFS=":$DIFS"
michael@13 3284 for dir in ${DIRS} switch-to-defdirs ${DIRS_DEFAULT}; do
michael@13 3285 [ ".$dir" = . ] && continue
michael@13 3286 [ ".$dir" = .switch-to-defdirs ] && found_indefdir=yes
michael@13 3287 [ ! -d $dir ] && continue
michael@13 3288
michael@13 3289 # search the file
michael@13 3290 OIFS3="$IFS"; IFS="$DIFS"
michael@13 3291 for file in '' `cd $dir && env -i /bin/ls lib${lib}.* 2>/dev/null`; do
michael@13 3292 [ ".$file" = . ] && continue
michael@13 3293 case $file in
michael@13 3294 *.so|*.so.[0-9]*|*.sl|*.sl.[0-9]* )
michael@13 3295 found=yes;
michael@13 3296 found_type=DSO;
michael@13 3297 break
michael@13 3298 ;;
michael@13 3299 *.lo|*.la )
michael@13 3300 found=yes;
michael@13 3301 found_type=PIC
michael@13 3302 ;;
michael@13 3303 *.a )
michael@13 3304 if [ ".$found_type" = . ]; then
michael@13 3305 found=yes
michael@13 3306 found_type=OBJ
michael@13 3307 fi
michael@13 3308 ;;
michael@13 3309 esac
michael@13 3310 done
michael@13 3311 IFS="$OIFS3"
michael@13 3312 if [ ".$found" = .yes ]; then
michael@13 3313 found_dir="$dir"
michael@13 3314 break
michael@13 3315 fi
michael@13 3316 done
michael@13 3317 IFS="$OIFS2"
michael@13 3318
michael@13 3319 if [ ".$found" = .yes ]; then
michael@13 3320 if [ ".$found_indefdir" != .yes ]; then
michael@13 3321 eval "dirlist=\"\${DIRS_${found_type}}:\""
michael@13 3322 case "$dirlist" in
michael@13 3323 *:$found_dir:* ) ;;
michael@13 3324 * ) eval "DIRS_${found_type}=\"\$DIRS_${found_type}:${found_dir}\"" ;;
michael@13 3325 esac
michael@13 3326 eval "LIBS_${found_type}=\"\$LIBS_${found_type}:$lib\""
michael@13 3327 else
michael@13 3328 eval "LIBS_${found_type}=\"\$LIBS_${found_type}:$lib\""
michael@13 3329 fi
michael@13 3330 else
michael@13 3331 LIBS_OBJ="$LIBS_OBJ:$lib"
michael@13 3332 #dirlist="`echo $DIRS $DIRS_DEFAULT | sed -e 's/:/ /g'`"
michael@13 3333 #echo "slo:Warning: library \"$lib\" not found in any of the following dirs:" 2>&1
michael@13 3334 #echo "slo:Warning: $dirlist" 1>&1
michael@13 3335 fi
michael@13 3336 done
michael@13 3337 IFS="$OIFS"
michael@13 3338
michael@13 3339 # also pass-through unused dirs even if it's useless
michael@13 3340 OIFS="$IFS"; IFS=':'
michael@13 3341 for dir in $DIRS; do
michael@13 3342 dirlist="${DIRS_OBJ}:${DIRS_PIC}:${DIRS_DSO}:"
michael@13 3343 case "$dirlist" in
michael@13 3344 *:$dir:* ) ;;
michael@13 3345 * ) DIRS_OBJ="$DIRS_OBJ:$dir" ;;
michael@13 3346 esac
michael@13 3347 done
michael@13 3348 IFS="$OIFS"
michael@13 3349
michael@13 3350 # reassemble the options but separated by type
michael@13 3351 for type in OBJ PIC DSO; do
michael@13 3352 OIFS="$IFS"; IFS=':'
michael@13 3353 eval "libs=\"\$LIBS_${type}\""
michael@13 3354 opts=''
michael@13 3355 for lib in $libs; do
michael@13 3356 [ ".$lib" = . ] && continue
michael@13 3357 opts="$opts -l$lib"
michael@13 3358 done
michael@13 3359 eval "LIBS_${type}=\"$opts\""
michael@13 3360
michael@13 3361 eval "dirs=\"\$DIRS_${type}\""
michael@13 3362 opts=''
michael@13 3363 for dir in $dirs; do
michael@13 3364 [ ".$dir" = . ] && continue
michael@13 3365 opts="$opts -L$dir"
michael@13 3366 done
michael@13 3367 eval "DIRS_${type}=\"$opts\""
michael@13 3368 IFS="$OIFS"
michael@13 3369 done
michael@13 3370
michael@13 3371 # give back results
michael@13 3372 for var in ARGV DIRS_OBJ LIBS_OBJ DIRS_PIC LIBS_PIC DIRS_DSO LIBS_DSO; do
michael@13 3373 eval "val=\"\$${var}\""
michael@13 3374 val="`echo $val | sed -e 's/^ *//'`"
michael@13 3375 echo "${opt_p}${var}=\"${val}\""
michael@13 3376 done
michael@13 3377
michael@13 3378 shtool_exit 0
michael@13 3379 ;;
michael@13 3380
michael@13 3381 scpp )
michael@13 3382 ##
michael@13 3383 ## scpp -- Sharing C Pre-Processor
michael@13 3384 ## Copyright (c) 1999-2007 Ralf S. Engelschall <rse@engelschall.com>
michael@13 3385 ##
michael@13 3386
michael@13 3387 srcs="$*"
michael@13 3388 output="${opt_o}.n"
michael@13 3389
michael@13 3390 # find a reasonable Awk
michael@13 3391 awk=''
michael@13 3392 paths=`echo $PATH |\
michael@13 3393 sed -e 's%/*:%:%g' -e 's%/$%%' \
michael@13 3394 -e 's/^:/.:/' -e 's/::/:.:/g' -e 's/:$/:./' \
michael@13 3395 -e 's/:/ /g'`
michael@13 3396 for name in gawk nawk awk; do
michael@13 3397 for path in $paths; do
michael@13 3398 if [ -r "$path/$name" ]; then
michael@13 3399 awk="$path/$name"
michael@13 3400 break
michael@13 3401 fi
michael@13 3402 done
michael@13 3403 if [ ".$awk" != . ]; then
michael@13 3404 break
michael@13 3405 fi
michael@13 3406 done
michael@13 3407 if [ ".$awk" = . ]; then
michael@13 3408 echo "$msgprefix:Error: cannot find a reasonable Awk" 1>&2
michael@13 3409 shtool_exit 1
michael@13 3410 fi
michael@13 3411
michael@13 3412 # parse source file(s)
michael@13 3413 if [ ".$opt_v" = .yes ]; then
michael@13 3414 echo "Parsing:" | $awk '{ printf("%s", $0); }' 1>&2
michael@13 3415 fi
michael@13 3416 for src in $srcs; do
michael@13 3417 if [ ".$opt_v" = .yes ]; then
michael@13 3418 echo $src | $awk '{ printf(" %s", $0); }' 1>&2
michael@13 3419 fi
michael@13 3420 if [ ".$opt_f" != . ]; then
michael@13 3421 inputcmd="sed"
michael@13 3422 OIFS="$IFS"; IFS="$ASC_NL"; set -- $opt_f; IFS="$OIFS"
michael@13 3423 for e
michael@13 3424 do
michael@13 3425 inputcmd="$inputcmd -e '$e'"
michael@13 3426 done
michael@13 3427 inputcmd="$inputcmd '$src'"
michael@13 3428 else
michael@13 3429 inputcmd="cat '$src'"
michael@13 3430 fi
michael@13 3431 eval $inputcmd |\
michael@13 3432 $awk '
michael@13 3433 BEGIN {
michael@13 3434 ln = 0;
michael@13 3435 fln = 0;
michael@13 3436 level = 0;
michael@13 3437 mode = "";
michael@13 3438 store = "";
michael@13 3439 }
michael@13 3440 {
michael@13 3441 ln++;
michael@13 3442 }
michael@13 3443 /^#if.*/ {
michael@13 3444 level++;
michael@13 3445 }
michael@13 3446 /^#if [a-zA-Z_][a-zA-Z0-9_]* *$/ {
michael@13 3447 if ($2 == define) {
michael@13 3448 mode = "D";
michael@13 3449 printf("D:#line %d \"%s\"\n", ln, src);
michael@13 3450 next;
michael@13 3451 }
michael@13 3452 }
michael@13 3453 /^#endif.*/ {
michael@13 3454 level--;
michael@13 3455 if (mode == "D" && level == 0) {
michael@13 3456 mode = "";
michael@13 3457 next;
michael@13 3458 }
michael@13 3459 }
michael@13 3460 /^[a-zA-Z_][a-zA-Z0-9_].*;.*/ {
michael@13 3461 if ($1 == class) {
michael@13 3462 printf("V:#line %d \"%s\"\n", ln, src);
michael@13 3463 printf("V:%s\n", $0);
michael@13 3464 printf("J:%s\n", $0);
michael@13 3465 next;
michael@13 3466 }
michael@13 3467 }
michael@13 3468 /^[a-zA-Z_][a-zA-Z0-9_].*=.*/ {
michael@13 3469 if ($1 == class) {
michael@13 3470 printf("V:#line %d \"%s\"\n", ln, src);
michael@13 3471 printf("V:%s\n", $0);
michael@13 3472 printf("J:%s\n", $0);
michael@13 3473 next;
michael@13 3474 }
michael@13 3475 }
michael@13 3476 /^[a-zA-Z_][a-zA-Z0-9_]*/ {
michael@13 3477 if ($1 == class) {
michael@13 3478 fln = ln;
michael@13 3479 store = $0;
michael@13 3480 mode = "F";
michael@13 3481 next;
michael@13 3482 }
michael@13 3483 }
michael@13 3484 /^\{ *$/ {
michael@13 3485 if (mode == "F") {
michael@13 3486 printf("F:#line %d \"%s\"\n", fln, src);
michael@13 3487 printf("F:%s;\n", store);
michael@13 3488 printf("I:%s;\n", store);
michael@13 3489 store = "";
michael@13 3490 mode = "";
michael@13 3491 next;
michael@13 3492 }
michael@13 3493 }
michael@13 3494 {
michael@13 3495 if (mode == "D")
michael@13 3496 printf("D:%s\n", $0);
michael@13 3497 else if (mode == "F")
michael@13 3498 store = store " " $0;
michael@13 3499 }
michael@13 3500 ' "src=$src" "define=$opt_D" "class=$opt_C" >>$tmpfile
michael@13 3501 done
michael@13 3502 if [ ".$opt_v" = .yes ]; then
michael@13 3503 echo "" 1>&2
michael@13 3504 fi
michael@13 3505
michael@13 3506 # start generating output header
michael@13 3507 echo "/* $opt_o -- autogenerated from $opt_t, DO NOT EDIT! */" >$output
michael@13 3508 echo "#line 1 \"$opt_t\"" >>$output
michael@13 3509 sed <$opt_t -e "1,/^${opt_M} *\$/p" -e 'd' |\
michael@13 3510 sed -e "/^${opt_M} *\$/d" >>$output
michael@13 3511
michael@13 3512 # merge in the define blocks
michael@13 3513 grep '^D:' $tmpfile | sed -e 's/^D://' >>$output
michael@13 3514
michael@13 3515 # generate standard prolog
michael@13 3516 echo "#line 1 \"_ON_THE_FLY_\"" >>$output
michael@13 3517 echo "" >>$output
michael@13 3518 echo "/* make sure the scpp source extensions are skipped */" >>$output
michael@13 3519 echo "#define $opt_D 0" >>$output
michael@13 3520 echo "#define $opt_C /**/" >>$output
michael@13 3521
michael@13 3522 # generate namespace hiding for variables
michael@13 3523 echo "" >>$output
michael@13 3524 echo "/* move intern variables to hidden namespace */" >>$output
michael@13 3525 grep '^J:' $tmpfile | sed >>$output \
michael@13 3526 -e 's/^J://' \
michael@13 3527 -e 's/ */ /g' \
michael@13 3528 -e 's/^[^=;]*[ *]\([a-zA-Z0-9_]*\)\[\];.*$/#define \1 __\1/' \
michael@13 3529 -e 's/^[^=;]*[ *]\([a-zA-Z0-9_]*\)\[\] =.*$/#define \1 __\1/' \
michael@13 3530 -e 's/^[^=;]*[ *]\([a-zA-Z0-9_]*\);.*$/#define \1 __\1/' \
michael@13 3531 -e 's/^[^=;]*[ *]\([a-zA-Z0-9_]*\) =.*$/#define \1 __\1/'
michael@13 3532
michael@13 3533 # generate namespace hiding for functions
michael@13 3534 echo "" >>$output
michael@13 3535 echo "/* move intern functions to hidden namespace */" >>$output
michael@13 3536 grep '^I:' $tmpfile | sed >>$output \
michael@13 3537 -e 's/^I://' \
michael@13 3538 -e 's/\([ (]\) */\1/g' \
michael@13 3539 -e 's/ *\([),]\)/\1/g' \
michael@13 3540 -e 's/^[^(]*[ *]\([a-zA-Z0-9_]*\)(.*$/#define \1 __\1/'
michael@13 3541
michael@13 3542 # generate prototypes for variables
michael@13 3543 echo "" >>$output
michael@13 3544 echo "/* prototypes for intern variables */" >>$output
michael@13 3545 grep '^V:' $tmpfile | sed >>$output \
michael@13 3546 -e 's/^V://' \
michael@13 3547 -e 's/ */ /g' \
michael@13 3548 -e 's/^\([^=;]*[ *][a-zA-Z0-9_]*\[\]\);.*$/\1;/' \
michael@13 3549 -e 's/^\([^=;]*[ *][a-zA-Z0-9_]*\[\]\) =.*$/\1;/' \
michael@13 3550 -e 's/^\([^=;]*[ *][a-zA-Z0-9_]*\);.*$/\1;/' \
michael@13 3551 -e 's/^\([^=;]*[ *][a-zA-Z0-9_]*\) =.*$/\1;/' \
michael@13 3552 -e 's/ ;/;/g' \
michael@13 3553 -e "s/^$opt_C /extern /"
michael@13 3554
michael@13 3555 # generate prototypes for functions
michael@13 3556 echo "" >>$output
michael@13 3557 echo "/* prototypes for intern functions */" >>$output
michael@13 3558 grep '^F:' $tmpfile | sed >>$output \
michael@13 3559 -e 's/^F://' \
michael@13 3560 -e 's/\([ (]\) */\1/g' \
michael@13 3561 -e 's/ *\([),]\)/\1/g' \
michael@13 3562 -e 's/\([* ]\)[a-zA-Z0-9_]*,/\1,/g' \
michael@13 3563 -e 's/\([* ]\)[a-zA-Z0-9_]*);/\1);/g' \
michael@13 3564 -e 's/(\*[a-zA-Z0-9_]*)(/(*)(/g' \
michael@13 3565 -e 's/\([ (]\) */\1/g' \
michael@13 3566 -e 's/ *\([),]\)/\1/g' \
michael@13 3567 -e "s/^$opt_C /extern /"
michael@13 3568
michael@13 3569 # finish generating output header
michael@13 3570 n=`(echo ''; sed <$opt_t -e "1,/^${opt_M} *\$/p" -e 'd') |\
michael@13 3571 wc -l | sed -e 's;^ *\([0-9]*\) *$;\1;'`
michael@13 3572 echo "#line $n \"$opt_t\"" >>$output
michael@13 3573 sed <$opt_t -e "/^${opt_M} *\$/,\$p" -e 'd' |\
michael@13 3574 sed -e "/^${opt_M} *\$/d" >>$output
michael@13 3575
michael@13 3576 # create final output file
michael@13 3577 if [ -f $opt_o ]; then
michael@13 3578 if [ ".$opt_p" = .yes ]; then
michael@13 3579 grep -v '^#line' $opt_o >$tmpfile.o
michael@13 3580 grep -v '^#line' $output >$tmpfile.n
michael@13 3581 out_old="$tmpfile.o"
michael@13 3582 out_new="$tmpfile.n"
michael@13 3583 else
michael@13 3584 out_old="$opt_o"
michael@13 3585 out_new="$output"
michael@13 3586 fi
michael@13 3587 if cmp -s $out_old $out_new; then
michael@13 3588 :
michael@13 3589 else
michael@13 3590 cp $output $opt_o
michael@13 3591 fi
michael@13 3592 else
michael@13 3593 cp $output $opt_o
michael@13 3594 fi
michael@13 3595 rm -f $output
michael@13 3596 rm -f $tmpfile $tmpfile.* >/dev/null 2>&1
michael@13 3597
michael@13 3598 shtool_exit 0
michael@13 3599 ;;
michael@13 3600
michael@13 3601 version )
michael@13 3602 ##
michael@13 3603 ## version -- Maintain a version information file
michael@13 3604 ## Copyright (c) 1994-2007 Ralf S. Engelschall <rse@engelschall.com>
michael@13 3605 ##
michael@13 3606
michael@13 3607 file="$1"
michael@13 3608
michael@13 3609 # determine prefix and name
michael@13 3610 name="$opt_n"
michael@13 3611 prefix="$opt_p"
michael@13 3612
michael@13 3613 # determine current version
michael@13 3614 triple="$opt_s"
michael@13 3615 if [ ".$triple" != . ]; then
michael@13 3616 # use given triple
michael@13 3617 if [ ".`echo $triple | grep '[0-9]*.[0-9]*[sabp.][0-9]*'`" = . ]; then
michael@13 3618 echo "$msgprefix:Error: invalid argument to option \`-s': \`$opt_s'" 1>&2
michael@13 3619 shtool_exit 1
michael@13 3620 fi
michael@13 3621 eval `echo $triple |\
michael@13 3622 sed -e 's%\([0-9]*\)\.\([0-9]*\)\([sabp.]\)\([0-9]*\).*%\
michael@13 3623 ver="\1";rev="\2";typ="\3";lev="\4"%'`
michael@13 3624 tim=calc
michael@13 3625 elif [ -r $file ]; then
michael@13 3626 # determine triple from given file
michael@13 3627 eval `grep 'Version [0-9]*.[0-9]*[sabp.][0-9]* ([0-9]*-[a-zA-Z]*-[0-9]*)' $file |\
michael@13 3628 sed -e 's%.*Version \([0-9]*\)\.\([0-9]*\)\([sabp.]\)\([0-9]*\) (\([0-9]*-[a-zA-Z]*-[0-9]*\)).*%\
michael@13 3629 ver="\1";rev="\2";typ="\3";lev="\4";tim="\5"%' -e 'q'`
michael@13 3630 else
michael@13 3631 # intialise to first version
michael@13 3632 ver=0
michael@13 3633 rev=1
michael@13 3634 typ=.
michael@13 3635 lev=0
michael@13 3636 tim=calc
michael@13 3637 fi
michael@13 3638
michael@13 3639 # determine new version in batch
michael@13 3640 if [ ".$opt_i" != . ]; then
michael@13 3641 case $opt_i in
michael@13 3642 v ) ver=`expr $ver + 1`
michael@13 3643 rev=0
michael@13 3644 lev=0
michael@13 3645 ;;
michael@13 3646 r ) rev=`expr $rev + 1`
michael@13 3647 lev=0
michael@13 3648 ;;
michael@13 3649 l ) lev=`expr $lev + 1`
michael@13 3650 ;;
michael@13 3651 * ) echo "$msgprefix:Error: invalid argument to option \`-i': \`$opt_i'" 1>&2
michael@13 3652 shtool_exit 1
michael@13 3653 ;;
michael@13 3654 esac
michael@13 3655 tim=calc
michael@13 3656 fi
michael@13 3657
michael@13 3658 # determine new version interactively
michael@13 3659 if [ ".$opt_e" = .yes ]; then
michael@13 3660 echo "old version: ${ver}.${rev}${typ}${lev}"
michael@13 3661 while [ 1 ]; do
michael@13 3662 echo dummy | awk '{ printf("new version: "); }'
michael@13 3663 read triple
michael@13 3664 case $triple in
michael@13 3665 [0-9]*.[0-9]*[sabp.][0-9]* )
michael@13 3666 ;;
michael@13 3667 * ) echo "$msgprefix:Error: invalid version string entered: \`$triple'" 1>&2
michael@13 3668 continue
michael@13 3669 ;;
michael@13 3670 esac
michael@13 3671 break
michael@13 3672 done
michael@13 3673 eval `echo $triple |\
michael@13 3674 sed -e 's%^\([0-9]*\)\.\([0-9]*\)\([sabp.]\)\([0-9]*\)$%\
michael@13 3675 ver="\1";rev="\2";typ="\3";lev="\4"%'`
michael@13 3676 tim=calc
michael@13 3677 fi
michael@13 3678
michael@13 3679 # determine hexadecimal and libtool value of version
michael@13 3680 case $typ in
michael@13 3681 a ) typnum=0; levnum=$lev ;;
michael@13 3682 b ) typnum=1; levnum=$lev ;;
michael@13 3683 p | . ) typnum=2; levnum=$lev ;;
michael@13 3684 s ) typnum=15; levnum=255 ;; # snapshots are special
michael@13 3685 esac
michael@13 3686 hex=`echo "$ver:$rev:$typnum:$levnum" |\
michael@13 3687 awk -F: '{ printf("0x%x%02x%1x%02x", $1, $2, $3, $4); }' |\
michael@13 3688 tr 'abcdef' 'ABCDEF'`
michael@13 3689 ltv=`echo "$ver:$rev:$typnum:$levnum" |\
michael@13 3690 awk -F: '{ printf("%d:%d", $1*10 + $2, $3*10 + $4); }'`
michael@13 3691
michael@13 3692 # determine date
michael@13 3693 if [ ".$tim" = .calc ]; then
michael@13 3694 day=`date '+%d'`
michael@13 3695 month=`date '+%m'`
michael@13 3696 year=`date '+%Y' 2>/dev/null`
michael@13 3697 if [ ".$time_year" = . ]; then
michael@13 3698 year=`date '+%y'`
michael@13 3699 case $year in
michael@13 3700 [5-9][0-9]) year="19$year" ;;
michael@13 3701 [0-4][0-9]) year="20$year" ;;
michael@13 3702 esac
michael@13 3703 fi
michael@13 3704 case $month in
michael@13 3705 1|01) month='Jan' ;;
michael@13 3706 2|02) month='Feb' ;;
michael@13 3707 3|03) month='Mar' ;;
michael@13 3708 4|04) month='Apr' ;;
michael@13 3709 5|05) month='May' ;;
michael@13 3710 6|06) month='Jun' ;;
michael@13 3711 7|07) month='Jul' ;;
michael@13 3712 8|08) month='Aug' ;;
michael@13 3713 9|09) month='Sep' ;;
michael@13 3714 10) month='Oct' ;;
michael@13 3715 11) month='Nov' ;;
michael@13 3716 12) month='Dec' ;;
michael@13 3717 esac
michael@13 3718 tim="${day}-${month}-${year}"
michael@13 3719 fi
michael@13 3720
michael@13 3721 # perform result actions
michael@13 3722 mode=show
michael@13 3723 if [ ".$opt_i" != . ]; then
michael@13 3724 mode=edit
michael@13 3725 elif [ ".$opt_e" = .yes ]; then
michael@13 3726 mode=edit
michael@13 3727 elif [ ".$opt_s" != . ]; then
michael@13 3728 mode=edit
michael@13 3729 fi
michael@13 3730 if [ ".$mode" = .show ]; then
michael@13 3731 # just display the current version
michael@13 3732 case $opt_d in
michael@13 3733 short )
michael@13 3734 echo "${ver}.${rev}${typ}${lev}"
michael@13 3735 ;;
michael@13 3736 long )
michael@13 3737 echo "${ver}.${rev}${typ}${lev} ($tim)"
michael@13 3738 ;;
michael@13 3739 libtool )
michael@13 3740 echo "${ltv}"
michael@13 3741 ;;
michael@13 3742 hex )
michael@13 3743 echo "${hex}"
michael@13 3744 ;;
michael@13 3745 * ) echo "$msgprefix:Error: invalid argument to option \`-d': \`$opt_d'" 1>&2
michael@13 3746 shtool_exit 1
michael@13 3747 ;;
michael@13 3748 esac
michael@13 3749 else
michael@13 3750 # update the version file
michael@13 3751
michael@13 3752 # pre-generate various strings
michael@13 3753 triple="${ver}.${rev}${typ}${lev}"
michael@13 3754 vHex="$hex"
michael@13 3755 vShort="${triple}"
michael@13 3756 vLong="${triple} (${tim})"
michael@13 3757 vTeX="This is ${name}, Version ${triple} (${tim})"
michael@13 3758 vGNU="${name} ${triple} (${tim})"
michael@13 3759 vWeb="${name}/${triple}"
michael@13 3760 vSCCS="@(#)${name} ${triple} (${tim})"
michael@13 3761 vRCS="\$Id: ${name} ${triple} (${tim}) \$"
michael@13 3762
michael@13 3763 # determine string out of filename
michael@13 3764 # (do NOT try to optimize this in any way because of portability)
michael@13 3765 filestr=`util_upper "$file" | tr './%+' '____' | sed -e 's/-/_/g'`
michael@13 3766
michael@13 3767 # generate uppercase prefix
michael@13 3768 prefixupper=`util_upper "$prefix"`
michael@13 3769
michael@13 3770 # create the version file according the the selected language
michael@13 3771 echo "new version: ${vLong}"
michael@13 3772
michael@13 3773 cp /dev/null $file
michael@13 3774 case $opt_l in
michael@13 3775 txt )
michael@13 3776 echo >>$file ""
michael@13 3777 echo >>$file " ${file} -- Version Information for ${name} (syntax: Text)"
michael@13 3778 echo >>$file " [automatically generated and maintained by GNU shtool]"
michael@13 3779 echo >>$file ""
michael@13 3780 echo >>$file " $vTeX"
michael@13 3781 echo >>$file ""
michael@13 3782 ;;
michael@13 3783 c )
michael@13 3784 echo >>$file "/*"
michael@13 3785 echo >>$file "** ${file} -- Version Information for ${name} (syntax: C/C++)"
michael@13 3786 echo >>$file "** [automatically generated and maintained by GNU shtool]"
michael@13 3787 echo >>$file "*/"
michael@13 3788 echo >>$file ""
michael@13 3789 echo >>$file "#ifdef _${filestr}_AS_HEADER_"
michael@13 3790 echo >>$file ""
michael@13 3791 echo >>$file "#ifndef _${filestr}_"
michael@13 3792 echo >>$file "#define _${filestr}_"
michael@13 3793 echo >>$file ""
michael@13 3794 echo >>$file "#define ${prefixupper}VERSION ${vHex}"
michael@13 3795 echo >>$file ""
michael@13 3796 echo >>$file "typedef struct {"
michael@13 3797 echo >>$file " const int v_hex;"
michael@13 3798 echo >>$file " const char *v_short;"
michael@13 3799 echo >>$file " const char *v_long;"
michael@13 3800 echo >>$file " const char *v_tex;"
michael@13 3801 echo >>$file " const char *v_gnu;"
michael@13 3802 echo >>$file " const char *v_web;"
michael@13 3803 echo >>$file " const char *v_sccs;"
michael@13 3804 echo >>$file " const char *v_rcs;"
michael@13 3805 echo >>$file "} ${prefix}version_t;"
michael@13 3806 echo >>$file ""
michael@13 3807 echo >>$file "extern ${prefix}version_t ${prefix}version;"
michael@13 3808 echo >>$file ""
michael@13 3809 echo >>$file "#endif /* _${filestr}_ */"
michael@13 3810 echo >>$file ""
michael@13 3811 echo >>$file "#else /* _${filestr}_AS_HEADER_ */"
michael@13 3812 echo >>$file ""
michael@13 3813 echo >>$file "#define _${filestr}_AS_HEADER_"
michael@13 3814 echo >>$file "#include \"${file}\""
michael@13 3815 echo >>$file "#undef _${filestr}_AS_HEADER_"
michael@13 3816 echo >>$file ""
michael@13 3817 echo >>$file "${prefix}version_t ${prefix}version = {"
michael@13 3818 echo >>$file " ${vHex},"
michael@13 3819 echo >>$file " \"${vShort}\","
michael@13 3820 echo >>$file " \"${vLong}\","
michael@13 3821 echo >>$file " \"${vTeX}\","
michael@13 3822 echo >>$file " \"${vGNU}\","
michael@13 3823 echo >>$file " \"${vWeb}\","
michael@13 3824 echo >>$file " \"${vSCCS}\","
michael@13 3825 echo >>$file " \"${vRCS}\""
michael@13 3826 echo >>$file "};"
michael@13 3827 echo >>$file ""
michael@13 3828 echo >>$file "#endif /* _${filestr}_AS_HEADER_ */"
michael@13 3829 echo >>$file ""
michael@13 3830 ;;
michael@13 3831 m4 )
michael@13 3832 echo >>$file "##"
michael@13 3833 echo >>$file "## ${file} -- Version Information for ${name} (syntax: M4)"
michael@13 3834 echo >>$file "## [automatically generated and maintained by GNU shtool]"
michael@13 3835 echo >>$file "##"
michael@13 3836 echo >>$file ""
michael@13 3837 echo >>$file "m4_define([v_hex], [${vHex}])"
michael@13 3838 echo >>$file "m4_define([v_short], [${vShort}])"
michael@13 3839 echo >>$file "m4_define([v_long], [${vLong}])"
michael@13 3840 echo >>$file "m4_define([v_tex], [${vTeX}])"
michael@13 3841 echo >>$file "m4_define([v_gnu], [${vGNU}])"
michael@13 3842 echo >>$file "m4_define([v_web], [${vWeb}])"
michael@13 3843 echo >>$file "m4_define([v_sccs], [${vSCCS}])"
michael@13 3844 echo >>$file "m4_define([v_rcs], [${vRCS}])"
michael@13 3845 echo >>$file ""
michael@13 3846 ;;
michael@13 3847 perl )
michael@13 3848 echo >>$file "##"
michael@13 3849 echo >>$file "## ${file} -- Version Information for ${name} (syntax: Perl)"
michael@13 3850 echo >>$file "## [automatically generated and maintained by GNU shtool]"
michael@13 3851 echo >>$file "##"
michael@13 3852 echo >>$file ""
michael@13 3853 echo >>$file "our \$${prefix}version = {"
michael@13 3854 echo >>$file " 'v_hex' => ${vHex},"
michael@13 3855 echo >>$file " 'v_short' => \"${vShort}\","
michael@13 3856 echo >>$file " 'v_long' => \"${vLong}\","
michael@13 3857 echo >>$file " 'v_tex' => \"${vTeX}\","
michael@13 3858 echo >>$file " 'v_gnu' => \"${vGNU}\","
michael@13 3859 echo >>$file " 'v_web' => \"${vWeb}\","
michael@13 3860 echo >>$file " 'v_sccs' => \"${vSCCS}\","
michael@13 3861 echo >>$file " 'v_rcs' => \"\\${vRCS}/\""
michael@13 3862 echo >>$file "};"
michael@13 3863 echo >>$file ""
michael@13 3864 echo >>$file "1;"
michael@13 3865 echo >>$file ""
michael@13 3866 ;;
michael@13 3867 python )
michael@13 3868 echo >>$file "##"
michael@13 3869 echo >>$file "## ${file} -- Version Information for ${name} (syntax: Python)"
michael@13 3870 echo >>$file "## [automatically generated and maintained by GNU shtool]"
michael@13 3871 echo >>$file "##"
michael@13 3872 echo >>$file ""
michael@13 3873 echo >>$file "class ${prefix}version:"
michael@13 3874 echo >>$file " v_hex = ${vHex}"
michael@13 3875 echo >>$file " v_short = \"${vShort}\""
michael@13 3876 echo >>$file " v_long = \"${vLong}\""
michael@13 3877 echo >>$file " v_tex = \"${vTeX}\""
michael@13 3878 echo >>$file " v_gnu = \"${vGNU}\""
michael@13 3879 echo >>$file " v_web = \"${vWeb}\""
michael@13 3880 echo >>$file " v_sccs = \"${vSCCS}\""
michael@13 3881 echo >>$file " v_rcs = \"${vRCS}\""
michael@13 3882 echo >>$file ""
michael@13 3883 ;;
michael@13 3884 * ) echo "$msgprefix:Error: invalid argument to option \`-l': \`$opt_l'" 1>&2
michael@13 3885 shtool_exit 1
michael@13 3886 ;;
michael@13 3887 esac
michael@13 3888 fi
michael@13 3889
michael@13 3890 shtool_exit 0
michael@13 3891 ;;
michael@13 3892
michael@13 3893 path )
michael@13 3894 ##
michael@13 3895 ## path -- Deal with program paths
michael@13 3896 ## Copyright (c) 1998-2007 Ralf S. Engelschall <rse@engelschall.com>
michael@13 3897 ##
michael@13 3898
michael@13 3899 namelist="$*"
michael@13 3900
michael@13 3901 # check whether the test command supports the -x option
michael@13 3902 if [ -x /bin/sh ] 2>/dev/null; then
michael@13 3903 minusx="-x"
michael@13 3904 else
michael@13 3905 minusx="-r"
michael@13 3906 fi
michael@13 3907
michael@13 3908 # split path string
michael@13 3909 paths="`echo $opt_p |\
michael@13 3910 sed -e 's/^:/.:/' \
michael@13 3911 -e 's/::/:.:/g' \
michael@13 3912 -e 's/:$/:./' \
michael@13 3913 -e 's/:/ /g'`"
michael@13 3914
michael@13 3915 # SPECIAL REQUEST
michael@13 3916 # translate forward to reverse path
michael@13 3917 if [ ".$opt_r" = .yes ]; then
michael@13 3918 if [ "x$namelist" = "x." ]; then
michael@13 3919 rp='.'
michael@13 3920 else
michael@13 3921 rp=''
michael@13 3922 for pe in `IFS="$IFS/"; echo $namelist`; do
michael@13 3923 rp="../$rp"
michael@13 3924 done
michael@13 3925 fi
michael@13 3926 echo $rp | sed -e 's:/$::'
michael@13 3927 shtool_exit 0
michael@13 3928 fi
michael@13 3929
michael@13 3930 # SPECIAL REQUEST
michael@13 3931 # strip out directory or base name
michael@13 3932 if [ ".$opt_d" = .yes ]; then
michael@13 3933 echo "$namelist" |\
michael@13 3934 sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;'
michael@13 3935 shtool_exit 0
michael@13 3936 fi
michael@13 3937 if [ ".$opt_b" = .yes ]; then
michael@13 3938 echo "$namelist" |\
michael@13 3939 sed -e 's;.*/\([^/]*\)$;\1;'
michael@13 3940 shtool_exit 0
michael@13 3941 fi
michael@13 3942
michael@13 3943 # MAGIC SITUATION
michael@13 3944 # Perl Interpreter (perl)
michael@13 3945 if [ ".$opt_m" = .yes ] && [ ".$namelist" = .perl ]; then
michael@13 3946 rm -f $tmpfile >/dev/null 2>&1
michael@13 3947 touch $tmpfile
michael@13 3948 found=0
michael@13 3949 pc=99
michael@13 3950 for dir in $paths; do
michael@13 3951 dir=`echo $dir | sed -e 's;/*$;;'`
michael@13 3952 nc=99
michael@13 3953 for name in perl perl5 miniperl; do
michael@13 3954 if [ $minusx "$dir/$name" ] && [ ! -d "$dir/$name" ]; then
michael@13 3955 perl="$dir/$name"
michael@13 3956 pv=`$perl -e 'printf("%.3f", $]);'`
michael@13 3957 echo "$pv:$pc:$nc:$perl" >>$tmpfile
michael@13 3958 found=1
michael@13 3959 fi
michael@13 3960 nc=`expr $nc - 1`
michael@13 3961 done
michael@13 3962 pc=`expr $pc - 1`
michael@13 3963 done
michael@13 3964 if [ $found = 1 ]; then
michael@13 3965 perl="`cat $tmpfile | sort -r -u | sed -e 'q' | cut -d: -f4`"
michael@13 3966 rm -f $tmpfile >/dev/null 2>&1
michael@13 3967 echo "$perl"
michael@13 3968 shtool_exit 0
michael@13 3969 fi
michael@13 3970 rm -f $tmpfile >/dev/null 2>&1
michael@13 3971 shtool_exit 1
michael@13 3972 fi
michael@13 3973
michael@13 3974 # MAGIC SITUATION
michael@13 3975 # C pre-processor (cpp)
michael@13 3976 if [ ".$opt_m" = .yes ] && [ ".$namelist" = .cpp ]; then
michael@13 3977 echo >$tmpfile.c "#include <assert.h>"
michael@13 3978 echo >>$tmpfile.c "Syntax Error"
michael@13 3979 # 1. try the standard cc -E approach
michael@13 3980 cpp="${CC-cc} -E"
michael@13 3981 (eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out
michael@13 3982 my_error=`grep -v '^ *+' $tmpfile.out`
michael@13 3983 if [ ".$my_error" != . ]; then
michael@13 3984 # 2. try the cc -E approach and GCC's -traditional-ccp option
michael@13 3985 cpp="${CC-cc} -E -traditional-cpp"
michael@13 3986 (eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out
michael@13 3987 my_error=`grep -v '^ *+' $tmpfile.out`
michael@13 3988 if [ ".$my_error" != . ]; then
michael@13 3989 # 3. try a standalone cpp command in path and lib dirs
michael@13 3990 for path in $paths /lib /usr/lib /usr/local/lib; do
michael@13 3991 path=`echo $path | sed -e 's;/*$;;'`
michael@13 3992 if [ $minusx "$path/cpp" ] && [ ! -d "$path/cpp" ]; then
michael@13 3993 cpp="$path/cpp"
michael@13 3994 break
michael@13 3995 fi
michael@13 3996 done
michael@13 3997 if [ ".$cpp" != . ]; then
michael@13 3998 (eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out
michael@13 3999 my_error=`grep -v '^ *+' $tmpfile.out`
michael@13 4000 if [ ".$my_error" != . ]; then
michael@13 4001 # ok, we gave up...
michael@13 4002 cpp=''
michael@13 4003 fi
michael@13 4004 fi
michael@13 4005 fi
michael@13 4006 fi
michael@13 4007 rm -f $tmpfile >/dev/null 2>&1
michael@13 4008 rm -f $tmpfile.c $tmpfile.out >/dev/null 2>&1
michael@13 4009 if [ ".$cpp" != . ]; then
michael@13 4010 echo "$cpp"
michael@13 4011 shtool_exit 0
michael@13 4012 fi
michael@13 4013 shtool_exit 1
michael@13 4014 fi
michael@13 4015
michael@13 4016 # STANDARD SITUATION
michael@13 4017 # iterate over names
michael@13 4018 for name in $namelist; do
michael@13 4019 # iterate over paths
michael@13 4020 for path in $paths; do
michael@13 4021 path=`echo $path | sed -e 's;/*$;;'`
michael@13 4022 if [ $minusx "$path/$name" ] && [ ! -d "$path/$name" ]; then
michael@13 4023 if [ ".$opt_s" != .yes ]; then
michael@13 4024 echo "$path/$name"
michael@13 4025 fi
michael@13 4026 shtool_exit 0
michael@13 4027 fi
michael@13 4028 done
michael@13 4029 done
michael@13 4030
michael@13 4031 shtool_exit 1
michael@13 4032 ;;
michael@13 4033
michael@13 4034 esac
michael@13 4035
michael@13 4036 shtool_exit 0
michael@13 4037

mercurial