install-sh (2386B)
1 #!/bin/sh 2 # This Source Code Form is subject to the terms of the Mozilla Public 3 # License, v. 2.0. If a copy of the MPL was not distributed with this 4 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 6 7 # 8 # install - install a program, script, or datafile 9 # This comes from X11R5; it is not part of GNU. 10 # 11 # $XConsortium: install.sh,v 1.2 89/12/18 14:47:22 jim Exp $ 12 # 13 # This script is compatible with the BSD install script, but was written 14 # from scratch. 15 # 16 17 18 # set DOITPROG to echo to test this script 19 20 # Don't use :- since 4.3BSD and earlier shells don't like it. 21 doit="${DOITPROG-}" 22 23 24 # put in absolute paths if you don't have them in your path; or use env. vars. 25 26 mvprog="${MVPROG-mv}" 27 cpprog="${CPPROG-cp}" 28 chmodprog="${CHMODPROG-chmod}" 29 chownprog="${CHOWNPROG-chown}" 30 chgrpprog="${CHGRPPROG-chgrp}" 31 stripprog="${STRIPPROG-strip}" 32 rmprog="${RMPROG-rm}" 33 34 instcmd="$mvprog" 35 chmodcmd="" 36 chowncmd="" 37 chgrpcmd="" 38 stripcmd="" 39 rmcmd="$rmprog -f" 40 mvcmd="$mvprog" 41 src="" 42 dst="" 43 44 while [ x"$1" != x ]; do 45 case $1 in 46 -c) instcmd="$cpprog" 47 shift 48 continue;; 49 50 -m) chmodcmd="$chmodprog $2" 51 shift 52 shift 53 continue;; 54 55 -o) chowncmd="$chownprog $2" 56 shift 57 shift 58 continue;; 59 60 -g) chgrpcmd="$chgrpprog $2" 61 shift 62 shift 63 continue;; 64 65 -s) stripcmd="$stripprog" 66 shift 67 continue;; 68 69 *) if [ x"$src" = x ] 70 then 71 src=$1 72 else 73 dst=$1 74 fi 75 shift 76 continue;; 77 esac 78 done 79 80 if [ x"$src" = x ] 81 then 82 echo "install: no input file specified" 83 exit 1 84 fi 85 86 if [ x"$dst" = x ] 87 then 88 echo "install: no destination specified" 89 exit 1 90 fi 91 92 93 # If destination is a directory, append the input filename; if your system 94 # does not like double slashes in filenames, you may need to add some logic 95 96 if [ -d $dst ] 97 then 98 dst="$dst"/`basename $src` 99 fi 100 101 # Make a temp file name in the proper directory. 102 103 dstdir=`dirname $dst` 104 dsttmp=$dstdir/#inst.$$# 105 106 # Move or copy the file name to the temp name 107 108 $doit $instcmd $src $dsttmp 109 110 # and set any options; do chmod last to preserve setuid bits 111 112 if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; fi 113 if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; fi 114 if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; fi 115 if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; fi 116 117 # Now rename the file to the real destination. 118 119 $doit $rmcmd $dst 120 $doit $mvcmd $dsttmp $dst 121 122 123 exit 0