3 # Copyright (c) 2013 Red Hat.
4 # Copyright (c) 2004 Silicon Graphics, Inc. All Rights Reserved.
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by the
8 # Free Software Foundation; either version 2 of the License, or (at your
9 # option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 # This script emulates bsd install and also recognises
17 # two environment variables, with the following semanitcs :-
19 # $DIST_MANIFEST - if set, the name of the file to append manifest
20 # information in the following format:
21 # File : f mode owner group src target
22 # Diretory: d mode owner group target
23 # Symlink : l linkval target
25 # $DIST_ROOT - if set, prepend to target
27 # The sematics of all combinations of these two variables
30 # $DIST_MANIFEST? $DIST_ROOT? | Copy? Append Manifest?
31 # -----------------------------+--------------------------
32 # not set not set | yes no
33 # not set set | yes no
34 # set not set | no yes
38 echo "Usage: $prog [-o owner] [-g group] [-m mode] -d directory"
39 echo "or $prog [-o owner] [-g group] [-m mode] file directory/file"
40 echo "or $prog [-o owner] [-g group] [-m mode] file file [file ...] directory"
41 echo "or $prog -S file target (creates \"target\" symlink)"
43 echo "The \$DIST_MANIFEST and \$DIST_ROOT environment variables affect the"
44 echo "behaviour of this command - see comments in the script."
52 if [ $# -eq 3 ] ; then
55 if [ $_st -ne 0 ] ; then
56 if [ $REAL_UID != '0' ] ; then
57 if [ ! -f $DIST_ROOT/.chown.quiet
] ; then
58 echo '==============================================='
59 echo Ownership of files under
${DIST_ROOT:-/}
60 echo cannot be changed
61 echo '==============================================='
62 if [ -n "$DIST_ROOT" ] ; then
63 touch $DIST_ROOT/.chown.quiet
77 echo $
* |
sed -e 's/\/\//\//g' >>${DIST_MANIFEST:-/dev/null}
81 # Test to use the functional id on Solaris
82 test -f /usr
/xpg
4/bin
/id
&& ID
=/usr
/xpg
4/bin
/id
90 OWNER
=`$ID -u 2>/dev/null`
91 GROUP
=`$ID -g 2>/dev/null`
92 if [ -z "$OWNER" -o -z "$GROUP" ]
96 OWNER
=`$ID | sed -e 's/.*uid=[^(]*(//' -e 's/).*//'`
97 GROUP
=`$ID | sed -e 's/.*gid=[^(]*(//' -e 's/).*//'`
101 # default is to install and don't append manifest
105 [ -n "$DIST_MANIFEST" -a -z "$DIST_ROOT" ] && INSTALL
=false
106 [ -n "$DIST_MANIFEST" ] && MANIFEST
="_manifest"
108 [ $# -eq 0 ] && _usage
112 RM
=rm; CP
=cp; LN
=ln; MKDIR
=mkdir
; CHMOD
=chmod; CHOWN
=_chown
114 RM
=true
; CP
=true
; LN
=true
; MKDIR
=true
; CHMOD
=true
; CHOWN
=true
118 test $REAL_UID -ne 0 && CHOWN
=true
119 test "$NO_CHOWN" = "true" && CHOWN
=true
121 while getopts "d:g:m:o:S:" c $
*
125 dir
=`echo $DIST_ROOT/$OPTARG | sed -e 's;//*;/;g'`
132 DIRMODE
=`expr $OPTARG`
148 shift `expr $OPTIND - 1`
165 $CHOWN $OWNER $GROUP $dir
168 $MANIFEST d
$DIRMODE $OWNER $GROUP `echo "$dir" | sed -e "s;^$DIST_ROOT;;"`
172 # fourth usage (symlink)
178 target
=`echo $DIST_ROOT/$1 | sed -e 's;//*;/;g'`
181 dir
=`dirname $target | sed -e 's;//*;/;g'`
182 [ ! -d $dir ] && mkdir
-p $dir
183 $LN -s -f $symlink $target
185 $MANIFEST l
$symlink `echo "$target" | sed -e "s;^$DIST_ROOT;;"`
192 # second usage: install file dir/name
193 # target 'name' is not necessarily the same as 'file'
194 # (Note: install file dir is ambiguous and not supported
197 dir
=$DIST_ROOT/`dirname $2`
198 dir
=`echo $dir | sed -e 's;//*;/;g'`
199 t_dir
=`echo "$dir" | sed -e "s;^$DIST_ROOT;;" | sed -e 's;//*;/;g'`
200 destfile
=`basename $2`
201 if [ -f $f -a -f $f.exe
]
203 # Windows hack -- executables present as foo and foo.exe,
204 # the foo one is visible to test(1) and ls(1), but not to
205 # cat(1)/cp(1) ... need to $RM/$CP the foo.exe one
207 if cat $f >/dev
/null
2>&1
212 destfile
=$destfile.exe
215 [ ! -d $dir ] && mkdir
-p $dir
216 if [ -d $dir/$destfile ]
218 echo ERROR
: unsupported
install usage
222 $RM -f $dir/$destfile
224 $CP $f $dir/$destfile
229 [ ! -d $dir/$destfile ] && $CHMOD $FILEMODE $dir/$destfile
233 $CHOWN $OWNER $GROUP $dir/$destfile
236 $MANIFEST f
$FILEMODE $OWNER $GROUP $HERE/$f $t_dir/$destfile
238 [ $status -ne 0 ] && break
242 # third usage: install file file [file ...] directory
251 dir
=`echo $DIST_ROOT/$1 | sed -e 's;//*;/;g'`
256 # At this stage, $list is the list of files to install
257 # in $dir. We create $dir if necessary
259 # t_dir is for the manifest, i.e. without $DIST_ROOT prefix
260 t_dir
=`echo "$dir" | sed -e "s;^$DIST_ROOT;;"`
264 if [ -f $f -a -f $f.exe
]
266 # Windows hack -- executables present as foo and foo.exe,
267 # the foo one is visible to test(1) and ls(1), but not to
268 # cat(1)/cp(1) ... need to $RM/$CP the foo.exe one
270 if cat $f >/dev
/null
2>&1
278 [ ! -d $dir ] && mkdir
-p $dir
285 $CHMOD $FILEMODE $dir/$f
289 $CHOWN $OWNER $GROUP $dir/$f
292 $MANIFEST f
$FILEMODE $OWNER $GROUP $HERE/$f $t_dir/$f
294 [ $status -ne 0 ] && break