#!/bin/sh # # install - install a program, script, or datafile # This comes from X11R5. # # $XConsortium: install.sh,v 1.2 89/12/18 14:47:22 jim Exp $ # # Copyright 1991 by the Massachusetts Institute of Technology # # Permission to use, copy, modify, distribute, and sell this software and its # documentation for any purpose is hereby granted without fee, provided that # the above copyright notice appear in all copies and that both that # copyright notice and this permission notice appear in supporting # documentation, and that the name of M.I.T. not be used in advertising or # publicity pertaining to distribution of the software without specific, # written prior permission. M.I.T. makes no representations about the # suitability of this software for any purpose. It is provided "as is" # without express or implied warranty. # # This script is compatible with the BSD install script, but was written # from scratch. # # set DOITPROG to echo to test this script # Don't use :- since 4.3BSD and earlier shells don't like it. setglobal doit = $(DOITPROG-) # put in absolute paths if you don't have them in your path; or use env. vars. setglobal mvprog = $(MVPROG-mv) setglobal cpprog = $(CPPROG-cp) setglobal chmodprog = $(CHMODPROG-chmod) setglobal chownprog = $(CHOWNPROG-chown) setglobal chgrpprog = $(CHGRPPROG-chgrp) setglobal stripprog = $(STRIPPROG-strip) setglobal rmprog = $(RMPROG-rm) setglobal mkdirprog = $(MKDIRPROG-mkdir) setglobal tranformbasename = ''"" setglobal transform_arg = ''"" setglobal instcmd = $mvprog setglobal chmodcmd = ""$chmodprog 0755"" setglobal chowncmd = ''"" setglobal chgrpcmd = ''"" setglobal stripcmd = ''"" setglobal rmcmd = ""$rmprog -f"" setglobal mvcmd = $mvprog setglobal src = ''"" setglobal dst = ''"" setglobal dir_arg = ''"" while test x"$1" != x { match $1 { with -c setglobal instcmd = $cpprog shift continue with -d setglobal dir_arg = 'true' shift continue with -m setglobal chmodcmd = ""$chmodprog $2"" shift shift continue with -o setglobal chowncmd = ""$chownprog $2"" shift shift continue with -g setglobal chgrpcmd = ""$chgrpprog $2"" shift shift continue with -s setglobal stripcmd = $stripprog shift continue with -t=* setglobal transformarg = $[echo $1 | sed 's/-t=//] shift continue with -b=* setglobal transformbasename = $[echo $1 | sed 's/-b=//] shift continue with * if test x"$src" = x { setglobal src = $1 } else { # this colon is to work around a 386BSD /bin/sh bug : setglobal dst = $1 } shift continue } } if test x"$src" = x { echo "install: no input file specified" exit 1 } else { true } if test x"$dir_arg" != x { setglobal dst = $src setglobal src = ''"" if test -d $dst { setglobal instcmd = ':' } else { setglobal instcmd = 'mkdir' } } else { # Waiting for this to be detected by the "$instcmd $src $dsttmp" command # might cause directories to be created, which would be especially bad # if $src (and thus $dsttmp) contains '*'. if test -f $src -o -d $src { true } else { echo "install: $src does not exist" exit 1 } if test x"$dst" = x { echo "install: no destination specified" exit 1 } else { true } # If destination is a directory, append the input filename; if your system # does not like double slashes in filenames, you may need to add some logic if test -d $dst { setglobal dst = ""$dst"/$[basename $src]" } else { true } } ## this sed command emulates the dirname command setglobal dstdir = $[echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,] # Make sure that the destination directory exists. # this part is taken from Noah Friedman's mkinstalldirs script # Skip lots of stat calls in the usual case. if test ! -d $dstdir { setglobal defaultIFS = '' '' setglobal IFS = $(IFS-${defaultIFS}) setglobal oIFS = $(IFS) # Some sh's can't handle IFS=/ for some reason. setglobal IFS = ''%'' set - $[echo $(dstdir) | sed -e 's@/@%@g' -e 's@^%@/@] setglobal IFS = $(oIFS) setglobal pathcomp = '''' while test $Argc -ne 0 { setglobal pathcomp = ""$(pathcomp)$(1)"" shift if test ! -d $(pathcomp) { $mkdirprog $(pathcomp) } else { true } setglobal pathcomp = ""$(pathcomp)/"" } } if test x"$dir_arg" != x { $doit $instcmd $dst && if test x"$chowncmd" != x { $doit $chowncmd $dst; } else { true ; } && if test x"$chgrpcmd" != x { $doit $chgrpcmd $dst; } else { true ; } && if test x"$stripcmd" != x { $doit $stripcmd $dst; } else { true ; } && if test x"$chmodcmd" != x { $doit $chmodcmd $dst; } else { true ; } } else { # If we're going to rename the final executable, determine the name now. if test x"$transformarg" = x { setglobal dstfile = $[basename $dst] } else { setglobal dstfile = "$[basename $dst $transformbasename | sed $transformarg]$transformbasename" } # don't allow the sed command to completely eliminate the filename if test x"$dstfile" = x { setglobal dstfile = $[basename $dst] } else { true } # Make a temp file name in the proper directory. setglobal dsttmp = "$dstdir/#inst.$Pid#" # Move or copy the file name to the temp name $doit $instcmd $src $dsttmp && trap "rm -f $(dsttmp)" 0 && # and set any options; do chmod last to preserve setuid bits # If any of these fail, we abort the whole thing. If we want to # ignore errors from any of these, just make sure not to ignore # errors from the above "$doit $instcmd $src $dsttmp" command. if test x"$chowncmd" != x { $doit $chowncmd $dsttmp; } else { true;} && if test x"$chgrpcmd" != x { $doit $chgrpcmd $dsttmp; } else { true;} && if test x"$stripcmd" != x { $doit $stripcmd $dsttmp; } else { true;} && if test x"$chmodcmd" != x { $doit $chmodcmd $dsttmp; } else { true;} && # Now rename the file to the real destination. $doit $rmcmd -f $dstdir/$dstfile && $doit $mvcmd $dsttmp $dstdir/$dstfile } && exit 0