Erik Grinaker is sharing code with you

Bitbucket is a code hosting site. Unlimited public and private repositories. Free for small teams.

Don't show this again

erikg / Revelation

Revelation is a password manager for the GNOME desktop, released under the GNU GPL license. It stores all your accounts and passwords in a single, secure place, and gives you access to it through a user-friendly graphical interface.

Clone this repository (size: 2.0 MB): HTTPS / SSH
hg clone https://bitbucket.org/erikg/revelation
hg clone ssh://hg@bitbucket.org/erikg/revelation

Revelation / install-sh

commit
e92f2103325c
parent
e7337e848a4c
branch
default
tags
revelation-0.4.7

set release date

1
a207757f8451
#!/bin/sh
2
a207757f8451
#
3
a207757f8451
# install - install a program, script, or datafile
4
a207757f8451
#
5
a207757f8451
# This originates from X11R5 (mit/util/scripts/install.sh), which was
6
a207757f8451
# later released in X11R6 (xc/config/util/install.sh) with the
7
a207757f8451
# following copyright and license.
8
a207757f8451
#
9
a207757f8451
# Copyright (C) 1994 X Consortium
10
a207757f8451
#
11
a207757f8451
# Permission is hereby granted, free of charge, to any person obtaining a copy
12
a207757f8451
# of this software and associated documentation files (the "Software"), to
13
a207757f8451
# deal in the Software without restriction, including without limitation the
14
a207757f8451
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
15
a207757f8451
# sell copies of the Software, and to permit persons to whom the Software is
16
a207757f8451
# furnished to do so, subject to the following conditions:
17
a207757f8451
#
18
a207757f8451
# The above copyright notice and this permission notice shall be included in
19
a207757f8451
# all copies or substantial portions of the Software.
20
a207757f8451
#
21
a207757f8451
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
a207757f8451
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
a207757f8451
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
24
a207757f8451
# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
25
a207757f8451
# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
26
a207757f8451
# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
a207757f8451
#
28
a207757f8451
# Except as contained in this notice, the name of the X Consortium shall not
29
a207757f8451
# be used in advertising or otherwise to promote the sale, use or other deal-
30
a207757f8451
# ings in this Software without prior written authorization from the X Consor-
31
a207757f8451
# tium.
32
a207757f8451
#
33
a207757f8451
#
34
a207757f8451
# FSF changes to this file are in the public domain.
35
a207757f8451
#
36
a207757f8451
# Calling this script install-sh is preferred over install.sh, to prevent
37
a207757f8451
# `make' implicit rules from creating a file called install from it
38
a207757f8451
# when there is no Makefile.
39
a207757f8451
#
40
a207757f8451
# This script is compatible with the BSD install script, but was written
41
a207757f8451
# from scratch.  It can only install one file at a time, a restriction
42
a207757f8451
# shared with many OS's install programs.
43
a207757f8451
44
a207757f8451
45
a207757f8451
# set DOITPROG to echo to test this script
46
a207757f8451
47
a207757f8451
# Don't use :- since 4.3BSD and earlier shells don't like it.
48
a207757f8451
doit="${DOITPROG-}"
49
a207757f8451
50
a207757f8451
51
a207757f8451
# put in absolute paths if you don't have them in your path; or use env. vars.
52
a207757f8451
53
a207757f8451
mvprog="${MVPROG-mv}"
54
a207757f8451
cpprog="${CPPROG-cp}"
55
a207757f8451
chmodprog="${CHMODPROG-chmod}"
56
a207757f8451
chownprog="${CHOWNPROG-chown}"
57
a207757f8451
chgrpprog="${CHGRPPROG-chgrp}"
58
a207757f8451
stripprog="${STRIPPROG-strip}"
59
a207757f8451
rmprog="${RMPROG-rm}"
60
a207757f8451
mkdirprog="${MKDIRPROG-mkdir}"
61
a207757f8451
62
a207757f8451
transformbasename=""
63
a207757f8451
transform_arg=""
64
a207757f8451
instcmd="$mvprog"
65
a207757f8451
chmodcmd="$chmodprog 0755"
66
a207757f8451
chowncmd=""
67
a207757f8451
chgrpcmd=""
68
a207757f8451
stripcmd=""
69
a207757f8451
rmcmd="$rmprog -f"
70
a207757f8451
mvcmd="$mvprog"
71
a207757f8451
src=""
72
a207757f8451
dst=""
73
a207757f8451
dir_arg=""
74
a207757f8451
75
a207757f8451
while [ x"$1" != x ]; do
76
a207757f8451
    case $1 in
77
a207757f8451
	-c) instcmd=$cpprog
78
a207757f8451
	    shift
79
a207757f8451
	    continue;;
