openpkg/shtool

Thu, 04 Oct 2012 20:30:05 +0200

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 04 Oct 2012 20:30:05 +0200
changeset 715
c10fb90893b9
parent 13
cb59d6afeb61
permissions
-rw-r--r--

Correct out of date build configuration, porting to Solaris 11 network
link infrastructure and new libpcap logic. This additionally allows for
device drivers in subdirectories of /dev. Correct packaged nmap
personalities and signatures to work out of the box. Finally, hack
arpd logic to properly close sockets and quit on TERM by repeating
signaling in the run command script. Sadly, all this fails to correct
the run time behaviour of honeyd which fails to bind to the IP layer.

michael@13 1 #!/bin/sh
michael@13 2 ##
michael@13 3 ## GNU shtool -- The GNU Portable Shell Tool
michael@428 4 ## Copyright (c) 1994-2008 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@428 9 ## Version: 2.0.8 (18-Jul-2008)
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@428 93 echo "This is GNU shtool, version 2.0.8 (18-Jul-2008)"
michael@428 94 echo 'Copyright (c) 1994-2008 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@428 160 echo "GNU shtool 2.0.8 (18-Jul-2008)"
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@428 650 ## Copyright (c) 1998-2008 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@428 961 ## Copyright (c) 1998-2008 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@428 1089 ## Copyright (c) 1998-2008 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@428 1154 ## Copyright (c) 1998-2008 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@428 1200 ## Copyright (c) 1999-2008 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@428 1292 ## Copyright (c) 1997-2008 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@428 1455 ## Copyright (c) 1996-2008 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@428 1543 ## Copyright (c) 1998-2008 Ralf S. Engelschall <rse@engelschall.com>
michael@13 1544 ##
michael@13 1545
michael@13 1546 # determine source(s) and destination
michael@428 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@428 1631 presrc=`echo $srcdir | sed -e 's;^\([^/][^/]*\)/.*;\1;'`
michael@428 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@428 1637 srcdir=`echo $srcdir | sed -e 's;^[^/][^/]*/*;;'`
michael@428 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@428 1651 fi
michael@13 1652 if [ $oneisabs = 0 ]; then
michael@13 1653 allow_relative_srcpre=yes
michael@428 1654 fi
michael@13 1655 if [ ".$opt_s" != .yes ]; then
michael@13 1656 allow_relative_srcpre=no
michael@428 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@428 1682 # special case (usually on "mkln -s /foo /foo/bar", etc)
michael@428 1683 if [ ".$srcpre$srcdir$srcbase" = . ]; then
michael@428 1684 srcdir="."
michael@428 1685 fi
michael@428 1686
michael@13 1687 # now finalize source and destination directory paths
michael@13 1688 srcdir=`echo $srcdir | sed -e 's;\([^/]\)$;\1/;'`
michael@13 1689 dstdir=`echo $dstdir | sed -e 's;\([^/]\)$;\1/;'`
michael@13 1690
michael@13 1691 # run the final link command
michael@13 1692 if [ ".$opt_t" = .yes ]; then
michael@13 1693 echo "ln$lnopt $srcpre$srcdir$srcbase $dstpre$dstdir$dstbase"
michael@13 1694 fi
michael@13 1695 eval ln$lnopt $srcpre$srcdir$srcbase $dstpre$dstdir$dstbase
michael@13 1696 done
michael@13 1697
michael@13 1698 shtool_exit 0
michael@13 1699 ;;
michael@13 1700
michael@13 1701 mkshadow )
michael@13 1702 ##
michael@13 1703 ## mkshadow -- Make a shadow tree through symbolic links
michael@428 1704 ## Copyright (c) 1998-2008 Ralf S. Engelschall <rse@engelschall.com>
michael@13 1705 ##
michael@13 1706
michael@13 1707 # source and destination directory
michael@13 1708 src=`echo "$1" | sed -e 's:/$::' -e 's:^\./\(.\):\1:'`
michael@13 1709 dst=`echo "$2" | sed -e 's:/$::' -e 's:^\./\(.\):\1:'`
michael@13 1710
michael@13 1711 # check whether source exists
michael@13 1712 if [ ! -d $src ]; then
michael@13 1713 echo "$msgprefix:Error: source directory not found: \`$src'" 1>&2
michael@13 1714 shtool_exit 1
michael@13 1715 fi
michael@13 1716
michael@13 1717 # determine if one of the paths is an absolute path,
michael@13 1718 # because then we have to use an absolute symlink
michael@13 1719 oneisabs=0
michael@13 1720 case $src in
michael@13 1721 /* ) oneisabs=1 ;;
michael@13 1722 esac
michael@13 1723 case $dst in
michael@13 1724 /* ) oneisabs=1 ;;
michael@13 1725 esac
michael@13 1726
michael@13 1727 # determine reverse directory for destination directory
michael@13 1728 dstrevdir=''
michael@13 1729 if [ $oneisabs = 0 ]; then
michael@13 1730 # derive reverse path from forward path
michael@13 1731 pwd=`pwd`
michael@13 1732 OIFS="$IFS"; IFS='/'
michael@13 1733 for pe in $dst; do
michael@13 1734 if [ "x$pe" = "x.." ]; then
michael@13 1735 OIFS2="$IFS"; IFS="$DIFS"
michael@13 1736 eval `echo "$pwd" |\
michael@13 1737 sed -e 's:\([^/]*\)$:; dir="\1":' \
michael@13 1738 -e 's:^\(.*\)/[^/]*;:pwd="\1";:'\
michael@13 1739 -e 's:^;:pwd="";:'`
michael@13 1740 dstrevdir="$dir/$dstrevdir"
michael@13 1741 IFS="$OIFS2"
michael@13 1742 else
michael@13 1743 dstrevdir="../$dstrevdir"
michael@13 1744 fi
michael@13 1745 done
michael@13 1746 IFS="$OIFS"
michael@13 1747 else
michael@13 1748 src="`cd $src; pwd`";
michael@13 1749 fi
michael@13 1750
michael@13 1751 # create directory tree at destination
michael@13 1752 if [ ! -d $dst ]; then
michael@13 1753 if [ ".$opt_t" = .yes ]; then
michael@13 1754 echo "mkdir $dst" 1>&2
michael@13 1755 fi
michael@13 1756 mkdir $dst
michael@13 1757 fi
michael@13 1758 if [ ".$opt_a" = .yes ]; then
michael@13 1759 DIRS=`cd $src; find . -type d -print |\
michael@13 1760 sed -e '/^\.$/d' -e 's:^\./::'`
michael@13 1761 else
michael@13 1762 DIRS=`cd $src; find . -type d -print |\
michael@13 1763 sed -e '/\/CVS/d' -e '/^\.$/d' -e 's:^\./::'`
michael@13 1764 fi
michael@13 1765 for dir in $DIRS; do
michael@13 1766 if [ ".$opt_t" = .yes ]; then
michael@13 1767 echo "mkdir $dst/$dir" 1>&2
michael@13 1768 fi
michael@13 1769 mkdir $dst/$dir
michael@13 1770 done
michael@13 1771
michael@13 1772 # fill directory tree with symlinks to files
michael@13 1773 if [ ".$opt_a" = .yes ]; then
michael@13 1774 FILES="`cd $src; find . -depth -print |\
michael@13 1775 sed -e 's/^\.\///'`"
michael@13 1776 else
michael@13 1777 FILES="`cd $src; find . -depth -print |\
michael@13 1778 sed -e '/\.o$/d' -e '/\.a$/d' -e '/\.so$/d' \
michael@13 1779 -e '/\.cvsignore$/d' -e '/\/CVS/d' \
michael@13 1780 -e '/\/\.#/d' -e '/\.orig$/d' \
michael@13 1781 -e 's/^\.\///'`"
michael@13 1782 fi
michael@13 1783 for file in $FILES; do
michael@13 1784 # don't use `-type f' above for find because of symlinks
michael@13 1785 if [ -d "$src/$file" ]; then
michael@13 1786 continue
michael@13 1787 fi
michael@13 1788 basename=`echo $file | sed -e 's:^.*/::'`
michael@13 1789 dir=`echo $file | sed -e 's:[^/]*$::' -e 's:/$::' -e 's:$:/:' -e 's:^/$::'`
michael@13 1790 from=`echo "$src/$file" | sed -e 's/^\.\///'`
michael@13 1791 to="$dst/$dir$basename"
michael@13 1792 if [ $oneisabs = 0 ]; then
michael@13 1793 if [ ".$dir" != . ]; then
michael@13 1794 subdir=`echo $dir | sed -e 's:/$::'`
michael@13 1795 # derive reverse path from forward path
michael@13 1796 revdir=''
michael@13 1797 OIFS="$IFS"; IFS='/'
michael@13 1798 for pe in $subdir; do
michael@13 1799 revdir="../$revdir"
michael@13 1800 done
michael@13 1801 IFS="$OIFS"
michael@13 1802 # finalize from
michael@13 1803 from="$revdir$from"
michael@13 1804 fi
michael@13 1805 from="$dstrevdir$from"
michael@13 1806 fi
michael@13 1807 if [ ".$opt_v" = .yes ]; then
michael@13 1808 echo " $to" 1>&2
michael@13 1809 fi
michael@13 1810 if [ ".$opt_t" = .yes ]; then
michael@13 1811 echo "ln -s $from $to" 1>&2
michael@13 1812 fi
michael@13 1813 ln -s $from $to
michael@13 1814 done
michael@13 1815
michael@13 1816 shtool_exit 0
michael@13 1817 ;;
michael@13 1818
michael@13 1819 fixperm )
michael@13 1820 ##
michael@13 1821 ## fixperm -- Fix file permissions inside a source tree
michael@428 1822 ## Copyright (c) 1996-2008 Ralf S. Engelschall <rse@engelschall.com>
michael@13 1823 ##
michael@13 1824
michael@13 1825 paths="$*"
michael@13 1826
michael@13 1827 # check whether the test command supports the -x option
michael@13 1828 if [ -x /bin/sh ] 2>/dev/null; then
michael@13 1829 minusx="-x"
michael@13 1830 else
michael@13 1831 minusx="-r"
michael@13 1832 fi
michael@13 1833
michael@13 1834 # iterate over paths
michael@13 1835 for p in $paths; do
michael@13 1836 for file in `find $p -depth -print`; do
michael@13 1837 if [ -f $file ]; then
michael@13 1838 if [ $minusx $file ]; then
michael@13 1839 if [ ".$opt_v" = .yes ]; then
michael@13 1840 echo "-rwxr-xr-x $file" 2>&1
michael@13 1841 fi
michael@13 1842 if [ ".$opt_t" = .yes ]; then
michael@13 1843 echo "chmod 755 $file" 2>&1
michael@13 1844 fi
michael@13 1845 chmod 755 $file
michael@13 1846 else
michael@13 1847 if [ ".$opt_v" = .yes ]; then
michael@13 1848 echo "-rw-r--r-- $file" 2>&1
michael@13 1849 fi
michael@13 1850 if [ ".$opt_t" = .yes ]; then
michael@13 1851 echo "chmod 644 $file" 2>&1
michael@13 1852 fi
michael@13 1853 chmod 644 $file
michael@13 1854 fi
michael@13 1855 continue
michael@13 1856 fi
michael@13 1857 if [ -d $file ]; then
michael@13 1858 if [ ".$opt_v" = .yes ]; then
michael@13 1859 echo "drwxr-xr-x $file" 2>&1
michael@13 1860 fi
michael@13 1861 if [ ".$opt_t" = .yes ]; then
michael@13 1862 echo "chmod 755 $file" 2>&1
michael@13 1863 fi
michael@13 1864 chmod 755 $file
michael@13 1865 continue
michael@13 1866 fi
michael@13 1867 if [ ".$opt_v" = .yes ]; then
michael@13 1868 echo "?????????? $file" 2>&1
michael@13 1869 fi
michael@13 1870 done
michael@13 1871 done
michael@13 1872
michael@13 1873 shtool_exit 0
michael@13 1874 ;;
michael@13 1875
michael@13 1876 rotate )
michael@13 1877 ##
michael@13 1878 ## rotate -- Logfile rotation
michael@428 1879 ## Copyright (c) 2001-2008 Ralf S. Engelschall <rse@engelschall.com>
michael@13 1880 ##
michael@13 1881
michael@13 1882 # make sure we have at least one file to rotate
michael@13 1883 if [ ".$opt_n" = .0 ]; then
michael@13 1884 echo "$msgprefix:Error: invalid argument \`$opt_n' to option -n." 1>&2
michael@13 1885 shtool_exit 1
michael@13 1886 fi
michael@13 1887
michael@13 1888 # canonicalize -s option argument
michael@13 1889 if [ ".$opt_s" != . ]; then
michael@13 1890 if [ ".`expr $opt_s : '[0-9]*$'`" != .0 ]; then
michael@13 1891 :
michael@13 1892 elif [ ".`expr $opt_s : '[0-9]*[Kk]$'`" != .0 ]; then
michael@13 1893 opt_s=`expr $opt_s : '\([0-9]*\)[Kk]$'`
michael@13 1894 opt_s=`expr $opt_s \* 1024`
michael@13 1895 elif [ ".`expr $opt_s : '[0-9]*[Mm]$'`" != .0 ]; then
michael@13 1896 opt_s=`expr $opt_s : '\([0-9]*\)[Mm]$'`
michael@13 1897 opt_s=`expr $opt_s \* 1048576` # 1024*1024
michael@13 1898 elif [ ".`expr $opt_s : '[0-9]*[Gg]$'`" != .0 ]; then
michael@13 1899 opt_s=`expr $opt_s : '\([0-9]*\)[Gg]$'`
michael@13 1900 opt_s=`expr $opt_s \* 1073741824` # 1024*1024*1024
michael@13 1901 else
michael@13 1902 echo "$msgprefix:Error: invalid argument \`$opt_s' to option -s." 1>&2
michael@13 1903 shtool_exit 1
michael@13 1904 fi
michael@13 1905 fi
michael@13 1906
michael@13 1907 # option -d/-z consistency
michael@13 1908 if [ ".$opt_d" = .yes ] && [ ".$opt_z" = . ]; then
michael@13 1909 echo "$msgprefix:Error: option -d requires option -z." 1>&2
michael@13 1910 shtool_exit 1
michael@13 1911 fi
michael@13 1912
michael@13 1913 # make sure target directory exists
michael@13 1914 if [ ".$opt_a" != . ]; then
michael@13 1915 if [ ! -d $opt_a ]; then
michael@13 1916 if [ ".$opt_f" = .no ]; then
michael@13 1917 echo "$msgprefix:Error: archive directory \`$opt_a' does not exist." 1>&2
michael@13 1918 shtool_exit 1
michael@13 1919 fi
michael@13 1920 mkdir $opt_a || shtool_exit $?
michael@13 1921 chmod 755 $opt_a
michael@13 1922 fi
michael@13 1923 if [ ! -w $opt_a ]; then
michael@13 1924 echo "$msgprefix:Error: archive directory \`$opt_a' not writable." 1>&2
michael@13 1925 shtool_exit 1
michael@13 1926 fi
michael@13 1927 fi
michael@13 1928
michael@13 1929 # determine compression approach
michael@13 1930 if [ ".$opt_z" != . ]; then
michael@13 1931 comp_lvl="$opt_z"
michael@13 1932 comp_prg=""
michael@13 1933 case $comp_lvl in
michael@13 1934 *:* ) eval `echo $comp_lvl |\
michael@13 1935 sed -e 's%^\(.*\):\(.*\)$%comp_prg="\1"; comp_lvl="\2"%'` ;;
michael@13 1936 esac
michael@13 1937
michael@13 1938 # compression level consistency
michael@13 1939 case $comp_lvl in
michael@13 1940 [0-9] )
michael@13 1941 ;;
michael@13 1942 * ) echo "$msgprefix:Error: invalid compression level \`$comp_lvl'" 1>&2
michael@13 1943 shtool_exit 1
michael@13 1944 ;;
michael@13 1945 esac
michael@13 1946
michael@13 1947 # determine a suitable compression tool
michael@13 1948 if [ ".$comp_prg" = . ]; then
michael@13 1949 # check whether the test command supports the -x option
michael@13 1950 if [ -x /bin/sh ] 2>/dev/null; then
michael@13 1951 minusx="-x"
michael@13 1952 else
michael@13 1953 minusx="-r"
michael@13 1954 fi
michael@13 1955 # search for tools in $PATH
michael@13 1956 paths="`echo $PATH |\
michael@13 1957 sed -e 's%/*:%:%g' -e 's%/*$%%' \
michael@13 1958 -e 's/^:/.:/' -e 's/::/:.:/g' -e 's/:$/:./' \
michael@13 1959 -e 's/:/ /g'`"
michael@13 1960 for prg in bzip2 gzip compress; do
michael@13 1961 for path in $paths; do
michael@13 1962 if [ $minusx "$path/$prg" ] && [ ! -d "$path/$prg" ]; then
michael@13 1963 comp_prg="$prg"
michael@13 1964 break
michael@13 1965 fi
michael@13 1966 done
michael@13 1967 if [ ".$comp_prg" != . ]; then
michael@13 1968 break
michael@13 1969 fi
michael@13 1970 done
michael@13 1971 if [ ".$comp_prg" = . ]; then
michael@13 1972 echo "$msgprefix:Error: no suitable compression tool found in \$PATH" 1>&2
michael@13 1973 shtool_exit 1
michael@13 1974 fi
michael@13 1975 fi
michael@13 1976
michael@13 1977 # determine standard compression extension
michael@13 1978 # and make sure it is a known tool
michael@13 1979 case $comp_prg in
michael@13 1980 */bzip2 | bzip2 ) comp_ext="bz2" comp_lvl="-$comp_lvl" ;;
michael@13 1981 */gzip | gzip ) comp_ext="gz" comp_lvl="-$comp_lvl" ;;
michael@13 1982 */compress | compress ) comp_ext="Z"; comp_lvl="" ;;
michael@13 1983 * ) echo "$msgprefix:Error: tool \`$comp_prg' is not a known compression tool" 1>&2
michael@13 1984 shtool_exit 1
michael@13 1985 ;;
michael@13 1986 esac
michael@13 1987 comp_suf=".$comp_ext"
michael@13 1988 fi
michael@13 1989
michael@13 1990 # iterate over all given logfile arguments
michael@13 1991 for file in $*; do
michael@13 1992 # make sure the logfile exists
michael@13 1993 if [ ! -f $file ]; then
michael@13 1994 if [ ".$opt_f" = .yes ]; then
michael@13 1995 continue
michael@13 1996 fi
michael@13 1997 echo "$msgprefix:Error: logfile \`$file' not found" 1>&2
michael@13 1998 shtool_exit 1
michael@13 1999 fi
michael@13 2000
michael@13 2001 # determine log directory (where original logfile is placed)
michael@13 2002 ldir="."
michael@13 2003 case $file in
michael@13 2004 */* ) eval `echo $file | sed -e 's%^\(.*\)/\([^/]*\)$%ldir="\1"; file="\2";%'` ;;
michael@13 2005 esac
michael@13 2006
michael@13 2007 # determine archive directory (where rotated logfiles are placed)
michael@13 2008 adir="$ldir"
michael@13 2009 if [ ".$opt_a" != . ]; then
michael@13 2010 case "$opt_a" in
michael@13 2011 /* | ./* ) adir="$opt_a" ;;
michael@13 2012 * ) adir="$ldir/$opt_a" ;;
michael@13 2013 esac
michael@13 2014 fi
michael@13 2015
michael@13 2016 # optionally take logfile size into account
michael@13 2017 if [ ".$opt_s" != . ]; then
michael@13 2018 # determine size of logfile
michael@13 2019 set -- `env -i /bin/ls -l "$ldir/$file" | sed -e "s;$ldir/$file;;" |\
michael@13 2020 sed -e 's; -> .*$;;' -e 's;[ ][ ]*; ;g'`
michael@13 2021 n=`expr $# - 3`
michael@13 2022 eval "size=\`echo \${$n}\`"
michael@13 2023
michael@13 2024 # skip logfile if size is still too small
michael@13 2025 if [ $size -lt $opt_s ]; then
michael@13 2026 if [ ".$opt_v" = .yes ]; then
michael@13 2027 echo "$ldir/$file: still too small in size -- skipping"
michael@13 2028 fi
michael@13 2029 continue
michael@13 2030 fi
michael@13 2031 fi
michael@13 2032
michael@13 2033 # verbosity
michael@13 2034 if [ ".$opt_v" = .yes ]; then
michael@13 2035 echo "rotating $ldir/$file"
michael@13 2036 fi
michael@13 2037
michael@13 2038 # execute prolog
michael@13 2039 if [ ".$opt_P" != . ]; then
michael@428 2040 # pass current log file name to prolog
michael@428 2041 # prolog cannot be handed an argument as it may be
michael@428 2042 # called as "prolog && something"
michael@428 2043 SHTOOL_ROTATE_LOGFILE="$ldir/$file"
michael@428 2044 export SHTOOL_ROTATE_LOGFILE
michael@13 2045 if [ ".$opt_t" = .yes ]; then
michael@13 2046 echo "$opt_P"
michael@13 2047 fi
michael@13 2048 eval $opt_P
michael@13 2049 [ $? -ne 0 ] && shtool_exit $?
michael@13 2050 fi
michael@13 2051
michael@13 2052 # kick away out-rotated logfile
michael@13 2053 n=`expr $opt_n - 1`
michael@13 2054 n=`echo dummy | awk "{ printf(\"%0${opt_p}d\", n); }" n=$n`
michael@13 2055 if [ -f "${adir}/${file}.${n}${comp_suf}" ]; then
michael@13 2056 # optionally migrate away the out-rotated logfile
michael@13 2057 if [ ".$opt_M" != . ]; then
michael@13 2058 if [ ".$opt_t" = .yes ]; then
michael@13 2059 echo "$opt_M ${adir}/${file}.${n}${comp_suf}"
michael@13 2060 fi
michael@13 2061 eval "$opt_M ${adir}/${file}.${n}${comp_suf}"
michael@13 2062 [ $? -ne 0 ] && shtool_exit $?
michael@13 2063 fi
michael@13 2064 # finally get rid of the out-rotated logfile
michael@13 2065 if [ ".$opt_t" = .yes ]; then
michael@13 2066 echo "rm -f ${adir}/${file}.${n}${comp_suf}"
michael@13 2067 fi
michael@13 2068 rm -f ${adir}/${file}.${n}${comp_suf} || shtool_exit $?
michael@13 2069 fi
michael@13 2070
michael@13 2071 # rotate already archived logfiles
michael@13 2072 while [ $n -gt 0 ]; do
michael@13 2073 m=$n
michael@13 2074 n=`expr $n - 1`
michael@13 2075 n=`echo dummy | awk "{ printf(\"%0${opt_p}d\", n); }" n=$n`
michael@13 2076 if [ $n -eq 0 ] && [ ".$opt_d" = .yes ]; then
michael@13 2077 # special case: first rotation file under delayed compression situation
michael@13 2078 if [ ! -f "${adir}/${file}.${n}" ]; then
michael@13 2079 continue
michael@13 2080 fi
michael@13 2081
michael@13 2082 # compress file (delayed)
michael@13 2083 if [ ".$opt_b" = .yes ]; then
michael@13 2084 if [ ".$opt_t" = .yes ]; then
michael@13 2085 echo "mv ${adir}/${file}.${n} ${adir}/${file}.${m}"
michael@13 2086 fi
michael@13 2087 mv ${adir}/${file}.${n} ${adir}/${file}.${m} || shtool_exit $?
michael@13 2088 if [ ".$opt_t" = .yes ]; then
michael@13 2089 echo "(${comp_prg} ${comp_lvl} <${adir}/${file}.${m} >${adir}/${file}.${m}${comp_suf}; rm -f ${adir}/${file}.${m}) &"
michael@13 2090 fi
michael@13 2091 ( ${comp_prg} ${comp_lvl} \
michael@13 2092 <${adir}/${file}.${m} \
michael@13 2093 >${adir}/${file}.${m}${comp_suf} || shtool_exit $?
michael@13 2094 rm -f ${adir}/${file}.${m} || shtool_exit $?
michael@13 2095 ) </dev/null >/dev/null 2>&1 &
michael@13 2096 else
michael@13 2097 if [ ".$opt_t" = .yes ]; then
michael@13 2098 echo "${comp_prg} ${comp_lvl} <${adir}/${file}.${n} >${adir}/${file}.${m}${comp_suf}"
michael@13 2099 fi
michael@13 2100 ${comp_prg} ${comp_lvl} \
michael@13 2101 <${adir}/${file}.${n} \
michael@13 2102 >${adir}/${file}.${m}${comp_suf} || shtool_exit $?
michael@13 2103 if [ ".$opt_t" = .yes ]; then
michael@13 2104 echo "rm -f ${adir}/${file}.${n}"
michael@13 2105 fi
michael@13 2106 rm -f ${adir}/${file}.${n} || shtool_exit $?
michael@13 2107 fi
michael@13 2108
michael@13 2109 # fix file attributes
michael@13 2110 if [ ".$opt_o" != . ]; then
michael@13 2111 if [ ".$opt_t" = .yes ]; then
michael@13 2112 echo "chown $opt_o ${adir}/${file}.${m}${comp_suf}"
michael@13 2113 fi
michael@13 2114 chown $opt_o ${adir}/${file}.${m}${comp_suf} || shtool_exit $?
michael@13 2115 fi
michael@13 2116 if [ ".$opt_g" != . ]; then
michael@13 2117 if [ ".$opt_t" = .yes ]; then
michael@13 2118 echo "chgrp $opt_g ${adir}/${file}.${m}${comp_suf}"
michael@13 2119 fi
michael@13 2120 chgrp $opt_g ${adir}/${file}.${m}${comp_suf} || shtool_exit $?
michael@13 2121 fi
michael@13 2122 if [ ".$opt_m" != . ]; then
michael@13 2123 if [ ".$opt_t" = .yes ]; then
michael@13 2124 echo "chmod $opt_m ${adir}/${file}.${m}${comp_suf}"
michael@13 2125 fi
michael@13 2126 chmod $opt_m ${adir}/${file}.${m}${comp_suf} || shtool_exit $?
michael@13 2127 fi
michael@13 2128 else
michael@13 2129 # standard case: second and following rotation file
michael@13 2130 if [ ! -f "${adir}/${file}.${n}${comp_suf}" ]; then
michael@13 2131 continue
michael@13 2132 fi
michael@13 2133 if [ ".$opt_t" = .yes ]; then
michael@13 2134 echo "mv ${adir}/${file}.${n}${comp_suf} ${adir}/${file}.${m}${comp_suf}"
michael@13 2135 fi
michael@13 2136 mv ${adir}/${file}.${n}${comp_suf} ${adir}/${file}.${m}${comp_suf} || shtool_exit $?
michael@13 2137 fi
michael@13 2138 done
michael@13 2139
michael@13 2140 # move away current logfile
michael@13 2141 if [ ".$opt_c" = .yes ]; then
michael@13 2142 # approach: copy[+truncate]
michael@13 2143 if [ ".$opt_t" = .yes ]; then
michael@13 2144 echo "cp -p ${ldir}/${file} ${adir}/${file}.${n}"
michael@13 2145 fi
michael@13 2146 cp -p ${ldir}/${file} ${adir}/${file}.${n} || shtool_exit $?
michael@13 2147 if [ ".$opt_r" = .no ]; then
michael@13 2148 if [ ".$opt_t" = .yes ]; then
michael@13 2149 echo "cp /dev/null ${ldir}/${file}"
michael@13 2150 fi
michael@13 2151 cp /dev/null ${ldir}/${file} || shtool_exit $?
michael@13 2152 fi
michael@13 2153 else
michael@13 2154 # approach: move[+touch]
michael@13 2155 if [ ".$opt_t" = .yes ]; then
michael@13 2156 echo "mv ${ldir}/${file} ${adir}/${file}.${n}"
michael@13 2157 fi
michael@13 2158 mv ${ldir}/${file} ${adir}/${file}.${n} || shtool_exit $?
michael@13 2159 if [ ".$opt_r" = .no ]; then
michael@13 2160 if [ ".$opt_t" = .yes ]; then
michael@13 2161 echo "touch ${ldir}/${file}"
michael@13 2162 fi
michael@13 2163 touch ${ldir}/${file} || shtool_exit $?
michael@13 2164 # fix file attributes
michael@13 2165 if [ ".$opt_o" != . ]; then
michael@13 2166 if [ ".$opt_t" = .yes ]; then
michael@13 2167 echo "chown $opt_o ${ldir}/${file}"
michael@13 2168 fi
michael@13 2169 chown $opt_o ${ldir}/${file} || shtool_exit $?
michael@13 2170 fi
michael@13 2171 if [ ".$opt_g" != . ]; then
michael@13 2172 if [ ".$opt_t" = .yes ]; then
michael@13 2173 echo "chgrp $opt_g ${ldir}/${file}"
michael@13 2174 fi
michael@13 2175 chgrp $opt_g ${ldir}/${file} || shtool_exit $?
michael@13 2176 fi
michael@13 2177 if [ ".$opt_m" != . ]; then
michael@13 2178 if [ ".$opt_t" = .yes ]; then
michael@13 2179 echo "chmod $opt_m ${ldir}/${file}"
michael@13 2180 fi
michael@13 2181 chmod $opt_m ${ldir}/${file} || shtool_exit $?
michael@13 2182 fi
michael@13 2183 fi
michael@13 2184 fi
michael@13 2185
michael@13 2186 # regular compression step
michael@13 2187 if [ ".$opt_z" != . ] && [ ".$opt_d" = .no ]; then
michael@13 2188 # compress file
michael@13 2189 if [ ".$opt_b" = .yes ]; then
michael@13 2190 if [ ".$opt_t" = .yes ]; then
michael@13 2191 echo "(${comp_prg} ${comp_lvl} <${adir}/${file}.${n} >${adir}/${file}.${n}${comp_suf}; rm -f ${adir}/${file}.${n}) &"
michael@13 2192 fi
michael@13 2193 ( ${comp_prg} ${comp_lvl} \
michael@13 2194 <${adir}/${file}.${n} \
michael@13 2195 >${adir}/${file}.${n}${comp_suf} || shtool_exit $?
michael@13 2196 rm -f ${adir}/${file}.${n} || shtool_exit $?
michael@13 2197 ) </dev/null >/dev/null 2>&1 &
michael@13 2198 else
michael@13 2199 if [ ".$opt_t" = .yes ]; then
michael@13 2200 echo "${comp_prg} ${comp_lvl} <${adir}/${file}.${n} >${adir}/${file}.${n}${comp_suf}"
michael@13 2201 fi
michael@13 2202 ${comp_prg} ${comp_lvl} \
michael@13 2203 <${adir}/${file}.${n} \
michael@13 2204 >${adir}/${file}.${n}${comp_suf} || shtool_exit $?
michael@13 2205 if [ ".$opt_t" = .yes ]; then
michael@13 2206 echo "rm -f ${opt_a}${file}.${n}"
michael@13 2207 fi
michael@13 2208 rm -f ${adir}/${file}.${n} || shtool_exit $?
michael@13 2209 fi
michael@13 2210
michael@13 2211 # fix file attributes
michael@13 2212 if [ ".$opt_o" != . ]; then
michael@13 2213 if [ ".$opt_t" = .yes ]; then
michael@13 2214 echo "chown $opt_o ${adir}/${file}.${n}${comp_suf}"
michael@13 2215 fi
michael@13 2216 chown $opt_o ${adir}/${file}.${n}${comp_suf} || shtool_exit $?
michael@13 2217 fi
michael@13 2218 if [ ".$opt_g" != . ]; then
michael@13 2219 if [ ".$opt_t" = .yes ]; then
michael@13 2220 echo "chgrp $opt_g ${adir}/${file}.${n}${comp_suf}"
michael@13 2221 fi
michael@13 2222 chgrp $opt_g ${adir}/${file}.${n}${comp_suf} || shtool_exit $?
michael@13 2223 fi
michael@13 2224 if [ ".$opt_m" != . ]; then
michael@13 2225 if [ ".$opt_t" = .yes ]; then
michael@13 2226 echo "chmod $opt_m ${adir}/${file}.${n}${comp_suf}"
michael@13 2227 fi
michael@13 2228 chmod $opt_m ${adir}/${file}.${n}${comp_suf} || shtool_exit $?
michael@13 2229 fi
michael@13 2230 fi
michael@13 2231
michael@13 2232 # execute epilog
michael@13 2233 if [ ".$opt_E" != . ]; then
michael@428 2234 # pass archive file name to epilog command
michael@428 2235 # epilog cannot be handed an argument as it is often
michael@428 2236 # called as "epilog && something"
michael@428 2237 SHTOOL_ROTATE_LOGFILE="${adir}/${file}"
michael@428 2238 export SHTOOL_ROTATE_LOGFILE
michael@13 2239 if [ ".$opt_t" = .yes ]; then
michael@13 2240 echo "$opt_E"
michael@13 2241 fi
michael@13 2242 eval $opt_E
michael@13 2243 [ $? -ne 0 ] && shtool_exit $?
michael@13 2244 fi
michael@13 2245 done
michael@13 2246
michael@13 2247 shtool_exit 0
michael@13 2248 ;;
michael@13 2249
michael@13 2250 tarball )
michael@13 2251 ##
michael@13 2252 ## tarball -- Roll distribution tarballs
michael@428 2253 ## Copyright (c) 1999-2008 Ralf S. Engelschall <rse@engelschall.com>
michael@13 2254 ##
michael@13 2255
michael@13 2256 srcs="$*"
michael@13 2257
michael@13 2258 # check whether the test command supports the -x option
michael@13 2259 if [ -x /bin/sh ] 2>/dev/null; then
michael@13 2260 minusx="-x"
michael@13 2261 else
michael@13 2262 minusx="-r"
michael@13 2263 fi
michael@13 2264
michael@13 2265 # find the tools
michael@13 2266 paths="`echo $PATH |\
michael@13 2267 sed -e 's%/*:%:%g' -e 's%/*$%%' \
michael@13 2268 -e 's/^:/.:/' -e 's/::/:.:/g' -e 's/:$/:./' \
michael@13 2269 -e 's/:/ /g'`"
michael@13 2270 for spec in find:gfind,find tar:gtar,tar tardy:tardy,tarcust; do
michael@13 2271 prg=`echo $spec | sed -e 's/:.*$//'`
michael@13 2272 tools=`echo $spec | sed -e 's/^.*://'`
michael@13 2273 eval "prg_${prg}=''"
michael@13 2274 # iterate over tools
michael@13 2275 for tool in `echo $tools | sed -e 's/,/ /g'`; do
michael@13 2276 # iterate over paths
michael@13 2277 for path in $paths; do
michael@13 2278 if [ $minusx "$path/$tool" ] && [ ! -d "$path/$tool" ]; then
michael@13 2279 eval "prg_${prg}=\"$path/$tool\""
michael@13 2280 break
michael@13 2281 fi
michael@13 2282 done
michael@13 2283 eval "val=\$prg_${prg}"
michael@13 2284 if [ ".$val" != . ]; then
michael@13 2285 break
michael@13 2286 fi
michael@13 2287 done
michael@13 2288 done
michael@13 2289
michael@13 2290 # expand source paths
michael@13 2291 exclude=''
michael@13 2292 for pat in `echo $opt_e | sed 's/,/ /g'`; do
michael@13 2293 exclude="$exclude | grep -v '$pat'"
michael@13 2294 done
michael@13 2295 if [ ".$opt_t" = .yes ]; then
michael@13 2296 echo "cp /dev/null $tmpfile.lst" 1>&2
michael@13 2297 fi
michael@13 2298 cp /dev/null $tmpfile.lst
michael@13 2299 for src in $srcs; do
michael@13 2300 if [ -d $src ]; then
michael@13 2301 if [ ".$opt_t" = .yes ]; then
michael@13 2302 echo "(cd $src && $prg_find . -type f -depth -print) | sed -e 's:^\\.\$::' -e 's:^\\./::' | cat $exclude >>$tmpfile.lst" 1>&2
michael@13 2303 fi
michael@13 2304 (cd $src && $prg_find . -type f -depth -print) |\
michael@13 2305 sed -e 's:^\.$::' -e 's:^\./::' | eval cat $exclude >>$tmpfile.lst
michael@13 2306 else
michael@13 2307 if [ ".$opt_t" = .yes ]; then
michael@13 2308 echo "echo $src >>$tmpfile.lst" 1>&2
michael@13 2309 fi
michael@13 2310 echo $src >>$tmpfile.lst
michael@13 2311 fi
michael@13 2312 done
michael@13 2313 sort <$tmpfile.lst >$tmpfile.lst.n
michael@13 2314 mv $tmpfile.lst.n $tmpfile.lst
michael@13 2315 if [ ".$opt_v" = .yes ]; then
michael@13 2316 cat $tmpfile.lst | sed -e 's/^/ /' 1>&2
michael@13 2317 fi
michael@13 2318
michael@13 2319 # determine tarball file and directory name
michael@13 2320 if [ ".$opt_o" != . ]; then
michael@13 2321 tarfile="$opt_o"
michael@13 2322 if [ ".$opt_d" != . ]; then
michael@13 2323 tarname="$opt_d"
michael@13 2324 else
michael@13 2325 tarname=`echo $tarfile | sed -e 's/\.tar.*$//' -e 's;.*/\([^/]*\)$;\1;'`
michael@13 2326 fi
michael@13 2327 else
michael@13 2328 if [ ".$opt_d" != . ]; then
michael@13 2329 tarname="$opt_d"
michael@13 2330 elif [ -d "$from" ]; then
michael@13 2331 tarname=`echo $from | sed -e 's;.*/\([^/]*\)$;\1;'`
michael@13 2332 else
michael@13 2333 tarname="out"
michael@13 2334 fi
michael@13 2335 tarfile="$tarname.tar"
michael@13 2336 fi
michael@13 2337
michael@13 2338 # roll the tarball
michael@13 2339 compress=''
michael@13 2340 if [ ".$opt_c" != . ]; then
michael@13 2341 compress="| $opt_c"
michael@13 2342 fi
michael@13 2343 if [ ".$prg_tardy" != . ]; then
michael@13 2344 # the elegant hackers way
michael@13 2345 tardy_opt="--prefix=$tarname"
michael@13 2346 tardy_opt="$tardy_opt --user_number=0 --group_number=0" # security!
michael@13 2347 if [ ".$opt_u" != . ]; then
michael@13 2348 tardy_opt="$tardy_opt --user_name=$opt_u"
michael@13 2349 fi
michael@13 2350 if [ ".$opt_g" != . ]; then
michael@13 2351 tardy_opt="$tardy_opt --group_name=$opt_g"
michael@13 2352 fi
michael@13 2353 if [ ".$opt_t" = .yes ]; then
michael@13 2354 echo "cat $tmpfile.lst | xargs $prg_tar cf - | $prg_tardy $tardy_opt | cat $compress >$tmpfile.out" 1>&2
michael@13 2355 fi
michael@13 2356 cat $tmpfile.lst |\
michael@13 2357 xargs $prg_tar cf - |\
michael@13 2358 $prg_tardy $tardy_opt |\
michael@13 2359 eval cat $compress >$tmpfile.out
michael@13 2360 if [ ".$opt_t" = .yes ]; then
michael@13 2361 echo "cp $tmpfile.out $tarfile" 1>&2
michael@13 2362 fi
michael@13 2363 cp $tmpfile.out $tarfile
michael@13 2364 else
michael@13 2365 # the portable standard way
michael@13 2366 if [ ".$opt_t" = .yes ]; then
michael@13 2367 echo "mkdir $tmpdir/$tarname" 1>&2
michael@13 2368 fi
michael@13 2369 mkdir $tmpdir/$tarname || shtool_exit 1
michael@13 2370 if [ ".$opt_t" = .yes ]; then
michael@13 2371 echo "cat $tmpfile.lst | xargs $prg_tar cf - | (cd $tmpdir/$tarname && $prg_tar xf -)" 1>&2
michael@13 2372 fi
michael@13 2373 cat $tmpfile.lst |\
michael@13 2374 xargs $prg_tar cf - |\
michael@13 2375 (cd $tmpdir/$tarname && $prg_tar xf -)
michael@13 2376 if [ ".$opt_u" != . ]; then
michael@13 2377 if [ ".$opt_t" = .yes ]; then
michael@13 2378 echo "chown -R $opt_u $tmpdir/$tarname >/dev/null 2>&1" 2>&1
michael@13 2379 fi
michael@13 2380 chown -R $opt_u $tmpdir/$tarname >/dev/null 2>&1 ||\
michael@13 2381 echo "$msgprefix:Warning: cannot set user name \`$opt_u' (would require root privileges)"
michael@13 2382 fi
michael@13 2383 if [ ".$opt_g" != . ]; then
michael@13 2384 if [ ".$opt_t" = .yes ]; then
michael@13 2385 echo "chgrp -R $opt_g $tmpdir/$tarname >/dev/null 2>&1" 2>&1
michael@13 2386 fi
michael@13 2387 chgrp -R $opt_g $tmpdir/$tarname >/dev/null 2>&1 ||\
michael@13 2388 echo "$msgprefix:Warning: cannot set group name \`$opt_g' (would require root privileges)"
michael@13 2389 fi
michael@13 2390 if [ ".$opt_t" = .yes ]; then
michael@13 2391 echo "(cd $tmpdir && $prg_find $tarname -type f -depth -print | sort | xargs $prg_tar cf -) | cat $compress >$tmpfile.out" 1>&2
michael@13 2392 fi
michael@13 2393 (cd $tmpdir && $prg_find $tarname -type f -depth -print | sort | xargs $prg_tar cf -) |\
michael@13 2394 eval cat $compress >$tmpfile.out
michael@13 2395 if [ ".$opt_t" = .yes ]; then
michael@13 2396 echo "cp $tmpfile.out $tarfile" 1>&2
michael@13 2397 fi
michael@13 2398 cp $tmpfile.out $tarfile
michael@13 2399 if [ ".$opt_t" = .yes ]; then
michael@13 2400 echo "rm -rf $tmpdir/$tarname" 1>&2
michael@13 2401 fi
michael@13 2402 rm -rf $tmpdir/$tarname
michael@13 2403 fi
michael@13 2404
michael@13 2405 # cleanup
michael@13 2406 if [ ".$opt_t" = .yes ]; then
michael@13 2407 echo "rm -f $tmpfile.lst $tmpfile.out" 1>&2
michael@13 2408 fi
michael@13 2409 rm -f $tmpfile.lst $tmpfile.out
michael@13 2410
michael@13 2411 shtool_exit 0
michael@13 2412 ;;
michael@13 2413
michael@13 2414 subst )
michael@13 2415 ##
michael@13 2416 ## subst -- Apply sed(1) substitution operations
michael@428 2417 ## Copyright (c) 2001-2008 Ralf S. Engelschall <rse@engelschall.com>
michael@13 2418 ##
michael@13 2419
michael@13 2420 # remember optional list of file(s)
michael@13 2421 files="$*"
michael@13 2422 files_num="$#"
michael@13 2423
michael@13 2424 # parameter consistency check
michael@13 2425 if [ $# -eq 0 ] && [ ".$opt_b" != . ]; then
michael@13 2426 echo "$msgprefix:Error: option -b cannot be applied to stdin" 1>&2
michael@13 2427 shtool_exit 1
michael@13 2428 fi
michael@13 2429 if [ $# -eq 0 ] && [ ".$opt_s" = .yes ]; then
michael@13 2430 echo "$msgprefix:Error: option -s cannot be applied to stdin" 1>&2
michael@13 2431 shtool_exit 1
michael@13 2432 fi
michael@13 2433
michael@13 2434 # build underlying sed(1) command
michael@13 2435 sedcmd='sed'
michael@13 2436 if [ ".$opt_e" != . ]; then
michael@13 2437 OIFS="$IFS"; IFS="$ASC_NL"; set -- $opt_e; IFS="$OIFS"
michael@13 2438 for e
michael@13 2439 do
michael@13 2440 sedcmd="$sedcmd -e '$e'"
michael@13 2441 done
michael@13 2442 elif [ ".$opt_f" != . ]; then
michael@13 2443 if [ ! -f $opt_f ]; then
michael@13 2444 echo "$msgprefix:Error: command file \`$opt_f' not found or not a regular file" 1>&2
michael@13 2445 shtool_exit 1
michael@13 2446 fi
michael@13 2447 sedcmd="$sedcmd -f '$opt_f'"
michael@13 2448 else
michael@13 2449 echo "$msgprefix:Error: either -e option(s) or -f option required" 1>&2
michael@13 2450 shtool_exit 1
michael@13 2451 fi
michael@13 2452
michael@13 2453 # determine extension for original file
michael@13 2454 orig=".orig"
michael@13 2455 if [ ".$opt_b" != . ]; then
michael@13 2456 orig="$opt_b"
michael@13 2457 fi
michael@13 2458
michael@13 2459 # apply sed(1) operation(s)
michael@13 2460 if [ ".$files" != . ]; then
michael@13 2461 # apply operation(s) to files
michael@13 2462 substdone=no
michael@13 2463 for file in $files; do
michael@13 2464 test ".$file" = . && continue
michael@13 2465 if [ ! -f $file ]; then
michael@13 2466 echo "$msgprefix:Warning: file \`$file' not found or not a regular file" 1>&2
michael@13 2467 continue
michael@13 2468 fi
michael@13 2469
michael@13 2470 # handle interactive mode
michael@13 2471 if [ ".$opt_i" = .yes ]; then
michael@13 2472 eval "$sedcmd <$file >$file.new"
michael@13 2473 skip=no
michael@13 2474 if cmp $file $file.new >/dev/null 2>&1; then
michael@13 2475 rm -f $file.new
michael@13 2476 skip=yes
michael@13 2477 else
michael@13 2478 (diff -U1 $file $file.new >$tmpfile) 2>/dev/null
michael@13 2479 if [ ".`cat $tmpfile`" = . ]; then
michael@13 2480 (diff -C1 $file $file.new >$tmpfile) 2>/dev/null
michael@13 2481 if [ ".`cat $tmpfile`" = . ]; then
michael@13 2482 echo "$msgprefix:Warning: unable to show difference for file \`$file'" 1>&2
michael@13 2483 cp /dev/null $tmpfile
michael@13 2484 fi
michael@13 2485 fi
michael@13 2486 rm -f $file.new
michael@13 2487 cat $tmpfile
michael@13 2488 echo dummy | awk '{ printf("%s", TEXT); }' TEXT=">>> Apply [Y/n]: "
michael@13 2489 read input
michael@13 2490 if [ ".$input" != .Y ] &&\
michael@13 2491 [ ".$input" != .y ] &&\
michael@13 2492 [ ".$input" != . ]; then
michael@13 2493 skip=yes
michael@13 2494 fi
michael@13 2495 fi
michael@13 2496 if [ ".$skip" = .yes ]; then
michael@13 2497 if [ ".$opt_v" = .yes ]; then
michael@13 2498 echo "file \`$file' -- skipped" 1>&2
michael@13 2499 fi
michael@13 2500 continue
michael@13 2501 fi
michael@13 2502 fi
michael@13 2503
michael@13 2504 # apply sed(1) operation(s)
michael@13 2505 if [ ".$opt_v" = .yes ]; then
michael@13 2506 echo "patching \`$file'" 1>&2
michael@13 2507 fi
michael@13 2508 if [ ".$opt_t" = .yes ]; then
michael@13 2509 echo "\$ cp -p $file $file$orig"
michael@13 2510 echo "\$ chmod u+w $file"
michael@13 2511 echo "\$ $sedcmd <$file$orig >$file"
michael@13 2512 fi
michael@13 2513 if [ ".$opt_n" = .no ]; then
michael@13 2514 cp -p $file $file$orig
michael@13 2515 chmod u+w $file >/dev/null 2>&1 || true
michael@13 2516 eval "$sedcmd <$file$orig >$file"
michael@13 2517 fi
michael@13 2518
michael@13 2519 # optionally fix timestamp
michael@13 2520 if [ ".$opt_s" = .yes ]; then
michael@13 2521 if [ ".$opt_t" = .yes ]; then
michael@13 2522 echo "\$ touch -r $file$orig $file"
michael@13 2523 fi
michael@13 2524 if [ ".$opt_n" = .no ]; then
michael@13 2525 touch -r $file$orig $file
michael@13 2526 fi
michael@13 2527 fi
michael@13 2528
michael@428 2529 # optionally check whether any content change actually occurred
michael@13 2530 if [ ".$opt_q" = .no ]; then
michael@13 2531 if cmp $file$orig $file >/dev/null 2>&1; then
michael@13 2532 if [ ".$opt_w" = .yes ]; then
michael@13 2533 echo "$msgprefix:Warning: substitution resulted in no content change on file \"$file\"" 1>&2
michael@13 2534 fi
michael@13 2535 else
michael@13 2536 substdone=yes
michael@13 2537 fi
michael@13 2538 fi
michael@13 2539
michael@13 2540 # optionally remove preserved original file
michael@13 2541 if [ ".$opt_b" = . ]; then
michael@13 2542 if [ ".$opt_t" = .yes ]; then
michael@13 2543 echo "\$ rm -f $file$orig"
michael@13 2544 fi
michael@13 2545 if [ ".$opt_n" = .no ]; then
michael@13 2546 rm -f $file$orig
michael@13 2547 fi
michael@13 2548 fi
michael@13 2549 done
michael@13 2550 if [ ".$opt_q" = .no ] && [ ".$opt_w" = .no ]; then
michael@13 2551 if [ ".$substdone" = .no ]; then
michael@13 2552 if [ ".$files_num" = .1 ]; then
michael@13 2553 echo "$msgprefix:Warning: substitution resulted in no content change on file \"$file\"" 1>&2
michael@13 2554 else
michael@13 2555 echo "$msgprefix:Warning: substitution resulted in no content change on any file" 1>&2
michael@13 2556 fi
michael@13 2557 fi
michael@13 2558 fi
michael@13 2559 else
michael@13 2560 # apply operation(s) to stdin/stdout
michael@13 2561 if [ ".$opt_v" = .yes ]; then
michael@13 2562 echo "patching <stdin>" 1>&2
michael@13 2563 fi
michael@13 2564 if [ ".$opt_t" = .yes ]; then
michael@13 2565 echo "\$ $sedcmd"
michael@13 2566 fi
michael@13 2567 if [ ".$opt_n" = .no ]; then
michael@13 2568 eval "$sedcmd"
michael@13 2569 fi
michael@13 2570 fi
michael@13 2571
michael@13 2572 shtool_exit 0
michael@13 2573 ;;
michael@13 2574
michael@13 2575 platform )
michael@13 2576 ##
michael@13 2577 ## platform -- Platform Identification Utility
michael@428 2578 ## Copyright (c) 2003-2008 Ralf S. Engelschall <rse@engelschall.com>
michael@13 2579 ##
michael@13 2580
michael@13 2581 # option post-processing
michael@13 2582 if [ ".$opt_t" != . ]; then
michael@13 2583 case "$opt_t" in
michael@13 2584 binary )
michael@13 2585 # binary package id (OpenPKG RPM)
michael@13 2586 opt_F="%<ap>-%<sp>"
michael@13 2587 opt_L=yes
michael@13 2588 opt_S=""
michael@13 2589 opt_C="+"
michael@13 2590 ;;
michael@13 2591 build )
michael@13 2592 # build time checking (OpenPKG RPM)
michael@13 2593 opt_F="%<at>-%<st>"
michael@13 2594 opt_L=yes
michael@13 2595 opt_S=""
michael@13 2596 opt_C="+"
michael@13 2597 ;;
michael@13 2598 gnu )
michael@13 2599 # GNU config.guess style <arch>-<vendor>-<os><osversion>
michael@13 2600 opt_F="%<at>-unknown-%<st>"
michael@13 2601 opt_L=yes
michael@13 2602 opt_S=""
michael@13 2603 opt_C="+"
michael@13 2604 ;;
michael@13 2605 web )
michael@13 2606 # non-whitespace HTTP Server-header id
michael@13 2607 opt_F="%<sp>-%<ap>"
michael@13 2608 opt_S="/"
michael@13 2609 opt_C="+"
michael@13 2610 ;;
michael@13 2611 summary)
michael@13 2612 # human readable verbose summary information
michael@13 2613 opt_F="Class: %[sc] (%[ac])\\nProduct: %[sp] (%[ap])\\nTechnology: %[st] (%[at])"
michael@13 2614 opt_S=" "
michael@13 2615 opt_C="/"
michael@13 2616 ;;
michael@13 2617 all-in-one )
michael@13 2618 # full-table all-in-one information
michael@13 2619 opt_F=""
michael@13 2620 opt_F="${opt_F}concise architecture class: %<ac>\\n"
michael@13 2621 opt_F="${opt_F}regular architecture class: %{ac}\\n"
michael@13 2622 opt_F="${opt_F}verbose architecture class: %[ac]\\n"
michael@13 2623 opt_F="${opt_F}concise architecture product: %<ap>\\n"
michael@13 2624 opt_F="${opt_F}regular architecture product: %{ap}\\n"
michael@13 2625 opt_F="${opt_F}verbose architecture product: %[ap]\\n"
michael@13 2626 opt_F="${opt_F}concise architecture technology: %<at>\\n"
michael@13 2627 opt_F="${opt_F}regular architecture technology: %{at}\\n"
michael@13 2628 opt_F="${opt_F}verbose architecture technology: %[at]\\n"
michael@13 2629 opt_F="${opt_F}concise system class: %<sc>\\n"
michael@13 2630 opt_F="${opt_F}regular system class: %{sc}\\n"
michael@13 2631 opt_F="${opt_F}verbose system class: %[sc]\\n"
michael@13 2632 opt_F="${opt_F}concise system product: %<sp>\\n"
michael@13 2633 opt_F="${opt_F}regular system product: %{sp}\\n"
michael@13 2634 opt_F="${opt_F}verbose system product: %[sp]\\n"
michael@13 2635 opt_F="${opt_F}concise system technology: %<st>\\n"
michael@13 2636 opt_F="${opt_F}regular system technology: %{st}\\n"
michael@13 2637 opt_F="${opt_F}verbose system technology: %[st]"
michael@13 2638 ;;
michael@13 2639 * )
michael@13 2640 echo "$msgprefix:Error: invalid type \`$opt_t'" 1>&2
michael@13 2641 exit 1
michael@13 2642 ;;
michael@13 2643 esac
michael@13 2644 fi
michael@13 2645
michael@13 2646 # assemble initial platform information
michael@13 2647 UNAME_MACHINE=`(uname -m) 2>/dev/null` ||\
michael@13 2648 UNAME_MACHINE=`(uname -p) 2>/dev/null` ||\
michael@13 2649 UNAME_MACHINE='unknown'
michael@13 2650 UNAME_SYSTEM=`(uname -s) 2>/dev/null` ||\
michael@13 2651 UNAME_SYSTEM='unknown'
michael@13 2652 UNAME_RELEASE=`(uname -r) 2>/dev/null` ||\
michael@13 2653 UNAME_RELEASE=`(uname -v) 2>/dev/null` ||\
michael@13 2654 UNAME_RELEASE='unknown'
michael@13 2655
michael@13 2656 UNAME="${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}"
michael@13 2657
michael@13 2658 AC=""; AP=""; AT=""
michael@13 2659 SC=""; SP=""; ST=""
michael@13 2660
michael@13 2661 # dispatch into platform specific sections
michael@13 2662 case "${UNAME}" in
michael@13 2663
michael@13 2664 # FreeBSD
michael@13 2665 *:FreeBSD:* )
michael@13 2666 # determine architecture
michael@13 2667 AC="${UNAME_MACHINE}"
michael@13 2668 case "${AC}" in
michael@13 2669 i386 ) AC="iX86" ;;
michael@13 2670 esac
michael@13 2671 AP="${AC}"
michael@13 2672 AT="${AP}"
michael@13 2673 if [ ".${AT}" = ".iX86" ]; then
michael@13 2674 case "`(/sbin/sysctl -n hw.model) 2>&1`" in
michael@13 2675 *"Xeon"* | *"Pentium Pro"* | *"Cyrix 6x86MX"* | *"Pentium II"* | *"Pentium III"* | *"Pentium 4"* | *"Celeron"* ) AT="i686" ;;
michael@13 2676 *"Pentium"* ) AT="i586" ;; *"i486[SD]X"* | *"Cyrix 486"* | *"Cyrix [56]x86"* | *"Blue Lightning" | *"Cyrix 486S/DX" ) AT="i486" ;;
michael@13 2677 *"i386[SD]X"* | *"NexGen 586"* ) AT="i386" ;;
michael@13 2678 esac
michael@13 2679 fi
michael@13 2680 # determine system
michael@13 2681 r=`echo "${UNAME_RELEASE}" |\
michael@13 2682 sed -e 's;[()];;' -e 's/\(-.*\)$/[\1]/'`
michael@13 2683 ST="FreeBSD ${r}"
michael@13 2684 SP="${ST}"
michael@13 2685 case "${r}" in
michael@13 2686 1.* ) SC="4.3BSD" ;;
michael@13 2687 * ) SC="4.4BSD" ;;
michael@13 2688 esac
michael@13 2689 ;;
michael@13 2690
michael@13 2691 # NetBSD
michael@13 2692 *:NetBSD:* )
michael@13 2693 # determine architecture
michael@13 2694 AT="${UNAME_MACHINE}"
michael@13 2695 AP="${AT}"
michael@13 2696 case "${AP}" in
michael@13 2697 i[3-6]86 ) AP="iX86" ;;
michael@13 2698 esac
michael@13 2699 AC="${AP}"
michael@13 2700 # determine system
michael@13 2701 r=`echo "${UNAME_RELEASE}" | sed -e 's/\([-_].*\)$/[\1]/'`
michael@13 2702 ST="NetBSD ${r}"
michael@13 2703 SP="${ST}"
michael@13 2704 case "${r}" in
michael@13 2705 0.* ) SC="4.3BSD" ;;
michael@13 2706 * ) SC="4.4BSD" ;;
michael@13 2707 esac
michael@13 2708 ;;
michael@13 2709
michael@13 2710 # OpenBSD
michael@13 2711 *:OpenBSD:* )
michael@13 2712 # determine architecture
michael@13 2713 AT="${UNAME_MACHINE}"
michael@13 2714 AP="${AT}"
michael@13 2715 case "${AP}" in
michael@13 2716 i[3-6]86 ) AP="iX86" ;;
michael@13 2717 esac
michael@13 2718 AC="${AP}"
michael@13 2719 # determine system
michael@13 2720 r=`echo "${UNAME_RELEASE}" | sed -e 's/\([-_].*\)$/[\1]/'`
michael@13 2721 ST="OpenBSD ${r}"
michael@13 2722 SP="${ST}"
michael@13 2723 SC="4.4BSD"
michael@13 2724 ;;
michael@13 2725
michael@428 2726 # DragonFly BSD
michael@428 2727 *:DragonFly:* )
michael@428 2728 # determine architecture
michael@428 2729 AT="${UNAME_MACHINE}"
michael@428 2730 AP="${AT}"
michael@428 2731 case "${AP}" in
michael@428 2732 i[3-6]86 ) AP="iX86" ;;
michael@428 2733 esac
michael@428 2734 AC="${AP}"
michael@428 2735 # determine system
michael@428 2736 r=`echo "${UNAME_RELEASE}" | sed -e 's/\([-_].*\)$/[\1]/'`
michael@428 2737 ST="DragonFly ${r}"
michael@428 2738 SP="${ST}"
michael@428 2739 SC="4.4BSD"
michael@428 2740 ;;
michael@428 2741
michael@13 2742 # GNU/Linux
michael@13 2743 *:Linux:* )
michael@13 2744 # determine architecture
michael@13 2745 AT="${UNAME_MACHINE}"
michael@13 2746 case "${AT}" in
michael@13 2747 ia64 ) AT="IA64" ;;
michael@13 2748 x86_64 ) AT='AMD64' ;;
michael@13 2749 parisc ) AT="HPPA32" ;;
michael@13 2750 parisc64 ) AT="HPPA64" ;;
michael@13 2751 esac
michael@13 2752 AP="${AT}"
michael@13 2753 case "${AP}" in
michael@13 2754 i[3-6]86 ) AP='iX86' ;;
michael@13 2755 esac
michael@13 2756 AC="${AP}"
michael@13 2757 # determine system
michael@13 2758 v_kern=`echo "${UNAME_RELEASE}" |\
michael@13 2759 sed -e 's/^\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/'`
michael@13 2760 v_libc=`(strings /lib/libc.so.* | grep '^GLIBC_' | sed -e 's/^GLIBC_//' |\
michael@13 2761 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 2762 ST="GNU/<Linux >${v_libc}/<${v_kern}>"
michael@13 2763 if [ -f /etc/lsb-release ]; then
michael@13 2764 eval `( . /etc/lsb-release
michael@13 2765 echo "SC=\"LSB${LSB_VERSION}\""
michael@13 2766 if [ ".${DISTRIB_ID}" != . -a ".${DISTRIB_RELEASE}" != . ]; then
michael@13 2767 echo "SP=\"${DISTRIB_ID} ${DISTRIB_RELEASE}\""
michael@13 2768 fi
michael@13 2769 ) 2>/dev/null`
michael@13 2770 fi
michael@13 2771 if [ ".$SP" = . ]; then
michael@13 2772 for tagfile in x \
michael@13 2773 `cd /etc && \
michael@13 2774 /bin/ls *[_-]release *[_-]version 2>/dev/null | env -i sort | \
michael@13 2775 sed -e '/^redhat-release$/d' -e '/^lsb-release$/d'; \
michael@13 2776 echo redhat-release lsb-release`
michael@13 2777 do
michael@13 2778 [ ".${tagfile}" = .x ] && continue
michael@13 2779 [ ! -f "/etc/${tagfile}" ] && continue
michael@13 2780 n=`echo ${tagfile} | sed -e 's/[_-]release$//' -e 's/[_-]version$//'`
michael@13 2781 v=`(grep VERSION /etc/${tagfile}; cat /etc/${tagfile}) | grep '[0-9]' | sed -e 'q' |\
michael@13 2782 sed -e 's/^/#/' \
michael@428 2783 -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\)\(\.[0-9][0-9]*\).*$/\1[\2]/' \
michael@13 2784 -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' \
michael@13 2785 -e 's/^#[^0-9]*\([0-9][0-9]*\).*$/\1/' \
michael@13 2786 -e 's/^#.*$//'`
michael@13 2787 case "`util_lower ${n}`" in
michael@13 2788 redhat )
michael@13 2789 if [ ".`egrep '(Red Hat Enterprise Linux|CentOS)' /etc/${tagfile}`" != . ]; then
michael@13 2790 n="<R>ed <H>at <E>nterprise <L>inux"
michael@13 2791 else
michael@13 2792 n="<R>ed <H>at <L>inux"
michael@13 2793 fi
michael@13 2794 ;;
michael@13 2795 debian ) n="Debian[ GNU/Linux]" ;;
michael@13 2796 ubuntu ) n="Ubuntu[ GNU/Linux]" ;;
michael@13 2797 fedora ) n="<Fedora> Core[ GNU/Linux]" ;;
michael@13 2798 suse ) n="[Novell ]SUSE[ Linux]" ;;
michael@13 2799 mandrake*|mandriva ) n="Mandriva[ Linux]" ;;
michael@13 2800 gentoo ) n="Gentoo[ GNU/Linux]" ;;
michael@13 2801 slackware ) n="Slackware[ Linux]" ;;
michael@13 2802 turbolinux ) n="TurboLinux" ;;
michael@13 2803 unitedlinux ) n="UnitedLinux" ;;
michael@13 2804 * ) n="${n}[ GNU/Linux]" ;;
michael@13 2805 esac
michael@13 2806 case "$n" in
michael@13 2807 *"<"*">"* ) SP="$n <$v>" ;;
michael@13 2808 * ) SP="$n $v" ;;
michael@13 2809 esac
michael@13 2810 break
michael@13 2811 done
michael@13 2812 fi
michael@13 2813 [ ".$SP" = . ] && SP="${ST}"
michael@13 2814 [ ".$SC" = . ] && SC="LSB"
michael@13 2815 ;;
michael@13 2816
michael@13 2817 # Sun Solaris
michael@13 2818 *:SunOS:* )
michael@13 2819 # determine architecture
michael@13 2820 AT="${UNAME_MACHINE}"
michael@13 2821 case "${AT}" in
michael@13 2822 i86pc )
michael@13 2823 AT="iX86"
michael@13 2824 case "`(/bin/isainfo -k) 2>&1`" in
michael@13 2825 amd64 ) AT="AMD64" ;;
michael@13 2826 esac
michael@13 2827 ;;
michael@13 2828 esac
michael@13 2829 AP="${AT}"
michael@13 2830 case "${AP}" in
michael@13 2831 sun4[cdm] ) AP="SPARC32" ;;
michael@13 2832 sun4[uv] ) AP="SPARC64" ;;
michael@13 2833 sun4* ) AP="SPARC" ;;
michael@13 2834 esac
michael@13 2835 AC="${AP}"
michael@13 2836 case "${AC}" in
michael@13 2837 SPARC* ) AC="SPARC" ;;
michael@13 2838 esac
michael@13 2839 # determine system
michael@13 2840 ST="[Sun ]SunOS ${UNAME_RELEASE}"
michael@13 2841 v=`echo "${UNAME_RELEASE}" |\
michael@13 2842 sed -e 's;^4\.;1.;' \
michael@13 2843 -e 's;^5\.\([0-6]\)[^0-9]*$;2.\1;' \
michael@13 2844 -e 's;^5\.\([0-9][0-9]*\).*;\1;'`
michael@13 2845 SP="[Sun ]Solaris $v"
michael@13 2846 case "${UNAME_RELEASE}" in
michael@13 2847 4.* ) SC="4.3BSD" ;;
michael@13 2848 5.* ) SC="SVR4" ;;
michael@13 2849 esac
michael@13 2850 ;;
michael@13 2851
michael@13 2852 # SCO UnixWare
michael@13 2853 *:UnixWare:* )
michael@13 2854 # determine architecture
michael@13 2855 AT="${UNAME_MACHINE}"
michael@13 2856 case "${AT}" in
michael@13 2857 i[3-6]86 | ix86at ) AT="iX86" ;;
michael@13 2858 esac
michael@13 2859 AP="${AT}"
michael@13 2860 # determine system
michael@13 2861 v=`/sbin/uname -v`
michael@13 2862 ST="[SCO ]UnixWare ${v}"
michael@13 2863 SP="${ST}"
michael@13 2864 SC="SVR${UNAME_RELEASE}"
michael@13 2865 ;;
michael@13 2866
michael@13 2867 # QNX
michael@13 2868 *:QNX:* )
michael@13 2869 # determine architecture
michael@13 2870 AT="${UNAME_MACHINE}"
michael@13 2871 case "${AT}" in
michael@13 2872 x86pc ) AT="iX86" ;;
michael@13 2873 esac
michael@13 2874 AP="${AT}"
michael@13 2875 # determine system
michael@13 2876 v="${UNAME_RELEASE}"
michael@13 2877 ST="QNX[ Neutrino RTOS] ${v}"
michael@13 2878 v=`echo "${v}" | sed -e 's;^\([0-9][0-9]*\.[0-9][0-9]*\).*$;\1;'`
michael@13 2879 SP="QNX[ Neutrino RTOS] ${v}"
michael@13 2880 SC="QNX"
michael@13 2881 ;;
michael@13 2882
michael@13 2883 # SGI IRIX
michael@13 2884 *:IRIX*:* )
michael@13 2885 # determine architecture
michael@13 2886 AT="${UNAME_MACHINE}"
michael@13 2887 AP="${AT}"
michael@13 2888 case "${AP}:${UNAME_SYSTEM}" in
michael@13 2889 IP*:IRIX64 ) AP="MIPS64" ;;
michael@13 2890 IP*:* ) AP="MIPS" ;;
michael@13 2891 esac
michael@13 2892 AC="${AP}"
michael@13 2893 # determine system
michael@13 2894 v=`(/bin/uname -R || /bin/uname -r) 2>/dev/null | sed -e 's;[0-9.]* ;;'`
michael@13 2895 ST="[SGI ]IRIX ${v}"
michael@13 2896 v="${UNAME_RELEASE}"
michael@13 2897 SP="[SGI ]IRIX ${v}"
michael@13 2898 SC="4.2BSD/SVR3"
michael@13 2899 ;;
michael@13 2900
michael@13 2901 # HP HP-UX
michael@13 2902 *:HP-UX:* )
michael@13 2903 # determine architecture
michael@13 2904 AT="${UNAME_MACHINE}"
michael@13 2905 case "${AT}" in
michael@13 2906 ia64 ) AT="IA64" ;;
michael@13 2907 9000/[34]?? ) AT=M68K ;;
michael@13 2908 9000/[678][0-9][0-9])
michael@13 2909 sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null`
michael@13 2910 sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`
michael@13 2911 case "${sc_cpu_version}" in
michael@13 2912 523 ) AT="HPPA1.0" ;;
michael@13 2913 528 ) AT="HPPA1.1" ;;
michael@13 2914 532 ) AT="HPPA2.0"
michael@13 2915 case "${sc_kernel_bits}" in
michael@13 2916 32 ) AT="${AT}n" ;;
michael@13 2917 64 ) AT="${AT}w" ;;
michael@13 2918 esac
michael@13 2919 ;;
michael@13 2920 esac
michael@13 2921 ;;
michael@13 2922 esac
michael@13 2923 AP="${AT}"
michael@13 2924 case "${AP}" in
michael@13 2925 HPPA* ) AP="HPPA" ;;
michael@13 2926 esac
michael@13 2927 AC="${AP}"
michael@13 2928 # determine system
michael@13 2929 v=`echo "${UNAME_RELEASE}" | sed -e 's;^[^0-9]*;;'`
michael@13 2930 ST="[HP ]<HP>-<UX ${v}>"
michael@13 2931 SP="${ST}"
michael@13 2932 case "${v}" in
michael@13 2933 10.* ) SC="SVR4.2" ;;
michael@13 2934 [7-9]* ) SC="SVR4" ;;
michael@13 2935 esac
michael@13 2936 ;;
michael@13 2937
michael@13 2938 # HP Tru64 (OSF1)
michael@13 2939 *:OSF1:* )
michael@13 2940 # determine architecture
michael@13 2941 AP="${UNAME_MACHINE}"
michael@13 2942 case "${AP}" in
michael@13 2943 alpha ) AP="Alpha" ;;
michael@13 2944 esac
michael@13 2945 alpha_type=`(/usr/sbin/psrinfo -v) 2>/dev/null |\
michael@13 2946 sed -n -e 's/^.*The alpha \([^ ][^ ]*\).*processor.*$/\1/p' | sed -e 'q'`
michael@13 2947 AT="${AP}${alpha_type}"
michael@13 2948 AC="${AP}"
michael@13 2949 # determine system
michael@13 2950 v=`echo "${UNAME_RELEASE}" | sed -e 's;^[VTX];;'`
michael@13 2951 ST="[HP ]Tru64 ${v}"
michael@13 2952 SP="${ST}"
michael@13 2953 SC="OSF1"
michael@13 2954 ;;
michael@13 2955
michael@13 2956 # IBM AIX
michael@13 2957 *:AIX:* )
michael@13 2958 # determine architecture
michael@428 2959 cpu_arch=RS6000
michael@13 2960 if [ -x /usr/sbin/lsdev -a -x /usr/sbin/lsattr ]; then
michael@13 2961 cpu_id=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`
michael@13 2962 if [ ".`/usr/sbin/lsattr -El ${cpu_id} | grep -i powerpc`" != . ]; then
michael@428 2963 cpu_arch=PPC
michael@13 2964 fi
michael@13 2965 elif [ -d /QOpenSys ]; then
michael@13 2966 # IBM i5/OS (aka OS/400) with PASE (Portable Application Solutions Environment)
michael@428 2967 cpu_arch=PPC
michael@13 2968 fi
michael@13 2969 if [ -x /usr/bin/oslevel ]; then
michael@13 2970 os_level=`/usr/bin/oslevel`
michael@13 2971 else
michael@13 2972 os_level="`uname -v`.`uname -r`"
michael@13 2973 fi
michael@13 2974 os_level=`echo "${os_level}" |\
michael@13 2975 sed -e 's;^\([0-9][0-9]*\.[0-9][0-9]*\)\(\.[0-9][0-9]*\)\(.*\)$;<\1>\2[\3];' \
michael@13 2976 -e 's;^\([0-9][0-9]*\.[0-9][0-9]*\)\(.*\)$;<\1>\2;'`
michael@13 2977 AT="${cpu_arch}"
michael@13 2978 AP="${AT}"
michael@13 2979 AC="${AP}"
michael@13 2980 # determine system
michael@13 2981 ST="[IBM ]<AIX >${os_level}"
michael@13 2982 SP="${ST}"
michael@13 2983 case "${os_level}" in
michael@13 2984 [12]* ) SC="SVR2" ;;
michael@13 2985 * ) SC="SVR4" ;;
michael@13 2986 esac
michael@13 2987 ;;
michael@13 2988
michael@13 2989 # Apple Mac OS X (Darwin)
michael@13 2990 *:Darwin:* )
michael@13 2991 # determine architecture
michael@13 2992 AT="`uname -p`"
michael@13 2993 case "${AT}" in
michael@13 2994 powerpc ) AT="PPC" ;;
michael@13 2995 esac
michael@13 2996 AP="${AT}"
michael@13 2997 case "${AP}" in
michael@13 2998 i?86 ) AP="iX86" ;;
michael@13 2999 esac
michael@13 3000 AC="${AP}"
michael@13 3001 # determine system
michael@13 3002 unset v1; unset v2; unset v3
michael@13 3003 eval `echo "${UNAME_RELEASE}" |\
michael@13 3004 sed -e 's/^/#/' \
michael@13 3005 -e 's/^#\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/v1="\1"; v2="\2"; v3="\3"/' \
michael@13 3006 -e 's/^#\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/v1="\1"; v2="\2"/' \
michael@13 3007 -e 's/^#\([0-9][0-9]*\).*$/v1="\1"/' \
michael@13 3008 -e 's/^#.*$/v1="0"/'`
michael@13 3009 ST="[Apple ]<${UNAME_SYSTEM} ${v1}>${v2+.$v2}${v3+[.$v3]}"
michael@13 3010 SP="$ST"
michael@13 3011 v="`(sw_vers) 2>/dev/null | grep 'ProductVersion:' | sed -e 's/^ProductVersion:[^0-9]*\([0-9][0-9.]*\).*$/\1/'`"
michael@13 3012 if [ ".$v" = . ]; then
michael@13 3013 for name in System Server; do
michael@13 3014 if [ -f /System/Library/CoreServices/${name}Version.plist ]; then
michael@13 3015 v=`(defaults read "/System/Library/CoreServices/${name}Version" "ProductVersion") 2>/dev/null`
michael@13 3016 [ ".$v" != . ] && break
michael@13 3017 fi
michael@13 3018 done
michael@13 3019 fi
michael@13 3020 if [ ".$v" != . ]; then
michael@13 3021 unset v1; unset v2; unset v3
michael@13 3022 eval `echo "${v}" |\
michael@13 3023 sed -e 's/^/#/' \
michael@13 3024 -e 's/^#\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/v1="\1"; v2="\2"; v3="\3"/' \
michael@13 3025 -e 's/^#\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/v1="\1"; v2="\2"/' \
michael@13 3026 -e 's/^#\([0-9][0-9]*\).*$/v1="\1"/' \
michael@13 3027 -e 's/^#.*$/v1="0"/'`
michael@13 3028 SP="[Apple ]Mac OS X ${v1}${v2+.$v2}${v3+[.$v3]}"
michael@13 3029 fi
michael@13 3030 SC="4.4BSD/Mach3.0"
michael@13 3031 ;;
michael@13 3032
michael@428 3033 # Windows/Cygwin
michael@428 3034 *:CYGWIN*:* )
michael@428 3035 # determine architecture
michael@428 3036 AT="`uname -m`"
michael@428 3037 AP="${AT}"
michael@428 3038 case "${AP}" in
michael@428 3039 i?86 ) AP="iX86" ;;
michael@428 3040 esac
michael@428 3041 AC="${AP}"
michael@428 3042 # determine system
michael@428 3043 unset v1; unset v2; unset v3
michael@428 3044 eval `echo "${UNAME_RELEASE}" |\
michael@428 3045 sed -e 's/^/#/' \
michael@428 3046 -e 's/^#\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/v1="\1"; v2="\2"; v3="\3"/' \
michael@428 3047 -e 's/^#\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/v1="\1"; v2="\2"/' \
michael@428 3048 -e 's/^#\([0-9][0-9]*\).*$/v1="\1"/' \
michael@428 3049 -e 's/^#.*$/v1="0"/'`
michael@428 3050 ST="Cygwin ${v1}${v2+.$v2}${v3+[.$v3]}"
michael@428 3051 SP="$ST"
michael@428 3052 SC="Windows"
michael@428 3053 v=`echo "${UNAME_SYSTEM}" | sed -e 's/^CYGWIN_NT-//' |\
michael@428 3054 sed -e 's/^/#/' -e 's/^#\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' -e 's/^#.*$//'`
michael@428 3055 case "$v" in
michael@428 3056 4.0 ) SC="$SC[ NT]" ;;
michael@428 3057 5.0 ) SC="$SC[ 2000]" ;;
michael@428 3058 5.1 ) SC="$SC[ XP]" ;;
michael@428 3059 6.0 ) SC="$SC[ Vista]" ;;
michael@428 3060 esac
michael@428 3061 ;;
michael@428 3062
michael@13 3063 # TODO ...ADD YOUR NEW PLATFORM CHECK HERE... TODO
michael@13 3064 # *:XXX:* )
michael@13 3065 # ...
michael@13 3066 # ;;
michael@13 3067
michael@13 3068 # ...A STILL UNKNOWN PLATFORM...
michael@13 3069 * )
michael@13 3070 AT=`echo "${UNAME_MACHINE}" | sed -e "s; ;${opt_C};g"`
michael@13 3071 AP="${AT}"
michael@13 3072 AC="${AP}"
michael@13 3073 v=`echo "${UNAME_RELEASE}" |\
michael@13 3074 sed -e 's/^/#/' \
michael@13 3075 -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' \
michael@13 3076 -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' \
michael@13 3077 -e 's/^#[^0-9]*\([0-9][0-9]*\).*$/\1/' \
michael@13 3078 -e 's/^#.*$/?/'`
michael@13 3079 ST="${UNAME_SYSTEM} ${v}"
michael@13 3080 SP="${ST}"
michael@13 3081 SC="${SP}"
michael@13 3082 ;;
michael@13 3083
michael@13 3084 esac
michael@13 3085
michael@13 3086 # provide fallback values
michael@13 3087 [ ".$AT" = . ] && AT="${AP:-${AC}}"
michael@13 3088 [ ".$AP" = . ] && AP="${AT:-${AC}}"
michael@13 3089 [ ".$AC" = . ] && AC="${AP:-${AT}}"
michael@13 3090 [ ".$ST" = . ] && ST="${SP:-${SC}}"
michael@13 3091 [ ".$SP" = . ] && SP="${ST:-${SC}}"
michael@13 3092 [ ".$SC" = . ] && SC="${SP:-${ST}}"
michael@13 3093
michael@13 3094 # support explicit enforced verbose/concise output
michael@13 3095 if [ ".$opt_v" = .yes ]; then
michael@13 3096 opt_F=`echo ":$opt_F" | sed -e 's/^://' -e 's/%\([as][cpt]\)/%[\1]/g'`
michael@13 3097 elif [ ".$opt_c" = .yes ]; then
michael@13 3098 opt_F=`echo ":$opt_F" | sed -e 's/^://' -e 's/%\([as][cpt]\)/%<\1>/g'`
michael@13 3099 fi
michael@13 3100
michael@13 3101 # provide verbose and concise variants
michael@13 3102 AC_V=""; AC_N=""; AC_C=""
michael@13 3103 AP_V=""; AP_N=""; AP_C=""
michael@13 3104 AT_V=""; AT_N=""; AT_C=""
michael@13 3105 SC_V=""; SC_N=""; SC_C=""
michael@13 3106 SP_V=""; SP_N=""; SP_C=""
michael@13 3107 ST_V=""; ST_N=""; ST_C=""
michael@13 3108 for var_lc in at ap ac st sp sc; do
michael@13 3109 case "$opt_F" in
michael@13 3110 *"%[${val_lc}]"* | *"%{${val_lc}}"* | *"%${val_lc}"* | *"%<${val_lc}>"* )
michael@13 3111 var_uc=`util_upper "$var_lc"`
michael@13 3112 eval "val=\"\$${var_uc}\""
michael@13 3113 val_V=""; val_N=""; val_C=""
michael@13 3114 case "$opt_F" in
michael@13 3115 *"%[${var_lc}]"* )
michael@13 3116 val_V=`echo ":$val" | \
michael@13 3117 sed -e 's/^://' \
michael@13 3118 -e 's;\[\([^]]*\)\];\1;g' \
michael@13 3119 -e 's;<\([^>]*\)>;\1;g' \
michael@13 3120 -e "s; ;§§;g" \
michael@13 3121 -e "s;/;%%;g" \
michael@13 3122 -e "s;§§;${opt_S};g" \
michael@13 3123 -e "s;%%;${opt_C};g"`
michael@13 3124 eval "${var_uc}_V=\"\${val_V}\""
michael@13 3125 ;;
michael@13 3126 esac
michael@13 3127 case "$opt_F" in
michael@13 3128 *"%{${var_lc}}"* | *"%${var_lc}"* )
michael@13 3129 val_N=`echo ":$val" | \
michael@13 3130 sed -e 's/^://' \
michael@13 3131 -e 's;\[\([^]]*\)\];;g' \
michael@13 3132 -e 's;<\([^>]*\)>;\1;g' \
michael@13 3133 -e "s; ;§§;g" \
michael@13 3134 -e "s;/;%%;g" \
michael@13 3135 -e "s;§§;${opt_S};g" \
michael@13 3136 -e "s;%%;${opt_C};g"`
michael@13 3137 eval "${var_uc}_N=\"\${val_N}\""
michael@13 3138 ;;
michael@13 3139 esac
michael@13 3140 case "$opt_F" in
michael@13 3141 *"%<${var_lc}>"* )
michael@13 3142 val_C=`echo ":$val" | \
michael@13 3143 sed -e 's/^://' \
michael@13 3144 -e 's;\[\([^]]*\)\];;g' \
michael@13 3145 -e 's;[^<]*<\([^>]*\)>[^<]*;\1;g' \
michael@13 3146 -e "s; ;§§;g" \
michael@13 3147 -e "s;/;%%;g" \
michael@13 3148 -e "s;§§;${opt_S};g" \
michael@13 3149 -e "s;%%;${opt_C};g"`
michael@13 3150 eval "${var_uc}_C=\"\${val_C}\""
michael@13 3151 ;;
michael@13 3152 esac
michael@13 3153 ;;
michael@13 3154 esac
michael@13 3155 done
michael@13 3156
michael@13 3157 # create output string
michael@13 3158 output=`echo ":$opt_F" |\
michael@13 3159 sed -e "s/^://" \
michael@13 3160 -e "s;%\\[ac\\];${AC_V};g" \
michael@13 3161 -e "s;%{ac};${AC_N};g" \
michael@13 3162 -e "s;%ac;${AC_N};g" \
michael@13 3163 -e "s;%<ac>;${AC_C};g" \
michael@13 3164 -e "s;%\\[ap\\];${AP_V};g" \
michael@13 3165 -e "s;%{ap};${AP_N};g" \
michael@13 3166 -e "s;%ap;${AP_N};g" \
michael@13 3167 -e "s;%<ap>;${AP_C};g" \
michael@13 3168 -e "s;%\\[at\\];${AT_V};g" \
michael@13 3169 -e "s;%{at};${AT_N};g" \
michael@13 3170 -e "s;%at;${AT_N};g" \
michael@13 3171 -e "s;%<at>;${AT_C};g" \
michael@13 3172 -e "s;%\\[sc\\];${SC_V};g" \
michael@13 3173 -e "s;%{sc};${SC_N};g" \
michael@13 3174 -e "s;%sc;${SC_N};g" \
michael@13 3175 -e "s;%<sc>;${SC_C};g" \
michael@13 3176 -e "s;%\\[sp\\];${SP_V};g" \
michael@13 3177 -e "s;%{sp};${SP_N};g" \
michael@13 3178 -e "s;%sp;${SP_N};g" \
michael@13 3179 -e "s;%<sp>;${SP_C};g" \
michael@13 3180 -e "s;%\\[st\\];${ST_V};g" \
michael@13 3181 -e "s;%{st};${ST_N};g" \
michael@13 3182 -e "s;%st;${ST_N};g" \
michael@13 3183 -e "s;%<st>;${ST_C};g" \
michael@13 3184 -e 's/\\\\n/^/g' |\
michael@13 3185 tr '^' '\012'`
michael@13 3186
michael@13 3187 # support lower/upper-case mapping
michael@13 3188 if [ ".$opt_L" = .yes ]; then
michael@13 3189 output=`util_lower "$output"`
michael@13 3190 elif [ ".$opt_U" = .yes ]; then
michael@13 3191 output=`util_upper "$output"`
michael@13 3192 fi
michael@13 3193
michael@13 3194 # display output string
michael@13 3195 if [ ".$opt_n" = .yes ]; then
michael@13 3196 echo . | awk '{ printf("%s", output); }' output="$output"
michael@13 3197 else
michael@13 3198 echo "$output"
michael@13 3199 fi
michael@13 3200
michael@13 3201 shtool_exit 0
michael@13 3202 ;;
michael@13 3203
michael@13 3204 arx )
michael@13 3205 ##
michael@13 3206 ## arx -- Extended archive command
michael@428 3207 ## Copyright (c) 1999-2008 Ralf S. Engelschall <rse@engelschall.com>
michael@13 3208 ##
michael@13 3209
michael@13 3210 ar_prg="$opt_C"
michael@13 3211 ar_cmd="$1"; shift
michael@13 3212 archive="$1"; shift
michael@13 3213 files="$*"
michael@13 3214
michael@13 3215 # walk through the file list and expand archives members
michael@13 3216 ar_tmpdir=`echo $archive | sed -e 's;[^/]*$;.arx;'`
michael@13 3217 nfiles=''
michael@13 3218 if [ ".$files" != . ]; then
michael@13 3219 for file in $files; do
michael@13 3220 if [ ! -f $file ]; then
michael@13 3221 echo "$msgprefix:Error: input file not found: $file" 1>&2
michael@13 3222 shtool_exit 1
michael@13 3223 fi
michael@13 3224 case $file in
michael@13 3225 *.a )
michael@13 3226 if [ ! -d $ar_tmpdir ]; then
michael@13 3227 if [ ".$opt_t" = .yes ]; then
michael@13 3228 echo "mkdir $ar_tmpdir" 1>&2
michael@13 3229 fi
michael@13 3230 mkdir $ar_tmpdir
michael@13 3231 fi
michael@13 3232 case $ar_tmpdir in
michael@13 3233 .arx )
michael@13 3234 from="../$file"
michael@13 3235 ;;
michael@13 3236 * )
michael@13 3237 dir=`echo $file | sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;' -e 's;^$;.;'`
michael@13 3238 base=`echo $file | sed -e 's;.*/\([^/]*\)$;\1;'`
michael@13 3239 from="`cd $dir; pwd`/$base"
michael@13 3240 ;;
michael@13 3241 esac
michael@13 3242 if [ ".$opt_t" = .yes ]; then
michael@13 3243 echo "(cd $ar_tmpdir && $ar_prg x $from)" 1>&2
michael@13 3244 fi
michael@13 3245 (cd $ar_tmpdir && eval $ar_prg x $from)
michael@13 3246 if [ $? -ne 0 ]; then
michael@13 3247 echo "$msgprefix:Error: member extraction failed for archive: $file" 1>&2
michael@13 3248 shtool_exit 1
michael@13 3249 fi
michael@13 3250 for member in - `eval $ar_prg t $file | sed -e '/_\.SYMDEF/d'`; do
michael@13 3251 [ ".$member" = .- ] && continue
michael@13 3252 nfiles="$nfiles $ar_tmpdir/$member"
michael@13 3253 done
michael@13 3254 ;;
michael@13 3255 * )
michael@13 3256 nfiles="$nfiles $file"
michael@13 3257 ;;
michael@13 3258 esac
michael@13 3259 done
michael@13 3260 fi
michael@13 3261
michael@13 3262 # run the final archive command
michael@13 3263 if [ ".$opt_t" = .yes ]; then
michael@13 3264 echo "$ar_prg $ar_cmd $archive $nfiles" 1>&2
michael@13 3265 fi
michael@13 3266 eval $ar_prg $ar_cmd $archive $nfiles
michael@13 3267 if [ $? -ne 0 ]; then
michael@13 3268 echo "$msgprefix:Error: archive command failed" 1>&2
michael@13 3269 shtool_exit $?
michael@13 3270 fi
michael@13 3271
michael@13 3272 # cleanup and die gracefully
michael@13 3273 if [ -d $ar_tmpdir ]; then
michael@13 3274 if [ ".$opt_t" = .yes ]; then
michael@13 3275 echo "rm -rf $ar_tmpdir" 1>&2
michael@13 3276 fi
michael@13 3277 rm -rf $ar_tmpdir
michael@13 3278 fi
michael@13 3279
michael@13 3280 shtool_exit 0
michael@13 3281 ;;
michael@13 3282
michael@13 3283 slo )
michael@13 3284 ##
michael@13 3285 ## slo -- Separate linker options by library class
michael@428 3286 ## Copyright (c) 1998-2008 Ralf S. Engelschall <rse@engelschall.com>
michael@13 3287 ##
michael@13 3288
michael@13 3289 DIFS="$IFS"
michael@13 3290
michael@13 3291 # parse out -L and -l options from command line
michael@13 3292 DIRS=''
michael@13 3293 LIBS=''
michael@13 3294 ARGV=''
michael@13 3295 optprev=''
michael@13 3296 for opt
michael@13 3297 do
michael@13 3298 # concatenate with previous option if exists
michael@13 3299 if [ ".$optprev" != . ]; then
michael@13 3300 opt="${optprev}${opt}";
michael@13 3301 optprev=''
michael@13 3302 fi
michael@13 3303 # remember options for arg if used stand-alone
michael@13 3304 if [ ".$opt" = ".-L" ] || [ ".$opt" = ".-l" ]; then
michael@13 3305 optprev="$opt"
michael@13 3306 continue;
michael@13 3307 fi
michael@13 3308 # split argument into option plus option argument
michael@13 3309 arg="`echo $opt | cut -c3-`"
michael@13 3310 opt="`echo $opt | cut -c1-2`"
michael@13 3311 # store into containers
michael@13 3312 case $opt in
michael@13 3313 -L) DIRS="$DIRS:$arg" ;;
michael@13 3314 -l) LIBS="$LIBS:$arg" ;;
michael@13 3315 *) ARGV="$ARGV $opt" ;;
michael@13 3316 esac
michael@13 3317 done
michael@13 3318
michael@13 3319 # set linker default directories
michael@13 3320 DIRS_DEFAULT='/lib:/usr/lib'
michael@13 3321 if [ ".$LD_LIBRARY_PATH" != . ]; then
michael@13 3322 DIRS_DEFAULT="$DIRS_DEFAULT:$LD_LIBRARY_PATH"
michael@13 3323 fi
michael@13 3324
michael@13 3325 # sort options by class
michael@13 3326 DIRS_OBJ=''
michael@13 3327 LIBS_OBJ=''
michael@13 3328 DIRS_PIC=''
michael@13 3329 LIBS_PIC=''
michael@13 3330 DIRS_DSO=''
michael@13 3331 LIBS_DSO=''
michael@13 3332
michael@13 3333 # for each library...
michael@13 3334 OIFS="$IFS"; IFS=':'
michael@13 3335 for lib in $LIBS; do
michael@13 3336 [ ".$lib" = . ] && continue
michael@13 3337
michael@13 3338 found='no'
michael@13 3339 found_indefdir='no'
michael@13 3340 found_type=''
michael@13 3341 found_dir=''
michael@13 3342
michael@13 3343 # for each directory...
michael@13 3344 OIFS2="$IFS"; IFS=":$DIFS"
michael@13 3345 for dir in ${DIRS} switch-to-defdirs ${DIRS_DEFAULT}; do
michael@13 3346 [ ".$dir" = . ] && continue
michael@13 3347 [ ".$dir" = .switch-to-defdirs ] && found_indefdir=yes
michael@13 3348 [ ! -d $dir ] && continue
michael@13 3349
michael@13 3350 # search the file
michael@13 3351 OIFS3="$IFS"; IFS="$DIFS"
michael@13 3352 for file in '' `cd $dir && env -i /bin/ls lib${lib}.* 2>/dev/null`; do
michael@13 3353 [ ".$file" = . ] && continue
michael@13 3354 case $file in
michael@13 3355 *.so|*.so.[0-9]*|*.sl|*.sl.[0-9]* )
michael@13 3356 found=yes;
michael@13 3357 found_type=DSO;
michael@13 3358 break
michael@13 3359 ;;
michael@13 3360 *.lo|*.la )
michael@13 3361 found=yes;
michael@13 3362 found_type=PIC
michael@13 3363 ;;
michael@13 3364 *.a )
michael@13 3365 if [ ".$found_type" = . ]; then
michael@13 3366 found=yes
michael@13 3367 found_type=OBJ
michael@13 3368 fi
michael@13 3369 ;;
michael@13 3370 esac
michael@13 3371 done
michael@13 3372 IFS="$OIFS3"
michael@13 3373 if [ ".$found" = .yes ]; then
michael@13 3374 found_dir="$dir"
michael@13 3375 break
michael@13 3376 fi
michael@13 3377 done
michael@13 3378 IFS="$OIFS2"
michael@13 3379
michael@13 3380 if [ ".$found" = .yes ]; then
michael@13 3381 if [ ".$found_indefdir" != .yes ]; then
michael@13 3382 eval "dirlist=\"\${DIRS_${found_type}}:\""
michael@13 3383 case "$dirlist" in
michael@13 3384 *:$found_dir:* ) ;;
michael@13 3385 * ) eval "DIRS_${found_type}=\"\$DIRS_${found_type}:${found_dir}\"" ;;
michael@13 3386 esac
michael@13 3387 eval "LIBS_${found_type}=\"\$LIBS_${found_type}:$lib\""
michael@13 3388 else
michael@13 3389 eval "LIBS_${found_type}=\"\$LIBS_${found_type}:$lib\""
michael@13 3390 fi
michael@13 3391 else
michael@13 3392 LIBS_OBJ="$LIBS_OBJ:$lib"
michael@13 3393 #dirlist="`echo $DIRS $DIRS_DEFAULT | sed -e 's/:/ /g'`"
michael@13 3394 #echo "slo:Warning: library \"$lib\" not found in any of the following dirs:" 2>&1
michael@13 3395 #echo "slo:Warning: $dirlist" 1>&1
michael@13 3396 fi
michael@13 3397 done
michael@13 3398 IFS="$OIFS"
michael@13 3399
michael@13 3400 # also pass-through unused dirs even if it's useless
michael@13 3401 OIFS="$IFS"; IFS=':'
michael@13 3402 for dir in $DIRS; do
michael@13 3403 dirlist="${DIRS_OBJ}:${DIRS_PIC}:${DIRS_DSO}:"
michael@13 3404 case "$dirlist" in
michael@13 3405 *:$dir:* ) ;;
michael@13 3406 * ) DIRS_OBJ="$DIRS_OBJ:$dir" ;;
michael@13 3407 esac
michael@13 3408 done
michael@13 3409 IFS="$OIFS"
michael@13 3410
michael@13 3411 # reassemble the options but separated by type
michael@13 3412 for type in OBJ PIC DSO; do
michael@13 3413 OIFS="$IFS"; IFS=':'
michael@13 3414 eval "libs=\"\$LIBS_${type}\""
michael@13 3415 opts=''
michael@13 3416 for lib in $libs; do
michael@13 3417 [ ".$lib" = . ] && continue
michael@13 3418 opts="$opts -l$lib"
michael@13 3419 done
michael@13 3420 eval "LIBS_${type}=\"$opts\""
michael@13 3421
michael@13 3422 eval "dirs=\"\$DIRS_${type}\""
michael@13 3423 opts=''
michael@13 3424 for dir in $dirs; do
michael@13 3425 [ ".$dir" = . ] && continue
michael@13 3426 opts="$opts -L$dir"
michael@13 3427 done
michael@13 3428 eval "DIRS_${type}=\"$opts\""
michael@13 3429 IFS="$OIFS"
michael@13 3430 done
michael@13 3431
michael@13 3432 # give back results
michael@13 3433 for var in ARGV DIRS_OBJ LIBS_OBJ DIRS_PIC LIBS_PIC DIRS_DSO LIBS_DSO; do
michael@13 3434 eval "val=\"\$${var}\""
michael@13 3435 val="`echo $val | sed -e 's/^ *//'`"
michael@13 3436 echo "${opt_p}${var}=\"${val}\""
michael@13 3437 done
michael@13 3438
michael@13 3439 shtool_exit 0
michael@13 3440 ;;
michael@13 3441
michael@13 3442 scpp )
michael@13 3443 ##
michael@13 3444 ## scpp -- Sharing C Pre-Processor
michael@428 3445 ## Copyright (c) 1999-2008 Ralf S. Engelschall <rse@engelschall.com>
michael@13 3446 ##
michael@13 3447
michael@13 3448 srcs="$*"
michael@13 3449 output="${opt_o}.n"
michael@13 3450
michael@13 3451 # find a reasonable Awk
michael@13 3452 awk=''
michael@13 3453 paths=`echo $PATH |\
michael@13 3454 sed -e 's%/*:%:%g' -e 's%/$%%' \
michael@13 3455 -e 's/^:/.:/' -e 's/::/:.:/g' -e 's/:$/:./' \
michael@13 3456 -e 's/:/ /g'`
michael@13 3457 for name in gawk nawk awk; do
michael@13 3458 for path in $paths; do
michael@13 3459 if [ -r "$path/$name" ]; then
michael@13 3460 awk="$path/$name"
michael@13 3461 break
michael@13 3462 fi
michael@13 3463 done
michael@13 3464 if [ ".$awk" != . ]; then
michael@13 3465 break
michael@13 3466 fi
michael@13 3467 done
michael@13 3468 if [ ".$awk" = . ]; then
michael@13 3469 echo "$msgprefix:Error: cannot find a reasonable Awk" 1>&2
michael@13 3470 shtool_exit 1
michael@13 3471 fi
michael@13 3472
michael@13 3473 # parse source file(s)
michael@13 3474 if [ ".$opt_v" = .yes ]; then
michael@13 3475 echo "Parsing:" | $awk '{ printf("%s", $0); }' 1>&2
michael@13 3476 fi
michael@13 3477 for src in $srcs; do
michael@13 3478 if [ ".$opt_v" = .yes ]; then
michael@13 3479 echo $src | $awk '{ printf(" %s", $0); }' 1>&2
michael@13 3480 fi
michael@13 3481 if [ ".$opt_f" != . ]; then
michael@13 3482 inputcmd="sed"
michael@13 3483 OIFS="$IFS"; IFS="$ASC_NL"; set -- $opt_f; IFS="$OIFS"
michael@13 3484 for e
michael@13 3485 do
michael@13 3486 inputcmd="$inputcmd -e '$e'"
michael@13 3487 done
michael@13 3488 inputcmd="$inputcmd '$src'"
michael@13 3489 else
michael@13 3490 inputcmd="cat '$src'"
michael@13 3491 fi
michael@13 3492 eval $inputcmd |\
michael@13 3493 $awk '
michael@13 3494 BEGIN {
michael@13 3495 ln = 0;
michael@13 3496 fln = 0;
michael@13 3497 level = 0;
michael@13 3498 mode = "";
michael@13 3499 store = "";
michael@13 3500 }
michael@13 3501 {
michael@13 3502 ln++;
michael@13 3503 }
michael@13 3504 /^#if.*/ {
michael@13 3505 level++;
michael@13 3506 }
michael@13 3507 /^#if [a-zA-Z_][a-zA-Z0-9_]* *$/ {
michael@13 3508 if ($2 == define) {
michael@13 3509 mode = "D";
michael@13 3510 printf("D:#line %d \"%s\"\n", ln, src);
michael@13 3511 next;
michael@13 3512 }
michael@13 3513 }
michael@13 3514 /^#endif.*/ {
michael@13 3515 level--;
michael@13 3516 if (mode == "D" && level == 0) {
michael@13 3517 mode = "";
michael@13 3518 next;
michael@13 3519 }
michael@13 3520 }
michael@13 3521 /^[a-zA-Z_][a-zA-Z0-9_].*;.*/ {
michael@13 3522 if ($1 == class) {
michael@13 3523 printf("V:#line %d \"%s\"\n", ln, src);
michael@13 3524 printf("V:%s\n", $0);
michael@13 3525 printf("J:%s\n", $0);
michael@13 3526 next;
michael@13 3527 }
michael@13 3528 }
michael@13 3529 /^[a-zA-Z_][a-zA-Z0-9_].*=.*/ {
michael@13 3530 if ($1 == class) {
michael@13 3531 printf("V:#line %d \"%s\"\n", ln, src);
michael@13 3532 printf("V:%s\n", $0);
michael@13 3533 printf("J:%s\n", $0);
michael@13 3534 next;
michael@13 3535 }
michael@13 3536 }
michael@13 3537 /^[a-zA-Z_][a-zA-Z0-9_]*/ {
michael@13 3538 if ($1 == class) {
michael@13 3539 fln = ln;
michael@13 3540 store = $0;
michael@13 3541 mode = "F";
michael@13 3542 next;
michael@13 3543 }
michael@13 3544 }
michael@13 3545 /^\{ *$/ {
michael@13 3546 if (mode == "F") {
michael@13 3547 printf("F:#line %d \"%s\"\n", fln, src);
michael@13 3548 printf("F:%s;\n", store);
michael@13 3549 printf("I:%s;\n", store);
michael@13 3550 store = "";
michael@13 3551 mode = "";
michael@13 3552 next;
michael@13 3553 }
michael@13 3554 }
michael@13 3555 {
michael@13 3556 if (mode == "D")
michael@13 3557 printf("D:%s\n", $0);
michael@13 3558 else if (mode == "F")
michael@13 3559 store = store " " $0;
michael@13 3560 }
michael@13 3561 ' "src=$src" "define=$opt_D" "class=$opt_C" >>$tmpfile
michael@13 3562 done
michael@13 3563 if [ ".$opt_v" = .yes ]; then
michael@13 3564 echo "" 1>&2
michael@13 3565 fi
michael@13 3566
michael@13 3567 # start generating output header
michael@13 3568 echo "/* $opt_o -- autogenerated from $opt_t, DO NOT EDIT! */" >$output
michael@13 3569 echo "#line 1 \"$opt_t\"" >>$output
michael@13 3570 sed <$opt_t -e "1,/^${opt_M} *\$/p" -e 'd' |\
michael@13 3571 sed -e "/^${opt_M} *\$/d" >>$output
michael@13 3572
michael@13 3573 # merge in the define blocks
michael@13 3574 grep '^D:' $tmpfile | sed -e 's/^D://' >>$output
michael@13 3575
michael@13 3576 # generate standard prolog
michael@13 3577 echo "#line 1 \"_ON_THE_FLY_\"" >>$output
michael@13 3578 echo "" >>$output
michael@13 3579 echo "/* make sure the scpp source extensions are skipped */" >>$output
michael@13 3580 echo "#define $opt_D 0" >>$output
michael@13 3581 echo "#define $opt_C /**/" >>$output
michael@13 3582
michael@13 3583 # generate namespace hiding for variables
michael@13 3584 echo "" >>$output
michael@13 3585 echo "/* move intern variables to hidden namespace */" >>$output
michael@13 3586 grep '^J:' $tmpfile | sed >>$output \
michael@13 3587 -e 's/^J://' \
michael@13 3588 -e 's/ */ /g' \
michael@13 3589 -e 's/^[^=;]*[ *]\([a-zA-Z0-9_]*\)\[\];.*$/#define \1 __\1/' \
michael@13 3590 -e 's/^[^=;]*[ *]\([a-zA-Z0-9_]*\)\[\] =.*$/#define \1 __\1/' \
michael@13 3591 -e 's/^[^=;]*[ *]\([a-zA-Z0-9_]*\);.*$/#define \1 __\1/' \
michael@13 3592 -e 's/^[^=;]*[ *]\([a-zA-Z0-9_]*\) =.*$/#define \1 __\1/'
michael@13 3593
michael@13 3594 # generate namespace hiding for functions
michael@13 3595 echo "" >>$output
michael@13 3596 echo "/* move intern functions to hidden namespace */" >>$output
michael@13 3597 grep '^I:' $tmpfile | sed >>$output \
michael@13 3598 -e 's/^I://' \
michael@13 3599 -e 's/\([ (]\) */\1/g' \
michael@13 3600 -e 's/ *\([),]\)/\1/g' \
michael@13 3601 -e 's/^[^(]*[ *]\([a-zA-Z0-9_]*\)(.*$/#define \1 __\1/'
michael@13 3602
michael@13 3603 # generate prototypes for variables
michael@13 3604 echo "" >>$output
michael@13 3605 echo "/* prototypes for intern variables */" >>$output
michael@13 3606 grep '^V:' $tmpfile | sed >>$output \
michael@13 3607 -e 's/^V://' \
michael@13 3608 -e 's/ */ /g' \
michael@13 3609 -e 's/^\([^=;]*[ *][a-zA-Z0-9_]*\[\]\);.*$/\1;/' \
michael@13 3610 -e 's/^\([^=;]*[ *][a-zA-Z0-9_]*\[\]\) =.*$/\1;/' \
michael@13 3611 -e 's/^\([^=;]*[ *][a-zA-Z0-9_]*\);.*$/\1;/' \
michael@13 3612 -e 's/^\([^=;]*[ *][a-zA-Z0-9_]*\) =.*$/\1;/' \
michael@13 3613 -e 's/ ;/;/g' \
michael@13 3614 -e "s/^$opt_C /extern /"
michael@13 3615
michael@13 3616 # generate prototypes for functions
michael@13 3617 echo "" >>$output
michael@13 3618 echo "/* prototypes for intern functions */" >>$output
michael@13 3619 grep '^F:' $tmpfile | sed >>$output \
michael@13 3620 -e 's/^F://' \
michael@13 3621 -e 's/\([ (]\) */\1/g' \
michael@13 3622 -e 's/ *\([),]\)/\1/g' \
michael@13 3623 -e 's/\([* ]\)[a-zA-Z0-9_]*,/\1,/g' \
michael@13 3624 -e 's/\([* ]\)[a-zA-Z0-9_]*);/\1);/g' \
michael@13 3625 -e 's/(\*[a-zA-Z0-9_]*)(/(*)(/g' \
michael@13 3626 -e 's/\([ (]\) */\1/g' \
michael@13 3627 -e 's/ *\([),]\)/\1/g' \
michael@13 3628 -e "s/^$opt_C /extern /"
michael@13 3629
michael@13 3630 # finish generating output header
michael@13 3631 n=`(echo ''; sed <$opt_t -e "1,/^${opt_M} *\$/p" -e 'd') |\
michael@13 3632 wc -l | sed -e 's;^ *\([0-9]*\) *$;\1;'`
michael@13 3633 echo "#line $n \"$opt_t\"" >>$output
michael@13 3634 sed <$opt_t -e "/^${opt_M} *\$/,\$p" -e 'd' |\
michael@13 3635 sed -e "/^${opt_M} *\$/d" >>$output
michael@13 3636
michael@13 3637 # create final output file
michael@13 3638 if [ -f $opt_o ]; then
michael@13 3639 if [ ".$opt_p" = .yes ]; then
michael@13 3640 grep -v '^#line' $opt_o >$tmpfile.o
michael@13 3641 grep -v '^#line' $output >$tmpfile.n
michael@13 3642 out_old="$tmpfile.o"
michael@13 3643 out_new="$tmpfile.n"
michael@13 3644 else
michael@13 3645 out_old="$opt_o"
michael@13 3646 out_new="$output"
michael@13 3647 fi
michael@13 3648 if cmp -s $out_old $out_new; then
michael@13 3649 :
michael@13 3650 else
michael@13 3651 cp $output $opt_o
michael@13 3652 fi
michael@13 3653 else
michael@13 3654 cp $output $opt_o
michael@13 3655 fi
michael@13 3656 rm -f $output
michael@13 3657 rm -f $tmpfile $tmpfile.* >/dev/null 2>&1
michael@13 3658
michael@13 3659 shtool_exit 0
michael@13 3660 ;;
michael@13 3661
michael@13 3662 version )
michael@13 3663 ##
michael@13 3664 ## version -- Maintain a version information file
michael@428 3665 ## Copyright (c) 1994-2008 Ralf S. Engelschall <rse@engelschall.com>
michael@13 3666 ##
michael@13 3667
michael@13 3668 file="$1"
michael@13 3669
michael@13 3670 # determine prefix and name
michael@13 3671 name="$opt_n"
michael@13 3672 prefix="$opt_p"
michael@13 3673
michael@13 3674 # determine current version
michael@13 3675 triple="$opt_s"
michael@13 3676 if [ ".$triple" != . ]; then
michael@13 3677 # use given triple
michael@13 3678 if [ ".`echo $triple | grep '[0-9]*.[0-9]*[sabp.][0-9]*'`" = . ]; then
michael@13 3679 echo "$msgprefix:Error: invalid argument to option \`-s': \`$opt_s'" 1>&2
michael@13 3680 shtool_exit 1
michael@13 3681 fi
michael@13 3682 eval `echo $triple |\
michael@13 3683 sed -e 's%\([0-9]*\)\.\([0-9]*\)\([sabp.]\)\([0-9]*\).*%\
michael@13 3684 ver="\1";rev="\2";typ="\3";lev="\4"%'`
michael@13 3685 tim=calc
michael@13 3686 elif [ -r $file ]; then
michael@13 3687 # determine triple from given file
michael@13 3688 eval `grep 'Version [0-9]*.[0-9]*[sabp.][0-9]* ([0-9]*-[a-zA-Z]*-[0-9]*)' $file |\
michael@13 3689 sed -e 's%.*Version \([0-9]*\)\.\([0-9]*\)\([sabp.]\)\([0-9]*\) (\([0-9]*-[a-zA-Z]*-[0-9]*\)).*%\
michael@13 3690 ver="\1";rev="\2";typ="\3";lev="\4";tim="\5"%' -e 'q'`
michael@13 3691 else
michael@13 3692 # intialise to first version
michael@13 3693 ver=0
michael@13 3694 rev=1
michael@13 3695 typ=.
michael@13 3696 lev=0
michael@13 3697 tim=calc
michael@13 3698 fi
michael@13 3699
michael@13 3700 # determine new version in batch
michael@13 3701 if [ ".$opt_i" != . ]; then
michael@13 3702 case $opt_i in
michael@13 3703 v ) ver=`expr $ver + 1`
michael@13 3704 rev=0
michael@13 3705 lev=0
michael@13 3706 ;;
michael@13 3707 r ) rev=`expr $rev + 1`
michael@13 3708 lev=0
michael@13 3709 ;;
michael@13 3710 l ) lev=`expr $lev + 1`
michael@13 3711 ;;
michael@13 3712 * ) echo "$msgprefix:Error: invalid argument to option \`-i': \`$opt_i'" 1>&2
michael@13 3713 shtool_exit 1
michael@13 3714 ;;
michael@13 3715 esac
michael@13 3716 tim=calc
michael@13 3717 fi
michael@13 3718
michael@13 3719 # determine new version interactively
michael@13 3720 if [ ".$opt_e" = .yes ]; then
michael@13 3721 echo "old version: ${ver}.${rev}${typ}${lev}"
michael@13 3722 while [ 1 ]; do
michael@13 3723 echo dummy | awk '{ printf("new version: "); }'
michael@13 3724 read triple
michael@13 3725 case $triple in
michael@13 3726 [0-9]*.[0-9]*[sabp.][0-9]* )
michael@13 3727 ;;
michael@13 3728 * ) echo "$msgprefix:Error: invalid version string entered: \`$triple'" 1>&2
michael@13 3729 continue
michael@13 3730 ;;
michael@13 3731 esac
michael@13 3732 break
michael@13 3733 done
michael@13 3734 eval `echo $triple |\
michael@13 3735 sed -e 's%^\([0-9]*\)\.\([0-9]*\)\([sabp.]\)\([0-9]*\)$%\
michael@13 3736 ver="\1";rev="\2";typ="\3";lev="\4"%'`
michael@13 3737 tim=calc
michael@13 3738 fi
michael@13 3739
michael@13 3740 # determine hexadecimal and libtool value of version
michael@13 3741 case $typ in
michael@13 3742 a ) typnum=0; levnum=$lev ;;
michael@13 3743 b ) typnum=1; levnum=$lev ;;
michael@13 3744 p | . ) typnum=2; levnum=$lev ;;
michael@13 3745 s ) typnum=15; levnum=255 ;; # snapshots are special
michael@13 3746 esac
michael@13 3747 hex=`echo "$ver:$rev:$typnum:$levnum" |\
michael@13 3748 awk -F: '{ printf("0x%x%02x%1x%02x", $1, $2, $3, $4); }' |\
michael@13 3749 tr 'abcdef' 'ABCDEF'`
michael@13 3750 ltv=`echo "$ver:$rev:$typnum:$levnum" |\
michael@13 3751 awk -F: '{ printf("%d:%d", $1*10 + $2, $3*10 + $4); }'`
michael@13 3752
michael@13 3753 # determine date
michael@13 3754 if [ ".$tim" = .calc ]; then
michael@13 3755 day=`date '+%d'`
michael@13 3756 month=`date '+%m'`
michael@13 3757 year=`date '+%Y' 2>/dev/null`
michael@13 3758 if [ ".$time_year" = . ]; then
michael@13 3759 year=`date '+%y'`
michael@13 3760 case $year in
michael@13 3761 [5-9][0-9]) year="19$year" ;;
michael@13 3762 [0-4][0-9]) year="20$year" ;;
michael@13 3763 esac
michael@13 3764 fi
michael@13 3765 case $month in
michael@13 3766 1|01) month='Jan' ;;
michael@13 3767 2|02) month='Feb' ;;
michael@13 3768 3|03) month='Mar' ;;
michael@13 3769 4|04) month='Apr' ;;
michael@13 3770 5|05) month='May' ;;
michael@13 3771 6|06) month='Jun' ;;
michael@13 3772 7|07) month='Jul' ;;
michael@13 3773 8|08) month='Aug' ;;
michael@13 3774 9|09) month='Sep' ;;
michael@13 3775 10) month='Oct' ;;
michael@13 3776 11) month='Nov' ;;
michael@13 3777 12) month='Dec' ;;
michael@13 3778 esac
michael@13 3779 tim="${day}-${month}-${year}"
michael@13 3780 fi
michael@13 3781
michael@13 3782 # perform result actions
michael@13 3783 mode=show
michael@13 3784 if [ ".$opt_i" != . ]; then
michael@13 3785 mode=edit
michael@13 3786 elif [ ".$opt_e" = .yes ]; then
michael@13 3787 mode=edit
michael@13 3788 elif [ ".$opt_s" != . ]; then
michael@13 3789 mode=edit
michael@13 3790 fi
michael@13 3791 if [ ".$mode" = .show ]; then
michael@13 3792 # just display the current version
michael@13 3793 case $opt_d in
michael@13 3794 short )
michael@13 3795 echo "${ver}.${rev}${typ}${lev}"
michael@13 3796 ;;
michael@13 3797 long )
michael@13 3798 echo "${ver}.${rev}${typ}${lev} ($tim)"
michael@13 3799 ;;
michael@13 3800 libtool )
michael@13 3801 echo "${ltv}"
michael@13 3802 ;;
michael@13 3803 hex )
michael@13 3804 echo "${hex}"
michael@13 3805 ;;
michael@13 3806 * ) echo "$msgprefix:Error: invalid argument to option \`-d': \`$opt_d'" 1>&2
michael@13 3807 shtool_exit 1
michael@13 3808 ;;
michael@13 3809 esac
michael@13 3810 else
michael@13 3811 # update the version file
michael@13 3812
michael@13 3813 # pre-generate various strings
michael@13 3814 triple="${ver}.${rev}${typ}${lev}"
michael@13 3815 vHex="$hex"
michael@13 3816 vShort="${triple}"
michael@13 3817 vLong="${triple} (${tim})"
michael@13 3818 vTeX="This is ${name}, Version ${triple} (${tim})"
michael@13 3819 vGNU="${name} ${triple} (${tim})"
michael@13 3820 vWeb="${name}/${triple}"
michael@13 3821 vSCCS="@(#)${name} ${triple} (${tim})"
michael@13 3822 vRCS="\$Id: ${name} ${triple} (${tim}) \$"
michael@13 3823
michael@13 3824 # determine string out of filename
michael@13 3825 # (do NOT try to optimize this in any way because of portability)
michael@13 3826 filestr=`util_upper "$file" | tr './%+' '____' | sed -e 's/-/_/g'`
michael@13 3827
michael@13 3828 # generate uppercase prefix
michael@13 3829 prefixupper=`util_upper "$prefix"`
michael@13 3830
michael@13 3831 # create the version file according the the selected language
michael@13 3832 echo "new version: ${vLong}"
michael@13 3833
michael@13 3834 cp /dev/null $file
michael@13 3835 case $opt_l in
michael@13 3836 txt )
michael@13 3837 echo >>$file ""
michael@13 3838 echo >>$file " ${file} -- Version Information for ${name} (syntax: Text)"
michael@13 3839 echo >>$file " [automatically generated and maintained by GNU shtool]"
michael@13 3840 echo >>$file ""
michael@13 3841 echo >>$file " $vTeX"
michael@13 3842 echo >>$file ""
michael@13 3843 ;;
michael@13 3844 c )
michael@13 3845 echo >>$file "/*"
michael@13 3846 echo >>$file "** ${file} -- Version Information for ${name} (syntax: C/C++)"
michael@13 3847 echo >>$file "** [automatically generated and maintained by GNU shtool]"
michael@13 3848 echo >>$file "*/"
michael@13 3849 echo >>$file ""
michael@13 3850 echo >>$file "#ifdef _${filestr}_AS_HEADER_"
michael@13 3851 echo >>$file ""
michael@13 3852 echo >>$file "#ifndef _${filestr}_"
michael@13 3853 echo >>$file "#define _${filestr}_"
michael@13 3854 echo >>$file ""
michael@13 3855 echo >>$file "#define ${prefixupper}VERSION ${vHex}"
michael@13 3856 echo >>$file ""
michael@13 3857 echo >>$file "typedef struct {"
michael@13 3858 echo >>$file " const int v_hex;"
michael@13 3859 echo >>$file " const char *v_short;"
michael@13 3860 echo >>$file " const char *v_long;"
michael@13 3861 echo >>$file " const char *v_tex;"
michael@13 3862 echo >>$file " const char *v_gnu;"
michael@13 3863 echo >>$file " const char *v_web;"
michael@13 3864 echo >>$file " const char *v_sccs;"
michael@13 3865 echo >>$file " const char *v_rcs;"
michael@13 3866 echo >>$file "} ${prefix}version_t;"
michael@13 3867 echo >>$file ""
michael@13 3868 echo >>$file "extern ${prefix}version_t ${prefix}version;"
michael@13 3869 echo >>$file ""
michael@13 3870 echo >>$file "#endif /* _${filestr}_ */"
michael@13 3871 echo >>$file ""
michael@13 3872 echo >>$file "#else /* _${filestr}_AS_HEADER_ */"
michael@13 3873 echo >>$file ""
michael@13 3874 echo >>$file "#define _${filestr}_AS_HEADER_"
michael@13 3875 echo >>$file "#include \"${file}\""
michael@13 3876 echo >>$file "#undef _${filestr}_AS_HEADER_"
michael@13 3877 echo >>$file ""
michael@13 3878 echo >>$file "${prefix}version_t ${prefix}version = {"
michael@13 3879 echo >>$file " ${vHex},"
michael@13 3880 echo >>$file " \"${vShort}\","
michael@13 3881 echo >>$file " \"${vLong}\","
michael@13 3882 echo >>$file " \"${vTeX}\","
michael@13 3883 echo >>$file " \"${vGNU}\","
michael@13 3884 echo >>$file " \"${vWeb}\","
michael@13 3885 echo >>$file " \"${vSCCS}\","
michael@13 3886 echo >>$file " \"${vRCS}\""
michael@13 3887 echo >>$file "};"
michael@13 3888 echo >>$file ""
michael@13 3889 echo >>$file "#endif /* _${filestr}_AS_HEADER_ */"
michael@13 3890 echo >>$file ""
michael@13 3891 ;;
michael@13 3892 m4 )
michael@13 3893 echo >>$file "##"
michael@13 3894 echo >>$file "## ${file} -- Version Information for ${name} (syntax: M4)"
michael@13 3895 echo >>$file "## [automatically generated and maintained by GNU shtool]"
michael@13 3896 echo >>$file "##"
michael@13 3897 echo >>$file ""
michael@13 3898 echo >>$file "m4_define([v_hex], [${vHex}])"
michael@13 3899 echo >>$file "m4_define([v_short], [${vShort}])"
michael@13 3900 echo >>$file "m4_define([v_long], [${vLong}])"
michael@13 3901 echo >>$file "m4_define([v_tex], [${vTeX}])"
michael@13 3902 echo >>$file "m4_define([v_gnu], [${vGNU}])"
michael@13 3903 echo >>$file "m4_define([v_web], [${vWeb}])"
michael@13 3904 echo >>$file "m4_define([v_sccs], [${vSCCS}])"
michael@13 3905 echo >>$file "m4_define([v_rcs], [${vRCS}])"
michael@13 3906 echo >>$file ""
michael@13 3907 ;;
michael@13 3908 perl )
michael@13 3909 echo >>$file "##"
michael@13 3910 echo >>$file "## ${file} -- Version Information for ${name} (syntax: Perl)"
michael@13 3911 echo >>$file "## [automatically generated and maintained by GNU shtool]"
michael@13 3912 echo >>$file "##"
michael@13 3913 echo >>$file ""
michael@13 3914 echo >>$file "our \$${prefix}version = {"
michael@13 3915 echo >>$file " 'v_hex' => ${vHex},"
michael@13 3916 echo >>$file " 'v_short' => \"${vShort}\","
michael@13 3917 echo >>$file " 'v_long' => \"${vLong}\","
michael@13 3918 echo >>$file " 'v_tex' => \"${vTeX}\","
michael@13 3919 echo >>$file " 'v_gnu' => \"${vGNU}\","
michael@13 3920 echo >>$file " 'v_web' => \"${vWeb}\","
michael@13 3921 echo >>$file " 'v_sccs' => \"${vSCCS}\","
michael@13 3922 echo >>$file " 'v_rcs' => \"\\${vRCS}/\""
michael@13 3923 echo >>$file "};"
michael@13 3924 echo >>$file ""
michael@13 3925 echo >>$file "1;"
michael@13 3926 echo >>$file ""
michael@13 3927 ;;
michael@13 3928 python )
michael@13 3929 echo >>$file "##"
michael@13 3930 echo >>$file "## ${file} -- Version Information for ${name} (syntax: Python)"
michael@13 3931 echo >>$file "## [automatically generated and maintained by GNU shtool]"
michael@13 3932 echo >>$file "##"
michael@13 3933 echo >>$file ""
michael@13 3934 echo >>$file "class ${prefix}version:"
michael@13 3935 echo >>$file " v_hex = ${vHex}"
michael@13 3936 echo >>$file " v_short = \"${vShort}\""
michael@13 3937 echo >>$file " v_long = \"${vLong}\""
michael@13 3938 echo >>$file " v_tex = \"${vTeX}\""
michael@13 3939 echo >>$file " v_gnu = \"${vGNU}\""
michael@13 3940 echo >>$file " v_web = \"${vWeb}\""
michael@13 3941 echo >>$file " v_sccs = \"${vSCCS}\""
michael@13 3942 echo >>$file " v_rcs = \"${vRCS}\""
michael@13 3943 echo >>$file ""
michael@13 3944 ;;
michael@13 3945 * ) echo "$msgprefix:Error: invalid argument to option \`-l': \`$opt_l'" 1>&2
michael@13 3946 shtool_exit 1
michael@13 3947 ;;
michael@13 3948 esac
michael@13 3949 fi
michael@13 3950
michael@13 3951 shtool_exit 0
michael@13 3952 ;;
michael@13 3953
michael@13 3954 path )
michael@13 3955 ##
michael@13 3956 ## path -- Deal with program paths
michael@428 3957 ## Copyright (c) 1998-2008 Ralf S. Engelschall <rse@engelschall.com>
michael@13 3958 ##
michael@13 3959
michael@13 3960 namelist="$*"
michael@13 3961
michael@13 3962 # check whether the test command supports the -x option
michael@13 3963 if [ -x /bin/sh ] 2>/dev/null; then
michael@13 3964 minusx="-x"
michael@13 3965 else
michael@13 3966 minusx="-r"
michael@13 3967 fi
michael@13 3968
michael@13 3969 # split path string
michael@13 3970 paths="`echo $opt_p |\
michael@13 3971 sed -e 's/^:/.:/' \
michael@13 3972 -e 's/::/:.:/g' \
michael@13 3973 -e 's/:$/:./' \
michael@13 3974 -e 's/:/ /g'`"
michael@13 3975
michael@13 3976 # SPECIAL REQUEST
michael@13 3977 # translate forward to reverse path
michael@13 3978 if [ ".$opt_r" = .yes ]; then
michael@13 3979 if [ "x$namelist" = "x." ]; then
michael@13 3980 rp='.'
michael@13 3981 else
michael@13 3982 rp=''
michael@13 3983 for pe in `IFS="$IFS/"; echo $namelist`; do
michael@13 3984 rp="../$rp"
michael@13 3985 done
michael@13 3986 fi
michael@13 3987 echo $rp | sed -e 's:/$::'
michael@13 3988 shtool_exit 0
michael@13 3989 fi
michael@13 3990
michael@13 3991 # SPECIAL REQUEST
michael@13 3992 # strip out directory or base name
michael@13 3993 if [ ".$opt_d" = .yes ]; then
michael@13 3994 echo "$namelist" |\
michael@13 3995 sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;'
michael@13 3996 shtool_exit 0
michael@13 3997 fi
michael@13 3998 if [ ".$opt_b" = .yes ]; then
michael@13 3999 echo "$namelist" |\
michael@13 4000 sed -e 's;.*/\([^/]*\)$;\1;'
michael@13 4001 shtool_exit 0
michael@13 4002 fi
michael@13 4003
michael@13 4004 # MAGIC SITUATION
michael@13 4005 # Perl Interpreter (perl)
michael@13 4006 if [ ".$opt_m" = .yes ] && [ ".$namelist" = .perl ]; then
michael@13 4007 rm -f $tmpfile >/dev/null 2>&1
michael@13 4008 touch $tmpfile
michael@13 4009 found=0
michael@13 4010 pc=99
michael@13 4011 for dir in $paths; do
michael@13 4012 dir=`echo $dir | sed -e 's;/*$;;'`
michael@13 4013 nc=99
michael@13 4014 for name in perl perl5 miniperl; do
michael@13 4015 if [ $minusx "$dir/$name" ] && [ ! -d "$dir/$name" ]; then
michael@13 4016 perl="$dir/$name"
michael@13 4017 pv=`$perl -e 'printf("%.3f", $]);'`
michael@13 4018 echo "$pv:$pc:$nc:$perl" >>$tmpfile
michael@13 4019 found=1
michael@13 4020 fi
michael@13 4021 nc=`expr $nc - 1`
michael@13 4022 done
michael@13 4023 pc=`expr $pc - 1`
michael@13 4024 done
michael@13 4025 if [ $found = 1 ]; then
michael@13 4026 perl="`cat $tmpfile | sort -r -u | sed -e 'q' | cut -d: -f4`"
michael@13 4027 rm -f $tmpfile >/dev/null 2>&1
michael@13 4028 echo "$perl"
michael@13 4029 shtool_exit 0
michael@13 4030 fi
michael@13 4031 rm -f $tmpfile >/dev/null 2>&1
michael@13 4032 shtool_exit 1
michael@13 4033 fi
michael@13 4034
michael@13 4035 # MAGIC SITUATION
michael@13 4036 # C pre-processor (cpp)
michael@13 4037 if [ ".$opt_m" = .yes ] && [ ".$namelist" = .cpp ]; then
michael@13 4038 echo >$tmpfile.c "#include <assert.h>"
michael@13 4039 echo >>$tmpfile.c "Syntax Error"
michael@13 4040 # 1. try the standard cc -E approach
michael@13 4041 cpp="${CC-cc} -E"
michael@13 4042 (eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out
michael@13 4043 my_error=`grep -v '^ *+' $tmpfile.out`
michael@13 4044 if [ ".$my_error" != . ]; then
michael@13 4045 # 2. try the cc -E approach and GCC's -traditional-ccp option
michael@13 4046 cpp="${CC-cc} -E -traditional-cpp"
michael@13 4047 (eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out
michael@13 4048 my_error=`grep -v '^ *+' $tmpfile.out`
michael@13 4049 if [ ".$my_error" != . ]; then
michael@13 4050 # 3. try a standalone cpp command in path and lib dirs
michael@13 4051 for path in $paths /lib /usr/lib /usr/local/lib; do
michael@13 4052 path=`echo $path | sed -e 's;/*$;;'`
michael@13 4053 if [ $minusx "$path/cpp" ] && [ ! -d "$path/cpp" ]; then
michael@13 4054 cpp="$path/cpp"
michael@13 4055 break
michael@13 4056 fi
michael@13 4057 done
michael@13 4058 if [ ".$cpp" != . ]; then
michael@13 4059 (eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out
michael@13 4060 my_error=`grep -v '^ *+' $tmpfile.out`
michael@13 4061 if [ ".$my_error" != . ]; then
michael@13 4062 # ok, we gave up...
michael@13 4063 cpp=''
michael@13 4064 fi
michael@13 4065 fi
michael@13 4066 fi
michael@13 4067 fi
michael@13 4068 rm -f $tmpfile >/dev/null 2>&1
michael@13 4069 rm -f $tmpfile.c $tmpfile.out >/dev/null 2>&1
michael@13 4070 if [ ".$cpp" != . ]; then
michael@13 4071 echo "$cpp"
michael@13 4072 shtool_exit 0
michael@13 4073 fi
michael@13 4074 shtool_exit 1
michael@13 4075 fi
michael@13 4076
michael@13 4077 # STANDARD SITUATION
michael@13 4078 # iterate over names
michael@13 4079 for name in $namelist; do
michael@13 4080 # iterate over paths
michael@13 4081 for path in $paths; do
michael@13 4082 path=`echo $path | sed -e 's;/*$;;'`
michael@13 4083 if [ $minusx "$path/$name" ] && [ ! -d "$path/$name" ]; then
michael@13 4084 if [ ".$opt_s" != .yes ]; then
michael@13 4085 echo "$path/$name"
michael@13 4086 fi
michael@13 4087 shtool_exit 0
michael@13 4088 fi
michael@13 4089 done
michael@13 4090 done
michael@13 4091
michael@13 4092 shtool_exit 1
michael@13 4093 ;;
michael@13 4094
michael@13 4095 esac
michael@13 4096
michael@13 4097 shtool_exit 0
michael@13 4098

mercurial