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