| 1 |
#!/bin/sh |
| 2 |
## |
| 3 |
## GNU shtool -- The GNU Portable Shell Tool |
| 4 |
## Copyright (c) 1994-2008 Ralf S. Engelschall <[email protected]> |
| 5 |
## |
| 6 |
## See http://www.gnu.org/software/shtool/ for more information. |
| 7 |
## See ftp://ftp.gnu.org/gnu/shtool/ for latest version. |
| 8 |
## |
| 9 |
## Version: 2.0.8 (18-Jul-2008) |
| 10 |
## Contents: 2/19 available modules |
| 11 |
## |
| 12 |
|
| 13 |
## |
| 14 |
## This program is free software; you can redistribute it and/or modify |
| 15 |
## it under the terms of the GNU General Public License as published by |
| 16 |
## the Free Software Foundation; either version 2 of the License, or |
| 17 |
## (at your option) any later version. |
| 18 |
## |
| 19 |
## This program is distributed in the hope that it will be useful, |
| 20 |
## but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 |
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 22 |
## General Public License for more details. |
| 23 |
## |
| 24 |
## You should have received a copy of the GNU General Public License |
| 25 |
## along with this program; if not, write to the Free Software |
| 26 |
## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
| 27 |
## USA, or contact Ralf S. Engelschall <[email protected]>. |
| 28 |
## |
| 29 |
## NOTICE: Given that you include this file verbatim into your own |
| 30 |
## source tree, you are justified in saying that it remains separate |
| 31 |
## from your package, and that this way you are simply just using GNU |
| 32 |
## shtool. So, in this situation, there is no requirement that your |
| 33 |
## package itself is licensed under the GNU General Public License in |
| 34 |
## order to take advantage of GNU shtool. |
| 35 |
## |
| 36 |
|
| 37 |
## |
| 38 |
## Usage: shtool [<options>] [<cmd-name> [<cmd-options>] [<cmd-args>]] |
| 39 |
## |
| 40 |
## Available commands: |
| 41 |
## install Install a program, script or datafile |
| 42 |
## mkdir Make one or more directories |
| 43 |
## |
| 44 |
## Not available commands (because module was not built-in): |
| 45 |
## echo Print string with optional construct expansion |
| 46 |
## mdate Pretty-print modification time of a file or dir |
| 47 |
## table Pretty-print a field-separated list as a table |
| 48 |
## prop Display progress with a running propeller |
| 49 |
## move Move files with simultaneous substitution |
| 50 |
## mkln Make link with calculation of relative paths |
| 51 |
## mkshadow Make a shadow tree through symbolic links |
| 52 |
## fixperm Fix file permissions inside a source tree |
| 53 |
## rotate Logfile rotation |
| 54 |
## tarball Roll distribution tarballs |
| 55 |
## subst Apply sed(1) substitution operations |
| 56 |
## platform Platform Identification Utility |
| 57 |
## arx Extended archive command |
| 58 |
## slo Separate linker options by library class |
| 59 |
## scpp Sharing C Pre-Processor |
| 60 |
## version Maintain a version information file |
| 61 |
## path Deal with program paths |
| 62 |
## |
| 63 |
|
| 64 |
# maximum Bourne-Shell compatibility |
| 65 |
if [ ".$ZSH_VERSION" != . ] && (emulate sh) >/dev/null 2>&1; then |
| 66 |
# reconfigure zsh(1) |
| 67 |
emulate sh |
| 68 |
NULLCMD=: |
| 69 |
alias -g '${1+"$@"}'='"$@"' |
| 70 |
elif [ ".$BASH_VERSION" != . ] && (set -o posix) >/dev/null 2>&1; then |
| 71 |
# reconfigure bash(1) |
| 72 |
set -o posix |
| 73 |
fi |
| 74 |
|
| 75 |
# maximum independence of NLS nuisances |
| 76 |
for var in \ |
| 77 |
LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \ |
| 78 |
LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \ |
| 79 |
LC_TELEPHONE LC_TIME |
| 80 |
do |
| 81 |
if (set +x; test -z "`(eval $var=C; export $var) 2>&1`"); then |
| 82 |
eval $var=C; export $var |
| 83 |
else |
| 84 |
unset $var |
| 85 |
fi |
| 86 |
done |
| 87 |
|
| 88 |
# initial command line handling |
| 89 |
if [ $# -eq 0 ]; then |
| 90 |
echo "$0:Error: invalid command line" 1>&2 |
| 91 |
echo "$0:Hint: run \`$0 -h' for usage" 1>&2 |
| 92 |
exit 1 |
| 93 |
fi |
| 94 |
if [ ".$1" = ".-h" ] || [ ".$1" = ".--help" ]; then |
| 95 |
echo "This is GNU shtool, version 2.0.8 (18-Jul-2008)" |
| 96 |
echo 'Copyright (c) 1994-2008 Ralf S. Engelschall <[email protected]>' |
| 97 |
echo 'Report bugs to <[email protected]>' |
| 98 |
echo '' |
| 99 |
echo 'Usage: shtool [<options>] [<cmd-name> [<cmd-options>] [<cmd-args>]]' |
| 100 |
echo '' |
| 101 |
echo 'Available global <options>:' |
| 102 |
echo ' -v, --version display shtool version information' |
| 103 |
echo ' -h, --help display shtool usage help page (this one)' |
| 104 |
echo ' -d, --debug display shell trace information' |
| 105 |
echo ' -r, --recreate recreate this shtool script via shtoolize' |
| 106 |
echo '' |
| 107 |
echo 'Available <cmd-name> [<cmd-options>] [<cmd-args>]:' |
| 108 |
echo ' install [-v|--verbose] [-t|--trace] [-d|--mkdir] [-c|--copy]' |
| 109 |
echo ' [-C|--compare-copy] [-s|--strip] [-m|--mode <mode>]' |
| 110 |
echo ' [-o|--owner <owner>] [-g|--group <group>] [-e|--exec' |
| 111 |
echo ' <sed-cmd>] <file> [<file> ...] <path>' |
| 112 |
echo ' mkdir [-t|--trace] [-f|--force] [-p|--parents] [-m|--mode' |
| 113 |
echo ' <mode>] [-o|--owner <owner>] [-g|--group <group>] <dir>' |
| 114 |
echo ' [<dir> ...]' |
| 115 |
echo '' |
| 116 |
echo 'Not available <cmd-name> (because module was not built-in):' |
| 117 |
echo ' echo [-n|--newline] [-e|--expand] [<string> ...]' |
| 118 |
echo ' mdate [-n|--newline] [-z|--zero] [-s|--shorten] [-d|--digits]' |
| 119 |
echo ' [-f|--field-sep <str>] [-o|--order <spec>] <path>' |
| 120 |
echo ' table [-F|--field-sep <sep>] [-w|--width <width>] [-c|--columns' |
| 121 |
echo ' <cols>] [-s|--strip <strip>] <str><sep><str>...' |
| 122 |
echo ' prop [-p|--prefix <str>]' |
| 123 |
echo ' move [-v|--verbose] [-t|--trace] [-e|--expand] [-p|--preserve]' |
| 124 |
echo ' <src-file> <dst-file>' |
| 125 |
echo ' mkln [-t|--trace] [-f|--force] [-s|--symbolic] <src-path>' |
| 126 |
echo ' [<src-path> ...] <dst-path>' |
| 127 |
echo ' mkshadow [-v|--verbose] [-t|--trace] [-a|--all] <src-dir> <dst-dir>' |
| 128 |
echo ' fixperm [-v|--verbose] [-t|--trace] <path> [<path> ...]' |
| 129 |
echo ' rotate [-v|--verbose] [-t|--trace] [-f|--force] [-n|--num-files' |
| 130 |
echo ' <count>] [-s|--size <size>] [-c|--copy] [-r|--remove]' |
| 131 |
echo ' [-a|--archive-dir <dir>] [-z|--compress [<tool>:]<level>]' |
| 132 |
echo ' [-b|--background] [-d|--delay] [-p|--pad <len>] [-m|--mode' |
| 133 |
echo ' <mode>] [-o|--owner <owner>] [-g|--group <group>] [-M|--migrate' |
| 134 |
echo ' <cmd>] [-P|--prolog <cmd>] [-E|--epilog <cmd>] <file> [...]' |
| 135 |
echo ' tarball [-t|--trace] [-v|--verbose] [-o|--output <tarball>]' |
| 136 |
echo ' [-c|--compress <prog>] [-d|--directory <dir>] [-u|--user' |
| 137 |
echo ' <user>] [-g|--group <group>] [-e|--exclude <pattern>]' |
| 138 |
echo ' <path> [<path> ...]' |
| 139 |
echo ' subst [-v|--verbose] [-t|--trace] [-n|--nop] [-w|--warning]' |
| 140 |
echo ' [-q|--quiet] [-s|--stealth] [-i|--interactive] [-b|--backup' |
| 141 |
echo ' <ext>] [-e|--exec <cmd>] [-f|--file <cmd-file>] [<file>]' |
| 142 |
echo ' [...]' |
| 143 |
echo ' platform [-F|--format <format>] [-S|--sep <string>] [-C|--conc' |
| 144 |
echo ' <string>] [-L|--lower] [-U|--upper] [-v|--verbose]' |
| 145 |
echo ' [-c|--concise] [-n|--no-newline] [-t|--type <type>]' |
| 146 |
echo ' [-V|--version] [-h|--help]' |
| 147 |
echo ' arx [-t|--trace] [-C|--command <cmd>] <op> <archive> [<file>' |
| 148 |
echo ' ...]' |
| 149 |
echo ' slo [-p|--prefix <str>] -- -L<dir> -l<lib> [-L<dir> -l<lib>' |
| 150 |
echo ' ...]' |
| 151 |
echo ' scpp [-v|--verbose] [-p|--preserve] [-f|--filter <filter>]' |
| 152 |
echo ' [-o|--output <ofile>] [-t|--template <tfile>] [-M|--mark' |
| 153 |
echo ' <mark>] [-D|--define <dname>] [-C|--class <cname>]' |
| 154 |
echo ' <file> [<file> ...]' |
| 155 |
echo ' version [-l|--language <lang>] [-n|--name <name>] [-p|--prefix' |
| 156 |
echo ' <prefix>] [-s|--set <version>] [-e|--edit] [-i|--increase' |
| 157 |
echo ' <knob>] [-d|--display <type>] <file>' |
| 158 |
echo ' path [-s|--suppress] [-r|--reverse] [-d|--dirname] [-b|--basename]' |
| 159 |
echo ' [-m|--magic] [-p|--path <path>] <str> [<str> ...]' |
| 160 |
echo '' |
| 161 |
exit 0 |
| 162 |
fi |
| 163 |
if [ ".$1" = ".-v" ] || [ ".$1" = ".--version" ]; then |
| 164 |
echo "GNU shtool 2.0.8 (18-Jul-2008)" |
| 165 |
exit 0 |
| 166 |
fi |
| 167 |
if [ ".$1" = ".-r" ] || [ ".$1" = ".--recreate" ]; then |
| 168 |
shtoolize -oshtool install mkdir |
| 169 |
exit 0 |
| 170 |
fi |
| 171 |
if [ ".$1" = ".-d" ] || [ ".$1" = ".--debug" ]; then |
| 172 |
shift |
| 173 |
set -x |
| 174 |
fi |
| 175 |
name=`echo "$0" | sed -e 's;.*/\([^/]*\)$;\1;' -e 's;-sh$;;' -e 's;\.sh$;;'` |
| 176 |
case "$name" in |
| 177 |
install|mkdir ) |
| 178 |
# implicit tool command selection |
| 179 |
tool="$name" |
| 180 |
;; |
| 181 |
* ) |
| 182 |
# explicit tool command selection |
| 183 |
tool="$1" |
| 184 |
shift |
| 185 |
;; |
| 186 |
esac |
| 187 |
arg_spec="" |
| 188 |
opt_spec="" |
| 189 |
gen_tmpfile=no |
| 190 |
|
| 191 |
## |
| 192 |
## DISPATCH INTO SCRIPT PROLOG |
| 193 |
## |
| 194 |
|
| 195 |
case $tool in |
| 196 |
install ) |
| 197 |
str_tool="install" |
| 198 |
str_usage="[-v|--verbose] [-t|--trace] [-d|--mkdir] [-c|--copy] [-C|--compare-copy] [-s|--strip] [-m|--mode <mode>] [-o|--owner <owner>] [-g|--group <group>] [-e|--exec <sed-cmd>] <file> [<file> ...] <path>" |
| 199 |
arg_spec="1+" |
| 200 |
opt_spec="v.t.d.c.C.s.m:o:g:e+" |
| 201 |
opt_alias="v:verbose,t:trace,d:mkdir,c:copy,C:compare-copy,s:strip,m:mode,o:owner,g:group,e:exec" |
| 202 |
opt_v=no |
| 203 |
opt_t=no |
| 204 |
opt_d=no |
| 205 |
opt_c=no |
| 206 |
opt_C=no |
| 207 |
opt_s=no |
| 208 |
opt_m="0755" |
| 209 |
opt_o="" |
| 210 |
opt_g="" |
| 211 |
opt_e="" |
| 212 |
;; |
| 213 |
mkdir ) |
| 214 |
str_tool="mkdir" |
| 215 |
str_usage="[-t|--trace] [-f|--force] [-p|--parents] [-m|--mode <mode>] [-o|--owner <owner>] [-g|--group <group>] <dir> [<dir> ...]" |
| 216 |
arg_spec="1+" |
| 217 |
opt_spec="t.f.p.m:o:g:" |
| 218 |
opt_alias="t:trace,f:force,p:parents,m:mode,o:owner,g:group" |
| 219 |
opt_t=no |
| 220 |
opt_f=no |
| 221 |
opt_p=no |
| 222 |
opt_m="" |
| 223 |
opt_o="" |
| 224 |
opt_g="" |
| 225 |
;; |
| 226 |
-* ) |
| 227 |
echo "$0:Error: unknown option \`$tool'" 2>&1 |
| 228 |
echo "$0:Hint: run \`$0 -h' for usage" 2>&1 |
| 229 |
exit 1 |
| 230 |
;; |
| 231 |
* ) |
| 232 |
echo "$0:Error: unknown command \`$tool'" 2>&1 |
| 233 |
echo "$0:Hint: run \`$0 -h' for usage" 2>&1 |
| 234 |
exit 1 |
| 235 |
;; |
| 236 |
esac |
| 237 |
|
| 238 |
## |
| 239 |
## COMMON UTILITY CODE |
| 240 |
## |
| 241 |
|
| 242 |
# commonly used ASCII values |
| 243 |
ASC_TAB=" " |
| 244 |
ASC_NL=" |
| 245 |
" |
| 246 |
|
| 247 |
# determine name of tool |
| 248 |
if [ ".$tool" != . ]; then |
| 249 |
# used inside shtool script |
| 250 |
toolcmd="$0 $tool" |
| 251 |
toolcmdhelp="shtool $tool" |
| 252 |
msgprefix="shtool:$tool" |
| 253 |
else |
| 254 |
# used as standalone script |
| 255 |
toolcmd="$0" |
| 256 |
toolcmdhelp="sh $0" |
| 257 |
msgprefix="$str_tool" |
| 258 |
fi |
| 259 |
|
| 260 |
# parse argument specification string |
| 261 |
eval `echo $arg_spec |\ |
| 262 |
sed -e 's/^\([0-9]*\)\([+=]\)/arg_NUMS=\1; arg_MODE=\2/'` |
| 263 |
|
| 264 |
# parse option specification string |
| 265 |
eval `echo h.$opt_spec |\ |
| 266 |
sed -e 's/\([a-zA-Z0-9]\)\([.:+]\)/opt_MODE_\1=\2;/g'` |
| 267 |
|
| 268 |
# parse option alias string |
| 269 |
eval `echo h:help,$opt_alias |\ |
| 270 |
sed -e 's/-/_/g' -e 's/\([a-zA-Z0-9]\):\([^,]*\),*/opt_ALIAS_\2=\1;/g'` |
| 271 |
|
| 272 |
# interate over argument line |
| 273 |
opt_PREV='' |
| 274 |
while [ $# -gt 0 ]; do |
| 275 |
# special option stops processing |
| 276 |
if [ ".$1" = ".--" ]; then |
| 277 |
shift |
| 278 |
break |
| 279 |
fi |
| 280 |
|
| 281 |
# determine option and argument |
| 282 |
opt_ARG_OK=no |
| 283 |
if [ ".$opt_PREV" != . ]; then |
| 284 |
# merge previous seen option with argument |
| 285 |
opt_OPT="$opt_PREV" |
| 286 |
opt_ARG="$1" |
| 287 |
opt_ARG_OK=yes |
| 288 |
opt_PREV='' |
| 289 |
else |
| 290 |
# split argument into option and argument |
| 291 |
case "$1" in |
| 292 |
--[a-zA-Z0-9]*=*) |
| 293 |
eval `echo "x$1" |\ |
| 294 |
sed -e 's/^x--\([a-zA-Z0-9-]*\)=\(.*\)$/opt_OPT="\1";opt_ARG="\2"/'` |
| 295 |
opt_STR=`echo $opt_OPT | sed -e 's/-/_/g'` |
| 296 |
eval "opt_OPT=\${opt_ALIAS_${opt_STR}-${opt_OPT}}" |
| 297 |
;; |
| 298 |
--[a-zA-Z0-9]*) |
| 299 |
opt_OPT=`echo "x$1" | cut -c4-` |
| 300 |
opt_STR=`echo $opt_OPT | sed -e 's/-/_/g'` |
| 301 |
eval "opt_OPT=\${opt_ALIAS_${opt_STR}-${opt_OPT}}" |
| 302 |
opt_ARG='' |
| 303 |
;; |
| 304 |
-[a-zA-Z0-9]*) |
| 305 |
eval `echo "x$1" |\ |
| 306 |
sed -e 's/^x-\([a-zA-Z0-9]\)/opt_OPT="\1";/' \ |
| 307 |
-e 's/";\(.*\)$/"; opt_ARG="\1"/'` |
| 308 |
;; |
| 309 |
-[a-zA-Z0-9]) |
| 310 |
opt_OPT=`echo "x$1" | cut -c3-` |
| 311 |
opt_ARG='' |
| 312 |
;; |
| 313 |
*) |
| 314 |
break |
| 315 |
;; |
| 316 |
esac |
| 317 |
fi |
| 318 |
|
| 319 |
# eat up option |
| 320 |
shift |
| 321 |
|
| 322 |
# determine whether option needs an argument |
| 323 |
eval "opt_MODE=\$opt_MODE_${opt_OPT}" |
| 324 |
if [ ".$opt_ARG" = . ] && [ ".$opt_ARG_OK" != .yes ]; then |
| 325 |
if [ ".$opt_MODE" = ".:" ] || [ ".$opt_MODE" = ".+" ]; then |
| 326 |
opt_PREV="$opt_OPT" |
| 327 |
continue |
| 328 |
fi |
| 329 |
fi |
| 330 |
|
| 331 |
# process option |
| 332 |
case $opt_MODE in |
| 333 |
'.' ) |
| 334 |
# boolean option |
| 335 |
eval "opt_${opt_OPT}=yes" |
| 336 |
;; |
| 337 |
':' ) |
| 338 |
# option with argument (multiple occurances override) |
| 339 |
eval "opt_${opt_OPT}=\"\$opt_ARG\"" |
| 340 |
;; |
| 341 |
'+' ) |
| 342 |
# option with argument (multiple occurances append) |
| 343 |
eval "opt_${opt_OPT}=\"\$opt_${opt_OPT}\${ASC_NL}\$opt_ARG\"" |
| 344 |
;; |
| 345 |
* ) |
| 346 |
echo "$msgprefix:Error: unknown option: \`$opt_OPT'" 1>&2 |
| 347 |
echo "$msgprefix:Hint: run \`$toolcmdhelp -h' or \`man shtool' for details" 1>&2 |
| 348 |
exit 1 |
| 349 |
;; |
| 350 |
esac |
| 351 |
done |
| 352 |
if [ ".$opt_PREV" != . ]; then |
| 353 |
echo "$msgprefix:Error: missing argument to option \`$opt_PREV'" 1>&2 |
| 354 |
echo "$msgprefix:Hint: run \`$toolcmdhelp -h' or \`man shtool' for details" 1>&2 |
| 355 |
exit 1 |
| 356 |
fi |
| 357 |
|
| 358 |
# process help option |
| 359 |
if [ ".$opt_h" = .yes ]; then |
| 360 |
echo "Usage: $toolcmdhelp $str_usage" |
| 361 |
exit 0 |
| 362 |
fi |
| 363 |
|
| 364 |
# complain about incorrect number of arguments |
| 365 |
case $arg_MODE in |
| 366 |
'=' ) |
| 367 |
if [ $# -ne $arg_NUMS ]; then |
| 368 |
echo "$msgprefix:Error: invalid number of arguments (exactly $arg_NUMS expected)" 1>&2 |
| 369 |
echo "$msgprefix:Hint: run \`$toolcmd -h' or \`man shtool' for details" 1>&2 |
| 370 |
exit 1 |
| 371 |
fi |
| 372 |
;; |
| 373 |
'+' ) |
| 374 |
if [ $# -lt $arg_NUMS ]; then |
| 375 |
echo "$msgprefix:Error: invalid number of arguments (at least $arg_NUMS expected)" 1>&2 |
| 376 |
echo "$msgprefix:Hint: run \`$toolcmd -h' or \`man shtool' for details" 1>&2 |
| 377 |
exit 1 |
| 378 |
fi |
| 379 |
;; |
| 380 |
esac |
| 381 |
|
| 382 |
# establish a temporary file on request |
| 383 |
if [ ".$gen_tmpfile" = .yes ]; then |
| 384 |
# create (explicitly) secure temporary directory |
| 385 |
if [ ".$TMPDIR" != . ]; then |
| 386 |
tmpdir="$TMPDIR" |
| 387 |
elif [ ".$TEMPDIR" != . ]; then |
| 388 |
tmpdir="$TEMPDIR" |
| 389 |
else |
| 390 |
tmpdir="/tmp" |
| 391 |
fi |
| 392 |
tmpdir="$tmpdir/.shtool.$$" |
| 393 |
( umask 077 |
| 394 |
rm -rf "$tmpdir" >/dev/null 2>&1 || true |
| 395 |
mkdir "$tmpdir" >/dev/null 2>&1 |
| 396 |
if [ $? -ne 0 ]; then |
| 397 |
echo "$msgprefix:Error: failed to create temporary directory \`$tmpdir'" 1>&2 |
| 398 |
exit 1 |
| 399 |
fi |
| 400 |
) |
| 401 |
|
| 402 |
# create (implicitly) secure temporary file |
| 403 |
tmpfile="$tmpdir/shtool.tmp" |
| 404 |
touch "$tmpfile" |
| 405 |
fi |
| 406 |
|
| 407 |
# utility function: map string to lower case |
| 408 |
util_lower () { |
| 409 |
echo "$1" | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' |
| 410 |
} |
| 411 |
|
| 412 |
# utility function: map string to upper case |
| 413 |
util_upper () { |
| 414 |
echo "$1" | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
| 415 |
} |
| 416 |
|
| 417 |
# cleanup procedure |
| 418 |
shtool_exit () { |
| 419 |
rc="$1" |
| 420 |
if [ ".$gen_tmpfile" = .yes ]; then |
| 421 |
rm -rf "$tmpdir" >/dev/null 2>&1 || true |
| 422 |
fi |
| 423 |
exit $rc |
| 424 |
} |
| 425 |
|
| 426 |
## |
| 427 |
## DISPATCH INTO SCRIPT BODY |
| 428 |
## |
| 429 |
|
| 430 |
case $tool in |
| 431 |
|
| 432 |
install ) |
| 433 |
## |
| 434 |
## install -- Install a program, script or datafile |
| 435 |
## Copyright (c) 1997-2008 Ralf S. Engelschall <[email protected]> |
| 436 |
## |
| 437 |
|
| 438 |
# special case: "shtool install -d <dir> [...]" internally |
| 439 |
# maps to "shtool mkdir -f -p -m 755 <dir> [...]" |
| 440 |
if [ "$opt_d" = yes ]; then |
| 441 |
cmd="$0 mkdir -f -p -m 755" |
| 442 |
if [ ".$opt_o" != . ]; then |
| 443 |
cmd="$cmd -o '$opt_o'" |
| 444 |
fi |
| 445 |
if [ ".$opt_g" != . ]; then |
| 446 |
cmd="$cmd -g '$opt_g'" |
| 447 |
fi |
| 448 |
if [ ".$opt_v" = .yes ]; then |
| 449 |
cmd="$cmd -v" |
| 450 |
fi |
| 451 |
if [ ".$opt_t" = .yes ]; then |
| 452 |
cmd="$cmd -t" |
| 453 |
fi |
| 454 |
for dir in "$@"; do |
| 455 |
eval "$cmd $dir" || shtool_exit $? |
| 456 |
done |
| 457 |
shtool_exit 0 |
| 458 |
fi |
| 459 |
|
| 460 |
# determine source(s) and destination |
| 461 |
argc=$# |
| 462 |
srcs="" |
| 463 |
while [ $# -gt 1 ]; do |
| 464 |
srcs="$srcs $1" |
| 465 |
shift |
| 466 |
done |
| 467 |
dstpath="$1" |
| 468 |
|
| 469 |
# type check for destination |
| 470 |
dstisdir=0 |
| 471 |
if [ -d $dstpath ]; then |
| 472 |
dstpath=`echo "$dstpath" | sed -e 's:/$::'` |
| 473 |
dstisdir=1 |
| 474 |
fi |
| 475 |
|
| 476 |
# consistency check for destination |
| 477 |
if [ $argc -gt 2 ] && [ $dstisdir = 0 ]; then |
| 478 |
echo "$msgprefix:Error: multiple sources require destination to be directory" 1>&2 |
| 479 |
shtool_exit 1 |
| 480 |
fi |
| 481 |
|
| 482 |
# iterate over all source(s) |
| 483 |
for src in $srcs; do |
| 484 |
dst=$dstpath |
| 485 |
|
| 486 |
# if destination is a directory, append the input filename |
| 487 |
if [ $dstisdir = 1 ]; then |
| 488 |
dstfile=`echo "$src" | sed -e 's;.*/\([^/]*\)$;\1;'` |
| 489 |
dst="$dst/$dstfile" |
| 490 |
fi |
| 491 |
|
| 492 |
# check for correct arguments |
| 493 |
if [ ".$src" = ".$dst" ]; then |
| 494 |
echo "$msgprefix:Warning: source and destination are the same - skipped" 1>&2 |
| 495 |
continue |
| 496 |
fi |
| 497 |
if [ -d "$src" ]; then |
| 498 |
echo "$msgprefix:Warning: source \`$src' is a directory - skipped" 1>&2 |
| 499 |
continue |
| 500 |
fi |
| 501 |
|
| 502 |
# make a temp file name in the destination directory |
| 503 |
dsttmp=`echo $dst |\ |
| 504 |
sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;' -e 's;^$;.;' \ |
| 505 |
-e "s;\$;/#INST@$$#;"` |
| 506 |
|
| 507 |
# verbosity |
| 508 |
if [ ".$opt_v" = .yes ]; then |
| 509 |
echo "$src -> $dst" 1>&2 |
| 510 |
fi |
| 511 |
|
| 512 |
# copy or move the file name to the temp name |
| 513 |
# (because we might be not allowed to change the source) |
| 514 |
if [ ".$opt_C" = .yes ]; then |
| 515 |
opt_c=yes |
| 516 |
fi |
| 517 |
if [ ".$opt_c" = .yes ]; then |
| 518 |
if [ ".$opt_t" = .yes ]; then |
| 519 |
echo "cp $src $dsttmp" 1>&2 |
| 520 |
fi |
| 521 |
cp "$src" "$dsttmp" || shtool_exit $? |
| 522 |
else |
| 523 |
if [ ".$opt_t" = .yes ]; then |
| 524 |
echo "mv $src $dsttmp" 1>&2 |
| 525 |
fi |
| 526 |
mv "$src" "$dsttmp" || shtool_exit $? |
| 527 |
fi |
| 528 |
|
| 529 |
# adjust the target file |
| 530 |
if [ ".$opt_e" != . ]; then |
| 531 |
sed='sed' |
| 532 |
OIFS="$IFS"; IFS="$ASC_NL"; set -- $opt_e; IFS="$OIFS" |
| 533 |
for e |
| 534 |
do |
| 535 |
sed="$sed -e '$e'" |
| 536 |
done |
| 537 |
cp "$dsttmp" "$dsttmp.old" |
| 538 |
chmod u+w $dsttmp |
| 539 |
eval "$sed <$dsttmp.old >$dsttmp" || shtool_exit $? |
| 540 |
rm -f $dsttmp.old |
| 541 |
fi |
| 542 |
if [ ".$opt_s" = .yes ]; then |
| 543 |
if [ ".$opt_t" = .yes ]; then |
| 544 |
echo "strip $dsttmp" 1>&2 |
| 545 |
fi |
| 546 |
strip $dsttmp || shtool_exit $? |
| 547 |
fi |
| 548 |
if [ ".$opt_o" != . ]; then |
| 549 |
if [ ".$opt_t" = .yes ]; then |
| 550 |
echo "chown $opt_o $dsttmp" 1>&2 |
| 551 |
fi |
| 552 |
chown $opt_o $dsttmp || shtool_exit $? |
| 553 |
fi |
| 554 |
if [ ".$opt_g" != . ]; then |
| 555 |
if [ ".$opt_t" = .yes ]; then |
| 556 |
echo "chgrp $opt_g $dsttmp" 1>&2 |
| 557 |
fi |
| 558 |
chgrp $opt_g $dsttmp || shtool_exit $? |
| 559 |
fi |
| 560 |
if [ ".$opt_m" != ".-" ]; then |
| 561 |
if [ ".$opt_t" = .yes ]; then |
| 562 |
echo "chmod $opt_m $dsttmp" 1>&2 |
| 563 |
fi |
| 564 |
chmod $opt_m $dsttmp || shtool_exit $? |
| 565 |
fi |
| 566 |
|
| 567 |
# determine whether to do a quick install |
| 568 |
# (has to be done _after_ the strip was already done) |
| 569 |
quick=no |
| 570 |
if [ ".$opt_C" = .yes ]; then |
| 571 |
if [ -r $dst ]; then |
| 572 |
if cmp -s "$src" "$dst"; then |
| 573 |
quick=yes |
| 574 |
fi |
| 575 |
fi |
| 576 |
fi |
| 577 |
|
| 578 |
# finally, install the file to the real destination |
| 579 |
if [ $quick = yes ]; then |
| 580 |
if [ ".$opt_t" = .yes ]; then |
| 581 |
echo "rm -f $dsttmp" 1>&2 |
| 582 |
fi |
| 583 |
rm -f $dsttmp |
| 584 |
else |
| 585 |
if [ ".$opt_t" = .yes ]; then |
| 586 |
echo "rm -f $dst && mv $dsttmp $dst" 1>&2 |
| 587 |
fi |
| 588 |
rm -f $dst && mv $dsttmp $dst |
| 589 |
fi |
| 590 |
done |
| 591 |
|
| 592 |
shtool_exit 0 |
| 593 |
;; |
| 594 |
|
| 595 |
mkdir ) |
| 596 |
## |
| 597 |
## mkdir -- Make one or more directories |
| 598 |
## Copyright (c) 1996-2008 Ralf S. Engelschall <[email protected]> |
| 599 |
## |
| 600 |
|
| 601 |
errstatus=0 |
| 602 |
for p in ${1+"$@"}; do |
| 603 |
# if the directory already exists... |
| 604 |
if [ -d "$p" ]; then |
| 605 |
if [ ".$opt_f" = .no ] && [ ".$opt_p" = .no ]; then |
| 606 |
echo "$msgprefix:Error: directory already exists: $p" 1>&2 |
| 607 |
errstatus=1 |
| 608 |
break |
| 609 |
else |
| 610 |
continue |
| 611 |
fi |
| 612 |
fi |
| 613 |
# if the directory has to be created... |
| 614 |
if [ ".$opt_p" = .no ]; then |
| 615 |
if [ ".$opt_t" = .yes ]; then |
| 616 |
echo "mkdir $p" 1>&2 |
| 617 |
fi |
| 618 |
mkdir $p || errstatus=$? |
| 619 |
if [ ".$opt_o" != . ]; then |
| 620 |
if [ ".$opt_t" = .yes ]; then |
| 621 |
echo "chown $opt_o $p" 1>&2 |
| 622 |
fi |
| 623 |
chown $opt_o $p || errstatus=$? |
| 624 |
fi |
| 625 |
if [ ".$opt_g" != . ]; then |
| 626 |
if [ ".$opt_t" = .yes ]; then |
| 627 |
echo "chgrp $opt_g $p" 1>&2 |
| 628 |
fi |
| 629 |
chgrp $opt_g $p || errstatus=$? |
| 630 |
fi |
| 631 |
if [ ".$opt_m" != . ]; then |
| 632 |
if [ ".$opt_t" = .yes ]; then |
| 633 |
echo "chmod $opt_m $p" 1>&2 |
| 634 |
fi |
| 635 |
chmod $opt_m $p || errstatus=$? |
| 636 |
fi |
| 637 |
else |
| 638 |
# the smart situation |
| 639 |
set fnord `echo ":$p" |\ |
| 640 |
sed -e 's/^:\//%/' \ |
| 641 |
-e 's/^://' \ |
| 642 |
-e 's/\// /g' \ |
| 643 |
-e 's/^%/\//'` |
| 644 |
shift |
| 645 |
pathcomp='' |
| 646 |
for d in ${1+"$@"}; do |
| 647 |
pathcomp="$pathcomp$d" |
| 648 |
case "$pathcomp" in |
| 649 |
-* ) pathcomp="./$pathcomp" ;; |
| 650 |
esac |
| 651 |
if [ ! -d "$pathcomp" ]; then |
| 652 |
if [ ".$opt_t" = .yes ]; then |
| 653 |
echo "mkdir $pathcomp" 1>&2 |
| 654 |
fi |
| 655 |
mkdir $pathcomp || errstatus=$? |
| 656 |
if [ ".$opt_o" != . ]; then |
| 657 |
if [ ".$opt_t" = .yes ]; then |
| 658 |
echo "chown $opt_o $pathcomp" 1>&2 |
| 659 |
fi |
| 660 |
chown $opt_o $pathcomp || errstatus=$? |
| 661 |
fi |
| 662 |
if [ ".$opt_g" != . ]; then |
| 663 |
if [ ".$opt_t" = .yes ]; then |
| 664 |
echo "chgrp $opt_g $pathcomp" 1>&2 |
| 665 |
fi |
| 666 |
chgrp $opt_g $pathcomp || errstatus=$? |
| 667 |
fi |
| 668 |
if [ ".$opt_m" != . ]; then |
| 669 |
if [ ".$opt_t" = .yes ]; then |
| 670 |
echo "chmod $opt_m $pathcomp" 1>&2 |
| 671 |
fi |
| 672 |
chmod $opt_m $pathcomp || errstatus=$? |
| 673 |
fi |
| 674 |
fi |
| 675 |
pathcomp="$pathcomp/" |
| 676 |
done |
| 677 |
fi |
| 678 |
done |
| 679 |
|
| 680 |
shtool_exit $errstatus |
| 681 |
;; |
| 682 |
|
| 683 |
esac |
| 684 |
|
| 685 |
shtool_exit 0 |
| 686 |
|