masqmail

annotate install-sh @ 209:10da50168dab

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