annotate kdiff3/admin/install-sh @ 26:07416314eb5e

Allow CTRL-Tab for Windows
author joachim99
date Sat, 11 Oct 2003 12:45:25 +0000
parents 415083d043f3
children efe33e938730
rev   line source
joachim99@2 1 #!/bin/sh
joachim99@2 2 #
joachim99@2 3 # install - install a program, script, or datafile
joachim99@2 4 # This comes from X11R5 (mit/util/scripts/install.sh).
joachim99@2 5 #
joachim99@2 6 # Copyright 1991 by the Massachusetts Institute of Technology
joachim99@2 7 #
joachim99@2 8 # Permission to use, copy, modify, distribute, and sell this software and its
joachim99@2 9 # documentation for any purpose is hereby granted without fee, provided that
joachim99@2 10 # the above copyright notice appear in all copies and that both that
joachim99@2 11 # copyright notice and this permission notice appear in supporting
joachim99@2 12 # documentation, and that the name of M.I.T. not be used in advertising or
joachim99@2 13 # publicity pertaining to distribution of the software without specific,
joachim99@2 14 # written prior permission. M.I.T. makes no representations about the
joachim99@2 15 # suitability of this software for any purpose. It is provided "as is"
joachim99@2 16 # without express or implied warranty.
joachim99@2 17 #
joachim99@2 18 # Calling this script install-sh is preferred over install.sh, to prevent
joachim99@2 19 # `make' implicit rules from creating a file called install from it
joachim99@2 20 # when there is no Makefile.
joachim99@2 21 #
joachim99@2 22 # This script is compatible with the BSD install script, but was written
joachim99@2 23 # from scratch. It can only install one file at a time, a restriction
joachim99@2 24 # shared with many OS's install programs.
joachim99@2 25
joachim99@2 26
joachim99@2 27 # set DOITPROG to echo to test this script
joachim99@2 28
joachim99@2 29 # Don't use :- since 4.3BSD and earlier shells don't like it.
joachim99@2 30 doit="${DOITPROG-}"
joachim99@2 31
joachim99@2 32
joachim99@2 33 # put in absolute paths if you don't have them in your path; or use env. vars.
joachim99@2 34
joachim99@2 35 mvprog="${MVPROG-mv}"
joachim99@2 36 cpprog="${CPPROG-cp}"
joachim99@2 37 chmodprog="${CHMODPROG-chmod}"
joachim99@2 38 chownprog="${CHOWNPROG-chown}"
joachim99@2 39 chgrpprog="${CHGRPPROG-chgrp}"
joachim99@2 40 stripprog="${STRIPPROG-strip}"
joachim99@2 41 rmprog="${RMPROG-rm}"
joachim99@2 42 mkdirprog="${MKDIRPROG-mkdir}"
joachim99@2 43
joachim99@2 44 transformbasename=""
joachim99@2 45 transform_arg=""
joachim99@2 46 instcmd="$mvprog"
joachim99@2 47 chmodcmd="$chmodprog 0755"
joachim99@2 48 chowncmd=""
joachim99@2 49 chgrpcmd=""
joachim99@2 50 stripcmd=""
joachim99@2 51 rmcmd="$rmprog -f"
joachim99@2 52 mvcmd="$mvprog"
joachim99@2 53 src=""
joachim99@2 54 dst=""
joachim99@2 55 dir_arg=""
joachim99@2 56
joachim99@2 57 while [ x"$1" != x ]; do
joachim99@2 58 case $1 in
joachim99@2 59 -c) instcmd="$cpprog"
joachim99@2 60 shift
joachim99@2 61 continue;;
joachim99@2 62
joachim99@2 63 -d) dir_arg=true
joachim99@2 64 shift
joachim99@2 65 continue;;
joachim99@2 66
joachim99@2 67 -m) chmodcmd="$chmodprog $2"
joachim99@2 68 shift
joachim99@2 69 shift
joachim99@2 70 continue;;
joachim99@2 71
joachim99@2 72 -o) chowncmd="$chownprog $2"
joachim99@2 73 shift
joachim99@2 74 shift
joachim99@2 75 continue;;
joachim99@2 76
joachim99@2 77 -g) chgrpcmd="$chgrpprog $2"
joachim99@2 78 shift
joachim99@2 79 shift
joachim99@2 80 continue;;
joachim99@2 81
joachim99@2 82 -s) stripcmd="$stripprog"
joachim99@2 83 shift
joachim99@2 84 continue;;
joachim99@2 85
joachim99@2 86 -t=*) transformarg=`echo $1 | sed 's/-t=//'`
joachim99@2 87 shift
joachim99@2 88 continue;;
joachim99@2 89
joachim99@2 90 -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
joachim99@2 91 shift
joachim99@2 92 continue;;
joachim99@2 93
joachim99@2 94 *) if [ x"$src" = x ]
joachim99@2 95 then
joachim99@2 96 src=$1
joachim99@2 97 else
joachim99@2 98 # this colon is to work around a 386BSD /bin/sh bug
joachim99@2 99 :
joachim99@2 100 dst=$1
joachim99@2 101 fi
joachim99@2 102 shift
joachim99@2 103 continue;;
joachim99@2 104 esac
joachim99@2 105 done
joachim99@2 106
joachim99@2 107 if [ x"$src" = x ]
joachim99@2 108 then
joachim99@2 109 echo "install: no input file specified"
joachim99@2 110 exit 1
joachim99@2 111 else
joachim99@14 112 :
joachim99@2 113 fi
joachim99@2 114
joachim99@2 115 if [ x"$dir_arg" != x ]; then
joachim99@2 116 dst=$src
joachim99@2 117 src=""
joachim99@2 118
joachim99@2 119 if [ -d $dst ]; then
joachim99@2 120 instcmd=:
joachim99@2 121 chmodcmd=""
joachim99@2 122 else
joachim99@14 123 instcmd=$mkdirprog
joachim99@2 124 fi
joachim99@2 125 else
joachim99@2 126
joachim99@2 127 # Waiting for this to be detected by the "$instcmd $src $dsttmp" command
joachim99@2 128 # might cause directories to be created, which would be especially bad
joachim99@2 129 # if $src (and thus $dsttmp) contains '*'.
joachim99@2 130
joachim99@14 131 if [ -f "$src" ] || [ -d "$src" ]
joachim99@2 132 then
joachim99@14 133 :
joachim99@2 134 else
joachim99@2 135 echo "install: $src does not exist"
joachim99@2 136 exit 1
joachim99@2 137 fi
joachim99@2 138
joachim99@2 139 if [ x"$dst" = x ]
joachim99@2 140 then
joachim99@2 141 echo "install: no destination specified"
joachim99@2 142 exit 1
joachim99@2 143 else
joachim99@14 144 :
joachim99@2 145 fi
joachim99@2 146
joachim99@2 147 # If destination is a directory, append the input filename; if your system
joachim99@2 148 # does not like double slashes in filenames, you may need to add some logic
joachim99@2 149
joachim99@2 150 if [ -d $dst ]
joachim99@2 151 then
joachim99@2 152 dst="$dst"/`basename $src`
joachim99@2 153 else
joachim99@14 154 :
joachim99@2 155 fi
joachim99@2 156 fi
joachim99@2 157
joachim99@2 158 ## this sed command emulates the dirname command
joachim99@2 159 dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
joachim99@2 160
joachim99@2 161 # Make sure that the destination directory exists.
joachim99@2 162 # this part is taken from Noah Friedman's mkinstalldirs script
joachim99@2 163
joachim99@2 164 # Skip lots of stat calls in the usual case.
joachim99@2 165 if [ ! -d "$dstdir" ]; then
joachim99@14 166 defaultIFS='
joachim99@14 167 '
joachim99@2 168 IFS="${IFS-${defaultIFS}}"
joachim99@2 169
joachim99@2 170 oIFS="${IFS}"
joachim99@2 171 # Some sh's can't handle IFS=/ for some reason.
joachim99@2 172 IFS='%'
joachim99@2 173 set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
joachim99@2 174 IFS="${oIFS}"
joachim99@2 175
joachim99@2 176 pathcomp=''
joachim99@2 177
joachim99@2 178 while [ $# -ne 0 ] ; do
joachim99@2 179 pathcomp="${pathcomp}${1}"
joachim99@2 180 shift
joachim99@2 181
joachim99@2 182 if [ ! -d "${pathcomp}" ] ;
joachim99@2 183 then
joachim99@2 184 $mkdirprog "${pathcomp}"
joachim99@2 185 else
joachim99@14 186 :
joachim99@2 187 fi
joachim99@2 188
joachim99@2 189 pathcomp="${pathcomp}/"
joachim99@2 190 done
joachim99@2 191 fi
joachim99@2 192
joachim99@2 193 if [ x"$dir_arg" != x ]
joachim99@2 194 then
joachim99@2 195 $doit $instcmd $dst &&
joachim99@2 196
joachim99@14 197 if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else : ; fi &&
joachim99@14 198 if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else : ; fi &&
joachim99@14 199 if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else : ; fi &&
joachim99@14 200 if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else : ; fi
joachim99@2 201 else
joachim99@2 202
joachim99@2 203 # If we're going to rename the final executable, determine the name now.
joachim99@2 204
joachim99@2 205 if [ x"$transformarg" = x ]
joachim99@2 206 then
joachim99@2 207 dstfile=`basename $dst`
joachim99@2 208 else
joachim99@2 209 dstfile=`basename $dst $transformbasename |
joachim99@2 210 sed $transformarg`$transformbasename
joachim99@2 211 fi
joachim99@2 212
joachim99@2 213 # don't allow the sed command to completely eliminate the filename
joachim99@2 214
joachim99@2 215 if [ x"$dstfile" = x ]
joachim99@2 216 then
joachim99@2 217 dstfile=`basename $dst`
joachim99@2 218 else
joachim99@14 219 :
joachim99@2 220 fi
joachim99@2 221
joachim99@2 222 # Make a temp file name in the proper directory.
joachim99@2 223
joachim99@2 224 dsttmp=$dstdir/#inst.$$#
joachim99@2 225
joachim99@2 226 # Move or copy the file name to the temp name
joachim99@2 227
joachim99@2 228 $doit $instcmd $src $dsttmp &&
joachim99@2 229
joachim99@2 230 trap "rm -f ${dsttmp}" 0 &&
joachim99@2 231
joachim99@2 232 # and set any options; do chmod last to preserve setuid bits
joachim99@2 233
joachim99@2 234 # If any of these fail, we abort the whole thing. If we want to
joachim99@2 235 # ignore errors from any of these, just make sure not to ignore
joachim99@2 236 # errors from the above "$doit $instcmd $src $dsttmp" command.
joachim99@2 237
joachim99@14 238 if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else :;fi &&
joachim99@14 239 if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else :;fi &&
joachim99@14 240 if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else :;fi &&
joachim99@14 241 if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else :;fi &&
joachim99@2 242
joachim99@2 243 # Now rename the file to the real destination.
joachim99@2 244
joachim99@2 245 $doit $rmcmd -f $dstdir/$dstfile &&
joachim99@2 246 $doit $mvcmd $dsttmp $dstdir/$dstfile
joachim99@2 247
joachim99@2 248 fi &&
joachim99@2 249
joachim99@2 250
joachim99@2 251 exit 0