]> git.ipfire.org Git - thirdparty/cups.git/blame - install-sh
Changelog.
[thirdparty/cups.git] / install-sh
CommitLineData
ee1fd936 1#!/bin/sh
2#
7bbfe47b 3# "$Id$"
ee1fd936 4#
7bbfe47b 5# Install a program, script, or datafile.
6#
743deecf 7# Copyright 2008-2012 by Apple Inc.
7bbfe47b 8#
9# This script is not compatible with BSD (or any other) install program, as it
10# allows owner and group changes to fail with a warning and makes sure that the
11# destination directory permissions are as specified - BSD install and the
12# original X11 install script did not change permissions of existing
13# directories. It also does not support the transform options since CUPS does
14# not use them...
15#
16# Original script from X11R5 (mit/util/scripts/install.sh)
ee1fd936 17# Copyright 1991 by the Massachusetts Institute of Technology
18#
19# Permission to use, copy, modify, distribute, and sell this software and its
20# documentation for any purpose is hereby granted without fee, provided that
21# the above copyright notice appear in all copies and that both that
22# copyright notice and this permission notice appear in supporting
23# documentation, and that the name of M.I.T. not be used in advertising or
24# publicity pertaining to distribution of the software without specific,
25# written prior permission. M.I.T. makes no representations about the
26# suitability of this software for any purpose. It is provided "as is"
27# without express or implied warranty.
28#
29# Calling this script install-sh is preferred over install.sh, to prevent
30# `make' implicit rules from creating a file called install from it
31# when there is no Makefile.
ee1fd936 32
33# set DOITPROG to echo to test this script
ee1fd936 34# Don't use :- since 4.3BSD and earlier shells don't like it.
35doit="${DOITPROG-}"
36
7bbfe47b 37# Force umask to 022...
38umask 022
ee1fd936 39
40# put in absolute paths if you don't have them in your path; or use env. vars.
ee1fd936 41mvprog="${MVPROG-mv}"
42cpprog="${CPPROG-cp}"
43chmodprog="${CHMODPROG-chmod}"
44chownprog="${CHOWNPROG-chown}"
45chgrpprog="${CHGRPPROG-chgrp}"
46stripprog="${STRIPPROG-strip}"
47rmprog="${RMPROG-rm}"
48mkdirprog="${MKDIRPROG-mkdir}"
743deecf 49gzipprog="${GZIPPROG-gzip}"
ee1fd936 50
51transformbasename=""
52transform_arg=""
53instcmd="$mvprog"
54chmodcmd="$chmodprog 0755"
55chowncmd=""
56chgrpcmd=""
57stripcmd=""
58rmcmd="$rmprog -f"
59mvcmd="$mvprog"
60src=""
61dst=""
62dir_arg=""
63
7c56f88d 64gzipcp() {
743deecf 65 # gzipcp from to
66 $gzipprog -9 <"$1" >"$2"
67}
68
ee1fd936 69while [ x"$1" != x ]; do
7bbfe47b 70 case $1 in
71 -c)
72 instcmd="$cpprog"
73 shift
74 continue
75 ;;
76
77 -d)
78 dir_arg=true
79 shift
80 continue
81 ;;
82
83 -m)
84 chmodcmd="$chmodprog $2"
85 shift
86 shift
87 continue
88 ;;
89
90 -o)
91 chowncmd="$chownprog $2"
92 shift
93 shift
94 continue
95 ;;
96
97 -g)
98 chgrpcmd="$chgrpprog $2"
99 shift
100 shift
101 continue
102 ;;
103
104 -s)
105 stripcmd="$stripprog"
106 shift
107 continue
108 ;;
ee1fd936 109
743deecf 110 -z)
111 instcmd="gzipcp"
112 shift
113 continue
114 ;;
115
7bbfe47b 116 *)
117 if [ x"$src" = x ]; then
118 src="$1"
119 else
120 dst="$1"
121 fi
122 shift
123 continue
124 ;;
125 esac
ee1fd936 126done
127
7bbfe47b 128if [ x"$src" = x ]; then
129 echo "install-sh: No input file specified"
ee1fd936 130 exit 1
ee1fd936 131fi
132
133if [ x"$dir_arg" != x ]; then
7bbfe47b 134 dst="$src"
ee1fd936 135 src=""
743deecf 136
7bbfe47b 137 if [ -d "$dst" ]; then
ee1fd936 138 instcmd=:
ee1fd936 139 else
04d23db5 140 instcmd=$mkdirprog
ee1fd936 141 fi
142else
7bbfe47b 143 # Waiting for this to be detected by the "$instcmd $src $dsttmp" command
743deecf 144 # might cause directories to be created, which would be especially bad
7bbfe47b 145 # if $src (and thus $dsttmp) contains '*'.
146 if [ ! -f "$src" -a ! -d "$src" ]; then
147 echo "install: $src does not exist"
ee1fd936 148 exit 1
149 fi
743deecf 150
7bbfe47b 151 if [ x"$dst" = x ]; then
152 echo "install: No destination specified"
ee1fd936 153 exit 1
ee1fd936 154 fi
155
7bbfe47b 156 # If destination is a directory, append the input filename.
157 if [ -d "$dst" ]; then
158 dst="$dst/`basename $src`"
ee1fd936 159 fi
160fi
161
162## this sed command emulates the dirname command
7bbfe47b 163dstdir="`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`"
ee1fd936 164
165# Make sure that the destination directory exists.
7bbfe47b 166# This part is taken from Noah Friedman's mkinstalldirs script
ee1fd936 167
168# Skip lots of stat calls in the usual case.
169if [ ! -d "$dstdir" ]; then
7bbfe47b 170 defaultIFS='
04d23db5 171 '
7bbfe47b 172 IFS="${IFS-${defaultIFS}}"
ee1fd936 173
7bbfe47b 174 oIFS="${IFS}"
175 # Some sh's can't handle IFS=/ for some reason.
176 IFS='%'
177 set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
178 IFS="${oIFS}"
ee1fd936 179
7bbfe47b 180 pathcomp=''
ee1fd936 181
7bbfe47b 182 while [ $# -ne 0 ] ; do
183 pathcomp="${pathcomp}${1}"
184 shift
ee1fd936 185
7bbfe47b 186 if [ ! -d "${pathcomp}" ]; then $doit $mkdirprog "${pathcomp}"; fi
ee1fd936 187
7bbfe47b 188 pathcomp="${pathcomp}/"
189 done
ee1fd936 190fi
191
7bbfe47b 192if [ x"$dir_arg" != x ]; then
193 # Make a directory...
194 $doit $instcmd $dst || exit 1
ee1fd936 195
7bbfe47b 196 # Allow chown/chgrp to fail, but log a warning
197 if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst || echo "warning: Unable to change owner of $dst!"; fi
198 if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst || echo "warning: Unable to change group of $dst!"; fi
199 if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst || exit 1; fi
ee1fd936 200else
7bbfe47b 201 # Install a file...
202 dstfile="`basename $dst`"
ee1fd936 203
7bbfe47b 204 # Check the destination file - for libraries just use the "-x" option
205 # to strip...
e545002d 206 case "$dstfile" in
207 *.a | *.dylib | *.sl | *.sl.* | *.so | *.so.*)
208 stripopt="-x"
209 ;;
210 *)
211 stripopt=""
212 ;;
213 esac
214
7bbfe47b 215 # Make a temp file name in the proper directory.
216 dsttmp="$dstdir/#inst.$$#"
ee1fd936 217
7bbfe47b 218 # Move or copy the file name to the temp name
219 $doit $instcmd $src $dsttmp || exit 1
ee1fd936 220
7bbfe47b 221 # Update permissions and strip as needed, then move to the final name.
222 # If the chmod, strip, rm, or mv commands fail, remove the installed
223 # file...
505b184d 224 if [ x"$stripcmd" != x ]; then $doit $stripcmd $stripopt "$dsttmp" || echo "warning: Unable to strip $dst!"; fi
7bbfe47b 225 if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dsttmp" || echo "warning: Unable to change owner of $dst!"; fi
226 if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dsttmp" || echo "warning: Unable to change group of $dst!"; fi
ee1fd936 227
228 trap "rm -f ${dsttmp}" 0 &&
7bbfe47b 229 if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dsttmp"; fi &&
230 $doit $rmcmd -f "$dstdir/$dstfile" &&
231 $doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
232fi
ee1fd936 233
234exit 0