aboutsummaryrefslogtreecommitdiff
path: root/libltdl/install-sh
diff options
context:
space:
mode:
Diffstat (limited to 'libltdl/install-sh')
-rwxr-xr-xlibltdl/install-sh102
1 files changed, 52 insertions, 50 deletions
diff --git a/libltdl/install-sh b/libltdl/install-sh
index 4d4a9519..e4160c99 100755
--- a/libltdl/install-sh
+++ b/libltdl/install-sh
@@ -1,7 +1,7 @@
1#!/bin/sh 1#!/bin/sh
2# install - install a program, script, or datafile 2# install - install a program, script, or datafile
3 3
4scriptversion=2005-05-14.22 4scriptversion=2004-04-01.17
5 5
6# This originates from X11R5 (mit/util/scripts/install.sh), which was 6# This originates from X11R5 (mit/util/scripts/install.sh), which was
7# later released in X11R6 (xc/config/util/install.sh) with the 7# later released in X11R6 (xc/config/util/install.sh) with the
@@ -58,6 +58,9 @@ stripprog="${STRIPPROG-strip}"
58rmprog="${RMPROG-rm}" 58rmprog="${RMPROG-rm}"
59mkdirprog="${MKDIRPROG-mkdir}" 59mkdirprog="${MKDIRPROG-mkdir}"
60 60
61transformbasename=
62transform_arg=
63instcmd="$mvprog"
61chmodcmd="$chmodprog 0755" 64chmodcmd="$chmodprog 0755"
62chowncmd= 65chowncmd=
63chgrpcmd= 66chgrpcmd=
@@ -67,27 +70,23 @@ mvcmd="$mvprog"
67src= 70src=
68dst= 71dst=
69dir_arg= 72dir_arg=
70dstarg=
71no_target_directory=
72 73
73usage="Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE 74usage="Usage: $0 [OPTION]... SRCFILE DSTFILE
74 or: $0 [OPTION]... SRCFILES... DIRECTORY 75 or: $0 [OPTION]... SRCFILES... DIRECTORY
75 or: $0 [OPTION]... -t DIRECTORY SRCFILES... 76 or: $0 -d DIRECTORIES...
76 or: $0 [OPTION]... -d DIRECTORIES...
77 77
78In the 1st form, copy SRCFILE to DSTFILE. 78In the first form, install SRCFILE to DSTFILE, removing SRCFILE by default.
79In the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 79In the second, create the directory path DIR.
80In the 4th, create DIRECTORIES.
81 80
82Options: 81Options:
83-c (ignored) 82-b=TRANSFORMBASENAME
83-c copy source (using $cpprog) instead of moving (using $mvprog).
84-d create directories instead of installing files. 84-d create directories instead of installing files.
85-g GROUP $chgrpprog installed files to GROUP. 85-g GROUP $chgrp installed files to GROUP.
86-m MODE $chmodprog installed files to MODE. 86-m MODE $chmod installed files to MODE.
87-o USER $chownprog installed files to USER. 87-o USER $chown installed files to USER.
88-s $stripprog installed files. 88-s strip installed files (using $stripprog).
89-t DIRECTORY install into DIRECTORY. 89-t=TRANSFORM
90-T report an error if DSTFILE is a directory.
91--help display this help and exit. 90--help display this help and exit.
92--version display version info and exit. 91--version display version info and exit.
93 92
@@ -97,7 +96,12 @@ Environment variables override the default commands:
97 96
98while test -n "$1"; do 97while test -n "$1"; do
99 case $1 in 98 case $1 in
100 -c) shift 99 -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
100 shift
101 continue;;
102
103 -c) instcmd=$cpprog
104 shift
101 continue;; 105 continue;;
102 106
103 -d) dir_arg=true 107 -d) dir_arg=true
@@ -109,7 +113,7 @@ while test -n "$1"; do
109 shift 113 shift
110 continue;; 114 continue;;
111 115
112 --help) echo "$usage"; exit $?;; 116 --help) echo "$usage"; exit 0;;
113 117
114 -m) chmodcmd="$chmodprog $2" 118 -m) chmodcmd="$chmodprog $2"
115 shift 119 shift
@@ -125,20 +129,14 @@ while test -n "$1"; do
125 shift 129 shift
126 continue;; 130 continue;;
127 131
128 -t) dstarg=$2 132 -t=*) transformarg=`echo $1 | sed 's/-t=//'`
129 shift 133 shift
130 shift 134 continue;;
131 continue;;
132
133 -T) no_target_directory=true
134 shift
135 continue;;
136 135
137 --version) echo "$0 $scriptversion"; exit $?;; 136 --version) echo "$0 $scriptversion"; exit 0;;
138 137
139 *) # When -d is used, all remaining arguments are directories to create. 138 *) # When -d is used, all remaining arguments are directories to create.
140 # When -t is used, the destination is already specified. 139 test -n "$dir_arg" && break
141 test -n "$dir_arg$dstarg" && break
142 # Otherwise, the last argument is the destination. Remove it from $@. 140 # Otherwise, the last argument is the destination. Remove it from $@.
143 for arg 141 for arg
144 do 142 do
@@ -176,13 +174,13 @@ do
176 src= 174 src=
177 175
178 if test -d "$dst"; then 176 if test -d "$dst"; then
179 mkdircmd=: 177 instcmd=:
180 chmodcmd= 178 chmodcmd=
181 else 179 else
182 mkdircmd=$mkdirprog 180 instcmd=$mkdirprog
183 fi 181 fi
184 else 182 else
185 # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 183 # Waiting for this to be detected by the "$instcmd $src $dsttmp" command
186 # might cause directories to be created, which would be especially bad 184 # might cause directories to be created, which would be especially bad
187 # if $src (and thus $dsttmp) contains '*'. 185 # if $src (and thus $dsttmp) contains '*'.
188 if test ! -f "$src" && test ! -d "$src"; then 186 if test ! -f "$src" && test ! -d "$src"; then
@@ -204,16 +202,12 @@ do
204 # If destination is a directory, append the input filename; won't work 202 # If destination is a directory, append the input filename; won't work
205 # if double slashes aren't ignored. 203 # if double slashes aren't ignored.
206 if test -d "$dst"; then 204 if test -d "$dst"; then
207 if test -n "$no_target_directory"; then
208 echo "$0: $dstarg: Is a directory" >&2
209 exit 1
210 fi
211 dst=$dst/`basename "$src"` 205 dst=$dst/`basename "$src"`
212 fi 206 fi
213 fi 207 fi
214 208
215 # This sed command emulates the dirname command. 209 # This sed command emulates the dirname command.
216 dstdir=`echo "$dst" | sed -e 's,/*$,,;s,[^/]*$,,;s,/*$,,;s,^$,.,'` 210 dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
217 211
218 # Make sure that the destination directory exists. 212 # Make sure that the destination directory exists.
219 213
@@ -226,8 +220,7 @@ do
226 oIFS=$IFS 220 oIFS=$IFS
227 # Some sh's can't handle IFS=/ for some reason. 221 # Some sh's can't handle IFS=/ for some reason.
228 IFS='%' 222 IFS='%'
229 set x `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'` 223 set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
230 shift
231 IFS=$oIFS 224 IFS=$oIFS
232 225
233 pathcomp= 226 pathcomp=
@@ -236,42 +229,51 @@ do
236 pathcomp=$pathcomp$1 229 pathcomp=$pathcomp$1
237 shift 230 shift
238 if test ! -d "$pathcomp"; then 231 if test ! -d "$pathcomp"; then
239 $mkdirprog "$pathcomp" 232 $mkdirprog "$pathcomp" || lasterr=$?
240 # mkdir can fail with a `File exist' error in case several 233 # mkdir can fail with a `File exist' error in case several
241 # install-sh are creating the directory concurrently. This 234 # install-sh are creating the directory concurrently. This
242 # is OK. 235 # is OK.
243 test -d "$pathcomp" || exit 236 test ! -d "$pathcomp" && { (exit ${lasterr-1}); exit; }
244 fi 237 fi
245 pathcomp=$pathcomp/ 238 pathcomp=$pathcomp/
246 done 239 done
247 fi 240 fi
248 241
249 if test -n "$dir_arg"; then 242 if test -n "$dir_arg"; then
250 $doit $mkdircmd "$dst" \ 243 $doit $instcmd "$dst" \
251 && { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \ 244 && { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \
252 && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \ 245 && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \
253 && { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \ 246 && { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \
254 && { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; } 247 && { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; }
255 248
256 else 249 else
257 dstfile=`basename "$dst"` 250 # If we're going to rename the final executable, determine the name now.
251 if test -z "$transformarg"; then
252 dstfile=`basename "$dst"`
253 else
254 dstfile=`basename "$dst" $transformbasename \
255 | sed $transformarg`$transformbasename
256 fi
257
258 # don't allow the sed command to completely eliminate the filename.
259 test -z "$dstfile" && dstfile=`basename "$dst"`
258 260
259 # Make a couple of temp file names in the proper directory. 261 # Make a couple of temp file names in the proper directory.
260 dsttmp=$dstdir/_inst.$$_ 262 dsttmp=$dstdir/_inst.$$_
261 rmtmp=$dstdir/_rm.$$_ 263 rmtmp=$dstdir/_rm.$$_
262 264
263 # Trap to clean up those temp files at exit. 265 # Trap to clean up those temp files at exit.
264 trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 266 trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0
265 trap '(exit $?); exit' 1 2 13 15 267 trap '(exit $?); exit' 1 2 13 15
266 268
267 # Copy the file name to the temp name. 269 # Move or copy the file name to the temp name
268 $doit $cpprog "$src" "$dsttmp" && 270 $doit $instcmd "$src" "$dsttmp" &&
269 271
270 # and set any options; do chmod last to preserve setuid bits. 272 # and set any options; do chmod last to preserve setuid bits.
271 # 273 #
272 # If any of these fail, we abort the whole thing. If we want to 274 # If any of these fail, we abort the whole thing. If we want to
273 # ignore errors from any of these, just make sure not to ignore 275 # ignore errors from any of these, just make sure not to ignore
274 # errors from the above "$doit $cpprog $src $dsttmp" command. 276 # errors from the above "$doit $instcmd $src $dsttmp" command.
275 # 277 #
276 { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \ 278 { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \
277 && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \ 279 && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \
@@ -296,7 +298,7 @@ do
296 || $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \ 298 || $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \
297 || { 299 || {
298 echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2 300 echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
299 (exit 1); exit 1 301 (exit 1); exit
300 } 302 }
301 else 303 else
302 : 304 :
@@ -307,12 +309,12 @@ do
307 $doit $mvcmd "$dsttmp" "$dstdir/$dstfile" 309 $doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
308 } 310 }
309 } 311 }
310 fi || { (exit 1); exit 1; } 312 fi || { (exit 1); exit; }
311done 313done
312 314
313# The final little trick to "correctly" pass the exit status to the exit trap. 315# The final little trick to "correctly" pass the exit status to the exit trap.
314{ 316{
315 (exit 0); exit 0 317 (exit 0); exit
316} 318}
317 319
318# Local variables: 320# Local variables: