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