💾 Archived View for gemini.rmf-dev.com › repo › Vaati › Menkar › files › 4d4a9519eaf88b18fb157dfe5fa… captured on 2022-07-16 at 17:10:01. Gemini links have been rewritten to link to archived content

View Raw

More Information

➡️ Next capture (2023-01-29)

-=-=-=-=-=-=-

0 #!/bin/sh

1 # install - install a program, script, or datafile

2

3 scriptversion=2005-05-14.22

4

5 # This originates from X11R5 (mit/util/scripts/install.sh), which was

6 # later released in X11R6 (xc/config/util/install.sh) with the

7 # following copyright and license.

8 #

9 # Copyright (C) 1994 X Consortium

10 #

11 # Permission is hereby granted, free of charge, to any person obtaining a copy

12 # of this software and associated documentation files (the "Software"), to

13 # deal in the Software without restriction, including without limitation the

14 # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or

15 # sell copies of the Software, and to permit persons to whom the Software is

16 # furnished to do so, subject to the following conditions:

17 #

18 # The above copyright notice and this permission notice shall be included in

19 # all copies or substantial portions of the Software.

20 #

21 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR

22 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

23 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

24 # X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN

25 # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-

26 # TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

27 #

28 # Except as contained in this notice, the name of the X Consortium shall not

29 # be used in advertising or otherwise to promote the sale, use or other deal-

30 # ings in this Software without prior written authorization from the X Consor-

31 # tium.

32 #

33 #

34 # FSF changes to this file are in the public domain.

35 #

36 # Calling this script install-sh is preferred over install.sh, to prevent

37 # `make' implicit rules from creating a file called install from it

38 # when there is no Makefile.

39 #

40 # This script is compatible with the BSD install script, but was written

41 # from scratch. It can only install one file at a time, a restriction

42 # shared with many OS's install programs.

43

44 # set DOITPROG to echo to test this script

45

46 # Don't use :- since 4.3BSD and earlier shells don't like it.

47 doit="${DOITPROG-}"

48

49 # put in absolute paths if you don't have them in your path; or use env. vars.

50

51 mvprog="${MVPROG-mv}"

52 cpprog="${CPPROG-cp}"

53 chmodprog="${CHMODPROG-chmod}"

54 chownprog="${CHOWNPROG-chown}"

55 chgrpprog="${CHGRPPROG-chgrp}"

56 stripprog="${STRIPPROG-strip}"

57 rmprog="${RMPROG-rm}"

58 mkdirprog="${MKDIRPROG-mkdir}"

59

60 chmodcmd="$chmodprog 0755"

61 chowncmd=

62 chgrpcmd=

63 stripcmd=

64 rmcmd="$rmprog -f"

65 mvcmd="$mvprog"

66 src=

67 dst=

68 dir_arg=

69 dstarg=

70 no_target_directory=

71

72 usage="Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE

73 or: $0 [OPTION]... SRCFILES... DIRECTORY

74 or: $0 [OPTION]... -t DIRECTORY SRCFILES...

75 or: $0 [OPTION]... -d DIRECTORIES...

76

77 In the 1st form, copy SRCFILE to DSTFILE.

78 In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.

79 In the 4th, create DIRECTORIES.

80

81 Options:

82 -c (ignored)

83 -d create directories instead of installing files.

84 -g GROUP $chgrpprog installed files to GROUP.

85 -m MODE $chmodprog installed files to MODE.

86 -o USER $chownprog installed files to USER.

87 -s $stripprog installed files.

88 -t DIRECTORY install into DIRECTORY.

89 -T report an error if DSTFILE is a directory.

90 --help display this help and exit.

91 --version display version info and exit.

92

93 Environment variables override the default commands:

94 CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG

95 "

96

97 while test -n "$1"; do

98 case $1 in

99 -c) shift

100 continue;;

101

102 -d) dir_arg=true

103 shift

104 continue;;

105

106 -g) chgrpcmd="$chgrpprog $2"

107 shift

108 shift

109 continue;;

110

111 --help) echo "$usage"; exit $?;;

112

113 -m) chmodcmd="$chmodprog $2"

114 shift

115 shift

116 continue;;

117

118 -o) chowncmd="$chownprog $2"

119 shift

120 shift

121 continue;;

122

123 -s) stripcmd=$stripprog

124 shift

125 continue;;

126

127 -t) dstarg=$2

128 shift

129 shift

130 continue;;

131

132 -T) no_target_directory=true

133 shift

134 continue;;

135

136 --version) echo "$0 $scriptversion"; exit $?;;

137

138 *) # When -d is used, all remaining arguments are directories to create.

139 # When -t is used, the destination is already specified.

140 test -n "$dir_arg$dstarg" && break

141 # Otherwise, the last argument is the destination. Remove it from $@.

142 for arg

143 do

144 if test -n "$dstarg"; then

145 # $@ is not empty: it contains at least $arg.

146 set fnord "$@" "$dstarg"

147 shift # fnord

148 fi

149 shift # arg

150 dstarg=$arg

151 done

152 break;;

153 esac

154 done

155

156 if test -z "$1"; then

157 if test -z "$dir_arg"; then

158 echo "$0: no input file specified." >&2

159 exit 1

160 fi

161 # It's OK to call `install-sh -d' without argument.

162 # This can happen when creating conditional directories.

163 exit 0

164 fi

165

166 for src

167 do

168 # Protect names starting with `-'.

169 case $src in

170 -*) src=./$src ;;

171 esac

172

173 if test -n "$dir_arg"; then

174 dst=$src

175 src=

176

177 if test -d "$dst"; then

178 mkdircmd=:

179 chmodcmd=

180 else

181 mkdircmd=$mkdirprog

182 fi

183 else

184 # Waiting for this to be detected by the "$cpprog $src $dsttmp" command

185 # might cause directories to be created, which would be especially bad

186 # if $src (and thus $dsttmp) contains '*'.

187 if test ! -f "$src" && test ! -d "$src"; then

188 echo "$0: $src does not exist." >&2

189 exit 1

190 fi

191

192 if test -z "$dstarg"; then

193 echo "$0: no destination specified." >&2

194 exit 1

195 fi

196

197 dst=$dstarg

198 # Protect names starting with `-'.

199 case $dst in

200 -*) dst=./$dst ;;

201 esac

202

203 # If destination is a directory, append the input filename; won't work

204 # if double slashes aren't ignored.

205 if test -d "$dst"; then

206 if test -n "$no_target_directory"; then

207 echo "$0: $dstarg: Is a directory" >&2

208 exit 1

209 fi

210 dst=$dst/`basename "$src"`

211 fi

212 fi

213

214 # This sed command emulates the dirname command.

215 dstdir=`echo "$dst" | sed -e 's,/*$,,;s,[^/]*$,,;s,/*$,,;s,^$,.,'`

216

217 # Make sure that the destination directory exists.

218

219 # Skip lots of stat calls in the usual case.

220 if test ! -d "$dstdir"; then

221 defaultIFS='

222 '

223 IFS="${IFS-$defaultIFS}"

224

225 oIFS=$IFS

226 # Some sh's can't handle IFS=/ for some reason.

227 IFS='%!'(MISSING)

228 set x `echo "$dstdir" | sed -e 's@/@%!@(MISSING)g' -e 's@^%!@(MISSING)/@'`

229 shift

230 IFS=$oIFS

231

232 pathcomp=

233

234 while test $# -ne 0 ; do

235 pathcomp=$pathcomp$1

236 shift

237 if test ! -d "$pathcomp"; then

238 $mkdirprog "$pathcomp"

239 # mkdir can fail with a `File exist' error in case several

240 # install-sh are creating the directory concurrently. This

241 # is OK.

242 test -d "$pathcomp" || exit

243 fi

244 pathcomp=$pathcomp/

245 done

246 fi

247

248 if test -n "$dir_arg"; then

249 $doit $mkdircmd "$dst" \

250 && { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \

251 && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \

252 && { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \

253 && { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; }

254

255 else

256 dstfile=`basename "$dst"`

257

258 # Make a couple of temp file names in the proper directory.

259 dsttmp=$dstdir/_inst.$_

260 rmtmp=$dstdir/_rm.$_

261

262 # Trap to clean up those temp files at exit.

263 trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0

264 trap '(exit $?); exit' 1 2 13 15

265

266 # Copy the file name to the temp name.

267 $doit $cpprog "$src" "$dsttmp" &&

268

269 # and set any options; do chmod last to preserve setuid bits.

270 #

271 # If any of these fail, we abort the whole thing. If we want to

272 # ignore errors from any of these, just make sure not to ignore

273 # errors from the above "$doit $cpprog $src $dsttmp" command.

274 #

275 { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \

276 && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \

277 && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \

278 && { test -z "$chmodcmd" || $doit $chmodcmd "$dsttmp"; } &&

279

280 # Now rename the file to the real destination.

281 { $doit $mvcmd -f "$dsttmp" "$dstdir/$dstfile" 2>/dev/null \

282 || {

283 # The rename failed, perhaps because mv can't rename something else

284 # to itself, or perhaps because mv is so ancient that it does not

285 # support -f.

286

287 # Now remove or move aside any old file at destination location.

288 # We try this two ways since rm can't unlink itself on some

289 # systems and the destination file might be busy for other

290 # reasons. In this case, the final cleanup might fail but the new

291 # file should still install successfully.

292 {

293 if test -f "$dstdir/$dstfile"; then

294 $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \

295 || $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \

296 || {

297 echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2

298 (exit 1); exit 1

299 }

300 else

301 :

302 fi

303 } &&

304

305 # Now rename the file to the real destination.

306 $doit $mvcmd "$dsttmp" "$dstdir/$dstfile"

307 }

308 }

309 fi || { (exit 1); exit 1; }

310 done

311

312 # The final little trick to "correctly" pass the exit status to the exit trap.

313 {

314 (exit 0); exit 0

315 }

316

317 # Local variables:

318 # eval: (add-hook 'write-file-hooks 'time-stamp)

319 # time-stamp-start: "scriptversion="

320 # time-stamp-format: "%!:(MISSING)y-%!m(MISSING)-%!d(MISSING).%!H(MISSING)"

321 # time-stamp-end: "$"

322 # End:

323