80
a207757f8451
81
a207757f8451
	-d) dir_arg=true
82
a207757f8451
	    shift
83
a207757f8451
	    continue;;
84
a207757f8451
85
a207757f8451
	-m) chmodcmd="$chmodprog $2"
86
a207757f8451
	    shift
87
a207757f8451
	    shift
88
a207757f8451
	    continue;;
89
a207757f8451
90
a207757f8451
	-o) chowncmd="$chownprog $2"
91
a207757f8451
	    shift
92
a207757f8451
	    shift
93
a207757f8451
	    continue;;
94
a207757f8451
95
a207757f8451
	-g) chgrpcmd="$chgrpprog $2"
96
a207757f8451
	    shift
97
a207757f8451
	    shift
98
a207757f8451
	    continue;;
99
a207757f8451
100
a207757f8451
	-s) stripcmd=$stripprog
101
a207757f8451
	    shift
102
a207757f8451
	    continue;;
103
a207757f8451
104
a207757f8451
	-t=*) transformarg=`echo $1 | sed 's/-t=//'`
105
a207757f8451
	    shift
106
a207757f8451
	    continue;;
107
a207757f8451
108
a207757f8451
	-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
109
a207757f8451
	    shift
110
a207757f8451
	    continue;;
111
a207757f8451
112
a207757f8451
	*)  if [ x"$src" = x ]
113
a207757f8451
	    then
114
a207757f8451
		src=$1
115
a207757f8451
	    else
116
a207757f8451
		# this colon is to work around a 386BSD /bin/sh bug
117
a207757f8451
		:
118
a207757f8451
		dst=$1
119
a207757f8451
	    fi
120
a207757f8451
	    shift
121
a207757f8451
	    continue;;
122
a207757f8451
    esac
123
a207757f8451
done
124
a207757f8451
125
a207757f8451
if [ x"$src" = x ]
126
a207757f8451
then
127
a207757f8451
	echo "$0: no input file specified" >&2
128
a207757f8451
	exit 1
129
a207757f8451
else
130
a207757f8451
	:
131
a207757f8451
fi
132
a207757f8451
133
a207757f8451
if [ x"$dir_arg" != x ]; then
134
a207757f8451
	dst=$src
135
a207757f8451
	src=""
136
a207757f8451
137
a207757f8451
	if [ -d "$dst" ]; then
138
a207757f8451
		instcmd=:
139
a207757f8451
		chmodcmd=""
140
a207757f8451
	else
141
a207757f8451
		instcmd=$mkdirprog
142
a207757f8451
	fi
143
a207757f8451
else
144
a207757f8451
145
a207757f8451
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
146
a207757f8451
# might cause directories to be created, which would be especially bad
147
a207757f8451
# if $src (and thus $dsttmp) contains '*'.
148
a207757f8451
149
a207757f8451
	if [ -f "$src" ] || [ -d "$src" ]
150
a207757f8451
	then
151
a207757f8451
		:
152
a207757f8451
	else
153
a207757f8451
		echo "$0: $src does not exist" >&2
154
a207757f8451
		exit 1
155
a207757f8451
	fi
156
a207757f8451
157
a207757f8451
	if [ x"$dst" = x ]
158
a207757f8451
	then
159
a207757f8451
		echo "$0: no destination specified" >&2
160
a207757f8451
		exit 1
161
a207757f8451
	else
162
a207757f8451
		:
163
a207757f8451
	fi
164
a207757f8451
165
a207757f8451
# If destination is a directory, append the input filename; if your system
166
a207757f8451
# does not like double slashes in filenames, you may need to add some logic
167
a207757f8451
168
a207757f8451
	if [ -d "$dst" ]
169
a207757f8451
	then
170
a207757f8451
		dst=$dst/`basename "$src"`
171
a207757f8451
	else
172
a207757f8451
		:
173
a207757f8451
	fi
174
a207757f8451
fi
175
a207757f8451
176
a207757f8451
## this sed command emulates the dirname command
177
a207757f8451
dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
178
a207757f8451
179
a207757f8451
# Make sure that the destination directory exists.
180
a207757f8451
#  this part is taken from Noah Friedman's mkinstalldirs script
181
a207757f8451
182
a207757f8451
# Skip lots of stat calls in the usual case.
183
a207757f8451
if [ ! -d "$dstdir" ]; then
184
a207757f8451
defaultIFS='
185
a207757f8451
	'
186
a207757f8451
IFS="${IFS-$defaultIFS}"
187
a207757f8451
188
a207757f8451
oIFS=$IFS
189
a207757f8451
# Some sh's can't handle IFS=/ for some reason.
190
a207757f8451
IFS='%'
191
a207757f8451
set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
192
a207757f8451
IFS=$oIFS
193
a207757f8451
194
a207757f8451
pathcomp=''
195
a207757f8451
196
a207757f8451
while [ $# -ne 0 ] ; do
197
a207757f8451
	pathcomp=$pathcomp$1
198
a207757f8451
	shift
199
a207757f8451
200
a207757f8451
	if [ ! -d "$pathcomp" ] ;
201
a207757f8451
        then
202
a207757f8451
		$mkdirprog "$pathcomp"
203
a207757f8451
	else
204
a207757f8451
		:
205
a207757f8451
	fi
206
a207757f8451
207
a207757f8451
	pathcomp=$pathcomp/
208
a207757f8451
done
209
a207757f8451
fi
210
a207757f8451
211
a207757f8451
if [ x"$dir_arg" != x ]
212
a207757f8451
then
213
a207757f8451
	$doit $instcmd "$dst" &&
214
a207757f8451
215
a207757f8451
	if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dst"; else : ; fi &&
216
a207757f8451
	if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dst"; else : ; fi &&
217
a207757f8451
	if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dst"; else : ; fi &&
218
a207757f8451
	if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dst"; else : ; fi
219
a207757f8451
else
220
a207757f8451
221
a207757f8451
# If we're going to rename the final executable, determine the name now.
222
a207757f8451
223
a207757f8451
	if [ x"$transformarg" = x ]
224
a207757f8451
	then
225
a207757f8451
		dstfile=`basename "$dst"`
226
a207757f8451
	else
227
a207757f8451
		dstfile=`basename "$dst" $transformbasename |
228
a207757f8451
			sed $transformarg`$transformbasename
229
a207757f8451
	fi
230
a207757f8451
231
a207757f8451
# don't allow the sed command to completely eliminate the filename
232
a207757f8451
233
a207757f8451
	if [ x"$dstfile" = x ]
234
a207757f8451
	then
235
a207757f8451
		dstfile=`basename "$dst"`
236
a207757f8451
	else
237
a207757f8451
		:
238
a207757f8451
	fi
239
a207757f8451
240
a207757f8451
# Make a couple of temp file names in the proper directory.
241
a207757f8451
242
a207757f8451
	dsttmp=$dstdir/_inst.$$_
243
a207757f8451
	rmtmp=$dstdir/_rm.$$_
244
a207757f8451
245
a207757f8451
# Trap to clean up temp files at exit.
246
a207757f8451
247
a207757f8451
	trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0
248
a207757f8451
	trap '(exit $?); exit' 1 2 13 15
249
a207757f8451
250
a207757f8451
# Move or copy the file name to the temp name
251
a207757f8451
252
a207757f8451
	$doit $instcmd "$src" "$dsttmp" &&
253
a207757f8451
254
a207757f8451
# and set any options; do chmod last to preserve setuid bits
255
a207757f8451
256
a207757f8451
# If any of these fail, we abort the whole thing.  If we want to
257
a207757f8451
# ignore errors from any of these, just make sure not to ignore
258
a207757f8451
# errors from the above "$doit $instcmd $src $dsttmp" command.
259
a207757f8451
260
a207757f8451
	if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dsttmp"; else :;fi &&
261
a207757f8451
	if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dsttmp"; else :;fi &&
262
a207757f8451
	if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dsttmp"; else :;fi &&
263
a207757f8451
	if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dsttmp"; else :;fi &&
264
a207757f8451
265
a207757f8451
# Now remove or move aside any old file at destination location.  We try this
266
a207757f8451
# two ways since rm can't unlink itself on some systems and the destination
267
a207757f8451
# file might be busy for other reasons.  In this case, the final cleanup
268
a207757f8451
# might fail but the new file should still install successfully.
269
a207757f8451
270
a207757f8451
{
271
a207757f8451
	if [ -f "$dstdir/$dstfile" ]
272
a207757f8451
	then
273
a207757f8451
		$doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null ||
274
a207757f8451
		$doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null ||
275
a207757f8451
		{
276
a207757f8451
		  echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
277
a207757f8451
		  (exit 1); exit
278
a207757f8451
		}
279
a207757f8451
	else
280
a207757f8451
		:
281
a207757f8451
	fi
282
a207757f8451
} &&
283
a207757f8451
284
a207757f8451
# Now rename the file to the real destination.
285
a207757f8451
286
a207757f8451
	$doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
287
a207757f8451
288
a207757f8451
fi &&
289
a207757f8451
290
a207757f8451
# The final little trick to "correctly" pass the exit status to the exit trap.
291
a207757f8451
292
a207757f8451
{
293
a207757f8451
	(exit 0); exit
294
a207757f8451
}