3 # SPDX-License-Identifier: GPL-2.0
4 # Copyright (c) 2000-2001 Silicon Graphics, Inc. All Rights Reserved.
6 # This script emulates bsd install and also recognises
7 # two environment variables, with the following semantics :-
9 # $DIST_MANIFEST - if set, the name of the file to append manifest
10 # information in the following format:
11 # File : f mode owner group src target
12 # Directory: d mode owner group target
13 # Symlink : l linkval target
15 # $DIST_ROOT - if set, prepend to target
17 # The sematics of all combinations of these two variables
20 # $DIST_MANIFEST? $DIST_ROOT? | Copy? Append Manifest?
21 # -----------------------------+--------------------------
22 # not set not set | yes no
23 # not set set | yes no
24 # set not set | no yes
28 echo "Usage: $prog [-o owner] [-g group] [-m mode] -d directory"
29 echo "or $prog [-D] [-o owner] [-g group] [-m mode] file directory/file"
30 echo "or $prog [-o owner] [-g group] [-m mode] file [file ...] directory"
31 echo "or $prog -S file target (creates \"target\" symlink)"
32 echo "or $prog -T lt_arg [-o owner] [-g group] [-m mode] libtool.lai directory"
34 echo "The \$DIST_MANIFEST and \$DIST_ROOT environment variables affect the"
35 echo "behaviour of this command - see comments in the script."
36 echo "The -D flag is only available for the second usage, and causes"
37 echo "the target directory to be created before installing the file."
45 if [ $# -eq 3 ] ; then
48 if [ $_st -ne 0 ] ; then
49 if [ $REAL_UID != '0' ] ; then
50 if [ ! -f $DIST_ROOT/.chown.quiet ] ; then
51 echo '==============================================='
52 echo Ownership of files under ${DIST_ROOT:-/}
53 echo cannot be changed
54 echo '==============================================='
55 if [ -n "$DIST_ROOT" ] ; then
56 touch $DIST_ROOT/.chown.quiet
70 echo $* | sed -e 's/\/\//\//g' >>${DIST_MANIFEST:-/dev/null}
85 # default is to install and don't append manifest
89 : ${DIST_ROOT:=${DESTDIR}}
91 [ -n "$DIST_MANIFEST" -a -z "$DIST_ROOT" ] && INSTALL=false
92 [ -n "$DIST_MANIFEST" ] && MANIFEST="_manifest"
94 [ $# -eq 0 ] && _usage
98 CP=cp; LN=ln; MKDIR=mkdir; CHMOD=chmod; CHOWN=_chown
100 CP=true; LN=true; MKDIR=true; CHMOD=true; CHOWN=true
103 [ -n "$DIST_ROOT" -a $REAL_UID -ne 0 ] && CHOWN=true
105 while getopts "Dcm:d:S:o:g:T:" c $*
117 DIRMODE=`expr $OPTARG`
128 dir=$DIST_ROOT/$OPTARG
141 shift `expr $OPTIND - 1`
158 $CHOWN $OWNER $GROUP $dir
161 $MANIFEST d $DIRMODE $OWNER $GROUP ${dir#$DIST_ROOT}
165 # fourth usage (symlink)
173 $LN -s -f $symlink $target
175 $MANIFEST l $symlink ${target#$DIST_ROOT}
179 # -T (install libs built by libtool)
186 # source the libtool variables
187 if [ ! -f $libtool_lai ]
189 echo "$prog: Unable to find libtool library file $libtool_lai"
197 # Loop until we find libfoo.so.x.y.z, then break out.
198 for solib in $library_names
200 # does it have enough parts? libfoo.so.x.y.z == 5
201 cnt=`echo "$solib" | sed -e 's/\./ /g' | wc -w`
204 install_name=$target/$solib
205 $CP $solib $install_name
207 $MANIFEST f $FILEMODE $OWNER $GROUP $HERE/$solib ${install_name#$DIST_ROOT}
216 # ln -s libfoo.so.x.y.z to libfoo.so.x
217 from_parts=5 # libfoo.so.x.y.z
218 to_parts=3 # libfoo.so.x
221 # ln -s libfoo.so.x to libfoo.so
222 from_parts=3 # libfoo.so.x
223 to_parts=2 # libfoo.so
226 echo "$prog: -T $lt_install invalid"
231 # Loop until we find the names, then break out.
232 for solib in $library_names
234 # does it have enough parts?
235 cnt=`echo "$solib" | sed -e 's/\./ /g' | wc -w`
236 if [ $cnt -eq $from_parts ]
239 elif [ $cnt -eq $to_parts ]
244 if [ -n "$from_name" ] && [ -n "$to_name" ]
246 install_name=$target/$to_name
247 $LN -s -f $from_name $install_name
249 $MANIFEST l $from_name ${install_name#$DIST_ROOT}
255 install_name=$target/$old_library
256 $CP $old_library $install_name
258 $MANIFEST f $FILEMODE $OWNER $GROUP $HERE/$old_library ${install_name#$DIST_ROOT}
261 echo "$prog: -T $lt_install invalid"
267 old_lib|so_dot_version)
270 $CHMOD $FILEMODE $install_name
271 $CHOWN $OWNER $GROUP $install_name
288 mkdir -p `dirname $dir`
296 $CHMOD $FILEMODE $dir/$f
300 $CHOWN $OWNER $GROUP $dir/$f
303 $MANIFEST f $FILEMODE $OWNER $GROUP $HERE/$f ${dir#$DIST_ROOT}/$f
305 $CHMOD $FILEMODE $dir
309 $CHOWN $OWNER $GROUP $dir
312 $MANIFEST f $FILEMODE $OWNER $GROUP $HERE/$dir ${dir#$DIST_ROOT}
331 # echo DIR=$dir list=\"$list\"
338 $CHMOD $FILEMODE $dir/$f
342 $CHOWN $OWNER $GROUP $dir/$f
345 $MANIFEST f $FILEMODE $OWNER $GROUP $HERE/$f ${dir#$DIST_ROOT}/$f
347 [ $status -ne 0 ] && break