security/nss/tests/pkcs11/netscape/trivial/install-sh

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rwxr-xr-x

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial