michael@13: #!/bin/sh michael@13: ## michael@13: ## GNU shtool -- The GNU Portable Shell Tool michael@13: ## Copyright (c) 1994-2007 Ralf S. Engelschall michael@13: ## michael@13: ## See http://www.gnu.org/software/shtool/ for more information. michael@13: ## See ftp://ftp.gnu.org/gnu/shtool/ for latest version. michael@13: ## michael@13: ## Version: 2.0.7 (19-May-2007) michael@13: ## Contents: all available modules michael@13: ## michael@13: michael@13: ## michael@13: ## This program is free software; you can redistribute it and/or modify michael@13: ## it under the terms of the GNU General Public License as published by michael@13: ## the Free Software Foundation; either version 2 of the License, or michael@13: ## (at your option) any later version. michael@13: ## michael@13: ## This program is distributed in the hope that it will be useful, michael@13: ## but WITHOUT ANY WARRANTY; without even the implied warranty of michael@13: ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU michael@13: ## General Public License for more details. michael@13: ## michael@13: ## You should have received a copy of the GNU General Public License michael@13: ## along with this program; if not, write to the Free Software michael@13: ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, michael@13: ## USA, or contact Ralf S. Engelschall . michael@13: ## michael@13: ## NOTICE: Given that you include this file verbatim into your own michael@13: ## source tree, you are justified in saying that it remains separate michael@13: ## from your package, and that this way you are simply just using GNU michael@13: ## shtool. So, in this situation, there is no requirement that your michael@13: ## package itself is licensed under the GNU General Public License in michael@13: ## order to take advantage of GNU shtool. michael@13: ## michael@13: michael@13: ## michael@13: ## Usage: shtool [] [ [] []] michael@13: ## michael@13: ## Available commands: michael@13: ## echo Print string with optional construct expansion michael@13: ## mdate Pretty-print modification time of a file or dir michael@13: ## table Pretty-print a field-separated list as a table michael@13: ## prop Display progress with a running propeller michael@13: ## move Move files with simultaneous substitution michael@13: ## install Install a program, script or datafile michael@13: ## mkdir Make one or more directories michael@13: ## mkln Make link with calculation of relative paths michael@13: ## mkshadow Make a shadow tree through symbolic links michael@13: ## fixperm Fix file permissions inside a source tree michael@13: ## rotate Logfile rotation michael@13: ## tarball Roll distribution tarballs michael@13: ## subst Apply sed(1) substitution operations michael@13: ## platform Platform Identification Utility michael@13: ## arx Extended archive command michael@13: ## slo Separate linker options by library class michael@13: ## scpp Sharing C Pre-Processor michael@13: ## version Maintain a version information file michael@13: ## path Deal with program paths michael@13: ## michael@13: michael@13: # maximum Bourne-Shell compatibility michael@13: if [ ".$ZSH_VERSION" != . ] && (emulate sh) >/dev/null 2>&1; then michael@13: # reconfigure zsh(1) michael@13: emulate sh michael@13: NULLCMD=: michael@13: alias -g '${1+"$@"}'='"$@"' michael@13: elif [ ".$BASH_VERSION" != . ] && (set -o posix) >/dev/null 2>&1; then michael@13: # reconfigure bash(1) michael@13: set -o posix michael@13: fi michael@13: michael@13: # maximum independence of NLS nuisances michael@13: for var in \ michael@13: LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \ michael@13: LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \ michael@13: LC_TELEPHONE LC_TIME michael@13: do michael@13: if (set +x; test -z "`(eval $var=C; export $var) 2>&1`"); then michael@13: eval $var=C; export $var michael@13: else michael@13: unset $var michael@13: fi michael@13: done michael@13: michael@13: # initial command line handling michael@13: if [ $# -eq 0 ]; then michael@13: echo "$0:Error: invalid command line" 1>&2 michael@13: echo "$0:Hint: run \`$0 -h' for usage" 1>&2 michael@13: exit 1 michael@13: fi michael@13: if [ ".$1" = ".-h" ] || [ ".$1" = ".--help" ]; then michael@13: echo "This is GNU shtool, version 2.0.7 (19-May-2007)" michael@13: echo 'Copyright (c) 1994-2007 Ralf S. Engelschall ' michael@13: echo 'Report bugs to ' michael@13: echo '' michael@13: echo 'Usage: shtool [] [ [] []]' michael@13: echo '' michael@13: echo 'Available global :' michael@13: echo ' -v, --version display shtool version information' michael@13: echo ' -h, --help display shtool usage help page (this one)' michael@13: echo ' -d, --debug display shell trace information' michael@13: echo ' -r, --recreate recreate this shtool script via shtoolize' michael@13: echo '' michael@13: echo 'Available [] []:' michael@13: echo ' echo [-n|--newline] [-e|--expand] [ ...]' michael@13: echo ' mdate [-n|--newline] [-z|--zero] [-s|--shorten] [-d|--digits]' michael@13: echo ' [-f|--field-sep ] [-o|--order ] ' michael@13: echo ' table [-F|--field-sep ] [-w|--width ] [-c|--columns' michael@13: echo ' ] [-s|--strip ] ...' michael@13: echo ' prop [-p|--prefix ]' michael@13: echo ' move [-v|--verbose] [-t|--trace] [-e|--expand] [-p|--preserve]' michael@13: echo ' ' michael@13: echo ' install [-v|--verbose] [-t|--trace] [-d|--mkdir] [-c|--copy]' michael@13: echo ' [-C|--compare-copy] [-s|--strip] [-m|--mode ]' michael@13: echo ' [-o|--owner ] [-g|--group ] [-e|--exec' michael@13: echo ' ] [ ...] ' michael@13: echo ' mkdir [-t|--trace] [-f|--force] [-p|--parents] [-m|--mode' michael@13: echo ' ] [-o|--owner ] [-g|--group ] ' michael@13: echo ' [ ...]' michael@13: echo ' mkln [-t|--trace] [-f|--force] [-s|--symbolic] ' michael@13: echo ' [ ...] ' michael@13: echo ' mkshadow [-v|--verbose] [-t|--trace] [-a|--all] ' michael@13: echo ' fixperm [-v|--verbose] [-t|--trace] [ ...]' michael@13: echo ' rotate [-v|--verbose] [-t|--trace] [-f|--force] [-n|--num-files' michael@13: echo ' ] [-s|--size ] [-c|--copy] [-r|--remove]' michael@13: echo ' [-a|--archive-dir ] [-z|--compress [:]]' michael@13: echo ' [-b|--background] [-d|--delay] [-p|--pad ] [-m|--mode' michael@13: echo ' ] [-o|--owner ] [-g|--group ] [-M|--migrate' michael@13: echo ' ] [-P|--prolog ] [-E|--epilog ] [...]' michael@13: echo ' tarball [-t|--trace] [-v|--verbose] [-o|--output ]' michael@13: echo ' [-c|--compress ] [-d|--directory ] [-u|--user' michael@13: echo ' ] [-g|--group ] [-e|--exclude ]' michael@13: echo ' [ ...]' michael@13: echo ' subst [-v|--verbose] [-t|--trace] [-n|--nop] [-w|--warning]' michael@13: echo ' [-q|--quiet] [-s|--stealth] [-i|--interactive] [-b|--backup' michael@13: echo ' ] [-e|--exec ] [-f|--file ] []' michael@13: echo ' [...]' michael@13: echo ' platform [-F|--format ] [-S|--sep ] [-C|--conc' michael@13: echo ' ] [-L|--lower] [-U|--upper] [-v|--verbose]' michael@13: echo ' [-c|--concise] [-n|--no-newline] [-t|--type ]' michael@13: echo ' [-V|--version] [-h|--help]' michael@13: echo ' arx [-t|--trace] [-C|--command ] [' michael@13: echo ' ...]' michael@13: echo ' slo [-p|--prefix ] -- -L -l [-L -l' michael@13: echo ' ...]' michael@13: echo ' scpp [-v|--verbose] [-p|--preserve] [-f|--filter ]' michael@13: echo ' [-o|--output ] [-t|--template ] [-M|--mark' michael@13: echo ' ] [-D|--define ] [-C|--class ]' michael@13: echo ' [ ...]' michael@13: echo ' version [-l|--language ] [-n|--name ] [-p|--prefix' michael@13: echo ' ] [-s|--set ] [-e|--edit] [-i|--increase' michael@13: echo ' ] [-d|--display ] ' michael@13: echo ' path [-s|--suppress] [-r|--reverse] [-d|--dirname] [-b|--basename]' michael@13: echo ' [-m|--magic] [-p|--path ] [ ...]' michael@13: echo '' michael@13: exit 0 michael@13: fi michael@13: if [ ".$1" = ".-v" ] || [ ".$1" = ".--version" ]; then michael@13: echo "GNU shtool 2.0.7 (19-May-2007)" michael@13: exit 0 michael@13: fi michael@13: if [ ".$1" = ".-r" ] || [ ".$1" = ".--recreate" ]; then michael@13: shtoolize -oshtool all michael@13: exit 0 michael@13: fi michael@13: if [ ".$1" = ".-d" ] || [ ".$1" = ".--debug" ]; then michael@13: shift michael@13: set -x michael@13: fi michael@13: name=`echo "$0" | sed -e 's;.*/\([^/]*\)$;\1;' -e 's;-sh$;;' -e 's;\.sh$;;'` michael@13: case "$name" in michael@13: echo|mdate|table|prop|move|install|mkdir|mkln|mkshadow|fixperm|rotate|tarball|subst|platform|arx|slo|scpp|version|path ) michael@13: # implicit tool command selection michael@13: tool="$name" michael@13: ;; michael@13: * ) michael@13: # explicit tool command selection michael@13: tool="$1" michael@13: shift michael@13: ;; michael@13: esac michael@13: arg_spec="" michael@13: opt_spec="" michael@13: gen_tmpfile=no michael@13: michael@13: ## michael@13: ## DISPATCH INTO SCRIPT PROLOG michael@13: ## michael@13: michael@13: case $tool in michael@13: echo ) michael@13: str_tool="echo" michael@13: str_usage="[-n|--newline] [-e|--expand] [ ...]" michael@13: arg_spec="0+" michael@13: opt_spec="n.e." michael@13: opt_alias="n:newline,e:expand" michael@13: opt_n=no michael@13: opt_e=no michael@13: ;; michael@13: mdate ) michael@13: str_tool="mdate" michael@13: str_usage="[-n|--newline] [-z|--zero] [-s|--shorten] [-d|--digits] [-f|--field-sep ] [-o|--order ] " michael@13: arg_spec="1=" michael@13: opt_spec="n.z.s.d.f:o:" michael@13: opt_alias="n:newline,z:zero,s:shorten,d:digits,f:field-sep,o:order" michael@13: opt_n=no michael@13: opt_z=no michael@13: opt_s=no michael@13: opt_d=no michael@13: opt_f=" " michael@13: opt_o="dmy" michael@13: ;; michael@13: table ) michael@13: str_tool="table" michael@13: str_usage="[-F|--field-sep ] [-w|--width ] [-c|--columns ] [-s|--strip ] ..." michael@13: arg_spec="1+" michael@13: opt_spec="F:w:c:s:" michael@13: opt_alias="F:field-sep,w:width,c:columns,s:strip" michael@13: opt_F=":" michael@13: opt_w=15 michael@13: opt_c=3 michael@13: opt_s=79 michael@13: ;; michael@13: prop ) michael@13: str_tool="prop" michael@13: str_usage="[-p|--prefix ]" michael@13: arg_spec="0=" michael@13: opt_spec="p:" michael@13: opt_alias="p:prefix" michael@13: opt_p="" michael@13: ;; michael@13: move ) michael@13: str_tool="move" michael@13: str_usage="[-v|--verbose] [-t|--trace] [-e|--expand] [-p|--preserve] " michael@13: arg_spec="2=" michael@13: opt_spec="v.t.e.p." michael@13: opt_alias="v:verbose,t:trace,e:expand,p:preserve" michael@13: opt_v=no michael@13: opt_t=no michael@13: opt_e=no michael@13: opt_p=no michael@13: ;; michael@13: install ) michael@13: str_tool="install" michael@13: str_usage="[-v|--verbose] [-t|--trace] [-d|--mkdir] [-c|--copy] [-C|--compare-copy] [-s|--strip] [-m|--mode ] [-o|--owner ] [-g|--group ] [-e|--exec ] [ ...] " michael@13: arg_spec="1+" michael@13: opt_spec="v.t.d.c.C.s.m:o:g:e+" michael@13: 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: opt_v=no michael@13: opt_t=no michael@13: opt_d=no michael@13: opt_c=no michael@13: opt_C=no michael@13: opt_s=no michael@13: opt_m="0755" michael@13: opt_o="" michael@13: opt_g="" michael@13: opt_e="" michael@13: ;; michael@13: mkdir ) michael@13: str_tool="mkdir" michael@13: str_usage="[-t|--trace] [-f|--force] [-p|--parents] [-m|--mode ] [-o|--owner ] [-g|--group ] [ ...]" michael@13: arg_spec="1+" michael@13: opt_spec="t.f.p.m:o:g:" michael@13: opt_alias="t:trace,f:force,p:parents,m:mode,o:owner,g:group" michael@13: opt_t=no michael@13: opt_f=no michael@13: opt_p=no michael@13: opt_m="" michael@13: opt_o="" michael@13: opt_g="" michael@13: ;; michael@13: mkln ) michael@13: str_tool="mkln" michael@13: str_usage="[-t|--trace] [-f|--force] [-s|--symbolic] [ ...] " michael@13: arg_spec="2+" michael@13: opt_spec="t.f.s." michael@13: opt_alias="t:trace,f:force,s:symbolic" michael@13: opt_t=no michael@13: opt_f=no michael@13: opt_s=no michael@13: ;; michael@13: mkshadow ) michael@13: str_tool="mkshadow" michael@13: str_usage="[-v|--verbose] [-t|--trace] [-a|--all] " michael@13: arg_spec="2=" michael@13: opt_spec="v.t.a." michael@13: opt_alias="v:verbose,t:trace,a:all" michael@13: opt_v=no michael@13: opt_t=no michael@13: opt_a=no michael@13: ;; michael@13: fixperm ) michael@13: str_tool="fixperm" michael@13: str_usage="[-v|--verbose] [-t|--trace] [ ...]" michael@13: arg_spec="1+" michael@13: opt_spec="v.t." michael@13: opt_alias="v:verbose,t:trace" michael@13: opt_v=no michael@13: opt_t=no michael@13: ;; michael@13: rotate ) michael@13: str_tool="rotate" michael@13: str_usage="[-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 ] [-m|--mode ] [-o|--owner ] [-g|--group ] [-M|--migrate ] [-P|--prolog ] [-E|--epilog ] [...]" michael@13: arg_spec="1+" michael@13: opt_spec="v.t.f.n:s:c.r.a:z:b.d.p:o:g:m:M:P:E:" michael@13: 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: opt_v=no michael@13: opt_t=no michael@13: opt_f=no michael@13: opt_n=10 michael@13: opt_s="" michael@13: opt_c=no michael@13: opt_r=no michael@13: opt_a="" michael@13: opt_z="" michael@13: opt_b=no michael@13: opt_d=no michael@13: opt_p=1 michael@13: opt_o="" michael@13: opt_g="" michael@13: opt_m="" michael@13: opt_M="" michael@13: opt_P="" michael@13: opt_E="" michael@13: ;; michael@13: tarball ) michael@13: str_tool="tarball" michael@13: str_usage="[-t|--trace] [-v|--verbose] [-o|--output ] [-c|--compress ] [-d|--directory ] [-u|--user ] [-g|--group ] [-e|--exclude ] [ ...]" michael@13: gen_tmpfile=yes michael@13: arg_spec="1+" michael@13: opt_spec="t.v.o:c:d:u:g:e:" michael@13: opt_alias="t:trace,v:verbose,o:output,c:compress,d:directory,u:user,g:group,e:exclude" michael@13: opt_t=no michael@13: opt_v=no michael@13: opt_o="" michael@13: opt_c="" michael@13: opt_d="" michael@13: opt_u="" michael@13: opt_g="" michael@13: opt_e="CVS,\\.cvsignore,\\.svn,\\.[oa]\$" michael@13: ;; michael@13: subst ) michael@13: str_tool="subst" michael@13: str_usage="[-v|--verbose] [-t|--trace] [-n|--nop] [-w|--warning] [-q|--quiet] [-s|--stealth] [-i|--interactive] [-b|--backup ] [-e|--exec ] [-f|--file ] [] [...]" michael@13: gen_tmpfile=yes michael@13: arg_spec="0+" michael@13: opt_spec="v.t.n.w.q.s.i.b:e+f:" michael@13: opt_alias="v:verbose,t:trace,n:nop,w:warning,q:quiet,s:stealth,i:interactive,b:backup,e:exec,f:file" michael@13: opt_v=no michael@13: opt_t=no michael@13: opt_n=no michael@13: opt_w=no michael@13: opt_q=no michael@13: opt_s=no michael@13: opt_i=no michael@13: opt_b="" michael@13: opt_e="" michael@13: opt_f="" michael@13: ;; michael@13: platform ) michael@13: str_tool="platform" michael@13: str_usage="[-F|--format ] [-S|--sep ] [-C|--conc ] [-L|--lower] [-U|--upper] [-v|--verbose] [-c|--concise] [-n|--no-newline] [-t|--type ] [-V|--version] [-h|--help]" michael@13: arg_spec="0=" michael@13: opt_spec="F:S:C:L.U.v.c.n.t:d.V.h." michael@13: 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: opt_F="%{sp} (%{ap})" michael@13: opt_S=" " michael@13: opt_C="/" michael@13: opt_L=no michael@13: opt_U=no michael@13: opt_t="" michael@13: opt_v=no michael@13: opt_c=no michael@13: opt_n=no michael@13: opt_V=no michael@13: opt_h=no michael@13: ;; michael@13: arx ) michael@13: str_tool="arx" michael@13: str_usage="[-t|--trace] [-C|--command ] [ ...]" michael@13: arg_spec="2+" michael@13: opt_spec="t.C:" michael@13: opt_alias="t:trace,C:command" michael@13: opt_t=no michael@13: opt_C="ar" michael@13: ;; michael@13: slo ) michael@13: str_tool="slo" michael@13: str_usage="[-p|--prefix ] -- -L -l [-L -l ...]" michael@13: arg_spec="1+" michael@13: opt_spec="p:" michael@13: opt_alias="p:prefix" michael@13: opt_p="SLO_" michael@13: ;; michael@13: scpp ) michael@13: str_tool="scpp" michael@13: str_usage="[-v|--verbose] [-p|--preserve] [-f|--filter ] [-o|--output ] [-t|--template ] [-M|--mark ] [-D|--define ] [-C|--class ] [ ...]" michael@13: gen_tmpfile=yes michael@13: arg_spec="1+" michael@13: opt_spec="v.p.f+o:t:M:D:C:" michael@13: opt_alias="v:verbose,p:preserve,f:filter,o:output,t:template,M:mark,D:define,C:class" michael@13: opt_v=no michael@13: opt_p=no michael@13: opt_f="" michael@13: opt_o="lib.h" michael@13: opt_t="lib.h.in" michael@13: opt_M="%%MARK%%" michael@13: opt_D="cpp" michael@13: opt_C="intern" michael@13: ;; michael@13: version ) michael@13: str_tool="version" michael@13: str_usage="[-l|--language ] [-n|--name ] [-p|--prefix ] [-s|--set ] [-e|--edit] [-i|--increase ] [-d|--display ] " michael@13: arg_spec="1=" michael@13: opt_spec="l:n:p:s:i:e.d:" michael@13: opt_alias="l:language,n:name,p:prefix,s:set,e:edit,i:increase,d:display" michael@13: opt_l="txt" michael@13: opt_n="unknown" michael@13: opt_p="" michael@13: opt_s="" michael@13: opt_e="no" michael@13: opt_i="" michael@13: opt_d="short" michael@13: ;; michael@13: path ) michael@13: str_tool="path" michael@13: str_usage="[-s|--suppress] [-r|--reverse] [-d|--dirname] [-b|--basename] [-m|--magic] [-p|--path ] [ ...]" michael@13: gen_tmpfile=yes michael@13: arg_spec="1+" michael@13: opt_spec="s.r.d.b.m.p:" michael@13: opt_alias="s:suppress,r:reverse,d:dirname,b:basename,m:magic,p:path" michael@13: opt_s=no michael@13: opt_r=no michael@13: opt_d=no michael@13: opt_b=no michael@13: opt_m=no michael@13: opt_p="$PATH" michael@13: ;; michael@13: -* ) michael@13: echo "$0:Error: unknown option \`$tool'" 2>&1 michael@13: echo "$0:Hint: run \`$0 -h' for usage" 2>&1 michael@13: exit 1 michael@13: ;; michael@13: * ) michael@13: echo "$0:Error: unknown command \`$tool'" 2>&1 michael@13: echo "$0:Hint: run \`$0 -h' for usage" 2>&1 michael@13: exit 1 michael@13: ;; michael@13: esac michael@13: michael@13: ## michael@13: ## COMMON UTILITY CODE michael@13: ## michael@13: michael@13: # commonly used ASCII values michael@13: ASC_TAB=" " michael@13: ASC_NL=" michael@13: " michael@13: michael@13: # determine name of tool michael@13: if [ ".$tool" != . ]; then michael@13: # used inside shtool script michael@13: toolcmd="$0 $tool" michael@13: toolcmdhelp="shtool $tool" michael@13: msgprefix="shtool:$tool" michael@13: else michael@13: # used as standalone script michael@13: toolcmd="$0" michael@13: toolcmdhelp="sh $0" michael@13: msgprefix="$str_tool" michael@13: fi michael@13: michael@13: # parse argument specification string michael@13: eval `echo $arg_spec |\ michael@13: sed -e 's/^\([0-9]*\)\([+=]\)/arg_NUMS=\1; arg_MODE=\2/'` michael@13: michael@13: # parse option specification string michael@13: eval `echo h.$opt_spec |\ michael@13: sed -e 's/\([a-zA-Z0-9]\)\([.:+]\)/opt_MODE_\1=\2;/g'` michael@13: michael@13: # parse option alias string michael@13: eval `echo h:help,$opt_alias |\ michael@13: sed -e 's/-/_/g' -e 's/\([a-zA-Z0-9]\):\([^,]*\),*/opt_ALIAS_\2=\1;/g'` michael@13: michael@13: # interate over argument line michael@13: opt_PREV='' michael@13: while [ $# -gt 0 ]; do michael@13: # special option stops processing michael@13: if [ ".$1" = ".--" ]; then michael@13: shift michael@13: break michael@13: fi michael@13: michael@13: # determine option and argument michael@13: opt_ARG_OK=no michael@13: if [ ".$opt_PREV" != . ]; then michael@13: # merge previous seen option with argument michael@13: opt_OPT="$opt_PREV" michael@13: opt_ARG="$1" michael@13: opt_ARG_OK=yes michael@13: opt_PREV='' michael@13: else michael@13: # split argument into option and argument michael@13: case "$1" in michael@13: --[a-zA-Z0-9]*=*) michael@13: eval `echo "x$1" |\ michael@13: sed -e 's/^x--\([a-zA-Z0-9-]*\)=\(.*\)$/opt_OPT="\1";opt_ARG="\2"/'` michael@13: opt_STR=`echo $opt_OPT | sed -e 's/-/_/g'` michael@13: eval "opt_OPT=\${opt_ALIAS_${opt_STR}-${opt_OPT}}" michael@13: ;; michael@13: --[a-zA-Z0-9]*) michael@13: opt_OPT=`echo "x$1" | cut -c4-` michael@13: opt_STR=`echo $opt_OPT | sed -e 's/-/_/g'` michael@13: eval "opt_OPT=\${opt_ALIAS_${opt_STR}-${opt_OPT}}" michael@13: opt_ARG='' michael@13: ;; michael@13: -[a-zA-Z0-9]*) michael@13: eval `echo "x$1" |\ michael@13: sed -e 's/^x-\([a-zA-Z0-9]\)/opt_OPT="\1";/' \ michael@13: -e 's/";\(.*\)$/"; opt_ARG="\1"/'` michael@13: ;; michael@13: -[a-zA-Z0-9]) michael@13: opt_OPT=`echo "x$1" | cut -c3-` michael@13: opt_ARG='' michael@13: ;; michael@13: *) michael@13: break michael@13: ;; michael@13: esac michael@13: fi michael@13: michael@13: # eat up option michael@13: shift michael@13: michael@13: # determine whether option needs an argument michael@13: eval "opt_MODE=\$opt_MODE_${opt_OPT}" michael@13: if [ ".$opt_ARG" = . ] && [ ".$opt_ARG_OK" != .yes ]; then michael@13: if [ ".$opt_MODE" = ".:" ] || [ ".$opt_MODE" = ".+" ]; then michael@13: opt_PREV="$opt_OPT" michael@13: continue michael@13: fi michael@13: fi michael@13: michael@13: # process option michael@13: case $opt_MODE in michael@13: '.' ) michael@13: # boolean option michael@13: eval "opt_${opt_OPT}=yes" michael@13: ;; michael@13: ':' ) michael@13: # option with argument (multiple occurances override) michael@13: eval "opt_${opt_OPT}=\"\$opt_ARG\"" michael@13: ;; michael@13: '+' ) michael@13: # option with argument (multiple occurances append) michael@13: eval "opt_${opt_OPT}=\"\$opt_${opt_OPT}\${ASC_NL}\$opt_ARG\"" michael@13: ;; michael@13: * ) michael@13: echo "$msgprefix:Error: unknown option: \`$opt_OPT'" 1>&2 michael@13: echo "$msgprefix:Hint: run \`$toolcmdhelp -h' or \`man shtool' for details" 1>&2 michael@13: exit 1 michael@13: ;; michael@13: esac michael@13: done michael@13: if [ ".$opt_PREV" != . ]; then michael@13: echo "$msgprefix:Error: missing argument to option \`$opt_PREV'" 1>&2 michael@13: echo "$msgprefix:Hint: run \`$toolcmdhelp -h' or \`man shtool' for details" 1>&2 michael@13: exit 1 michael@13: fi michael@13: michael@13: # process help option michael@13: if [ ".$opt_h" = .yes ]; then michael@13: echo "Usage: $toolcmdhelp $str_usage" michael@13: exit 0 michael@13: fi michael@13: michael@13: # complain about incorrect number of arguments michael@13: case $arg_MODE in michael@13: '=' ) michael@13: if [ $# -ne $arg_NUMS ]; then michael@13: echo "$msgprefix:Error: invalid number of arguments (exactly $arg_NUMS expected)" 1>&2 michael@13: echo "$msgprefix:Hint: run \`$toolcmd -h' or \`man shtool' for details" 1>&2 michael@13: exit 1 michael@13: fi michael@13: ;; michael@13: '+' ) michael@13: if [ $# -lt $arg_NUMS ]; then michael@13: echo "$msgprefix:Error: invalid number of arguments (at least $arg_NUMS expected)" 1>&2 michael@13: echo "$msgprefix:Hint: run \`$toolcmd -h' or \`man shtool' for details" 1>&2 michael@13: exit 1 michael@13: fi michael@13: ;; michael@13: esac michael@13: michael@13: # establish a temporary file on request michael@13: if [ ".$gen_tmpfile" = .yes ]; then michael@13: # create (explicitly) secure temporary directory michael@13: if [ ".$TMPDIR" != . ]; then michael@13: tmpdir="$TMPDIR" michael@13: elif [ ".$TEMPDIR" != . ]; then michael@13: tmpdir="$TEMPDIR" michael@13: else michael@13: tmpdir="/tmp" michael@13: fi michael@13: tmpdir="$tmpdir/.shtool.$$" michael@13: ( umask 077 michael@13: rm -rf "$tmpdir" >/dev/null 2>&1 || true michael@13: mkdir "$tmpdir" >/dev/null 2>&1 michael@13: if [ $? -ne 0 ]; then michael@13: echo "$msgprefix:Error: failed to create temporary directory \`$tmpdir'" 1>&2 michael@13: exit 1 michael@13: fi michael@13: ) michael@13: michael@13: # create (implicitly) secure temporary file michael@13: tmpfile="$tmpdir/shtool.tmp" michael@13: touch "$tmpfile" michael@13: fi michael@13: michael@13: # utility function: map string to lower case michael@13: util_lower () { michael@13: echo "$1" | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' michael@13: } michael@13: michael@13: # utility function: map string to upper case michael@13: util_upper () { michael@13: echo "$1" | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' michael@13: } michael@13: michael@13: # cleanup procedure michael@13: shtool_exit () { michael@13: rc="$1" michael@13: if [ ".$gen_tmpfile" = .yes ]; then michael@13: rm -rf "$tmpdir" >/dev/null 2>&1 || true michael@13: fi michael@13: exit $rc michael@13: } michael@13: michael@13: ## michael@13: ## DISPATCH INTO SCRIPT BODY michael@13: ## michael@13: michael@13: case $tool in michael@13: michael@13: echo ) michael@13: ## michael@13: ## echo -- Print string with optional construct expansion michael@13: ## Copyright (c) 1998-2007 Ralf S. Engelschall michael@13: ## michael@13: michael@13: text="$*" michael@13: michael@13: # check for broken escape sequence expansion michael@13: seo='' michael@13: bytes=`echo '\1' | wc -c | awk '{ printf("%s", $1); }'` michael@13: if [ ".$bytes" != .3 ]; then michael@13: bytes=`echo -E '\1' | wc -c | awk '{ printf("%s", $1); }'` michael@13: if [ ".$bytes" = .3 ]; then michael@13: seo='-E' michael@13: fi michael@13: fi michael@13: michael@13: # check for existing -n option (to suppress newline) michael@13: minusn='' michael@13: bytes=`echo -n 123 2>/dev/null | wc -c | awk '{ printf("%s", $1); }'` michael@13: if [ ".$bytes" = .3 ]; then michael@13: minusn='-n' michael@13: fi michael@13: michael@13: # determine terminal bold sequence michael@13: term_bold='' michael@13: term_norm='' michael@13: if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%[Bb]'`" != . ]; then michael@13: case $TERM in michael@13: # for the most important terminal types we directly know the sequences michael@13: xterm|xterm*|vt220|vt220*) michael@13: term_bold=`awk 'BEGIN { printf("%c%c%c%c", 27, 91, 49, 109); }' /dev/null` michael@13: term_norm=`awk 'BEGIN { printf("%c%c%c", 27, 91, 109); }' /dev/null` michael@13: ;; michael@13: vt100|vt100*|cygwin) michael@13: term_bold=`awk 'BEGIN { printf("%c%c%c%c%c%c", 27, 91, 49, 109, 0, 0); }' /dev/null` michael@13: term_norm=`awk 'BEGIN { printf("%c%c%c%c%c", 27, 91, 109, 0, 0); }' /dev/null` michael@13: ;; michael@13: # for all others, we try to use a possibly existing `tput' or `tcout' utility michael@13: * ) michael@13: paths=`echo $PATH | sed -e 's/:/ /g'` michael@13: for tool in tput tcout; do michael@13: for dir in $paths; do michael@13: if [ -r "$dir/$tool" ]; then michael@13: for seq in bold md smso; do # 'smso' is last michael@13: bold="`$dir/$tool $seq 2>/dev/null`" michael@13: if [ ".$bold" != . ]; then michael@13: term_bold="$bold" michael@13: break michael@13: fi michael@13: done michael@13: if [ ".$term_bold" != . ]; then michael@13: for seq in sgr0 me rmso init reset; do # 'reset' is last michael@13: norm="`$dir/$tool $seq 2>/dev/null`" michael@13: if [ ".$norm" != . ]; then michael@13: term_norm="$norm" michael@13: break michael@13: fi michael@13: done michael@13: fi michael@13: break michael@13: fi michael@13: done michael@13: if [ ".$term_bold" != . ] && [ ".$term_norm" != . ]; then michael@13: break; michael@13: fi michael@13: done michael@13: ;; michael@13: esac michael@13: if [ ".$term_bold" = . ] || [ ".$term_norm" = . ]; then michael@13: echo "$msgprefix:Warning: unable to determine terminal sequence for bold mode" 1>&2 michael@13: term_bold='' michael@13: term_norm='' michael@13: fi michael@13: fi michael@13: michael@13: # determine user name michael@13: username='' michael@13: if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%[uUgG]'`" != . ]; then michael@13: username="`(id -un) 2>/dev/null`" michael@13: if [ ".$username" = . ]; then michael@13: str="`(id) 2>/dev/null`" michael@13: if [ ".`echo $str | grep '^uid[ ]*=[ ]*[0-9]*('`" != . ]; then michael@13: username=`echo $str | sed -e 's/^uid[ ]*=[ ]*[0-9]*(//' -e 's/).*$//'` michael@13: fi michael@13: if [ ".$username" = . ]; then michael@13: username="$LOGNAME" michael@13: if [ ".$username" = . ]; then michael@13: username="$USER" michael@13: if [ ".$username" = . ]; then michael@13: username="`(whoami) 2>/dev/null |\ michael@13: awk '{ printf("%s", $1); }'`" michael@13: if [ ".$username" = . ]; then michael@13: username="`(who am i) 2>/dev/null |\ michael@13: awk '{ printf("%s", $1); }'`" michael@13: if [ ".$username" = . ]; then michael@13: username='unknown' michael@13: fi michael@13: fi michael@13: fi michael@13: fi michael@13: fi michael@13: fi michael@13: fi michael@13: michael@13: # determine user id michael@13: userid='' michael@13: if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%U'`" != . ]; then michael@13: userid="`(id -u) 2>/dev/null`" michael@13: if [ ".$userid" = . ]; then michael@13: userid="`(id -u ${username}) 2>/dev/null`" michael@13: if [ ".$userid" = . ]; then michael@13: str="`(id) 2>/dev/null`" michael@13: if [ ".`echo $str | grep '^uid[ ]*=[ ]*[0-9]*('`" != . ]; then michael@13: userid=`echo $str | sed -e 's/^uid[ ]*=[ ]*//' -e 's/(.*$//'` michael@13: fi michael@13: if [ ".$userid" = . ]; then michael@13: userid=`(getent passwd ${username}) 2>/dev/null | \ michael@13: sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'` michael@13: if [ ".$userid" = . ]; then michael@13: userid=`grep "^${username}:" /etc/passwd 2>/dev/null | \ michael@13: sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'` michael@13: if [ ".$userid" = . ]; then michael@13: userid=`(ypmatch "${username}" passwd; nismatch "${username}" passwd) 2>/dev/null | \ michael@13: sed -e 'q' | sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'` michael@13: if [ ".$userid" = . ]; then michael@13: userid=`(nidump passwd . | grep "^${username}:") 2>/dev/null | \ michael@13: sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'` michael@13: if [ ".$userid" = . ]; then michael@13: userid='?' michael@13: fi michael@13: fi michael@13: fi michael@13: fi michael@13: fi michael@13: fi michael@13: fi michael@13: fi michael@13: michael@13: # determine (primary) group id michael@13: groupid='' michael@13: if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%[gG]'`" != . ]; then michael@13: groupid="`(id -g ${username}) 2>/dev/null`" michael@13: if [ ".$groupid" = . ]; then michael@13: str="`(id) 2>/dev/null`" michael@13: if [ ".`echo $str | grep 'gid[ ]*=[ ]*[0-9]*('`" != . ]; then michael@13: groupid=`echo $str | sed -e 's/^.*gid[ ]*=[ ]*//' -e 's/(.*$//'` michael@13: fi michael@13: if [ ".$groupid" = . ]; then michael@13: groupid=`(getent passwd ${username}) 2>/dev/null | \ michael@13: sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'` michael@13: if [ ".$groupid" = . ]; then michael@13: groupid=`grep "^${username}:" /etc/passwd 2>/dev/null | \ michael@13: sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'` michael@13: if [ ".$groupid" = . ]; then michael@13: groupid=`(ypmatch "${username}" passwd; nismatch "${username}" passwd) 2>/dev/null | \ michael@13: sed -e 'q' | sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'` michael@13: if [ ".$groupid" = . ]; then michael@13: groupid=`(nidump passwd . | grep "^${username}:") 2>/dev/null | \ michael@13: sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'` michael@13: if [ ".$groupid" = . ]; then michael@13: groupid='?' michael@13: fi michael@13: fi michael@13: fi michael@13: fi michael@13: fi michael@13: fi michael@13: fi michael@13: michael@13: # determine (primary) group name michael@13: groupname='' michael@13: if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%g'`" != . ]; then michael@13: groupname="`(id -gn ${username}) 2>/dev/null`" michael@13: if [ ".$groupname" = . ]; then michael@13: str="`(id) 2>/dev/null`" michael@13: if [ ".`echo $str | grep 'gid[ ]*=[ ]*[0-9]*('`" != . ]; then michael@13: groupname=`echo $str | sed -e 's/^.*gid[ ]*=[ ]*[0-9]*(//' -e 's/).*$//'` michael@13: fi michael@13: if [ ".$groupname" = . ]; then michael@13: groupname=`(getent group) 2>/dev/null | \ michael@13: grep "^[^:]*:[^:]*:${groupid}:" | \ michael@13: sed -e 's/:.*$//'` michael@13: if [ ".$groupname" = . ]; then michael@13: groupname=`grep "^[^:]*:[^:]*:${groupid}:" /etc/group 2>/dev/null | \ michael@13: sed -e 's/:.*$//'` michael@13: if [ ".$groupname" = . ]; then michael@13: groupname=`(ypcat group; niscat group) 2>/dev/null | \ michael@13: sed -e 'q' | grep "^[^:]*:[^:]*:${groupid}:" | \ michael@13: sed -e 's/:.*$//'` michael@13: if [ ".$groupname" = . ]; then michael@13: groupname=`(nidump group .) 2>/dev/null | \ michael@13: grep "^[^:]*:[^:]*:${groupid}:" | \ michael@13: sed -e 's/:.*$//'` michael@13: if [ ".$groupname" = . ]; then michael@13: groupname='?' michael@13: fi michael@13: fi michael@13: fi michael@13: fi michael@13: fi michael@13: fi michael@13: fi michael@13: michael@13: # determine host and domain name michael@13: hostname='' michael@13: domainname='' michael@13: if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%h'`" != . ]; then michael@13: hostname="`(uname -n) 2>/dev/null |\ michael@13: awk '{ printf("%s", $1); }'`" michael@13: if [ ".$hostname" = . ]; then michael@13: hostname="`(hostname) 2>/dev/null |\ michael@13: awk '{ printf("%s", $1); }'`" michael@13: if [ ".$hostname" = . ]; then michael@13: hostname='unknown' michael@13: fi michael@13: fi michael@13: case $hostname in michael@13: *.* ) michael@13: domainname=".`echo $hostname | cut -d. -f2-`" michael@13: hostname="`echo $hostname | cut -d. -f1`" michael@13: ;; michael@13: esac michael@13: fi michael@13: if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%d'`" != . ]; then michael@13: if [ ".$domainname" = . ]; then michael@13: if [ -f /etc/resolv.conf ]; then michael@13: domainname="`grep '^[ ]*domain' /etc/resolv.conf | sed -e 'q' |\ michael@13: sed -e 's/.*domain//' \ michael@13: -e 's/^[ ]*//' -e 's/^ *//' -e 's/^ *//' \ michael@13: -e 's/^\.//' -e 's/^/./' |\ michael@13: awk '{ printf("%s", $1); }'`" michael@13: if [ ".$domainname" = . ]; then michael@13: domainname="`grep '^[ ]*search' /etc/resolv.conf | sed -e 'q' |\ michael@13: sed -e 's/.*search//' \ michael@13: -e 's/^[ ]*//' -e 's/^ *//' -e 's/^ *//' \ michael@13: -e 's/ .*//' -e 's/ .*//' \ michael@13: -e 's/^\.//' -e 's/^/./' |\ michael@13: awk '{ printf("%s", $1); }'`" michael@13: fi michael@13: fi michael@13: fi michael@13: fi michael@13: michael@13: # determine current time michael@13: time_day='' michael@13: time_month='' michael@13: time_year='' michael@13: time_monthname='' michael@13: if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%[DMYm]'`" != . ]; then michael@13: time_day=`date '+%d'` michael@13: time_month=`date '+%m'` michael@13: time_year=`date '+%Y' 2>/dev/null` michael@13: if [ ".$time_year" = . ]; then michael@13: time_year=`date '+%y'` michael@13: case $time_year in michael@13: [5-9][0-9]) time_year="19$time_year" ;; michael@13: [0-4][0-9]) time_year="20$time_year" ;; michael@13: esac michael@13: fi michael@13: case $time_month in michael@13: 1|01) time_monthname='Jan' ;; michael@13: 2|02) time_monthname='Feb' ;; michael@13: 3|03) time_monthname='Mar' ;; michael@13: 4|04) time_monthname='Apr' ;; michael@13: 5|05) time_monthname='May' ;; michael@13: 6|06) time_monthname='Jun' ;; michael@13: 7|07) time_monthname='Jul' ;; michael@13: 8|08) time_monthname='Aug' ;; michael@13: 9|09) time_monthname='Sep' ;; michael@13: 10) time_monthname='Oct' ;; michael@13: 11) time_monthname='Nov' ;; michael@13: 12) time_monthname='Dec' ;; michael@13: esac michael@13: fi michael@13: michael@13: # expand special ``%x'' constructs michael@13: if [ ".$opt_e" = .yes ]; then michael@13: text=`echo $seo "$text" |\ michael@13: sed -e "s/%B/${term_bold}/g" \ michael@13: -e "s/%b/${term_norm}/g" \ michael@13: -e "s/%u/${username}/g" \ michael@13: -e "s/%U/${userid}/g" \ michael@13: -e "s/%g/${groupname}/g" \ michael@13: -e "s/%G/${groupid}/g" \ michael@13: -e "s/%h/${hostname}/g" \ michael@13: -e "s/%d/${domainname}/g" \ michael@13: -e "s/%D/${time_day}/g" \ michael@13: -e "s/%M/${time_month}/g" \ michael@13: -e "s/%Y/${time_year}/g" \ michael@13: -e "s/%m/${time_monthname}/g" 2>/dev/null` michael@13: fi michael@13: michael@13: # create output michael@13: if [ .$opt_n = .no ]; then michael@13: echo $seo "$text" michael@13: else michael@13: # the harder part: echo -n is best, because michael@13: # awk may complain about some \xx sequences. michael@13: if [ ".$minusn" != . ]; then michael@13: echo $seo $minusn "$text" michael@13: else michael@13: echo dummy | awk '{ printf("%s", TEXT); }' TEXT="$text" michael@13: fi michael@13: fi michael@13: michael@13: shtool_exit 0 michael@13: ;; michael@13: michael@13: mdate ) michael@13: ## michael@13: ## mdate -- Pretty-print modification time of a file or dir michael@13: ## Copyright (c) 1995-1997 Free Software Foundation, Inc. michael@13: ## Copyright (c) 1998-2007 Ralf S. Engelschall michael@13: ## michael@13: michael@13: fod="$1" michael@13: case "$opt_o" in michael@13: [dmy][dmy][dmy] ) michael@13: ;; michael@13: * ) echo "$msgprefix:Error: invalid argument to option \`-o': $opt_o" 1>&2 michael@13: shtool_exit 1 michael@13: ;; michael@13: esac michael@13: if [ ! -r "$fod" ]; then michael@13: echo "$msgprefix:Error: file or directory not found: $fod" 1>&2 michael@13: shtool_exit 1 michael@13: fi michael@13: michael@13: # GNU ls changes its time format in response to the TIME_STYLE michael@13: # variable. Since we cannot assume "unset" works, revert this michael@13: # variable to its documented default. michael@13: if [ ".$TIME_STYLE" != . ]; then michael@13: TIME_STYLE=posix-long-iso michael@13: export TIME_STYLE michael@13: fi michael@13: michael@13: # get the extended ls output of the file or directory. michael@13: if /bin/ls -L /dev/null >/dev/null 2>&1; then michael@13: set - x`/bin/ls -L -l -d $fod` michael@13: else michael@13: set - x`/bin/ls -l -d $fod` michael@13: fi michael@13: michael@13: # The month is at least the fourth argument michael@13: # (3 shifts here, the next inside the loop). michael@13: shift; shift; shift michael@13: michael@13: # Find the month. Next argument is day, followed by the year or time. michael@13: month="" michael@13: while [ ".$month" = . ]; do michael@13: shift michael@13: case $1 in michael@13: Jan) month=January; nummonth=1 ;; michael@13: Feb) month=February; nummonth=2 ;; michael@13: Mar) month=March; nummonth=3 ;; michael@13: Apr) month=April; nummonth=4 ;; michael@13: May) month=May; nummonth=5 ;; michael@13: Jun) month=June; nummonth=6 ;; michael@13: Jul) month=July; nummonth=7 ;; michael@13: Aug) month=August; nummonth=8 ;; michael@13: Sep) month=September; nummonth=9 ;; michael@13: Oct) month=October; nummonth=10 ;; michael@13: Nov) month=November; nummonth=11 ;; michael@13: Dec) month=December; nummonth=12 ;; michael@13: esac michael@13: done michael@13: day="$2" michael@13: year="$3" michael@13: michael@13: # We finally have to deal with the problem that the "ls" output michael@13: # gives either the time of the day or the year. michael@13: case $year in michael@13: *:*) michael@13: this_year=`date '+%Y' 2>/dev/null` michael@13: if [ ".$this_year" = . ]; then michael@13: this_year=`date '+%y'` michael@13: case $this_year in michael@13: [5-9][0-9]) this_year="19$this_year" ;; michael@13: [0-4][0-9]) this_year="20$this_year" ;; michael@13: esac michael@13: fi michael@13: # for the following months of the last year the time notation michael@13: # is usually also used for files modified in the last year. michael@13: this_month=`date '+%m'` michael@13: if (expr $nummonth \> $this_month) >/dev/null; then michael@13: this_year=`expr $this_year - 1` michael@13: fi michael@13: year="$this_year" michael@13: ;; michael@13: esac michael@13: michael@13: # Optionally fill day and month with leeding zeros michael@13: if [ ".$opt_z" = .yes ]; then michael@13: case $day in michael@13: [0-9][0-9] ) ;; michael@13: [0-9] ) day="0$day" ;; michael@13: esac michael@13: case $nummonth in michael@13: [0-9][0-9] ) ;; michael@13: [0-9] ) nummonth="0$nummonth" ;; michael@13: esac michael@13: fi michael@13: michael@13: # Optionally use digits for month michael@13: if [ ".$opt_d" = .yes ]; then michael@13: month="$nummonth" michael@13: fi michael@13: michael@13: # Optionally shorten the month name to three characters michael@13: if [ ".$opt_s" = .yes ]; then michael@13: month=`echo $month | cut -c1-3` michael@13: fi michael@13: michael@13: # Output the resulting date string michael@13: echo dummy | awk '{ michael@13: for (i = 0; i < 3; i++) { michael@13: now = substr(order, 1, 1); michael@13: order = substr(order, 2); michael@13: if (now == "d") michael@13: out = day; michael@13: else if (now == "m") michael@13: out = month; michael@13: else if (now == "y") michael@13: out = year; michael@13: if (i < 2) michael@13: printf("%s%s", out, field); michael@13: else michael@13: printf("%s", out); michael@13: } michael@13: if (newline != "yes") michael@13: printf("\n"); michael@13: }' "day=$day" "month=$month" "year=$year" \ michael@13: "field=$opt_f" "order=$opt_o" "newline=$opt_n" michael@13: michael@13: shtool_exit 0 michael@13: ;; michael@13: michael@13: table ) michael@13: ## michael@13: ## table -- Pretty-print a field-separated list as a table michael@13: ## Copyright (c) 1998-2007 Ralf S. Engelschall michael@13: ## michael@13: michael@13: if [ $opt_c -gt 4 ]; then michael@13: echo "$msgprefix:Error: Invalid number of colums (1..4 allowed only)" 1>&2 michael@13: shtool_exit 1 michael@13: fi michael@13: case "x$opt_F" in michael@13: x? ) ;; michael@13: * ) echo "$msgprefix:Error: Invalid separator (one char allowed only)" 1>&2; shtool_exit 1 ;; michael@13: esac michael@13: michael@13: # split the list into a table michael@13: list=` michael@13: IFS="$opt_F" michael@13: for entry in $*; do michael@13: if [ ".$entry" != . ]; then michael@13: echo "$entry" michael@13: fi michael@13: done |\ michael@13: awk " michael@13: BEGIN { list = \"\"; n = 0; } michael@13: { michael@13: list = list \\$1; michael@13: n = n + 1; michael@13: if (n < $opt_c) { michael@13: list = list \":\"; michael@13: } michael@13: if (n == $opt_c) { michael@13: list = list \"\\n\"; michael@13: n = 0; michael@13: } michael@13: } michael@13: END { print list; } michael@13: " michael@13: ` michael@13: michael@13: # format table cells and make sure table michael@13: # doesn't exceed maximum width michael@13: OIFS="$IFS" michael@13: IFS=' michael@13: ' michael@13: for entry in $list; do michael@13: case $opt_c in michael@13: 1 ) eval "echo \"\${entry}\" | awk -F: '{ printf(\"%-${opt_w}s\\n\", \$1); }'" ;; michael@13: 2 ) eval "echo \"\${entry}\" | awk -F: '{ printf(\"%-${opt_w}s %-${opt_w}s\\n\", \$1, \$2); }'" ;; michael@13: 3 ) eval "echo \"\${entry}\" | awk -F: '{ printf(\"%-${opt_w}s %-${opt_w}s %-${opt_w}s\\n\", \$1, \$2, \$3); }'" ;; michael@13: 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: esac michael@13: done |\ michael@13: awk "{ michael@13: if (length(\$0) > $opt_s) { michael@13: printf(\"%s\\n\", substr(\$0, 0, $opt_s-1)); michael@13: } else { michael@13: print \$0; michael@13: } michael@13: }" michael@13: IFS="$OIFS" michael@13: michael@13: shtool_exit 0 michael@13: ;; michael@13: michael@13: prop ) michael@13: ## michael@13: ## prop -- Display progress with a running propeller michael@13: ## Copyright (c) 1998-2007 Ralf S. Engelschall michael@13: ## michael@13: michael@13: perl='' michael@13: for dir in `echo $PATH | sed -e 's/:/ /g'` .; do michael@13: if [ -f "$dir/perl" ]; then michael@13: perl="$dir/perl" michael@13: break michael@13: fi michael@13: done michael@13: if [ ".$perl" != . ]; then michael@13: # Perl is preferred because writing to STDERR in michael@13: # Perl really writes immediately as one would expect michael@13: $perl -e ' michael@13: @p = ("|","/","-","\\"); michael@13: $i = 0; michael@13: while () { michael@13: printf(STDERR "\r%s...%s\b", $ARGV[0], $p[$i++]); michael@13: $i = 0 if ($i > 3); michael@13: } michael@13: printf(STDERR "\r%s \n", $ARGV[0]); michael@13: ' "$opt_p" michael@13: else michael@13: # But if Perl doesn't exists we use Awk even michael@13: # some Awk's buffer even the /dev/stderr writing :-( michael@13: awk ' michael@13: BEGIN { michael@13: split("|#/#-#\\", p, "#"); michael@13: i = 1; michael@13: } michael@13: { michael@13: printf("\r%s%c\b", prefix, p[i++]) > "/dev/stderr"; michael@13: if (i > 4) { i = 1; } michael@13: } michael@13: END { michael@13: printf("\r%s \n", prefix) > "/dev/stderr"; michael@13: } michael@13: ' "prefix=$opt_p" michael@13: fi michael@13: michael@13: shtool_exit 0 michael@13: ;; michael@13: michael@13: move ) michael@13: ## michael@13: ## move -- Move files with simultaneous substitution michael@13: ## Copyright (c) 1999-2007 Ralf S. Engelschall michael@13: ## michael@13: michael@13: src="$1" michael@13: dst="$2" michael@13: michael@13: # consistency checks michael@13: if [ ".$src" = . ] || [ ".$dst" = . ]; then michael@13: echo "$msgprefix:Error: Invalid arguments" 1>&2 michael@13: shtool_exit 1 michael@13: fi michael@13: if [ ".$src" = ".$dst" ]; then michael@13: echo "$msgprefix:Error: Source and destination files are the same" 1>&2 michael@13: shtool_exit 1 michael@13: fi michael@13: expsrc="$src" michael@13: if [ ".$opt_e" = .yes ]; then michael@13: expsrc="`echo $expsrc`" michael@13: fi michael@13: if [ ".$opt_e" = .yes ]; then michael@13: if [ ".`echo "$src" | sed -e 's;^.*\\*.*$;;'`" = ".$src" ]; then michael@13: echo "$msgprefix:Error: Source doesn't contain wildcard ('*'): $dst" 1>&2 michael@13: shtool_exit 1 michael@13: fi michael@13: if [ ".`echo "$dst" | sed -e 's;^.*%[1-9].*$;;'`" = ".$dst" ]; then michael@13: echo "$msgprefix:Error: Destination doesn't contain substitution ('%N'): $dst" 1>&2 michael@13: shtool_exit 1 michael@13: fi michael@13: if [ ".$expsrc" = ".$src" ]; then michael@13: echo "$msgprefix:Error: Sources not found or no asterisk : $src" 1>&2 michael@13: shtool_exit 1 michael@13: fi michael@13: else michael@13: if [ ! -r "$src" ]; then michael@13: echo "$msgprefix:Error: Source not found: $src" 1>&2 michael@13: shtool_exit 1 michael@13: fi michael@13: fi michael@13: michael@13: # determine substitution patterns michael@13: if [ ".$opt_e" = .yes ]; then michael@13: srcpat=`echo "$src" | sed -e 's/\\./\\\\./g' -e 's/;/\\;/g' -e 's;\\*;\\\\(.*\\\\);g'` michael@13: dstpat=`echo "$dst" | sed -e 's;%\([1-9]\);\\\\\1;g'` michael@13: fi michael@13: michael@13: # iterate over source(s) michael@13: for onesrc in $expsrc; do michael@13: if [ .$opt_e = .yes ]; then michael@13: onedst=`echo $onesrc | sed -e "s;$srcpat;$dstpat;"` michael@13: else michael@13: onedst="$dst" michael@13: fi michael@13: errorstatus=0 michael@13: if [ ".$opt_v" = .yes ]; then michael@13: echo "$onesrc -> $onedst" michael@13: fi michael@13: if [ ".$opt_p" = .yes ]; then michael@13: if [ -r $onedst ]; then michael@13: if cmp -s $onesrc $onedst; then michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "rm -f $onesrc" 1>&2 michael@13: fi michael@13: rm -f $onesrc || errorstatus=$? michael@13: else michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "mv -f $onesrc $onedst" 1>&2 michael@13: fi michael@13: mv -f $onesrc $onedst || errorstatus=$? michael@13: fi michael@13: else michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "mv -f $onesrc $onedst" 1>&2 michael@13: fi michael@13: mv -f $onesrc $onedst || errorstatus=$? michael@13: fi michael@13: else michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "mv -f $onesrc $onedst" 1>&2 michael@13: fi michael@13: mv -f $onesrc $onedst || errorstatus=$? michael@13: fi michael@13: if [ $errorstatus -ne 0 ]; then michael@13: break; michael@13: fi michael@13: done michael@13: michael@13: shtool_exit $errorstatus michael@13: ;; michael@13: michael@13: install ) michael@13: ## michael@13: ## install -- Install a program, script or datafile michael@13: ## Copyright (c) 1997-2007 Ralf S. Engelschall michael@13: ## michael@13: michael@13: # special case: "shtool install -d [...]" internally michael@13: # maps to "shtool mkdir -f -p -m 755 [...]" michael@13: if [ "$opt_d" = yes ]; then michael@13: cmd="$0 mkdir -f -p -m 755" michael@13: if [ ".$opt_o" != . ]; then michael@13: cmd="$cmd -o '$opt_o'" michael@13: fi michael@13: if [ ".$opt_g" != . ]; then michael@13: cmd="$cmd -g '$opt_g'" michael@13: fi michael@13: if [ ".$opt_v" = .yes ]; then michael@13: cmd="$cmd -v" michael@13: fi michael@13: if [ ".$opt_t" = .yes ]; then michael@13: cmd="$cmd -t" michael@13: fi michael@13: for dir in "$@"; do michael@13: eval "$cmd $dir" || shtool_exit $? michael@13: done michael@13: shtool_exit 0 michael@13: fi michael@13: michael@13: # determine source(s) and destination michael@13: argc=$# michael@13: srcs="" michael@13: while [ $# -gt 1 ]; do michael@13: srcs="$srcs $1" michael@13: shift michael@13: done michael@13: dstpath="$1" michael@13: michael@13: # type check for destination michael@13: dstisdir=0 michael@13: if [ -d $dstpath ]; then michael@13: dstpath=`echo "$dstpath" | sed -e 's:/$::'` michael@13: dstisdir=1 michael@13: fi michael@13: michael@13: # consistency check for destination michael@13: if [ $argc -gt 2 ] && [ $dstisdir = 0 ]; then michael@13: echo "$msgprefix:Error: multiple sources require destination to be directory" 1>&2 michael@13: shtool_exit 1 michael@13: fi michael@13: michael@13: # iterate over all source(s) michael@13: for src in $srcs; do michael@13: dst=$dstpath michael@13: michael@13: # if destination is a directory, append the input filename michael@13: if [ $dstisdir = 1 ]; then michael@13: dstfile=`echo "$src" | sed -e 's;.*/\([^/]*\)$;\1;'` michael@13: dst="$dst/$dstfile" michael@13: fi michael@13: michael@13: # check for correct arguments michael@13: if [ ".$src" = ".$dst" ]; then michael@13: echo "$msgprefix:Warning: source and destination are the same - skipped" 1>&2 michael@13: continue michael@13: fi michael@13: if [ -d "$src" ]; then michael@13: echo "$msgprefix:Warning: source \`$src' is a directory - skipped" 1>&2 michael@13: continue michael@13: fi michael@13: michael@13: # make a temp file name in the destination directory michael@13: dsttmp=`echo $dst |\ michael@13: sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;' -e 's;^$;.;' \ michael@13: -e "s;\$;/#INST@$$#;"` michael@13: michael@13: # verbosity michael@13: if [ ".$opt_v" = .yes ]; then michael@13: echo "$src -> $dst" 1>&2 michael@13: fi michael@13: michael@13: # copy or move the file name to the temp name michael@13: # (because we might be not allowed to change the source) michael@13: if [ ".$opt_C" = .yes ]; then michael@13: opt_c=yes michael@13: fi michael@13: if [ ".$opt_c" = .yes ]; then michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "cp $src $dsttmp" 1>&2 michael@13: fi michael@13: cp "$src" "$dsttmp" || shtool_exit $? michael@13: else michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "mv $src $dsttmp" 1>&2 michael@13: fi michael@13: mv "$src" "$dsttmp" || shtool_exit $? michael@13: fi michael@13: michael@13: # adjust the target file michael@13: if [ ".$opt_e" != . ]; then michael@13: sed='sed' michael@13: OIFS="$IFS"; IFS="$ASC_NL"; set -- $opt_e; IFS="$OIFS" michael@13: for e michael@13: do michael@13: sed="$sed -e '$e'" michael@13: done michael@13: cp "$dsttmp" "$dsttmp.old" michael@13: chmod u+w $dsttmp michael@13: eval "$sed <$dsttmp.old >$dsttmp" || shtool_exit $? michael@13: rm -f $dsttmp.old michael@13: fi michael@13: if [ ".$opt_s" = .yes ]; then michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "strip $dsttmp" 1>&2 michael@13: fi michael@13: strip $dsttmp || shtool_exit $? michael@13: fi michael@13: if [ ".$opt_o" != . ]; then michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "chown $opt_o $dsttmp" 1>&2 michael@13: fi michael@13: chown $opt_o $dsttmp || shtool_exit $? michael@13: fi michael@13: if [ ".$opt_g" != . ]; then michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "chgrp $opt_g $dsttmp" 1>&2 michael@13: fi michael@13: chgrp $opt_g $dsttmp || shtool_exit $? michael@13: fi michael@13: if [ ".$opt_m" != ".-" ]; then michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "chmod $opt_m $dsttmp" 1>&2 michael@13: fi michael@13: chmod $opt_m $dsttmp || shtool_exit $? michael@13: fi michael@13: michael@13: # determine whether to do a quick install michael@13: # (has to be done _after_ the strip was already done) michael@13: quick=no michael@13: if [ ".$opt_C" = .yes ]; then michael@13: if [ -r $dst ]; then michael@13: if cmp -s "$src" "$dst"; then michael@13: quick=yes michael@13: fi michael@13: fi michael@13: fi michael@13: michael@13: # finally, install the file to the real destination michael@13: if [ $quick = yes ]; then michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "rm -f $dsttmp" 1>&2 michael@13: fi michael@13: rm -f $dsttmp michael@13: else michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "rm -f $dst && mv $dsttmp $dst" 1>&2 michael@13: fi michael@13: rm -f $dst && mv $dsttmp $dst michael@13: fi michael@13: done michael@13: michael@13: shtool_exit 0 michael@13: ;; michael@13: michael@13: mkdir ) michael@13: ## michael@13: ## mkdir -- Make one or more directories michael@13: ## Copyright (c) 1996-2007 Ralf S. Engelschall michael@13: ## michael@13: michael@13: errstatus=0 michael@13: for p in ${1+"$@"}; do michael@13: # if the directory already exists... michael@13: if [ -d "$p" ]; then michael@13: if [ ".$opt_f" = .no ] && [ ".$opt_p" = .no ]; then michael@13: echo "$msgprefix:Error: directory already exists: $p" 1>&2 michael@13: errstatus=1 michael@13: break michael@13: else michael@13: continue michael@13: fi michael@13: fi michael@13: # if the directory has to be created... michael@13: if [ ".$opt_p" = .no ]; then michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "mkdir $p" 1>&2 michael@13: fi michael@13: mkdir $p || errstatus=$? michael@13: if [ ".$opt_o" != . ]; then michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "chown $opt_o $p" 1>&2 michael@13: fi michael@13: chown $opt_o $p || errstatus=$? michael@13: fi michael@13: if [ ".$opt_g" != . ]; then michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "chgrp $opt_g $p" 1>&2 michael@13: fi michael@13: chgrp $opt_g $p || errstatus=$? michael@13: fi michael@13: if [ ".$opt_m" != . ]; then michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "chmod $opt_m $p" 1>&2 michael@13: fi michael@13: chmod $opt_m $p || errstatus=$? michael@13: fi michael@13: else michael@13: # the smart situation michael@13: set fnord `echo ":$p" |\ michael@13: sed -e 's/^:\//%/' \ michael@13: -e 's/^://' \ michael@13: -e 's/\// /g' \ michael@13: -e 's/^%/\//'` michael@13: shift michael@13: pathcomp='' michael@13: for d in ${1+"$@"}; do michael@13: pathcomp="$pathcomp$d" michael@13: case "$pathcomp" in michael@13: -* ) pathcomp="./$pathcomp" ;; michael@13: esac michael@13: if [ ! -d "$pathcomp" ]; then michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "mkdir $pathcomp" 1>&2 michael@13: fi michael@13: mkdir $pathcomp || errstatus=$? michael@13: if [ ".$opt_o" != . ]; then michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "chown $opt_o $pathcomp" 1>&2 michael@13: fi michael@13: chown $opt_o $pathcomp || errstatus=$? michael@13: fi michael@13: if [ ".$opt_g" != . ]; then michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "chgrp $opt_g $pathcomp" 1>&2 michael@13: fi michael@13: chgrp $opt_g $pathcomp || errstatus=$? michael@13: fi michael@13: if [ ".$opt_m" != . ]; then michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "chmod $opt_m $pathcomp" 1>&2 michael@13: fi michael@13: chmod $opt_m $pathcomp || errstatus=$? michael@13: fi michael@13: fi michael@13: pathcomp="$pathcomp/" michael@13: done michael@13: fi michael@13: done michael@13: michael@13: shtool_exit $errstatus michael@13: ;; michael@13: michael@13: mkln ) michael@13: ## michael@13: ## mkln -- Make link with calculation of relative paths michael@13: ## Copyright (c) 1998-2007 Ralf S. Engelschall michael@13: ## michael@13: michael@13: # determine source(s) and destination michael@13: args=$? michael@13: srcs="" michael@13: while [ $# -gt 1 ]; do michael@13: srcs="$srcs $1" michael@13: shift michael@13: done michael@13: dst="$1" michael@13: if [ ! -d $dst ]; then michael@13: if [ $args -gt 2 ]; then michael@13: echo "$msgprefix:Error: multiple sources not allowed when target isn't a directory" 1>&2 michael@13: shtool_exit 1 michael@13: fi michael@13: fi michael@13: michael@13: # determine link options michael@13: lnopt="" michael@13: if [ ".$opt_f" = .yes ]; then michael@13: lnopt="$lnopt -f" michael@13: fi michael@13: if [ ".$opt_s" = .yes ]; then michael@13: lnopt="$lnopt -s" michael@13: fi michael@13: michael@13: # iterate over sources michael@13: for src in $srcs; do michael@13: # determine if one of the paths is an absolute path, michael@13: # because then we _have_ to use an absolute symlink michael@13: oneisabs=0 michael@13: srcisabs=0 michael@13: dstisabs=0 michael@13: case $src in michael@13: /* ) oneisabs=1; srcisabs=1 ;; michael@13: esac michael@13: case $dst in michael@13: /* ) oneisabs=1; dstisabs=1 ;; michael@13: esac michael@13: michael@13: # split source and destination into dir and base name michael@13: if [ -d $src ]; then michael@13: srcdir=`echo $src | sed -e 's;/*$;;'` michael@13: srcbase="" michael@13: else michael@13: srcdir=`echo $src | sed -e 's;^[^/]*$;;' -e 's;^\(.*/\)[^/]*$;\1;' -e 's;\(.\)/$;\1;'` michael@13: srcbase=`echo $src | sed -e 's;.*/\([^/]*\)$;\1;'` michael@13: fi michael@13: if [ -d $dst ]; then michael@13: dstdir=`echo $dst | sed -e 's;/*$;;'` michael@13: dstbase="" michael@13: else michael@13: dstdir=`echo $dst | sed -e 's;^[^/]*$;;' -e 's;^\(.*/\)[^/]*$;\1;' -e 's;\(.\)/$;\1;'` michael@13: dstbase=`echo $dst | sed -e 's;.*/\([^/]*\)$;\1;'` michael@13: fi michael@13: michael@13: # consistency check michael@13: if [ ".$dstdir" != . ]; then michael@13: if [ ! -d $dstdir ]; then michael@13: echo "$msgprefix:Error: destination directory not found: $dstdir" 1>&2 michael@13: shtool_exit 1 michael@13: fi michael@13: fi michael@13: michael@13: # make sure the source is reachable from the destination michael@13: if [ $dstisabs = 1 ]; then michael@13: if [ $srcisabs = 0 ]; then michael@13: if [ ".$srcdir" = . ]; then michael@13: srcdir="`pwd | sed -e 's;/*$;;'`" michael@13: srcisabs=1 michael@13: oneisabs=1 michael@13: elif [ -d $srcdir ]; then michael@13: srcdir="`cd $srcdir; pwd | sed -e 's;/*$;;'`" michael@13: srcisabs=1 michael@13: oneisabs=1 michael@13: fi michael@13: fi michael@13: fi michael@13: michael@13: # split away a common prefix michael@13: prefix="" michael@13: if [ ".$srcdir" = ".$dstdir" ] && [ ".$srcdir" != . ]; then michael@13: prefix="$srcdir/" michael@13: srcdir="" michael@13: dstdir="" michael@13: else michael@13: while [ ".$srcdir" != . ] && [ ".$dstdir" != . ]; do michael@13: presrc=`echo $srcdir | sed -e 's;^\([^/]*\)/.*;\1;'` michael@13: predst=`echo $dstdir | sed -e 's;^\([^/]*\)/.*;\1;'` michael@13: if [ ".$presrc" != ".$predst" ]; then michael@13: break michael@13: fi michael@13: prefix="$prefix$presrc/" michael@13: srcdir=`echo $srcdir | sed -e 's;^[^/]*/*;;'` michael@13: dstdir=`echo $dstdir | sed -e 's;^[^/]*/*;;'` michael@13: done michael@13: fi michael@13: michael@13: # destination prefix is just the common prefix michael@13: dstpre="$prefix" michael@13: michael@13: # determine source prefix which is the reverse directory michael@13: # step-up corresponding to the destination directory michael@13: srcpre="" michael@13: allow_relative_srcpre=no michael@13: if [ ".$prefix" != . ] && [ ".$prefix" != ./ ]; then michael@13: allow_relative_srcpre=yes michael@13: fi michael@13: if [ $oneisabs = 0 ]; then michael@13: allow_relative_srcpre=yes michael@13: fi michael@13: if [ ".$opt_s" != .yes ]; then michael@13: allow_relative_srcpre=no michael@13: fi michael@13: if [ ".$allow_relative_srcpre" = .yes ]; then michael@13: pl="$dstdir/" michael@13: OIFS="$IFS"; IFS='/' michael@13: for pe in $pl; do michael@13: [ ".$pe" = . ] && continue michael@13: [ ".$pe" = .. ] && continue michael@13: srcpre="../$srcpre" michael@13: done michael@13: IFS="$OIFS" michael@13: else michael@13: if [ $srcisabs = 1 ]; then michael@13: srcpre="$prefix" michael@13: fi michael@13: fi michael@13: michael@13: # determine destination symlink name michael@13: if [ ".$dstbase" = . ]; then michael@13: if [ ".$srcbase" != . ]; then michael@13: dstbase="$srcbase" michael@13: else michael@13: dstbase=`echo "$prefix$srcdir" | sed -e 's;/*$;;' -e 's;.*/\([^/]*\)$;\1;'` michael@13: fi michael@13: fi michael@13: michael@13: # now finalize source and destination directory paths michael@13: srcdir=`echo $srcdir | sed -e 's;\([^/]\)$;\1/;'` michael@13: dstdir=`echo $dstdir | sed -e 's;\([^/]\)$;\1/;'` michael@13: michael@13: # run the final link command michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "ln$lnopt $srcpre$srcdir$srcbase $dstpre$dstdir$dstbase" michael@13: fi michael@13: eval ln$lnopt $srcpre$srcdir$srcbase $dstpre$dstdir$dstbase michael@13: done michael@13: michael@13: shtool_exit 0 michael@13: ;; michael@13: michael@13: mkshadow ) michael@13: ## michael@13: ## mkshadow -- Make a shadow tree through symbolic links michael@13: ## Copyright (c) 1998-2007 Ralf S. Engelschall michael@13: ## michael@13: michael@13: # source and destination directory michael@13: src=`echo "$1" | sed -e 's:/$::' -e 's:^\./\(.\):\1:'` michael@13: dst=`echo "$2" | sed -e 's:/$::' -e 's:^\./\(.\):\1:'` michael@13: michael@13: # check whether source exists michael@13: if [ ! -d $src ]; then michael@13: echo "$msgprefix:Error: source directory not found: \`$src'" 1>&2 michael@13: shtool_exit 1 michael@13: fi michael@13: michael@13: # determine if one of the paths is an absolute path, michael@13: # because then we have to use an absolute symlink michael@13: oneisabs=0 michael@13: case $src in michael@13: /* ) oneisabs=1 ;; michael@13: esac michael@13: case $dst in michael@13: /* ) oneisabs=1 ;; michael@13: esac michael@13: michael@13: # determine reverse directory for destination directory michael@13: dstrevdir='' michael@13: if [ $oneisabs = 0 ]; then michael@13: # derive reverse path from forward path michael@13: pwd=`pwd` michael@13: OIFS="$IFS"; IFS='/' michael@13: for pe in $dst; do michael@13: if [ "x$pe" = "x.." ]; then michael@13: OIFS2="$IFS"; IFS="$DIFS" michael@13: eval `echo "$pwd" |\ michael@13: sed -e 's:\([^/]*\)$:; dir="\1":' \ michael@13: -e 's:^\(.*\)/[^/]*;:pwd="\1";:'\ michael@13: -e 's:^;:pwd="";:'` michael@13: dstrevdir="$dir/$dstrevdir" michael@13: IFS="$OIFS2" michael@13: else michael@13: dstrevdir="../$dstrevdir" michael@13: fi michael@13: done michael@13: IFS="$OIFS" michael@13: else michael@13: src="`cd $src; pwd`"; michael@13: fi michael@13: michael@13: # create directory tree at destination michael@13: if [ ! -d $dst ]; then michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "mkdir $dst" 1>&2 michael@13: fi michael@13: mkdir $dst michael@13: fi michael@13: if [ ".$opt_a" = .yes ]; then michael@13: DIRS=`cd $src; find . -type d -print |\ michael@13: sed -e '/^\.$/d' -e 's:^\./::'` michael@13: else michael@13: DIRS=`cd $src; find . -type d -print |\ michael@13: sed -e '/\/CVS/d' -e '/^\.$/d' -e 's:^\./::'` michael@13: fi michael@13: for dir in $DIRS; do michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "mkdir $dst/$dir" 1>&2 michael@13: fi michael@13: mkdir $dst/$dir michael@13: done michael@13: michael@13: # fill directory tree with symlinks to files michael@13: if [ ".$opt_a" = .yes ]; then michael@13: FILES="`cd $src; find . -depth -print |\ michael@13: sed -e 's/^\.\///'`" michael@13: else michael@13: FILES="`cd $src; find . -depth -print |\ michael@13: sed -e '/\.o$/d' -e '/\.a$/d' -e '/\.so$/d' \ michael@13: -e '/\.cvsignore$/d' -e '/\/CVS/d' \ michael@13: -e '/\/\.#/d' -e '/\.orig$/d' \ michael@13: -e 's/^\.\///'`" michael@13: fi michael@13: for file in $FILES; do michael@13: # don't use `-type f' above for find because of symlinks michael@13: if [ -d "$src/$file" ]; then michael@13: continue michael@13: fi michael@13: basename=`echo $file | sed -e 's:^.*/::'` michael@13: dir=`echo $file | sed -e 's:[^/]*$::' -e 's:/$::' -e 's:$:/:' -e 's:^/$::'` michael@13: from=`echo "$src/$file" | sed -e 's/^\.\///'` michael@13: to="$dst/$dir$basename" michael@13: if [ $oneisabs = 0 ]; then michael@13: if [ ".$dir" != . ]; then michael@13: subdir=`echo $dir | sed -e 's:/$::'` michael@13: # derive reverse path from forward path michael@13: revdir='' michael@13: OIFS="$IFS"; IFS='/' michael@13: for pe in $subdir; do michael@13: revdir="../$revdir" michael@13: done michael@13: IFS="$OIFS" michael@13: # finalize from michael@13: from="$revdir$from" michael@13: fi michael@13: from="$dstrevdir$from" michael@13: fi michael@13: if [ ".$opt_v" = .yes ]; then michael@13: echo " $to" 1>&2 michael@13: fi michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "ln -s $from $to" 1>&2 michael@13: fi michael@13: ln -s $from $to michael@13: done michael@13: michael@13: shtool_exit 0 michael@13: ;; michael@13: michael@13: fixperm ) michael@13: ## michael@13: ## fixperm -- Fix file permissions inside a source tree michael@13: ## Copyright (c) 1996-2007 Ralf S. Engelschall michael@13: ## michael@13: michael@13: paths="$*" michael@13: michael@13: # check whether the test command supports the -x option michael@13: if [ -x /bin/sh ] 2>/dev/null; then michael@13: minusx="-x" michael@13: else michael@13: minusx="-r" michael@13: fi michael@13: michael@13: # iterate over paths michael@13: for p in $paths; do michael@13: for file in `find $p -depth -print`; do michael@13: if [ -f $file ]; then michael@13: if [ $minusx $file ]; then michael@13: if [ ".$opt_v" = .yes ]; then michael@13: echo "-rwxr-xr-x $file" 2>&1 michael@13: fi michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "chmod 755 $file" 2>&1 michael@13: fi michael@13: chmod 755 $file michael@13: else michael@13: if [ ".$opt_v" = .yes ]; then michael@13: echo "-rw-r--r-- $file" 2>&1 michael@13: fi michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "chmod 644 $file" 2>&1 michael@13: fi michael@13: chmod 644 $file michael@13: fi michael@13: continue michael@13: fi michael@13: if [ -d $file ]; then michael@13: if [ ".$opt_v" = .yes ]; then michael@13: echo "drwxr-xr-x $file" 2>&1 michael@13: fi michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "chmod 755 $file" 2>&1 michael@13: fi michael@13: chmod 755 $file michael@13: continue michael@13: fi michael@13: if [ ".$opt_v" = .yes ]; then michael@13: echo "?????????? $file" 2>&1 michael@13: fi michael@13: done michael@13: done michael@13: michael@13: shtool_exit 0 michael@13: ;; michael@13: michael@13: rotate ) michael@13: ## michael@13: ## rotate -- Logfile rotation michael@13: ## Copyright (c) 2001-2007 Ralf S. Engelschall michael@13: ## michael@13: michael@13: # make sure we have at least one file to rotate michael@13: if [ ".$opt_n" = .0 ]; then michael@13: echo "$msgprefix:Error: invalid argument \`$opt_n' to option -n." 1>&2 michael@13: shtool_exit 1 michael@13: fi michael@13: michael@13: # canonicalize -s option argument michael@13: if [ ".$opt_s" != . ]; then michael@13: if [ ".`expr $opt_s : '[0-9]*$'`" != .0 ]; then michael@13: : michael@13: elif [ ".`expr $opt_s : '[0-9]*[Kk]$'`" != .0 ]; then michael@13: opt_s=`expr $opt_s : '\([0-9]*\)[Kk]$'` michael@13: opt_s=`expr $opt_s \* 1024` michael@13: elif [ ".`expr $opt_s : '[0-9]*[Mm]$'`" != .0 ]; then michael@13: opt_s=`expr $opt_s : '\([0-9]*\)[Mm]$'` michael@13: opt_s=`expr $opt_s \* 1048576` # 1024*1024 michael@13: elif [ ".`expr $opt_s : '[0-9]*[Gg]$'`" != .0 ]; then michael@13: opt_s=`expr $opt_s : '\([0-9]*\)[Gg]$'` michael@13: opt_s=`expr $opt_s \* 1073741824` # 1024*1024*1024 michael@13: else michael@13: echo "$msgprefix:Error: invalid argument \`$opt_s' to option -s." 1>&2 michael@13: shtool_exit 1 michael@13: fi michael@13: fi michael@13: michael@13: # option -d/-z consistency michael@13: if [ ".$opt_d" = .yes ] && [ ".$opt_z" = . ]; then michael@13: echo "$msgprefix:Error: option -d requires option -z." 1>&2 michael@13: shtool_exit 1 michael@13: fi michael@13: michael@13: # make sure target directory exists michael@13: if [ ".$opt_a" != . ]; then michael@13: if [ ! -d $opt_a ]; then michael@13: if [ ".$opt_f" = .no ]; then michael@13: echo "$msgprefix:Error: archive directory \`$opt_a' does not exist." 1>&2 michael@13: shtool_exit 1 michael@13: fi michael@13: mkdir $opt_a || shtool_exit $? michael@13: chmod 755 $opt_a michael@13: fi michael@13: if [ ! -w $opt_a ]; then michael@13: echo "$msgprefix:Error: archive directory \`$opt_a' not writable." 1>&2 michael@13: shtool_exit 1 michael@13: fi michael@13: fi michael@13: michael@13: # determine compression approach michael@13: if [ ".$opt_z" != . ]; then michael@13: comp_lvl="$opt_z" michael@13: comp_prg="" michael@13: case $comp_lvl in michael@13: *:* ) eval `echo $comp_lvl |\ michael@13: sed -e 's%^\(.*\):\(.*\)$%comp_prg="\1"; comp_lvl="\2"%'` ;; michael@13: esac michael@13: michael@13: # compression level consistency michael@13: case $comp_lvl in michael@13: [0-9] ) michael@13: ;; michael@13: * ) echo "$msgprefix:Error: invalid compression level \`$comp_lvl'" 1>&2 michael@13: shtool_exit 1 michael@13: ;; michael@13: esac michael@13: michael@13: # determine a suitable compression tool michael@13: if [ ".$comp_prg" = . ]; then michael@13: # check whether the test command supports the -x option michael@13: if [ -x /bin/sh ] 2>/dev/null; then michael@13: minusx="-x" michael@13: else michael@13: minusx="-r" michael@13: fi michael@13: # search for tools in $PATH michael@13: paths="`echo $PATH |\ michael@13: sed -e 's%/*:%:%g' -e 's%/*$%%' \ michael@13: -e 's/^:/.:/' -e 's/::/:.:/g' -e 's/:$/:./' \ michael@13: -e 's/:/ /g'`" michael@13: for prg in bzip2 gzip compress; do michael@13: for path in $paths; do michael@13: if [ $minusx "$path/$prg" ] && [ ! -d "$path/$prg" ]; then michael@13: comp_prg="$prg" michael@13: break michael@13: fi michael@13: done michael@13: if [ ".$comp_prg" != . ]; then michael@13: break michael@13: fi michael@13: done michael@13: if [ ".$comp_prg" = . ]; then michael@13: echo "$msgprefix:Error: no suitable compression tool found in \$PATH" 1>&2 michael@13: shtool_exit 1 michael@13: fi michael@13: fi michael@13: michael@13: # determine standard compression extension michael@13: # and make sure it is a known tool michael@13: case $comp_prg in michael@13: */bzip2 | bzip2 ) comp_ext="bz2" comp_lvl="-$comp_lvl" ;; michael@13: */gzip | gzip ) comp_ext="gz" comp_lvl="-$comp_lvl" ;; michael@13: */compress | compress ) comp_ext="Z"; comp_lvl="" ;; michael@13: * ) echo "$msgprefix:Error: tool \`$comp_prg' is not a known compression tool" 1>&2 michael@13: shtool_exit 1 michael@13: ;; michael@13: esac michael@13: comp_suf=".$comp_ext" michael@13: fi michael@13: michael@13: # iterate over all given logfile arguments michael@13: for file in $*; do michael@13: # make sure the logfile exists michael@13: if [ ! -f $file ]; then michael@13: if [ ".$opt_f" = .yes ]; then michael@13: continue michael@13: fi michael@13: echo "$msgprefix:Error: logfile \`$file' not found" 1>&2 michael@13: shtool_exit 1 michael@13: fi michael@13: michael@13: # determine log directory (where original logfile is placed) michael@13: ldir="." michael@13: case $file in michael@13: */* ) eval `echo $file | sed -e 's%^\(.*\)/\([^/]*\)$%ldir="\1"; file="\2";%'` ;; michael@13: esac michael@13: michael@13: # determine archive directory (where rotated logfiles are placed) michael@13: adir="$ldir" michael@13: if [ ".$opt_a" != . ]; then michael@13: case "$opt_a" in michael@13: /* | ./* ) adir="$opt_a" ;; michael@13: * ) adir="$ldir/$opt_a" ;; michael@13: esac michael@13: fi michael@13: michael@13: # optionally take logfile size into account michael@13: if [ ".$opt_s" != . ]; then michael@13: # determine size of logfile michael@13: set -- `env -i /bin/ls -l "$ldir/$file" | sed -e "s;$ldir/$file;;" |\ michael@13: sed -e 's; -> .*$;;' -e 's;[ ][ ]*; ;g'` michael@13: n=`expr $# - 3` michael@13: eval "size=\`echo \${$n}\`" michael@13: michael@13: # skip logfile if size is still too small michael@13: if [ $size -lt $opt_s ]; then michael@13: if [ ".$opt_v" = .yes ]; then michael@13: echo "$ldir/$file: still too small in size -- skipping" michael@13: fi michael@13: continue michael@13: fi michael@13: fi michael@13: michael@13: # verbosity michael@13: if [ ".$opt_v" = .yes ]; then michael@13: echo "rotating $ldir/$file" michael@13: fi michael@13: michael@13: # execute prolog michael@13: if [ ".$opt_P" != . ]; then michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "$opt_P" michael@13: fi michael@13: eval $opt_P michael@13: [ $? -ne 0 ] && shtool_exit $? michael@13: fi michael@13: michael@13: # kick away out-rotated logfile michael@13: n=`expr $opt_n - 1` michael@13: n=`echo dummy | awk "{ printf(\"%0${opt_p}d\", n); }" n=$n` michael@13: if [ -f "${adir}/${file}.${n}${comp_suf}" ]; then michael@13: # optionally migrate away the out-rotated logfile michael@13: if [ ".$opt_M" != . ]; then michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "$opt_M ${adir}/${file}.${n}${comp_suf}" michael@13: fi michael@13: eval "$opt_M ${adir}/${file}.${n}${comp_suf}" michael@13: [ $? -ne 0 ] && shtool_exit $? michael@13: fi michael@13: # finally get rid of the out-rotated logfile michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "rm -f ${adir}/${file}.${n}${comp_suf}" michael@13: fi michael@13: rm -f ${adir}/${file}.${n}${comp_suf} || shtool_exit $? michael@13: fi michael@13: michael@13: # rotate already archived logfiles michael@13: while [ $n -gt 0 ]; do michael@13: m=$n michael@13: n=`expr $n - 1` michael@13: n=`echo dummy | awk "{ printf(\"%0${opt_p}d\", n); }" n=$n` michael@13: if [ $n -eq 0 ] && [ ".$opt_d" = .yes ]; then michael@13: # special case: first rotation file under delayed compression situation michael@13: if [ ! -f "${adir}/${file}.${n}" ]; then michael@13: continue michael@13: fi michael@13: michael@13: # compress file (delayed) michael@13: if [ ".$opt_b" = .yes ]; then michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "mv ${adir}/${file}.${n} ${adir}/${file}.${m}" michael@13: fi michael@13: mv ${adir}/${file}.${n} ${adir}/${file}.${m} || shtool_exit $? michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "(${comp_prg} ${comp_lvl} <${adir}/${file}.${m} >${adir}/${file}.${m}${comp_suf}; rm -f ${adir}/${file}.${m}) &" michael@13: fi michael@13: ( ${comp_prg} ${comp_lvl} \ michael@13: <${adir}/${file}.${m} \ michael@13: >${adir}/${file}.${m}${comp_suf} || shtool_exit $? michael@13: rm -f ${adir}/${file}.${m} || shtool_exit $? michael@13: ) /dev/null 2>&1 & michael@13: else michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "${comp_prg} ${comp_lvl} <${adir}/${file}.${n} >${adir}/${file}.${m}${comp_suf}" michael@13: fi michael@13: ${comp_prg} ${comp_lvl} \ michael@13: <${adir}/${file}.${n} \ michael@13: >${adir}/${file}.${m}${comp_suf} || shtool_exit $? michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "rm -f ${adir}/${file}.${n}" michael@13: fi michael@13: rm -f ${adir}/${file}.${n} || shtool_exit $? michael@13: fi michael@13: michael@13: # fix file attributes michael@13: if [ ".$opt_o" != . ]; then michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "chown $opt_o ${adir}/${file}.${m}${comp_suf}" michael@13: fi michael@13: chown $opt_o ${adir}/${file}.${m}${comp_suf} || shtool_exit $? michael@13: fi michael@13: if [ ".$opt_g" != . ]; then michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "chgrp $opt_g ${adir}/${file}.${m}${comp_suf}" michael@13: fi michael@13: chgrp $opt_g ${adir}/${file}.${m}${comp_suf} || shtool_exit $? michael@13: fi michael@13: if [ ".$opt_m" != . ]; then michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "chmod $opt_m ${adir}/${file}.${m}${comp_suf}" michael@13: fi michael@13: chmod $opt_m ${adir}/${file}.${m}${comp_suf} || shtool_exit $? michael@13: fi michael@13: else michael@13: # standard case: second and following rotation file michael@13: if [ ! -f "${adir}/${file}.${n}${comp_suf}" ]; then michael@13: continue michael@13: fi michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "mv ${adir}/${file}.${n}${comp_suf} ${adir}/${file}.${m}${comp_suf}" michael@13: fi michael@13: mv ${adir}/${file}.${n}${comp_suf} ${adir}/${file}.${m}${comp_suf} || shtool_exit $? michael@13: fi michael@13: done michael@13: michael@13: # move away current logfile michael@13: if [ ".$opt_c" = .yes ]; then michael@13: # approach: copy[+truncate] michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "cp -p ${ldir}/${file} ${adir}/${file}.${n}" michael@13: fi michael@13: cp -p ${ldir}/${file} ${adir}/${file}.${n} || shtool_exit $? michael@13: if [ ".$opt_r" = .no ]; then michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "cp /dev/null ${ldir}/${file}" michael@13: fi michael@13: cp /dev/null ${ldir}/${file} || shtool_exit $? michael@13: fi michael@13: else michael@13: # approach: move[+touch] michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "mv ${ldir}/${file} ${adir}/${file}.${n}" michael@13: fi michael@13: mv ${ldir}/${file} ${adir}/${file}.${n} || shtool_exit $? michael@13: if [ ".$opt_r" = .no ]; then michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "touch ${ldir}/${file}" michael@13: fi michael@13: touch ${ldir}/${file} || shtool_exit $? michael@13: # fix file attributes michael@13: if [ ".$opt_o" != . ]; then michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "chown $opt_o ${ldir}/${file}" michael@13: fi michael@13: chown $opt_o ${ldir}/${file} || shtool_exit $? michael@13: fi michael@13: if [ ".$opt_g" != . ]; then michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "chgrp $opt_g ${ldir}/${file}" michael@13: fi michael@13: chgrp $opt_g ${ldir}/${file} || shtool_exit $? michael@13: fi michael@13: if [ ".$opt_m" != . ]; then michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "chmod $opt_m ${ldir}/${file}" michael@13: fi michael@13: chmod $opt_m ${ldir}/${file} || shtool_exit $? michael@13: fi michael@13: fi michael@13: fi michael@13: michael@13: # regular compression step michael@13: if [ ".$opt_z" != . ] && [ ".$opt_d" = .no ]; then michael@13: # compress file michael@13: if [ ".$opt_b" = .yes ]; then michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "(${comp_prg} ${comp_lvl} <${adir}/${file}.${n} >${adir}/${file}.${n}${comp_suf}; rm -f ${adir}/${file}.${n}) &" michael@13: fi michael@13: ( ${comp_prg} ${comp_lvl} \ michael@13: <${adir}/${file}.${n} \ michael@13: >${adir}/${file}.${n}${comp_suf} || shtool_exit $? michael@13: rm -f ${adir}/${file}.${n} || shtool_exit $? michael@13: ) /dev/null 2>&1 & michael@13: else michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "${comp_prg} ${comp_lvl} <${adir}/${file}.${n} >${adir}/${file}.${n}${comp_suf}" michael@13: fi michael@13: ${comp_prg} ${comp_lvl} \ michael@13: <${adir}/${file}.${n} \ michael@13: >${adir}/${file}.${n}${comp_suf} || shtool_exit $? michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "rm -f ${opt_a}${file}.${n}" michael@13: fi michael@13: rm -f ${adir}/${file}.${n} || shtool_exit $? michael@13: fi michael@13: michael@13: # fix file attributes michael@13: if [ ".$opt_o" != . ]; then michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "chown $opt_o ${adir}/${file}.${n}${comp_suf}" michael@13: fi michael@13: chown $opt_o ${adir}/${file}.${n}${comp_suf} || shtool_exit $? michael@13: fi michael@13: if [ ".$opt_g" != . ]; then michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "chgrp $opt_g ${adir}/${file}.${n}${comp_suf}" michael@13: fi michael@13: chgrp $opt_g ${adir}/${file}.${n}${comp_suf} || shtool_exit $? michael@13: fi michael@13: if [ ".$opt_m" != . ]; then michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "chmod $opt_m ${adir}/${file}.${n}${comp_suf}" michael@13: fi michael@13: chmod $opt_m ${adir}/${file}.${n}${comp_suf} || shtool_exit $? michael@13: fi michael@13: fi michael@13: michael@13: # execute epilog michael@13: if [ ".$opt_E" != . ]; then michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "$opt_E" michael@13: fi michael@13: eval $opt_E michael@13: [ $? -ne 0 ] && shtool_exit $? michael@13: fi michael@13: done michael@13: michael@13: shtool_exit 0 michael@13: ;; michael@13: michael@13: tarball ) michael@13: ## michael@13: ## tarball -- Roll distribution tarballs michael@13: ## Copyright (c) 1999-2007 Ralf S. Engelschall michael@13: ## michael@13: michael@13: srcs="$*" michael@13: michael@13: # check whether the test command supports the -x option michael@13: if [ -x /bin/sh ] 2>/dev/null; then michael@13: minusx="-x" michael@13: else michael@13: minusx="-r" michael@13: fi michael@13: michael@13: # find the tools michael@13: paths="`echo $PATH |\ michael@13: sed -e 's%/*:%:%g' -e 's%/*$%%' \ michael@13: -e 's/^:/.:/' -e 's/::/:.:/g' -e 's/:$/:./' \ michael@13: -e 's/:/ /g'`" michael@13: for spec in find:gfind,find tar:gtar,tar tardy:tardy,tarcust; do michael@13: prg=`echo $spec | sed -e 's/:.*$//'` michael@13: tools=`echo $spec | sed -e 's/^.*://'` michael@13: eval "prg_${prg}=''" michael@13: # iterate over tools michael@13: for tool in `echo $tools | sed -e 's/,/ /g'`; do michael@13: # iterate over paths michael@13: for path in $paths; do michael@13: if [ $minusx "$path/$tool" ] && [ ! -d "$path/$tool" ]; then michael@13: eval "prg_${prg}=\"$path/$tool\"" michael@13: break michael@13: fi michael@13: done michael@13: eval "val=\$prg_${prg}" michael@13: if [ ".$val" != . ]; then michael@13: break michael@13: fi michael@13: done michael@13: done michael@13: michael@13: # expand source paths michael@13: exclude='' michael@13: for pat in `echo $opt_e | sed 's/,/ /g'`; do michael@13: exclude="$exclude | grep -v '$pat'" michael@13: done michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "cp /dev/null $tmpfile.lst" 1>&2 michael@13: fi michael@13: cp /dev/null $tmpfile.lst michael@13: for src in $srcs; do michael@13: if [ -d $src ]; then michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "(cd $src && $prg_find . -type f -depth -print) | sed -e 's:^\\.\$::' -e 's:^\\./::' | cat $exclude >>$tmpfile.lst" 1>&2 michael@13: fi michael@13: (cd $src && $prg_find . -type f -depth -print) |\ michael@13: sed -e 's:^\.$::' -e 's:^\./::' | eval cat $exclude >>$tmpfile.lst michael@13: else michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "echo $src >>$tmpfile.lst" 1>&2 michael@13: fi michael@13: echo $src >>$tmpfile.lst michael@13: fi michael@13: done michael@13: sort <$tmpfile.lst >$tmpfile.lst.n michael@13: mv $tmpfile.lst.n $tmpfile.lst michael@13: if [ ".$opt_v" = .yes ]; then michael@13: cat $tmpfile.lst | sed -e 's/^/ /' 1>&2 michael@13: fi michael@13: michael@13: # determine tarball file and directory name michael@13: if [ ".$opt_o" != . ]; then michael@13: tarfile="$opt_o" michael@13: if [ ".$opt_d" != . ]; then michael@13: tarname="$opt_d" michael@13: else michael@13: tarname=`echo $tarfile | sed -e 's/\.tar.*$//' -e 's;.*/\([^/]*\)$;\1;'` michael@13: fi michael@13: else michael@13: if [ ".$opt_d" != . ]; then michael@13: tarname="$opt_d" michael@13: elif [ -d "$from" ]; then michael@13: tarname=`echo $from | sed -e 's;.*/\([^/]*\)$;\1;'` michael@13: else michael@13: tarname="out" michael@13: fi michael@13: tarfile="$tarname.tar" michael@13: fi michael@13: michael@13: # roll the tarball michael@13: compress='' michael@13: if [ ".$opt_c" != . ]; then michael@13: compress="| $opt_c" michael@13: fi michael@13: if [ ".$prg_tardy" != . ]; then michael@13: # the elegant hackers way michael@13: tardy_opt="--prefix=$tarname" michael@13: tardy_opt="$tardy_opt --user_number=0 --group_number=0" # security! michael@13: if [ ".$opt_u" != . ]; then michael@13: tardy_opt="$tardy_opt --user_name=$opt_u" michael@13: fi michael@13: if [ ".$opt_g" != . ]; then michael@13: tardy_opt="$tardy_opt --group_name=$opt_g" michael@13: fi michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "cat $tmpfile.lst | xargs $prg_tar cf - | $prg_tardy $tardy_opt | cat $compress >$tmpfile.out" 1>&2 michael@13: fi michael@13: cat $tmpfile.lst |\ michael@13: xargs $prg_tar cf - |\ michael@13: $prg_tardy $tardy_opt |\ michael@13: eval cat $compress >$tmpfile.out michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "cp $tmpfile.out $tarfile" 1>&2 michael@13: fi michael@13: cp $tmpfile.out $tarfile michael@13: else michael@13: # the portable standard way michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "mkdir $tmpdir/$tarname" 1>&2 michael@13: fi michael@13: mkdir $tmpdir/$tarname || shtool_exit 1 michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "cat $tmpfile.lst | xargs $prg_tar cf - | (cd $tmpdir/$tarname && $prg_tar xf -)" 1>&2 michael@13: fi michael@13: cat $tmpfile.lst |\ michael@13: xargs $prg_tar cf - |\ michael@13: (cd $tmpdir/$tarname && $prg_tar xf -) michael@13: if [ ".$opt_u" != . ]; then michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "chown -R $opt_u $tmpdir/$tarname >/dev/null 2>&1" 2>&1 michael@13: fi michael@13: chown -R $opt_u $tmpdir/$tarname >/dev/null 2>&1 ||\ michael@13: echo "$msgprefix:Warning: cannot set user name \`$opt_u' (would require root privileges)" michael@13: fi michael@13: if [ ".$opt_g" != . ]; then michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "chgrp -R $opt_g $tmpdir/$tarname >/dev/null 2>&1" 2>&1 michael@13: fi michael@13: chgrp -R $opt_g $tmpdir/$tarname >/dev/null 2>&1 ||\ michael@13: echo "$msgprefix:Warning: cannot set group name \`$opt_g' (would require root privileges)" michael@13: fi michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "(cd $tmpdir && $prg_find $tarname -type f -depth -print | sort | xargs $prg_tar cf -) | cat $compress >$tmpfile.out" 1>&2 michael@13: fi michael@13: (cd $tmpdir && $prg_find $tarname -type f -depth -print | sort | xargs $prg_tar cf -) |\ michael@13: eval cat $compress >$tmpfile.out michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "cp $tmpfile.out $tarfile" 1>&2 michael@13: fi michael@13: cp $tmpfile.out $tarfile michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "rm -rf $tmpdir/$tarname" 1>&2 michael@13: fi michael@13: rm -rf $tmpdir/$tarname michael@13: fi michael@13: michael@13: # cleanup michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "rm -f $tmpfile.lst $tmpfile.out" 1>&2 michael@13: fi michael@13: rm -f $tmpfile.lst $tmpfile.out michael@13: michael@13: shtool_exit 0 michael@13: ;; michael@13: michael@13: subst ) michael@13: ## michael@13: ## subst -- Apply sed(1) substitution operations michael@13: ## Copyright (c) 2001-2007 Ralf S. Engelschall michael@13: ## michael@13: michael@13: # remember optional list of file(s) michael@13: files="$*" michael@13: files_num="$#" michael@13: michael@13: # parameter consistency check michael@13: if [ $# -eq 0 ] && [ ".$opt_b" != . ]; then michael@13: echo "$msgprefix:Error: option -b cannot be applied to stdin" 1>&2 michael@13: shtool_exit 1 michael@13: fi michael@13: if [ $# -eq 0 ] && [ ".$opt_s" = .yes ]; then michael@13: echo "$msgprefix:Error: option -s cannot be applied to stdin" 1>&2 michael@13: shtool_exit 1 michael@13: fi michael@13: michael@13: # build underlying sed(1) command michael@13: sedcmd='sed' michael@13: if [ ".$opt_e" != . ]; then michael@13: OIFS="$IFS"; IFS="$ASC_NL"; set -- $opt_e; IFS="$OIFS" michael@13: for e michael@13: do michael@13: sedcmd="$sedcmd -e '$e'" michael@13: done michael@13: elif [ ".$opt_f" != . ]; then michael@13: if [ ! -f $opt_f ]; then michael@13: echo "$msgprefix:Error: command file \`$opt_f' not found or not a regular file" 1>&2 michael@13: shtool_exit 1 michael@13: fi michael@13: sedcmd="$sedcmd -f '$opt_f'" michael@13: else michael@13: echo "$msgprefix:Error: either -e option(s) or -f option required" 1>&2 michael@13: shtool_exit 1 michael@13: fi michael@13: michael@13: # determine extension for original file michael@13: orig=".orig" michael@13: if [ ".$opt_b" != . ]; then michael@13: orig="$opt_b" michael@13: fi michael@13: michael@13: # apply sed(1) operation(s) michael@13: if [ ".$files" != . ]; then michael@13: # apply operation(s) to files michael@13: substdone=no michael@13: for file in $files; do michael@13: test ".$file" = . && continue michael@13: if [ ! -f $file ]; then michael@13: echo "$msgprefix:Warning: file \`$file' not found or not a regular file" 1>&2 michael@13: continue michael@13: fi michael@13: michael@13: # handle interactive mode michael@13: if [ ".$opt_i" = .yes ]; then michael@13: eval "$sedcmd <$file >$file.new" michael@13: skip=no michael@13: if cmp $file $file.new >/dev/null 2>&1; then michael@13: rm -f $file.new michael@13: skip=yes michael@13: else michael@13: (diff -U1 $file $file.new >$tmpfile) 2>/dev/null michael@13: if [ ".`cat $tmpfile`" = . ]; then michael@13: (diff -C1 $file $file.new >$tmpfile) 2>/dev/null michael@13: if [ ".`cat $tmpfile`" = . ]; then michael@13: echo "$msgprefix:Warning: unable to show difference for file \`$file'" 1>&2 michael@13: cp /dev/null $tmpfile michael@13: fi michael@13: fi michael@13: rm -f $file.new michael@13: cat $tmpfile michael@13: echo dummy | awk '{ printf("%s", TEXT); }' TEXT=">>> Apply [Y/n]: " michael@13: read input michael@13: if [ ".$input" != .Y ] &&\ michael@13: [ ".$input" != .y ] &&\ michael@13: [ ".$input" != . ]; then michael@13: skip=yes michael@13: fi michael@13: fi michael@13: if [ ".$skip" = .yes ]; then michael@13: if [ ".$opt_v" = .yes ]; then michael@13: echo "file \`$file' -- skipped" 1>&2 michael@13: fi michael@13: continue michael@13: fi michael@13: fi michael@13: michael@13: # apply sed(1) operation(s) michael@13: if [ ".$opt_v" = .yes ]; then michael@13: echo "patching \`$file'" 1>&2 michael@13: fi michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "\$ cp -p $file $file$orig" michael@13: echo "\$ chmod u+w $file" michael@13: echo "\$ $sedcmd <$file$orig >$file" michael@13: fi michael@13: if [ ".$opt_n" = .no ]; then michael@13: cp -p $file $file$orig michael@13: chmod u+w $file >/dev/null 2>&1 || true michael@13: eval "$sedcmd <$file$orig >$file" michael@13: fi michael@13: michael@13: # optionally fix timestamp michael@13: if [ ".$opt_s" = .yes ]; then michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "\$ touch -r $file$orig $file" michael@13: fi michael@13: if [ ".$opt_n" = .no ]; then michael@13: touch -r $file$orig $file michael@13: fi michael@13: fi michael@13: michael@13: # optionally check whether any content change actually occurred michael@13: if [ ".$opt_q" = .no ]; then michael@13: if cmp $file$orig $file >/dev/null 2>&1; then michael@13: if [ ".$opt_w" = .yes ]; then michael@13: echo "$msgprefix:Warning: substitution resulted in no content change on file \"$file\"" 1>&2 michael@13: fi michael@13: else michael@13: substdone=yes michael@13: fi michael@13: fi michael@13: michael@13: # optionally remove preserved original file michael@13: if [ ".$opt_b" = . ]; then michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "\$ rm -f $file$orig" michael@13: fi michael@13: if [ ".$opt_n" = .no ]; then michael@13: rm -f $file$orig michael@13: fi michael@13: fi michael@13: done michael@13: if [ ".$opt_q" = .no ] && [ ".$opt_w" = .no ]; then michael@13: if [ ".$substdone" = .no ]; then michael@13: if [ ".$files_num" = .1 ]; then michael@13: echo "$msgprefix:Warning: substitution resulted in no content change on file \"$file\"" 1>&2 michael@13: else michael@13: echo "$msgprefix:Warning: substitution resulted in no content change on any file" 1>&2 michael@13: fi michael@13: fi michael@13: fi michael@13: else michael@13: # apply operation(s) to stdin/stdout michael@13: if [ ".$opt_v" = .yes ]; then michael@13: echo "patching " 1>&2 michael@13: fi michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "\$ $sedcmd" michael@13: fi michael@13: if [ ".$opt_n" = .no ]; then michael@13: eval "$sedcmd" michael@13: fi michael@13: fi michael@13: michael@13: shtool_exit 0 michael@13: ;; michael@13: michael@13: platform ) michael@13: ## michael@13: ## platform -- Platform Identification Utility michael@13: ## Copyright (c) 2003-2007 Ralf S. Engelschall michael@13: ## michael@13: michael@13: # option post-processing michael@13: if [ ".$opt_t" != . ]; then michael@13: case "$opt_t" in michael@13: binary ) michael@13: # binary package id (OpenPKG RPM) michael@13: opt_F="%-%" michael@13: opt_L=yes michael@13: opt_S="" michael@13: opt_C="+" michael@13: ;; michael@13: build ) michael@13: # build time checking (OpenPKG RPM) michael@13: opt_F="%-%" michael@13: opt_L=yes michael@13: opt_S="" michael@13: opt_C="+" michael@13: ;; michael@13: gnu ) michael@13: # GNU config.guess style -- michael@13: opt_F="%-unknown-%" michael@13: opt_L=yes michael@13: opt_S="" michael@13: opt_C="+" michael@13: ;; michael@13: web ) michael@13: # non-whitespace HTTP Server-header id michael@13: opt_F="%-%" michael@13: opt_S="/" michael@13: opt_C="+" michael@13: ;; michael@13: summary) michael@13: # human readable verbose summary information michael@13: opt_F="Class: %[sc] (%[ac])\\nProduct: %[sp] (%[ap])\\nTechnology: %[st] (%[at])" michael@13: opt_S=" " michael@13: opt_C="/" michael@13: ;; michael@13: all-in-one ) michael@13: # full-table all-in-one information michael@13: opt_F="" michael@13: opt_F="${opt_F}concise architecture class: %\\n" michael@13: opt_F="${opt_F}regular architecture class: %{ac}\\n" michael@13: opt_F="${opt_F}verbose architecture class: %[ac]\\n" michael@13: opt_F="${opt_F}concise architecture product: %\\n" michael@13: opt_F="${opt_F}regular architecture product: %{ap}\\n" michael@13: opt_F="${opt_F}verbose architecture product: %[ap]\\n" michael@13: opt_F="${opt_F}concise architecture technology: %\\n" michael@13: opt_F="${opt_F}regular architecture technology: %{at}\\n" michael@13: opt_F="${opt_F}verbose architecture technology: %[at]\\n" michael@13: opt_F="${opt_F}concise system class: %\\n" michael@13: opt_F="${opt_F}regular system class: %{sc}\\n" michael@13: opt_F="${opt_F}verbose system class: %[sc]\\n" michael@13: opt_F="${opt_F}concise system product: %\\n" michael@13: opt_F="${opt_F}regular system product: %{sp}\\n" michael@13: opt_F="${opt_F}verbose system product: %[sp]\\n" michael@13: opt_F="${opt_F}concise system technology: %\\n" michael@13: opt_F="${opt_F}regular system technology: %{st}\\n" michael@13: opt_F="${opt_F}verbose system technology: %[st]" michael@13: ;; michael@13: * ) michael@13: echo "$msgprefix:Error: invalid type \`$opt_t'" 1>&2 michael@13: exit 1 michael@13: ;; michael@13: esac michael@13: fi michael@13: michael@13: # assemble initial platform information michael@13: UNAME_MACHINE=`(uname -m) 2>/dev/null` ||\ michael@13: UNAME_MACHINE=`(uname -p) 2>/dev/null` ||\ michael@13: UNAME_MACHINE='unknown' michael@13: UNAME_SYSTEM=`(uname -s) 2>/dev/null` ||\ michael@13: UNAME_SYSTEM='unknown' michael@13: UNAME_RELEASE=`(uname -r) 2>/dev/null` ||\ michael@13: UNAME_RELEASE=`(uname -v) 2>/dev/null` ||\ michael@13: UNAME_RELEASE='unknown' michael@13: michael@13: UNAME="${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}" michael@13: michael@13: AC=""; AP=""; AT="" michael@13: SC=""; SP=""; ST="" michael@13: michael@13: # dispatch into platform specific sections michael@13: case "${UNAME}" in michael@13: michael@13: # FreeBSD michael@13: *:FreeBSD:* ) michael@13: # determine architecture michael@13: AC="${UNAME_MACHINE}" michael@13: case "${AC}" in michael@13: i386 ) AC="iX86" ;; michael@13: esac michael@13: AP="${AC}" michael@13: AT="${AP}" michael@13: if [ ".${AT}" = ".iX86" ]; then michael@13: case "`(/sbin/sysctl -n hw.model) 2>&1`" in michael@13: *"Xeon"* | *"Pentium Pro"* | *"Cyrix 6x86MX"* | *"Pentium II"* | *"Pentium III"* | *"Pentium 4"* | *"Celeron"* ) AT="i686" ;; michael@13: *"Pentium"* ) AT="i586" ;; *"i486[SD]X"* | *"Cyrix 486"* | *"Cyrix [56]x86"* | *"Blue Lightning" | *"Cyrix 486S/DX" ) AT="i486" ;; michael@13: *"i386[SD]X"* | *"NexGen 586"* ) AT="i386" ;; michael@13: esac michael@13: fi michael@13: # determine system michael@13: r=`echo "${UNAME_RELEASE}" |\ michael@13: sed -e 's;[()];;' -e 's/\(-.*\)$/[\1]/'` michael@13: ST="FreeBSD ${r}" michael@13: SP="${ST}" michael@13: case "${r}" in michael@13: 1.* ) SC="4.3BSD" ;; michael@13: * ) SC="4.4BSD" ;; michael@13: esac michael@13: ;; michael@13: michael@13: # NetBSD michael@13: *:NetBSD:* ) michael@13: # determine architecture michael@13: AT="${UNAME_MACHINE}" michael@13: AP="${AT}" michael@13: case "${AP}" in michael@13: i[3-6]86 ) AP="iX86" ;; michael@13: esac michael@13: AC="${AP}" michael@13: # determine system michael@13: r=`echo "${UNAME_RELEASE}" | sed -e 's/\([-_].*\)$/[\1]/'` michael@13: ST="NetBSD ${r}" michael@13: SP="${ST}" michael@13: case "${r}" in michael@13: 0.* ) SC="4.3BSD" ;; michael@13: * ) SC="4.4BSD" ;; michael@13: esac michael@13: ;; michael@13: michael@13: # OpenBSD michael@13: *:OpenBSD:* ) michael@13: # determine architecture michael@13: AT="${UNAME_MACHINE}" michael@13: AP="${AT}" michael@13: case "${AP}" in michael@13: i[3-6]86 ) AP="iX86" ;; michael@13: esac michael@13: AC="${AP}" michael@13: # determine system michael@13: r=`echo "${UNAME_RELEASE}" | sed -e 's/\([-_].*\)$/[\1]/'` michael@13: ST="OpenBSD ${r}" michael@13: SP="${ST}" michael@13: SC="4.4BSD" michael@13: ;; michael@13: michael@13: # GNU/Linux michael@13: *:Linux:* ) michael@13: # determine architecture michael@13: AT="${UNAME_MACHINE}" michael@13: case "${AT}" in michael@13: ia64 ) AT="IA64" ;; michael@13: x86_64 ) AT='AMD64' ;; michael@13: parisc ) AT="HPPA32" ;; michael@13: parisc64 ) AT="HPPA64" ;; michael@13: esac michael@13: AP="${AT}" michael@13: case "${AP}" in michael@13: i[3-6]86 ) AP='iX86' ;; michael@13: esac michael@13: AC="${AP}" michael@13: # determine system michael@13: v_kern=`echo "${UNAME_RELEASE}" |\ michael@13: sed -e 's/^\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/'` michael@13: v_libc=`(strings /lib/libc.so.* | grep '^GLIBC_' | sed -e 's/^GLIBC_//' |\ michael@13: 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: ST="GNU/${v_libc}/<${v_kern}>" michael@13: if [ -f /etc/lsb-release ]; then michael@13: eval `( . /etc/lsb-release michael@13: echo "SC=\"LSB${LSB_VERSION}\"" michael@13: if [ ".${DISTRIB_ID}" != . -a ".${DISTRIB_RELEASE}" != . ]; then michael@13: echo "SP=\"${DISTRIB_ID} ${DISTRIB_RELEASE}\"" michael@13: fi michael@13: ) 2>/dev/null` michael@13: fi michael@13: if [ ".$SP" = . ]; then michael@13: for tagfile in x \ michael@13: `cd /etc && \ michael@13: /bin/ls *[_-]release *[_-]version 2>/dev/null | env -i sort | \ michael@13: sed -e '/^redhat-release$/d' -e '/^lsb-release$/d'; \ michael@13: echo redhat-release lsb-release` michael@13: do michael@13: [ ".${tagfile}" = .x ] && continue michael@13: [ ! -f "/etc/${tagfile}" ] && continue michael@13: n=`echo ${tagfile} | sed -e 's/[_-]release$//' -e 's/[_-]version$//'` michael@13: v=`(grep VERSION /etc/${tagfile}; cat /etc/${tagfile}) | grep '[0-9]' | sed -e 'q' |\ michael@13: sed -e 's/^/#/' \ michael@13: -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' \ michael@13: -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' \ michael@13: -e 's/^#[^0-9]*\([0-9][0-9]*\).*$/\1/' \ michael@13: -e 's/^#.*$//'` michael@13: case "`util_lower ${n}`" in michael@13: redhat ) michael@13: if [ ".`egrep '(Red Hat Enterprise Linux|CentOS)' /etc/${tagfile}`" != . ]; then michael@13: n="ed at nterprise inux" michael@13: else michael@13: n="ed at inux" michael@13: fi michael@13: ;; michael@13: debian ) n="Debian[ GNU/Linux]" ;; michael@13: ubuntu ) n="Ubuntu[ GNU/Linux]" ;; michael@13: fedora ) n=" Core[ GNU/Linux]" ;; michael@13: suse ) n="[Novell ]SUSE[ Linux]" ;; michael@13: mandrake*|mandriva ) n="Mandriva[ Linux]" ;; michael@13: gentoo ) n="Gentoo[ GNU/Linux]" ;; michael@13: slackware ) n="Slackware[ Linux]" ;; michael@13: turbolinux ) n="TurboLinux" ;; michael@13: unitedlinux ) n="UnitedLinux" ;; michael@13: * ) n="${n}[ GNU/Linux]" ;; michael@13: esac michael@13: case "$n" in michael@13: *"<"*">"* ) SP="$n <$v>" ;; michael@13: * ) SP="$n $v" ;; michael@13: esac michael@13: break michael@13: done michael@13: fi michael@13: [ ".$SP" = . ] && SP="${ST}" michael@13: [ ".$SC" = . ] && SC="LSB" michael@13: ;; michael@13: michael@13: # Sun Solaris michael@13: *:SunOS:* ) michael@13: # determine architecture michael@13: AT="${UNAME_MACHINE}" michael@13: case "${AT}" in michael@13: i86pc ) michael@13: AT="iX86" michael@13: case "`(/bin/isainfo -k) 2>&1`" in michael@13: amd64 ) AT="AMD64" ;; michael@13: esac michael@13: ;; michael@13: esac michael@13: AP="${AT}" michael@13: case "${AP}" in michael@13: sun4[cdm] ) AP="SPARC32" ;; michael@13: sun4[uv] ) AP="SPARC64" ;; michael@13: sun4* ) AP="SPARC" ;; michael@13: esac michael@13: AC="${AP}" michael@13: case "${AC}" in michael@13: SPARC* ) AC="SPARC" ;; michael@13: esac michael@13: # determine system michael@13: ST="[Sun ]SunOS ${UNAME_RELEASE}" michael@13: v=`echo "${UNAME_RELEASE}" |\ michael@13: sed -e 's;^4\.;1.;' \ michael@13: -e 's;^5\.\([0-6]\)[^0-9]*$;2.\1;' \ michael@13: -e 's;^5\.\([0-9][0-9]*\).*;\1;'` michael@13: SP="[Sun ]Solaris $v" michael@13: case "${UNAME_RELEASE}" in michael@13: 4.* ) SC="4.3BSD" ;; michael@13: 5.* ) SC="SVR4" ;; michael@13: esac michael@13: ;; michael@13: michael@13: # SCO UnixWare michael@13: *:UnixWare:* ) michael@13: # determine architecture michael@13: AT="${UNAME_MACHINE}" michael@13: case "${AT}" in michael@13: i[3-6]86 | ix86at ) AT="iX86" ;; michael@13: esac michael@13: AP="${AT}" michael@13: # determine system michael@13: v=`/sbin/uname -v` michael@13: ST="[SCO ]UnixWare ${v}" michael@13: SP="${ST}" michael@13: SC="SVR${UNAME_RELEASE}" michael@13: ;; michael@13: michael@13: # QNX michael@13: *:QNX:* ) michael@13: # determine architecture michael@13: AT="${UNAME_MACHINE}" michael@13: case "${AT}" in michael@13: x86pc ) AT="iX86" ;; michael@13: esac michael@13: AP="${AT}" michael@13: # determine system michael@13: v="${UNAME_RELEASE}" michael@13: ST="QNX[ Neutrino RTOS] ${v}" michael@13: v=`echo "${v}" | sed -e 's;^\([0-9][0-9]*\.[0-9][0-9]*\).*$;\1;'` michael@13: SP="QNX[ Neutrino RTOS] ${v}" michael@13: SC="QNX" michael@13: ;; michael@13: michael@13: # SGI IRIX michael@13: *:IRIX*:* ) michael@13: # determine architecture michael@13: AT="${UNAME_MACHINE}" michael@13: AP="${AT}" michael@13: case "${AP}:${UNAME_SYSTEM}" in michael@13: IP*:IRIX64 ) AP="MIPS64" ;; michael@13: IP*:* ) AP="MIPS" ;; michael@13: esac michael@13: AC="${AP}" michael@13: # determine system michael@13: v=`(/bin/uname -R || /bin/uname -r) 2>/dev/null | sed -e 's;[0-9.]* ;;'` michael@13: ST="[SGI ]IRIX ${v}" michael@13: v="${UNAME_RELEASE}" michael@13: SP="[SGI ]IRIX ${v}" michael@13: SC="4.2BSD/SVR3" michael@13: ;; michael@13: michael@13: # HP HP-UX michael@13: *:HP-UX:* ) michael@13: # determine architecture michael@13: AT="${UNAME_MACHINE}" michael@13: case "${AT}" in michael@13: ia64 ) AT="IA64" ;; michael@13: 9000/[34]?? ) AT=M68K ;; michael@13: 9000/[678][0-9][0-9]) michael@13: sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` michael@13: sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` michael@13: case "${sc_cpu_version}" in michael@13: 523 ) AT="HPPA1.0" ;; michael@13: 528 ) AT="HPPA1.1" ;; michael@13: 532 ) AT="HPPA2.0" michael@13: case "${sc_kernel_bits}" in michael@13: 32 ) AT="${AT}n" ;; michael@13: 64 ) AT="${AT}w" ;; michael@13: esac michael@13: ;; michael@13: esac michael@13: ;; michael@13: esac michael@13: AP="${AT}" michael@13: case "${AP}" in michael@13: HPPA* ) AP="HPPA" ;; michael@13: esac michael@13: AC="${AP}" michael@13: # determine system michael@13: v=`echo "${UNAME_RELEASE}" | sed -e 's;^[^0-9]*;;'` michael@13: ST="[HP ]-" michael@13: SP="${ST}" michael@13: case "${v}" in michael@13: 10.* ) SC="SVR4.2" ;; michael@13: [7-9]* ) SC="SVR4" ;; michael@13: esac michael@13: ;; michael@13: michael@13: # HP Tru64 (OSF1) michael@13: *:OSF1:* ) michael@13: # determine architecture michael@13: AP="${UNAME_MACHINE}" michael@13: case "${AP}" in michael@13: alpha ) AP="Alpha" ;; michael@13: esac michael@13: alpha_type=`(/usr/sbin/psrinfo -v) 2>/dev/null |\ michael@13: sed -n -e 's/^.*The alpha \([^ ][^ ]*\).*processor.*$/\1/p' | sed -e 'q'` michael@13: AT="${AP}${alpha_type}" michael@13: AC="${AP}" michael@13: # determine system michael@13: v=`echo "${UNAME_RELEASE}" | sed -e 's;^[VTX];;'` michael@13: ST="[HP ]Tru64 ${v}" michael@13: SP="${ST}" michael@13: SC="OSF1" michael@13: ;; michael@13: michael@13: # IBM AIX michael@13: *:AIX:* ) michael@13: # determine architecture michael@13: cpu_arch=rs6000 michael@13: if [ -x /usr/sbin/lsdev -a -x /usr/sbin/lsattr ]; then michael@13: cpu_id=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` michael@13: if [ ".`/usr/sbin/lsattr -El ${cpu_id} | grep -i powerpc`" != . ]; then michael@13: cpu_arch=powerpc michael@13: fi michael@13: elif [ -d /QOpenSys ]; then michael@13: # IBM i5/OS (aka OS/400) with PASE (Portable Application Solutions Environment) michael@13: cpu_arch=powerpc michael@13: fi michael@13: if [ -x /usr/bin/oslevel ]; then michael@13: os_level=`/usr/bin/oslevel` michael@13: else michael@13: os_level="`uname -v`.`uname -r`" michael@13: fi michael@13: os_level=`echo "${os_level}" |\ michael@13: sed -e 's;^\([0-9][0-9]*\.[0-9][0-9]*\)\(\.[0-9][0-9]*\)\(.*\)$;<\1>\2[\3];' \ michael@13: -e 's;^\([0-9][0-9]*\.[0-9][0-9]*\)\(.*\)$;<\1>\2;'` michael@13: AT="${cpu_arch}" michael@13: AP="${AT}" michael@13: AC="${AP}" michael@13: # determine system michael@13: ST="[IBM ]${os_level}" michael@13: SP="${ST}" michael@13: case "${os_level}" in michael@13: [12]* ) SC="SVR2" ;; michael@13: * ) SC="SVR4" ;; michael@13: esac michael@13: ;; michael@13: michael@13: # Apple Mac OS X (Darwin) michael@13: *:Darwin:* ) michael@13: # determine architecture michael@13: AT="`uname -p`" michael@13: case "${AT}" in michael@13: powerpc ) AT="PPC" ;; michael@13: esac michael@13: AP="${AT}" michael@13: case "${AP}" in michael@13: i?86 ) AP="iX86" ;; michael@13: esac michael@13: AC="${AP}" michael@13: # determine system michael@13: unset v1; unset v2; unset v3 michael@13: eval `echo "${UNAME_RELEASE}" |\ michael@13: sed -e 's/^/#/' \ michael@13: -e 's/^#\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/v1="\1"; v2="\2"; v3="\3"/' \ michael@13: -e 's/^#\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/v1="\1"; v2="\2"/' \ michael@13: -e 's/^#\([0-9][0-9]*\).*$/v1="\1"/' \ michael@13: -e 's/^#.*$/v1="0"/'` michael@13: ST="[Apple ]<${UNAME_SYSTEM} ${v1}>${v2+.$v2}${v3+[.$v3]}" michael@13: SP="$ST" michael@13: v="`(sw_vers) 2>/dev/null | grep 'ProductVersion:' | sed -e 's/^ProductVersion:[^0-9]*\([0-9][0-9.]*\).*$/\1/'`" michael@13: if [ ".$v" = . ]; then michael@13: for name in System Server; do michael@13: if [ -f /System/Library/CoreServices/${name}Version.plist ]; then michael@13: v=`(defaults read "/System/Library/CoreServices/${name}Version" "ProductVersion") 2>/dev/null` michael@13: [ ".$v" != . ] && break michael@13: fi michael@13: done michael@13: fi michael@13: if [ ".$v" != . ]; then michael@13: unset v1; unset v2; unset v3 michael@13: eval `echo "${v}" |\ michael@13: sed -e 's/^/#/' \ michael@13: -e 's/^#\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/v1="\1"; v2="\2"; v3="\3"/' \ michael@13: -e 's/^#\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/v1="\1"; v2="\2"/' \ michael@13: -e 's/^#\([0-9][0-9]*\).*$/v1="\1"/' \ michael@13: -e 's/^#.*$/v1="0"/'` michael@13: SP="[Apple ]Mac OS X ${v1}${v2+.$v2}${v3+[.$v3]}" michael@13: fi michael@13: SC="4.4BSD/Mach3.0" michael@13: ;; michael@13: michael@13: # TODO ...ADD YOUR NEW PLATFORM CHECK HERE... TODO michael@13: # *:XXX:* ) michael@13: # ... michael@13: # ;; michael@13: michael@13: # ...A STILL UNKNOWN PLATFORM... michael@13: * ) michael@13: AT=`echo "${UNAME_MACHINE}" | sed -e "s; ;${opt_C};g"` michael@13: AP="${AT}" michael@13: AC="${AP}" michael@13: v=`echo "${UNAME_RELEASE}" |\ michael@13: sed -e 's/^/#/' \ michael@13: -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' \ michael@13: -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' \ michael@13: -e 's/^#[^0-9]*\([0-9][0-9]*\).*$/\1/' \ michael@13: -e 's/^#.*$/?/'` michael@13: ST="${UNAME_SYSTEM} ${v}" michael@13: SP="${ST}" michael@13: SC="${SP}" michael@13: ;; michael@13: michael@13: esac michael@13: michael@13: # provide fallback values michael@13: [ ".$AT" = . ] && AT="${AP:-${AC}}" michael@13: [ ".$AP" = . ] && AP="${AT:-${AC}}" michael@13: [ ".$AC" = . ] && AC="${AP:-${AT}}" michael@13: [ ".$ST" = . ] && ST="${SP:-${SC}}" michael@13: [ ".$SP" = . ] && SP="${ST:-${SC}}" michael@13: [ ".$SC" = . ] && SC="${SP:-${ST}}" michael@13: michael@13: # support explicit enforced verbose/concise output michael@13: if [ ".$opt_v" = .yes ]; then michael@13: opt_F=`echo ":$opt_F" | sed -e 's/^://' -e 's/%\([as][cpt]\)/%[\1]/g'` michael@13: elif [ ".$opt_c" = .yes ]; then michael@13: opt_F=`echo ":$opt_F" | sed -e 's/^://' -e 's/%\([as][cpt]\)/%<\1>/g'` michael@13: fi michael@13: michael@13: # provide verbose and concise variants michael@13: AC_V=""; AC_N=""; AC_C="" michael@13: AP_V=""; AP_N=""; AP_C="" michael@13: AT_V=""; AT_N=""; AT_C="" michael@13: SC_V=""; SC_N=""; SC_C="" michael@13: SP_V=""; SP_N=""; SP_C="" michael@13: ST_V=""; ST_N=""; ST_C="" michael@13: for var_lc in at ap ac st sp sc; do michael@13: case "$opt_F" in michael@13: *"%[${val_lc}]"* | *"%{${val_lc}}"* | *"%${val_lc}"* | *"%<${val_lc}>"* ) michael@13: var_uc=`util_upper "$var_lc"` michael@13: eval "val=\"\$${var_uc}\"" michael@13: val_V=""; val_N=""; val_C="" michael@13: case "$opt_F" in michael@13: *"%[${var_lc}]"* ) michael@13: val_V=`echo ":$val" | \ michael@13: sed -e 's/^://' \ michael@13: -e 's;\[\([^]]*\)\];\1;g' \ michael@13: -e 's;<\([^>]*\)>;\1;g' \ michael@13: -e "s; ;§§;g" \ michael@13: -e "s;/;%%;g" \ michael@13: -e "s;§§;${opt_S};g" \ michael@13: -e "s;%%;${opt_C};g"` michael@13: eval "${var_uc}_V=\"\${val_V}\"" michael@13: ;; michael@13: esac michael@13: case "$opt_F" in michael@13: *"%{${var_lc}}"* | *"%${var_lc}"* ) michael@13: val_N=`echo ":$val" | \ michael@13: sed -e 's/^://' \ michael@13: -e 's;\[\([^]]*\)\];;g' \ michael@13: -e 's;<\([^>]*\)>;\1;g' \ michael@13: -e "s; ;§§;g" \ michael@13: -e "s;/;%%;g" \ michael@13: -e "s;§§;${opt_S};g" \ michael@13: -e "s;%%;${opt_C};g"` michael@13: eval "${var_uc}_N=\"\${val_N}\"" michael@13: ;; michael@13: esac michael@13: case "$opt_F" in michael@13: *"%<${var_lc}>"* ) michael@13: val_C=`echo ":$val" | \ michael@13: sed -e 's/^://' \ michael@13: -e 's;\[\([^]]*\)\];;g' \ michael@13: -e 's;[^<]*<\([^>]*\)>[^<]*;\1;g' \ michael@13: -e "s; ;§§;g" \ michael@13: -e "s;/;%%;g" \ michael@13: -e "s;§§;${opt_S};g" \ michael@13: -e "s;%%;${opt_C};g"` michael@13: eval "${var_uc}_C=\"\${val_C}\"" michael@13: ;; michael@13: esac michael@13: ;; michael@13: esac michael@13: done michael@13: michael@13: # create output string michael@13: output=`echo ":$opt_F" |\ michael@13: sed -e "s/^://" \ michael@13: -e "s;%\\[ac\\];${AC_V};g" \ michael@13: -e "s;%{ac};${AC_N};g" \ michael@13: -e "s;%ac;${AC_N};g" \ michael@13: -e "s;%;${AC_C};g" \ michael@13: -e "s;%\\[ap\\];${AP_V};g" \ michael@13: -e "s;%{ap};${AP_N};g" \ michael@13: -e "s;%ap;${AP_N};g" \ michael@13: -e "s;%;${AP_C};g" \ michael@13: -e "s;%\\[at\\];${AT_V};g" \ michael@13: -e "s;%{at};${AT_N};g" \ michael@13: -e "s;%at;${AT_N};g" \ michael@13: -e "s;%;${AT_C};g" \ michael@13: -e "s;%\\[sc\\];${SC_V};g" \ michael@13: -e "s;%{sc};${SC_N};g" \ michael@13: -e "s;%sc;${SC_N};g" \ michael@13: -e "s;%;${SC_C};g" \ michael@13: -e "s;%\\[sp\\];${SP_V};g" \ michael@13: -e "s;%{sp};${SP_N};g" \ michael@13: -e "s;%sp;${SP_N};g" \ michael@13: -e "s;%;${SP_C};g" \ michael@13: -e "s;%\\[st\\];${ST_V};g" \ michael@13: -e "s;%{st};${ST_N};g" \ michael@13: -e "s;%st;${ST_N};g" \ michael@13: -e "s;%;${ST_C};g" \ michael@13: -e 's/\\\\n/^/g' |\ michael@13: tr '^' '\012'` michael@13: michael@13: # support lower/upper-case mapping michael@13: if [ ".$opt_L" = .yes ]; then michael@13: output=`util_lower "$output"` michael@13: elif [ ".$opt_U" = .yes ]; then michael@13: output=`util_upper "$output"` michael@13: fi michael@13: michael@13: # display output string michael@13: if [ ".$opt_n" = .yes ]; then michael@13: echo . | awk '{ printf("%s", output); }' output="$output" michael@13: else michael@13: echo "$output" michael@13: fi michael@13: michael@13: shtool_exit 0 michael@13: ;; michael@13: michael@13: arx ) michael@13: ## michael@13: ## arx -- Extended archive command michael@13: ## Copyright (c) 1999-2007 Ralf S. Engelschall michael@13: ## michael@13: michael@13: ar_prg="$opt_C" michael@13: ar_cmd="$1"; shift michael@13: archive="$1"; shift michael@13: files="$*" michael@13: michael@13: # walk through the file list and expand archives members michael@13: ar_tmpdir=`echo $archive | sed -e 's;[^/]*$;.arx;'` michael@13: nfiles='' michael@13: if [ ".$files" != . ]; then michael@13: for file in $files; do michael@13: if [ ! -f $file ]; then michael@13: echo "$msgprefix:Error: input file not found: $file" 1>&2 michael@13: shtool_exit 1 michael@13: fi michael@13: case $file in michael@13: *.a ) michael@13: if [ ! -d $ar_tmpdir ]; then michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "mkdir $ar_tmpdir" 1>&2 michael@13: fi michael@13: mkdir $ar_tmpdir michael@13: fi michael@13: case $ar_tmpdir in michael@13: .arx ) michael@13: from="../$file" michael@13: ;; michael@13: * ) michael@13: dir=`echo $file | sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;' -e 's;^$;.;'` michael@13: base=`echo $file | sed -e 's;.*/\([^/]*\)$;\1;'` michael@13: from="`cd $dir; pwd`/$base" michael@13: ;; michael@13: esac michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "(cd $ar_tmpdir && $ar_prg x $from)" 1>&2 michael@13: fi michael@13: (cd $ar_tmpdir && eval $ar_prg x $from) michael@13: if [ $? -ne 0 ]; then michael@13: echo "$msgprefix:Error: member extraction failed for archive: $file" 1>&2 michael@13: shtool_exit 1 michael@13: fi michael@13: for member in - `eval $ar_prg t $file | sed -e '/_\.SYMDEF/d'`; do michael@13: [ ".$member" = .- ] && continue michael@13: nfiles="$nfiles $ar_tmpdir/$member" michael@13: done michael@13: ;; michael@13: * ) michael@13: nfiles="$nfiles $file" michael@13: ;; michael@13: esac michael@13: done michael@13: fi michael@13: michael@13: # run the final archive command michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "$ar_prg $ar_cmd $archive $nfiles" 1>&2 michael@13: fi michael@13: eval $ar_prg $ar_cmd $archive $nfiles michael@13: if [ $? -ne 0 ]; then michael@13: echo "$msgprefix:Error: archive command failed" 1>&2 michael@13: shtool_exit $? michael@13: fi michael@13: michael@13: # cleanup and die gracefully michael@13: if [ -d $ar_tmpdir ]; then michael@13: if [ ".$opt_t" = .yes ]; then michael@13: echo "rm -rf $ar_tmpdir" 1>&2 michael@13: fi michael@13: rm -rf $ar_tmpdir michael@13: fi michael@13: michael@13: shtool_exit 0 michael@13: ;; michael@13: michael@13: slo ) michael@13: ## michael@13: ## slo -- Separate linker options by library class michael@13: ## Copyright (c) 1998-2007 Ralf S. Engelschall michael@13: ## michael@13: michael@13: DIFS="$IFS" michael@13: michael@13: # parse out -L and -l options from command line michael@13: DIRS='' michael@13: LIBS='' michael@13: ARGV='' michael@13: optprev='' michael@13: for opt michael@13: do michael@13: # concatenate with previous option if exists michael@13: if [ ".$optprev" != . ]; then michael@13: opt="${optprev}${opt}"; michael@13: optprev='' michael@13: fi michael@13: # remember options for arg if used stand-alone michael@13: if [ ".$opt" = ".-L" ] || [ ".$opt" = ".-l" ]; then michael@13: optprev="$opt" michael@13: continue; michael@13: fi michael@13: # split argument into option plus option argument michael@13: arg="`echo $opt | cut -c3-`" michael@13: opt="`echo $opt | cut -c1-2`" michael@13: # store into containers michael@13: case $opt in michael@13: -L) DIRS="$DIRS:$arg" ;; michael@13: -l) LIBS="$LIBS:$arg" ;; michael@13: *) ARGV="$ARGV $opt" ;; michael@13: esac michael@13: done michael@13: michael@13: # set linker default directories michael@13: DIRS_DEFAULT='/lib:/usr/lib' michael@13: if [ ".$LD_LIBRARY_PATH" != . ]; then michael@13: DIRS_DEFAULT="$DIRS_DEFAULT:$LD_LIBRARY_PATH" michael@13: fi michael@13: michael@13: # sort options by class michael@13: DIRS_OBJ='' michael@13: LIBS_OBJ='' michael@13: DIRS_PIC='' michael@13: LIBS_PIC='' michael@13: DIRS_DSO='' michael@13: LIBS_DSO='' michael@13: michael@13: # for each library... michael@13: OIFS="$IFS"; IFS=':' michael@13: for lib in $LIBS; do michael@13: [ ".$lib" = . ] && continue michael@13: michael@13: found='no' michael@13: found_indefdir='no' michael@13: found_type='' michael@13: found_dir='' michael@13: michael@13: # for each directory... michael@13: OIFS2="$IFS"; IFS=":$DIFS" michael@13: for dir in ${DIRS} switch-to-defdirs ${DIRS_DEFAULT}; do michael@13: [ ".$dir" = . ] && continue michael@13: [ ".$dir" = .switch-to-defdirs ] && found_indefdir=yes michael@13: [ ! -d $dir ] && continue michael@13: michael@13: # search the file michael@13: OIFS3="$IFS"; IFS="$DIFS" michael@13: for file in '' `cd $dir && env -i /bin/ls lib${lib}.* 2>/dev/null`; do michael@13: [ ".$file" = . ] && continue michael@13: case $file in michael@13: *.so|*.so.[0-9]*|*.sl|*.sl.[0-9]* ) michael@13: found=yes; michael@13: found_type=DSO; michael@13: break michael@13: ;; michael@13: *.lo|*.la ) michael@13: found=yes; michael@13: found_type=PIC michael@13: ;; michael@13: *.a ) michael@13: if [ ".$found_type" = . ]; then michael@13: found=yes michael@13: found_type=OBJ michael@13: fi michael@13: ;; michael@13: esac michael@13: done michael@13: IFS="$OIFS3" michael@13: if [ ".$found" = .yes ]; then michael@13: found_dir="$dir" michael@13: break michael@13: fi michael@13: done michael@13: IFS="$OIFS2" michael@13: michael@13: if [ ".$found" = .yes ]; then michael@13: if [ ".$found_indefdir" != .yes ]; then michael@13: eval "dirlist=\"\${DIRS_${found_type}}:\"" michael@13: case "$dirlist" in michael@13: *:$found_dir:* ) ;; michael@13: * ) eval "DIRS_${found_type}=\"\$DIRS_${found_type}:${found_dir}\"" ;; michael@13: esac michael@13: eval "LIBS_${found_type}=\"\$LIBS_${found_type}:$lib\"" michael@13: else michael@13: eval "LIBS_${found_type}=\"\$LIBS_${found_type}:$lib\"" michael@13: fi michael@13: else michael@13: LIBS_OBJ="$LIBS_OBJ:$lib" michael@13: #dirlist="`echo $DIRS $DIRS_DEFAULT | sed -e 's/:/ /g'`" michael@13: #echo "slo:Warning: library \"$lib\" not found in any of the following dirs:" 2>&1 michael@13: #echo "slo:Warning: $dirlist" 1>&1 michael@13: fi michael@13: done michael@13: IFS="$OIFS" michael@13: michael@13: # also pass-through unused dirs even if it's useless michael@13: OIFS="$IFS"; IFS=':' michael@13: for dir in $DIRS; do michael@13: dirlist="${DIRS_OBJ}:${DIRS_PIC}:${DIRS_DSO}:" michael@13: case "$dirlist" in michael@13: *:$dir:* ) ;; michael@13: * ) DIRS_OBJ="$DIRS_OBJ:$dir" ;; michael@13: esac michael@13: done michael@13: IFS="$OIFS" michael@13: michael@13: # reassemble the options but separated by type michael@13: for type in OBJ PIC DSO; do michael@13: OIFS="$IFS"; IFS=':' michael@13: eval "libs=\"\$LIBS_${type}\"" michael@13: opts='' michael@13: for lib in $libs; do michael@13: [ ".$lib" = . ] && continue michael@13: opts="$opts -l$lib" michael@13: done michael@13: eval "LIBS_${type}=\"$opts\"" michael@13: michael@13: eval "dirs=\"\$DIRS_${type}\"" michael@13: opts='' michael@13: for dir in $dirs; do michael@13: [ ".$dir" = . ] && continue michael@13: opts="$opts -L$dir" michael@13: done michael@13: eval "DIRS_${type}=\"$opts\"" michael@13: IFS="$OIFS" michael@13: done michael@13: michael@13: # give back results michael@13: for var in ARGV DIRS_OBJ LIBS_OBJ DIRS_PIC LIBS_PIC DIRS_DSO LIBS_DSO; do michael@13: eval "val=\"\$${var}\"" michael@13: val="`echo $val | sed -e 's/^ *//'`" michael@13: echo "${opt_p}${var}=\"${val}\"" michael@13: done michael@13: michael@13: shtool_exit 0 michael@13: ;; michael@13: michael@13: scpp ) michael@13: ## michael@13: ## scpp -- Sharing C Pre-Processor michael@13: ## Copyright (c) 1999-2007 Ralf S. Engelschall michael@13: ## michael@13: michael@13: srcs="$*" michael@13: output="${opt_o}.n" michael@13: michael@13: # find a reasonable Awk michael@13: awk='' michael@13: paths=`echo $PATH |\ michael@13: sed -e 's%/*:%:%g' -e 's%/$%%' \ michael@13: -e 's/^:/.:/' -e 's/::/:.:/g' -e 's/:$/:./' \ michael@13: -e 's/:/ /g'` michael@13: for name in gawk nawk awk; do michael@13: for path in $paths; do michael@13: if [ -r "$path/$name" ]; then michael@13: awk="$path/$name" michael@13: break michael@13: fi michael@13: done michael@13: if [ ".$awk" != . ]; then michael@13: break michael@13: fi michael@13: done michael@13: if [ ".$awk" = . ]; then michael@13: echo "$msgprefix:Error: cannot find a reasonable Awk" 1>&2 michael@13: shtool_exit 1 michael@13: fi michael@13: michael@13: # parse source file(s) michael@13: if [ ".$opt_v" = .yes ]; then michael@13: echo "Parsing:" | $awk '{ printf("%s", $0); }' 1>&2 michael@13: fi michael@13: for src in $srcs; do michael@13: if [ ".$opt_v" = .yes ]; then michael@13: echo $src | $awk '{ printf(" %s", $0); }' 1>&2 michael@13: fi michael@13: if [ ".$opt_f" != . ]; then michael@13: inputcmd="sed" michael@13: OIFS="$IFS"; IFS="$ASC_NL"; set -- $opt_f; IFS="$OIFS" michael@13: for e michael@13: do michael@13: inputcmd="$inputcmd -e '$e'" michael@13: done michael@13: inputcmd="$inputcmd '$src'" michael@13: else michael@13: inputcmd="cat '$src'" michael@13: fi michael@13: eval $inputcmd |\ michael@13: $awk ' michael@13: BEGIN { michael@13: ln = 0; michael@13: fln = 0; michael@13: level = 0; michael@13: mode = ""; michael@13: store = ""; michael@13: } michael@13: { michael@13: ln++; michael@13: } michael@13: /^#if.*/ { michael@13: level++; michael@13: } michael@13: /^#if [a-zA-Z_][a-zA-Z0-9_]* *$/ { michael@13: if ($2 == define) { michael@13: mode = "D"; michael@13: printf("D:#line %d \"%s\"\n", ln, src); michael@13: next; michael@13: } michael@13: } michael@13: /^#endif.*/ { michael@13: level--; michael@13: if (mode == "D" && level == 0) { michael@13: mode = ""; michael@13: next; michael@13: } michael@13: } michael@13: /^[a-zA-Z_][a-zA-Z0-9_].*;.*/ { michael@13: if ($1 == class) { michael@13: printf("V:#line %d \"%s\"\n", ln, src); michael@13: printf("V:%s\n", $0); michael@13: printf("J:%s\n", $0); michael@13: next; michael@13: } michael@13: } michael@13: /^[a-zA-Z_][a-zA-Z0-9_].*=.*/ { michael@13: if ($1 == class) { michael@13: printf("V:#line %d \"%s\"\n", ln, src); michael@13: printf("V:%s\n", $0); michael@13: printf("J:%s\n", $0); michael@13: next; michael@13: } michael@13: } michael@13: /^[a-zA-Z_][a-zA-Z0-9_]*/ { michael@13: if ($1 == class) { michael@13: fln = ln; michael@13: store = $0; michael@13: mode = "F"; michael@13: next; michael@13: } michael@13: } michael@13: /^\{ *$/ { michael@13: if (mode == "F") { michael@13: printf("F:#line %d \"%s\"\n", fln, src); michael@13: printf("F:%s;\n", store); michael@13: printf("I:%s;\n", store); michael@13: store = ""; michael@13: mode = ""; michael@13: next; michael@13: } michael@13: } michael@13: { michael@13: if (mode == "D") michael@13: printf("D:%s\n", $0); michael@13: else if (mode == "F") michael@13: store = store " " $0; michael@13: } michael@13: ' "src=$src" "define=$opt_D" "class=$opt_C" >>$tmpfile michael@13: done michael@13: if [ ".$opt_v" = .yes ]; then michael@13: echo "" 1>&2 michael@13: fi michael@13: michael@13: # start generating output header michael@13: echo "/* $opt_o -- autogenerated from $opt_t, DO NOT EDIT! */" >$output michael@13: echo "#line 1 \"$opt_t\"" >>$output michael@13: sed <$opt_t -e "1,/^${opt_M} *\$/p" -e 'd' |\ michael@13: sed -e "/^${opt_M} *\$/d" >>$output michael@13: michael@13: # merge in the define blocks michael@13: grep '^D:' $tmpfile | sed -e 's/^D://' >>$output michael@13: michael@13: # generate standard prolog michael@13: echo "#line 1 \"_ON_THE_FLY_\"" >>$output michael@13: echo "" >>$output michael@13: echo "/* make sure the scpp source extensions are skipped */" >>$output michael@13: echo "#define $opt_D 0" >>$output michael@13: echo "#define $opt_C /**/" >>$output michael@13: michael@13: # generate namespace hiding for variables michael@13: echo "" >>$output michael@13: echo "/* move intern variables to hidden namespace */" >>$output michael@13: grep '^J:' $tmpfile | sed >>$output \ michael@13: -e 's/^J://' \ michael@13: -e 's/ */ /g' \ michael@13: -e 's/^[^=;]*[ *]\([a-zA-Z0-9_]*\)\[\];.*$/#define \1 __\1/' \ michael@13: -e 's/^[^=;]*[ *]\([a-zA-Z0-9_]*\)\[\] =.*$/#define \1 __\1/' \ michael@13: -e 's/^[^=;]*[ *]\([a-zA-Z0-9_]*\);.*$/#define \1 __\1/' \ michael@13: -e 's/^[^=;]*[ *]\([a-zA-Z0-9_]*\) =.*$/#define \1 __\1/' michael@13: michael@13: # generate namespace hiding for functions michael@13: echo "" >>$output michael@13: echo "/* move intern functions to hidden namespace */" >>$output michael@13: grep '^I:' $tmpfile | sed >>$output \ michael@13: -e 's/^I://' \ michael@13: -e 's/\([ (]\) */\1/g' \ michael@13: -e 's/ *\([),]\)/\1/g' \ michael@13: -e 's/^[^(]*[ *]\([a-zA-Z0-9_]*\)(.*$/#define \1 __\1/' michael@13: michael@13: # generate prototypes for variables michael@13: echo "" >>$output michael@13: echo "/* prototypes for intern variables */" >>$output michael@13: grep '^V:' $tmpfile | sed >>$output \ michael@13: -e 's/^V://' \ michael@13: -e 's/ */ /g' \ michael@13: -e 's/^\([^=;]*[ *][a-zA-Z0-9_]*\[\]\);.*$/\1;/' \ michael@13: -e 's/^\([^=;]*[ *][a-zA-Z0-9_]*\[\]\) =.*$/\1;/' \ michael@13: -e 's/^\([^=;]*[ *][a-zA-Z0-9_]*\);.*$/\1;/' \ michael@13: -e 's/^\([^=;]*[ *][a-zA-Z0-9_]*\) =.*$/\1;/' \ michael@13: -e 's/ ;/;/g' \ michael@13: -e "s/^$opt_C /extern /" michael@13: michael@13: # generate prototypes for functions michael@13: echo "" >>$output michael@13: echo "/* prototypes for intern functions */" >>$output michael@13: grep '^F:' $tmpfile | sed >>$output \ michael@13: -e 's/^F://' \ michael@13: -e 's/\([ (]\) */\1/g' \ michael@13: -e 's/ *\([),]\)/\1/g' \ michael@13: -e 's/\([* ]\)[a-zA-Z0-9_]*,/\1,/g' \ michael@13: -e 's/\([* ]\)[a-zA-Z0-9_]*);/\1);/g' \ michael@13: -e 's/(\*[a-zA-Z0-9_]*)(/(*)(/g' \ michael@13: -e 's/\([ (]\) */\1/g' \ michael@13: -e 's/ *\([),]\)/\1/g' \ michael@13: -e "s/^$opt_C /extern /" michael@13: michael@13: # finish generating output header michael@13: n=`(echo ''; sed <$opt_t -e "1,/^${opt_M} *\$/p" -e 'd') |\ michael@13: wc -l | sed -e 's;^ *\([0-9]*\) *$;\1;'` michael@13: echo "#line $n \"$opt_t\"" >>$output michael@13: sed <$opt_t -e "/^${opt_M} *\$/,\$p" -e 'd' |\ michael@13: sed -e "/^${opt_M} *\$/d" >>$output michael@13: michael@13: # create final output file michael@13: if [ -f $opt_o ]; then michael@13: if [ ".$opt_p" = .yes ]; then michael@13: grep -v '^#line' $opt_o >$tmpfile.o michael@13: grep -v '^#line' $output >$tmpfile.n michael@13: out_old="$tmpfile.o" michael@13: out_new="$tmpfile.n" michael@13: else michael@13: out_old="$opt_o" michael@13: out_new="$output" michael@13: fi michael@13: if cmp -s $out_old $out_new; then michael@13: : michael@13: else michael@13: cp $output $opt_o michael@13: fi michael@13: else michael@13: cp $output $opt_o michael@13: fi michael@13: rm -f $output michael@13: rm -f $tmpfile $tmpfile.* >/dev/null 2>&1 michael@13: michael@13: shtool_exit 0 michael@13: ;; michael@13: michael@13: version ) michael@13: ## michael@13: ## version -- Maintain a version information file michael@13: ## Copyright (c) 1994-2007 Ralf S. Engelschall michael@13: ## michael@13: michael@13: file="$1" michael@13: michael@13: # determine prefix and name michael@13: name="$opt_n" michael@13: prefix="$opt_p" michael@13: michael@13: # determine current version michael@13: triple="$opt_s" michael@13: if [ ".$triple" != . ]; then michael@13: # use given triple michael@13: if [ ".`echo $triple | grep '[0-9]*.[0-9]*[sabp.][0-9]*'`" = . ]; then michael@13: echo "$msgprefix:Error: invalid argument to option \`-s': \`$opt_s'" 1>&2 michael@13: shtool_exit 1 michael@13: fi michael@13: eval `echo $triple |\ michael@13: sed -e 's%\([0-9]*\)\.\([0-9]*\)\([sabp.]\)\([0-9]*\).*%\ michael@13: ver="\1";rev="\2";typ="\3";lev="\4"%'` michael@13: tim=calc michael@13: elif [ -r $file ]; then michael@13: # determine triple from given file michael@13: eval `grep 'Version [0-9]*.[0-9]*[sabp.][0-9]* ([0-9]*-[a-zA-Z]*-[0-9]*)' $file |\ michael@13: sed -e 's%.*Version \([0-9]*\)\.\([0-9]*\)\([sabp.]\)\([0-9]*\) (\([0-9]*-[a-zA-Z]*-[0-9]*\)).*%\ michael@13: ver="\1";rev="\2";typ="\3";lev="\4";tim="\5"%' -e 'q'` michael@13: else michael@13: # intialise to first version michael@13: ver=0 michael@13: rev=1 michael@13: typ=. michael@13: lev=0 michael@13: tim=calc michael@13: fi michael@13: michael@13: # determine new version in batch michael@13: if [ ".$opt_i" != . ]; then michael@13: case $opt_i in michael@13: v ) ver=`expr $ver + 1` michael@13: rev=0 michael@13: lev=0 michael@13: ;; michael@13: r ) rev=`expr $rev + 1` michael@13: lev=0 michael@13: ;; michael@13: l ) lev=`expr $lev + 1` michael@13: ;; michael@13: * ) echo "$msgprefix:Error: invalid argument to option \`-i': \`$opt_i'" 1>&2 michael@13: shtool_exit 1 michael@13: ;; michael@13: esac michael@13: tim=calc michael@13: fi michael@13: michael@13: # determine new version interactively michael@13: if [ ".$opt_e" = .yes ]; then michael@13: echo "old version: ${ver}.${rev}${typ}${lev}" michael@13: while [ 1 ]; do michael@13: echo dummy | awk '{ printf("new version: "); }' michael@13: read triple michael@13: case $triple in michael@13: [0-9]*.[0-9]*[sabp.][0-9]* ) michael@13: ;; michael@13: * ) echo "$msgprefix:Error: invalid version string entered: \`$triple'" 1>&2 michael@13: continue michael@13: ;; michael@13: esac michael@13: break michael@13: done michael@13: eval `echo $triple |\ michael@13: sed -e 's%^\([0-9]*\)\.\([0-9]*\)\([sabp.]\)\([0-9]*\)$%\ michael@13: ver="\1";rev="\2";typ="\3";lev="\4"%'` michael@13: tim=calc michael@13: fi michael@13: michael@13: # determine hexadecimal and libtool value of version michael@13: case $typ in michael@13: a ) typnum=0; levnum=$lev ;; michael@13: b ) typnum=1; levnum=$lev ;; michael@13: p | . ) typnum=2; levnum=$lev ;; michael@13: s ) typnum=15; levnum=255 ;; # snapshots are special michael@13: esac michael@13: hex=`echo "$ver:$rev:$typnum:$levnum" |\ michael@13: awk -F: '{ printf("0x%x%02x%1x%02x", $1, $2, $3, $4); }' |\ michael@13: tr 'abcdef' 'ABCDEF'` michael@13: ltv=`echo "$ver:$rev:$typnum:$levnum" |\ michael@13: awk -F: '{ printf("%d:%d", $1*10 + $2, $3*10 + $4); }'` michael@13: michael@13: # determine date michael@13: if [ ".$tim" = .calc ]; then michael@13: day=`date '+%d'` michael@13: month=`date '+%m'` michael@13: year=`date '+%Y' 2>/dev/null` michael@13: if [ ".$time_year" = . ]; then michael@13: year=`date '+%y'` michael@13: case $year in michael@13: [5-9][0-9]) year="19$year" ;; michael@13: [0-4][0-9]) year="20$year" ;; michael@13: esac michael@13: fi michael@13: case $month in michael@13: 1|01) month='Jan' ;; michael@13: 2|02) month='Feb' ;; michael@13: 3|03) month='Mar' ;; michael@13: 4|04) month='Apr' ;; michael@13: 5|05) month='May' ;; michael@13: 6|06) month='Jun' ;; michael@13: 7|07) month='Jul' ;; michael@13: 8|08) month='Aug' ;; michael@13: 9|09) month='Sep' ;; michael@13: 10) month='Oct' ;; michael@13: 11) month='Nov' ;; michael@13: 12) month='Dec' ;; michael@13: esac michael@13: tim="${day}-${month}-${year}" michael@13: fi michael@13: michael@13: # perform result actions michael@13: mode=show michael@13: if [ ".$opt_i" != . ]; then michael@13: mode=edit michael@13: elif [ ".$opt_e" = .yes ]; then michael@13: mode=edit michael@13: elif [ ".$opt_s" != . ]; then michael@13: mode=edit michael@13: fi michael@13: if [ ".$mode" = .show ]; then michael@13: # just display the current version michael@13: case $opt_d in michael@13: short ) michael@13: echo "${ver}.${rev}${typ}${lev}" michael@13: ;; michael@13: long ) michael@13: echo "${ver}.${rev}${typ}${lev} ($tim)" michael@13: ;; michael@13: libtool ) michael@13: echo "${ltv}" michael@13: ;; michael@13: hex ) michael@13: echo "${hex}" michael@13: ;; michael@13: * ) echo "$msgprefix:Error: invalid argument to option \`-d': \`$opt_d'" 1>&2 michael@13: shtool_exit 1 michael@13: ;; michael@13: esac michael@13: else michael@13: # update the version file michael@13: michael@13: # pre-generate various strings michael@13: triple="${ver}.${rev}${typ}${lev}" michael@13: vHex="$hex" michael@13: vShort="${triple}" michael@13: vLong="${triple} (${tim})" michael@13: vTeX="This is ${name}, Version ${triple} (${tim})" michael@13: vGNU="${name} ${triple} (${tim})" michael@13: vWeb="${name}/${triple}" michael@13: vSCCS="@(#)${name} ${triple} (${tim})" michael@13: vRCS="\$Id: ${name} ${triple} (${tim}) \$" michael@13: michael@13: # determine string out of filename michael@13: # (do NOT try to optimize this in any way because of portability) michael@13: filestr=`util_upper "$file" | tr './%+' '____' | sed -e 's/-/_/g'` michael@13: michael@13: # generate uppercase prefix michael@13: prefixupper=`util_upper "$prefix"` michael@13: michael@13: # create the version file according the the selected language michael@13: echo "new version: ${vLong}" michael@13: michael@13: cp /dev/null $file michael@13: case $opt_l in michael@13: txt ) michael@13: echo >>$file "" michael@13: echo >>$file " ${file} -- Version Information for ${name} (syntax: Text)" michael@13: echo >>$file " [automatically generated and maintained by GNU shtool]" michael@13: echo >>$file "" michael@13: echo >>$file " $vTeX" michael@13: echo >>$file "" michael@13: ;; michael@13: c ) michael@13: echo >>$file "/*" michael@13: echo >>$file "** ${file} -- Version Information for ${name} (syntax: C/C++)" michael@13: echo >>$file "** [automatically generated and maintained by GNU shtool]" michael@13: echo >>$file "*/" michael@13: echo >>$file "" michael@13: echo >>$file "#ifdef _${filestr}_AS_HEADER_" michael@13: echo >>$file "" michael@13: echo >>$file "#ifndef _${filestr}_" michael@13: echo >>$file "#define _${filestr}_" michael@13: echo >>$file "" michael@13: echo >>$file "#define ${prefixupper}VERSION ${vHex}" michael@13: echo >>$file "" michael@13: echo >>$file "typedef struct {" michael@13: echo >>$file " const int v_hex;" michael@13: echo >>$file " const char *v_short;" michael@13: echo >>$file " const char *v_long;" michael@13: echo >>$file " const char *v_tex;" michael@13: echo >>$file " const char *v_gnu;" michael@13: echo >>$file " const char *v_web;" michael@13: echo >>$file " const char *v_sccs;" michael@13: echo >>$file " const char *v_rcs;" michael@13: echo >>$file "} ${prefix}version_t;" michael@13: echo >>$file "" michael@13: echo >>$file "extern ${prefix}version_t ${prefix}version;" michael@13: echo >>$file "" michael@13: echo >>$file "#endif /* _${filestr}_ */" michael@13: echo >>$file "" michael@13: echo >>$file "#else /* _${filestr}_AS_HEADER_ */" michael@13: echo >>$file "" michael@13: echo >>$file "#define _${filestr}_AS_HEADER_" michael@13: echo >>$file "#include \"${file}\"" michael@13: echo >>$file "#undef _${filestr}_AS_HEADER_" michael@13: echo >>$file "" michael@13: echo >>$file "${prefix}version_t ${prefix}version = {" michael@13: echo >>$file " ${vHex}," michael@13: echo >>$file " \"${vShort}\"," michael@13: echo >>$file " \"${vLong}\"," michael@13: echo >>$file " \"${vTeX}\"," michael@13: echo >>$file " \"${vGNU}\"," michael@13: echo >>$file " \"${vWeb}\"," michael@13: echo >>$file " \"${vSCCS}\"," michael@13: echo >>$file " \"${vRCS}\"" michael@13: echo >>$file "};" michael@13: echo >>$file "" michael@13: echo >>$file "#endif /* _${filestr}_AS_HEADER_ */" michael@13: echo >>$file "" michael@13: ;; michael@13: m4 ) michael@13: echo >>$file "##" michael@13: echo >>$file "## ${file} -- Version Information for ${name} (syntax: M4)" michael@13: echo >>$file "## [automatically generated and maintained by GNU shtool]" michael@13: echo >>$file "##" michael@13: echo >>$file "" michael@13: echo >>$file "m4_define([v_hex], [${vHex}])" michael@13: echo >>$file "m4_define([v_short], [${vShort}])" michael@13: echo >>$file "m4_define([v_long], [${vLong}])" michael@13: echo >>$file "m4_define([v_tex], [${vTeX}])" michael@13: echo >>$file "m4_define([v_gnu], [${vGNU}])" michael@13: echo >>$file "m4_define([v_web], [${vWeb}])" michael@13: echo >>$file "m4_define([v_sccs], [${vSCCS}])" michael@13: echo >>$file "m4_define([v_rcs], [${vRCS}])" michael@13: echo >>$file "" michael@13: ;; michael@13: perl ) michael@13: echo >>$file "##" michael@13: echo >>$file "## ${file} -- Version Information for ${name} (syntax: Perl)" michael@13: echo >>$file "## [automatically generated and maintained by GNU shtool]" michael@13: echo >>$file "##" michael@13: echo >>$file "" michael@13: echo >>$file "our \$${prefix}version = {" michael@13: echo >>$file " 'v_hex' => ${vHex}," michael@13: echo >>$file " 'v_short' => \"${vShort}\"," michael@13: echo >>$file " 'v_long' => \"${vLong}\"," michael@13: echo >>$file " 'v_tex' => \"${vTeX}\"," michael@13: echo >>$file " 'v_gnu' => \"${vGNU}\"," michael@13: echo >>$file " 'v_web' => \"${vWeb}\"," michael@13: echo >>$file " 'v_sccs' => \"${vSCCS}\"," michael@13: echo >>$file " 'v_rcs' => \"\\${vRCS}/\"" michael@13: echo >>$file "};" michael@13: echo >>$file "" michael@13: echo >>$file "1;" michael@13: echo >>$file "" michael@13: ;; michael@13: python ) michael@13: echo >>$file "##" michael@13: echo >>$file "## ${file} -- Version Information for ${name} (syntax: Python)" michael@13: echo >>$file "## [automatically generated and maintained by GNU shtool]" michael@13: echo >>$file "##" michael@13: echo >>$file "" michael@13: echo >>$file "class ${prefix}version:" michael@13: echo >>$file " v_hex = ${vHex}" michael@13: echo >>$file " v_short = \"${vShort}\"" michael@13: echo >>$file " v_long = \"${vLong}\"" michael@13: echo >>$file " v_tex = \"${vTeX}\"" michael@13: echo >>$file " v_gnu = \"${vGNU}\"" michael@13: echo >>$file " v_web = \"${vWeb}\"" michael@13: echo >>$file " v_sccs = \"${vSCCS}\"" michael@13: echo >>$file " v_rcs = \"${vRCS}\"" michael@13: echo >>$file "" michael@13: ;; michael@13: * ) echo "$msgprefix:Error: invalid argument to option \`-l': \`$opt_l'" 1>&2 michael@13: shtool_exit 1 michael@13: ;; michael@13: esac michael@13: fi michael@13: michael@13: shtool_exit 0 michael@13: ;; michael@13: michael@13: path ) michael@13: ## michael@13: ## path -- Deal with program paths michael@13: ## Copyright (c) 1998-2007 Ralf S. Engelschall michael@13: ## michael@13: michael@13: namelist="$*" michael@13: michael@13: # check whether the test command supports the -x option michael@13: if [ -x /bin/sh ] 2>/dev/null; then michael@13: minusx="-x" michael@13: else michael@13: minusx="-r" michael@13: fi michael@13: michael@13: # split path string michael@13: paths="`echo $opt_p |\ michael@13: sed -e 's/^:/.:/' \ michael@13: -e 's/::/:.:/g' \ michael@13: -e 's/:$/:./' \ michael@13: -e 's/:/ /g'`" michael@13: michael@13: # SPECIAL REQUEST michael@13: # translate forward to reverse path michael@13: if [ ".$opt_r" = .yes ]; then michael@13: if [ "x$namelist" = "x." ]; then michael@13: rp='.' michael@13: else michael@13: rp='' michael@13: for pe in `IFS="$IFS/"; echo $namelist`; do michael@13: rp="../$rp" michael@13: done michael@13: fi michael@13: echo $rp | sed -e 's:/$::' michael@13: shtool_exit 0 michael@13: fi michael@13: michael@13: # SPECIAL REQUEST michael@13: # strip out directory or base name michael@13: if [ ".$opt_d" = .yes ]; then michael@13: echo "$namelist" |\ michael@13: sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;' michael@13: shtool_exit 0 michael@13: fi michael@13: if [ ".$opt_b" = .yes ]; then michael@13: echo "$namelist" |\ michael@13: sed -e 's;.*/\([^/]*\)$;\1;' michael@13: shtool_exit 0 michael@13: fi michael@13: michael@13: # MAGIC SITUATION michael@13: # Perl Interpreter (perl) michael@13: if [ ".$opt_m" = .yes ] && [ ".$namelist" = .perl ]; then michael@13: rm -f $tmpfile >/dev/null 2>&1 michael@13: touch $tmpfile michael@13: found=0 michael@13: pc=99 michael@13: for dir in $paths; do michael@13: dir=`echo $dir | sed -e 's;/*$;;'` michael@13: nc=99 michael@13: for name in perl perl5 miniperl; do michael@13: if [ $minusx "$dir/$name" ] && [ ! -d "$dir/$name" ]; then michael@13: perl="$dir/$name" michael@13: pv=`$perl -e 'printf("%.3f", $]);'` michael@13: echo "$pv:$pc:$nc:$perl" >>$tmpfile michael@13: found=1 michael@13: fi michael@13: nc=`expr $nc - 1` michael@13: done michael@13: pc=`expr $pc - 1` michael@13: done michael@13: if [ $found = 1 ]; then michael@13: perl="`cat $tmpfile | sort -r -u | sed -e 'q' | cut -d: -f4`" michael@13: rm -f $tmpfile >/dev/null 2>&1 michael@13: echo "$perl" michael@13: shtool_exit 0 michael@13: fi michael@13: rm -f $tmpfile >/dev/null 2>&1 michael@13: shtool_exit 1 michael@13: fi michael@13: michael@13: # MAGIC SITUATION michael@13: # C pre-processor (cpp) michael@13: if [ ".$opt_m" = .yes ] && [ ".$namelist" = .cpp ]; then michael@13: echo >$tmpfile.c "#include " michael@13: echo >>$tmpfile.c "Syntax Error" michael@13: # 1. try the standard cc -E approach michael@13: cpp="${CC-cc} -E" michael@13: (eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out michael@13: my_error=`grep -v '^ *+' $tmpfile.out` michael@13: if [ ".$my_error" != . ]; then michael@13: # 2. try the cc -E approach and GCC's -traditional-ccp option michael@13: cpp="${CC-cc} -E -traditional-cpp" michael@13: (eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out michael@13: my_error=`grep -v '^ *+' $tmpfile.out` michael@13: if [ ".$my_error" != . ]; then michael@13: # 3. try a standalone cpp command in path and lib dirs michael@13: for path in $paths /lib /usr/lib /usr/local/lib; do michael@13: path=`echo $path | sed -e 's;/*$;;'` michael@13: if [ $minusx "$path/cpp" ] && [ ! -d "$path/cpp" ]; then michael@13: cpp="$path/cpp" michael@13: break michael@13: fi michael@13: done michael@13: if [ ".$cpp" != . ]; then michael@13: (eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out michael@13: my_error=`grep -v '^ *+' $tmpfile.out` michael@13: if [ ".$my_error" != . ]; then michael@13: # ok, we gave up... michael@13: cpp='' michael@13: fi michael@13: fi michael@13: fi michael@13: fi michael@13: rm -f $tmpfile >/dev/null 2>&1 michael@13: rm -f $tmpfile.c $tmpfile.out >/dev/null 2>&1 michael@13: if [ ".$cpp" != . ]; then michael@13: echo "$cpp" michael@13: shtool_exit 0 michael@13: fi michael@13: shtool_exit 1 michael@13: fi michael@13: michael@13: # STANDARD SITUATION michael@13: # iterate over names michael@13: for name in $namelist; do michael@13: # iterate over paths michael@13: for path in $paths; do michael@13: path=`echo $path | sed -e 's;/*$;;'` michael@13: if [ $minusx "$path/$name" ] && [ ! -d "$path/$name" ]; then michael@13: if [ ".$opt_s" != .yes ]; then michael@13: echo "$path/$name" michael@13: fi michael@13: shtool_exit 0 michael@13: fi michael@13: done michael@13: done michael@13: michael@13: shtool_exit 1 michael@13: ;; michael@13: michael@13: esac michael@13: michael@13: shtool_exit 0 michael@13: