]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - install-sh
Correct parsing of mount options from hasmntopt() - parse on ","
[thirdparty/xfsprogs-dev.git] / install-sh
1 #! /bin/sh
2 #
3 # Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 #
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of version 2 of the GNU General Public License as
7 # published by the Free Software Foundation.
8 #
9 # This program is distributed in the hope that it would be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 #
13 # Further, this software is distributed without any warranty that it is
14 # free of the rightful claim of any third person regarding infringement
15 # or the like. Any license provided herein, whether implied or
16 # otherwise, applies only to this software file. Patent licenses, if
17 # any, provided herein do not apply to combinations of this program with
18 # other software, or any other product whatsoever.
19 #
20 # You should have received a copy of the GNU General Public License along
21 # with this program; if not, write the Free Software Foundation, Inc., 59
22 # Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 #
24 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
25 # Mountain View, CA 94043, or:
26 #
27 # http://www.sgi.com
28 #
29 # For further information regarding this notice, see:
30 #
31 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
32 #
33
34 #
35 # This script emulates bsd install and also recognises
36 # two environment variables, with the following semantics :-
37 #
38 # $DIST_MANIFEST - if set, the name of the file to append manifest
39 # information in the following format:
40 # File : f mode owner group src target
41 # Directory: d mode owner group target
42 # Symlink : l linkval target
43 #
44 # $DIST_ROOT - if set, prepend to target
45 #
46 # The sematics of all combinations of these two variables
47 # are as follows:
48 #
49 # $DIST_MANIFEST? $DIST_ROOT? | Copy? Append Manifest?
50 # -----------------------------+--------------------------
51 # not set not set | yes no
52 # not set set | yes no
53 # set not set | no yes
54 # set set | yes yes
55 #
56 _usage() {
57 echo "Usage: $prog [-o owner] [-g group] [-m mode] -d directory"
58 echo "or $prog [-D] [-o owner] [-g group] [-m mode] file directory/file"
59 echo "or $prog [-o owner] [-g group] [-m mode] file [file ...] directory"
60 echo "or $prog -S file target (creates \"target\" symlink)"
61 echo ""
62 echo "The \$DIST_MANIFEST and \$DIST_ROOT environment variables affect the"
63 echo "behaviour of this command - see comments in the script."
64 echo "The -D flag is only available for the second usage, and causes"
65 echo "the target directory to be created before installing the file."
66 echo ""
67 exit 1
68 }
69
70 _chown ()
71 {
72 _st=255
73 if [ $# -eq 3 ] ; then
74 chown $1:$2 $3
75 _st=$?
76 if [ $_st -ne 0 ] ; then
77 if [ $REAL_UID != '0' ] ; then
78 if [ ! -f $DIST_ROOT/.chown.quite ] ; then
79 echo '==============================================='
80 echo Ownership of files under ${DIST_ROOT:-/}
81 echo cannot be changed
82 echo '==============================================='
83 if [ -n "$DIST_ROOT" ] ; then
84 touch $DIST_ROOT/.chown.quite
85 fi
86 fi
87 _st=0
88 fi
89 fi
90 fi
91
92 return $_st
93 }
94
95
96 _manifest ()
97 {
98 echo $* | sed -e 's/\/\//\//g' >>${DIST_MANIFEST:-/dev/null}
99 }
100
101 prog=`basename $0`
102 HERE=`pwd`
103 dflag=false
104 Dflag=false
105 Sflag=false
106 DIRMODE=755
107 FILEMODE=644
108 OWNER=`id -u`
109 GROUP=`id -g`
110 REAL_UID=$OWNER
111
112 # default is to install and don't append manifest
113 INSTALL=true
114 MANIFEST=:
115
116 [ -n "$DIST_MANIFEST" -a -z "$DIST_ROOT" ] && INSTALL=false
117 [ -n "$DIST_MANIFEST" ] && MANIFEST="_manifest"
118
119 [ $# -eq 0 ] && _usage
120
121 if $INSTALL
122 then
123 CP=cp; LN=ln; MKDIR=mkdir; CHMOD=chmod; CHOWN=_chown
124 else
125 CP=true; LN=true; MKDIR=true; CHMOD=true; CHOWN=true
126 fi
127
128 [ -n "$DIST_ROOT" -a $REAL_UID -ne 0 ] && CHOWN=true
129
130 while getopts "Dcm:d:S:o:g:" c $*
131 do
132 case $c in
133 c)
134 ;;
135 g)
136 GROUP=$OPTARG
137 ;;
138 o)
139 OWNER=$OPTARG
140 ;;
141 m)
142 DIRMODE=`expr $OPTARG`
143 FILEMODE=$DIRMODE
144 ;;
145 D)
146 Dflag=true
147 ;;
148 S)
149 symlink=$OPTARG
150 Sflag=true
151 ;;
152 d)
153 dir=$DIST_ROOT/$OPTARG
154 dflag=true
155 ;;
156 *)
157 _usage
158 ;;
159 esac
160 done
161
162 shift `expr $OPTIND - 1`
163
164 status=0
165 if $dflag
166 then
167 #
168 # first usage
169 #
170 $MKDIR -p $dir
171 status=$?
172 if [ $status -eq 0 ]
173 then
174 $CHMOD $DIRMODE $dir
175 status=$?
176 fi
177 if [ $status -eq 0 ]
178 then
179 $CHOWN $OWNER $GROUP $dir
180 status=$?
181 fi
182 $MANIFEST d $DIRMODE $OWNER $GROUP ${dir#$DIST_ROOT}
183 elif $Sflag
184 then
185 #
186 # fourth usage (symlink)
187 #
188 if [ $# -ne 1 ]
189 then
190 _usage
191 else
192 target=$DIST_ROOT/$1
193 fi
194 $LN -s -f $symlink $target
195 status=$?
196 $MANIFEST l $symlink ${target#$DIST_ROOT}
197 else
198 list=""
199 dir=""
200 if [ $# -eq 2 ]
201 then
202 #
203 # second usage
204 #
205 f=$1
206 dir=$DIST_ROOT/$2
207 if $Dflag
208 then
209 mkdir -p `dirname $dir`
210 fi
211 $CP $f $dir
212 status=$?
213 if [ $status -eq 0 ]
214 then
215 if [ -f $dir/$f ]
216 then
217 $CHMOD $FILEMODE $dir/$f
218 status=$?
219 if [ $status -eq 0 ]
220 then
221 $CHOWN $OWNER $GROUP $dir/$f
222 status=$?
223 fi
224 $MANIFEST f $FILEMODE $OWNER $GROUP $HERE/$f ${dir#$DIST_ROOT}/$f
225 elif [ -f $dir ]
226 then
227 $CHMOD $FILEMODE $dir
228 status=$?
229 if [ $status -eq 0 ]
230 then
231 $CHOWN $OWNER $GROUP $dir
232 status=$?
233 fi
234 $MANIFEST f $FILEMODE $OWNER $GROUP $HERE/$dir ${dir#$DIST_ROOT}
235 fi
236 fi
237 else
238 #
239 # third usage
240 #
241 n=1
242 while [ $# -gt 0 ]
243 do
244 if [ $# -gt 1 ]
245 then
246 list="$list $1"
247 else
248 dir=$DIST_ROOT/$1
249 fi
250 shift
251 done
252
253 # echo DIR=$dir list=\"$list\"
254 for f in $list
255 do
256 $CP $f $dir
257 status=$?
258 if [ $status -eq 0 ]
259 then
260 $CHMOD $FILEMODE $dir/$f
261 status=$?
262 if [ $status -eq 0 ]
263 then
264 $CHOWN $OWNER $GROUP $dir/$f
265 status=$?
266 fi
267 $MANIFEST f $FILEMODE $OWNER $GROUP $HERE/$f ${dir#$DIST_ROOT}/$f
268 fi
269 [ $status -ne 0 ] && break
270 done
271 fi
272 fi
273
274 exit $status