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