17b66cf61Sopenharmony_ci#!/bin/sh 27b66cf61Sopenharmony_ci# 37b66cf61Sopenharmony_ci# Install a program, script, or datafile. 47b66cf61Sopenharmony_ci# 57b66cf61Sopenharmony_ci# Copyright 2008-2009 by Apple Inc. 67b66cf61Sopenharmony_ci# 77b66cf61Sopenharmony_ci# This script is not compatible with BSD (or any other) install program, as it 87b66cf61Sopenharmony_ci# allows owner and group changes to fail with a warning and makes sure that the 97b66cf61Sopenharmony_ci# destination directory permissions are as specified - BSD install and the 107b66cf61Sopenharmony_ci# original X11 install script did not change permissions of existing 117b66cf61Sopenharmony_ci# directories. It also does not support the transform options since CUPS does 127b66cf61Sopenharmony_ci# not use them... 137b66cf61Sopenharmony_ci# 147b66cf61Sopenharmony_ci# Original script from X11R5 (mit/util/scripts/install.sh) 157b66cf61Sopenharmony_ci# Copyright 1991 by the Massachusetts Institute of Technology 167b66cf61Sopenharmony_ci# 177b66cf61Sopenharmony_ci# Permission to use, copy, modify, distribute, and sell this software and its 187b66cf61Sopenharmony_ci# documentation for any purpose is hereby granted without fee, provided that 197b66cf61Sopenharmony_ci# the above copyright notice appear in all copies and that both that 207b66cf61Sopenharmony_ci# copyright notice and this permission notice appear in supporting 217b66cf61Sopenharmony_ci# documentation, and that the name of M.I.T. not be used in advertising or 227b66cf61Sopenharmony_ci# publicity pertaining to distribution of the software without specific, 237b66cf61Sopenharmony_ci# written prior permission. M.I.T. makes no representations about the 247b66cf61Sopenharmony_ci# suitability of this software for any purpose. It is provided "as is" 257b66cf61Sopenharmony_ci# without express or implied warranty. 267b66cf61Sopenharmony_ci# 277b66cf61Sopenharmony_ci# Calling this script install-sh is preferred over install.sh, to prevent 287b66cf61Sopenharmony_ci# `make' implicit rules from creating a file called install from it 297b66cf61Sopenharmony_ci# when there is no Makefile. 307b66cf61Sopenharmony_ci 317b66cf61Sopenharmony_ci# set DOITPROG to echo to test this script 327b66cf61Sopenharmony_ci# Don't use :- since 4.3BSD and earlier shells don't like it. 337b66cf61Sopenharmony_cidoit="${DOITPROG-}" 347b66cf61Sopenharmony_ci 357b66cf61Sopenharmony_ci# Force umask to 022... 367b66cf61Sopenharmony_ciumask 022 377b66cf61Sopenharmony_ci 387b66cf61Sopenharmony_ci# put in absolute paths if you don't have them in your path; or use env. vars. 397b66cf61Sopenharmony_cimvprog="${MVPROG-mv}" 407b66cf61Sopenharmony_cicpprog="${CPPROG-cp}" 417b66cf61Sopenharmony_cichmodprog="${CHMODPROG-chmod}" 427b66cf61Sopenharmony_cichownprog="${CHOWNPROG-chown}" 437b66cf61Sopenharmony_cichgrpprog="${CHGRPPROG-chgrp}" 447b66cf61Sopenharmony_cistripprog="${STRIPPROG-strip}" 457b66cf61Sopenharmony_cirmprog="${RMPROG-rm}" 467b66cf61Sopenharmony_cimkdirprog="${MKDIRPROG-mkdir}" 477b66cf61Sopenharmony_ci 487b66cf61Sopenharmony_citransformbasename="" 497b66cf61Sopenharmony_citransform_arg="" 507b66cf61Sopenharmony_ciinstcmd="$mvprog" 517b66cf61Sopenharmony_cichmodcmd="$chmodprog 0755" 527b66cf61Sopenharmony_cichowncmd="" 537b66cf61Sopenharmony_cichgrpcmd="" 547b66cf61Sopenharmony_cistripcmd="" 557b66cf61Sopenharmony_cirmcmd="$rmprog -f" 567b66cf61Sopenharmony_cimvcmd="$mvprog" 577b66cf61Sopenharmony_cisrc="" 587b66cf61Sopenharmony_cidst="" 597b66cf61Sopenharmony_cidir_arg="" 607b66cf61Sopenharmony_ci 617b66cf61Sopenharmony_ciwhile [ x"$1" != x ]; do 627b66cf61Sopenharmony_ci case $1 in 637b66cf61Sopenharmony_ci -c) 647b66cf61Sopenharmony_ci instcmd="$cpprog" 657b66cf61Sopenharmony_ci shift 667b66cf61Sopenharmony_ci continue 677b66cf61Sopenharmony_ci ;; 687b66cf61Sopenharmony_ci 697b66cf61Sopenharmony_ci -d) 707b66cf61Sopenharmony_ci dir_arg=true 717b66cf61Sopenharmony_ci shift 727b66cf61Sopenharmony_ci continue 737b66cf61Sopenharmony_ci ;; 747b66cf61Sopenharmony_ci 757b66cf61Sopenharmony_ci -m) 767b66cf61Sopenharmony_ci chmodcmd="$chmodprog $2" 777b66cf61Sopenharmony_ci shift 787b66cf61Sopenharmony_ci shift 797b66cf61Sopenharmony_ci continue 807b66cf61Sopenharmony_ci ;; 817b66cf61Sopenharmony_ci 827b66cf61Sopenharmony_ci -o) 837b66cf61Sopenharmony_ci chowncmd="$chownprog $2" 847b66cf61Sopenharmony_ci shift 857b66cf61Sopenharmony_ci shift 867b66cf61Sopenharmony_ci continue 877b66cf61Sopenharmony_ci ;; 887b66cf61Sopenharmony_ci 897b66cf61Sopenharmony_ci -g) 907b66cf61Sopenharmony_ci chgrpcmd="$chgrpprog $2" 917b66cf61Sopenharmony_ci shift 927b66cf61Sopenharmony_ci shift 937b66cf61Sopenharmony_ci continue 947b66cf61Sopenharmony_ci ;; 957b66cf61Sopenharmony_ci 967b66cf61Sopenharmony_ci -s) 977b66cf61Sopenharmony_ci stripcmd="$stripprog" 987b66cf61Sopenharmony_ci shift 997b66cf61Sopenharmony_ci continue 1007b66cf61Sopenharmony_ci ;; 1017b66cf61Sopenharmony_ci 1027b66cf61Sopenharmony_ci *) 1037b66cf61Sopenharmony_ci if [ x"$src" = x ]; then 1047b66cf61Sopenharmony_ci src="$1" 1057b66cf61Sopenharmony_ci else 1067b66cf61Sopenharmony_ci dst="$1" 1077b66cf61Sopenharmony_ci fi 1087b66cf61Sopenharmony_ci shift 1097b66cf61Sopenharmony_ci continue 1107b66cf61Sopenharmony_ci ;; 1117b66cf61Sopenharmony_ci esac 1127b66cf61Sopenharmony_cidone 1137b66cf61Sopenharmony_ci 1147b66cf61Sopenharmony_ciif [ x"$src" = x ]; then 1157b66cf61Sopenharmony_ci echo "install-sh: No input file specified" 1167b66cf61Sopenharmony_ci exit 1 1177b66cf61Sopenharmony_cifi 1187b66cf61Sopenharmony_ci 1197b66cf61Sopenharmony_ciif [ x"$dir_arg" != x ]; then 1207b66cf61Sopenharmony_ci dst="$src" 1217b66cf61Sopenharmony_ci src="" 1227b66cf61Sopenharmony_ci 1237b66cf61Sopenharmony_ci if [ -d "$dst" ]; then 1247b66cf61Sopenharmony_ci instcmd=: 1257b66cf61Sopenharmony_ci else 1267b66cf61Sopenharmony_ci instcmd=$mkdirprog 1277b66cf61Sopenharmony_ci fi 1287b66cf61Sopenharmony_cielse 1297b66cf61Sopenharmony_ci # Waiting for this to be detected by the "$instcmd $src $dsttmp" command 1307b66cf61Sopenharmony_ci # might cause directories to be created, which would be especially bad 1317b66cf61Sopenharmony_ci # if $src (and thus $dsttmp) contains '*'. 1327b66cf61Sopenharmony_ci if [ ! -f "$src" -a ! -d "$src" ]; then 1337b66cf61Sopenharmony_ci echo "install: $src does not exist" 1347b66cf61Sopenharmony_ci exit 1 1357b66cf61Sopenharmony_ci fi 1367b66cf61Sopenharmony_ci 1377b66cf61Sopenharmony_ci if [ x"$dst" = x ]; then 1387b66cf61Sopenharmony_ci echo "install: No destination specified" 1397b66cf61Sopenharmony_ci exit 1 1407b66cf61Sopenharmony_ci fi 1417b66cf61Sopenharmony_ci 1427b66cf61Sopenharmony_ci # If destination is a directory, append the input filename. 1437b66cf61Sopenharmony_ci if [ -d "$dst" ]; then 1447b66cf61Sopenharmony_ci dst="$dst/`basename $src`" 1457b66cf61Sopenharmony_ci fi 1467b66cf61Sopenharmony_cifi 1477b66cf61Sopenharmony_ci 1487b66cf61Sopenharmony_ci## this sed command emulates the dirname command 1497b66cf61Sopenharmony_cidstdir="`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`" 1507b66cf61Sopenharmony_ci 1517b66cf61Sopenharmony_ci# Make sure that the destination directory exists. 1527b66cf61Sopenharmony_ci# This part is taken from Noah Friedman's mkinstalldirs script 1537b66cf61Sopenharmony_ci 1547b66cf61Sopenharmony_ci# Skip lots of stat calls in the usual case. 1557b66cf61Sopenharmony_ciif [ ! -d "$dstdir" ]; then 1567b66cf61Sopenharmony_ci defaultIFS=' 1577b66cf61Sopenharmony_ci ' 1587b66cf61Sopenharmony_ci IFS="${IFS-${defaultIFS}}" 1597b66cf61Sopenharmony_ci 1607b66cf61Sopenharmony_ci oIFS="${IFS}" 1617b66cf61Sopenharmony_ci # Some sh's can't handle IFS=/ for some reason. 1627b66cf61Sopenharmony_ci IFS='%' 1637b66cf61Sopenharmony_ci set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'` 1647b66cf61Sopenharmony_ci IFS="${oIFS}" 1657b66cf61Sopenharmony_ci 1667b66cf61Sopenharmony_ci pathcomp='' 1677b66cf61Sopenharmony_ci 1687b66cf61Sopenharmony_ci while [ $# -ne 0 ] ; do 1697b66cf61Sopenharmony_ci pathcomp="${pathcomp}${1}" 1707b66cf61Sopenharmony_ci shift 1717b66cf61Sopenharmony_ci 1727b66cf61Sopenharmony_ci if [ ! -d "${pathcomp}" ]; then $doit $mkdirprog "${pathcomp}"; fi 1737b66cf61Sopenharmony_ci 1747b66cf61Sopenharmony_ci pathcomp="${pathcomp}/" 1757b66cf61Sopenharmony_ci done 1767b66cf61Sopenharmony_cifi 1777b66cf61Sopenharmony_ci 1787b66cf61Sopenharmony_ciif [ x"$dir_arg" != x ]; then 1797b66cf61Sopenharmony_ci # Make a directory... 1807b66cf61Sopenharmony_ci $doit $instcmd $dst || exit 1 1817b66cf61Sopenharmony_ci 1827b66cf61Sopenharmony_ci # Allow chown/chgrp to fail, but log a warning 1837b66cf61Sopenharmony_ci if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst || echo "warning: Unable to change owner of $dst!"; fi 1847b66cf61Sopenharmony_ci if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst || echo "warning: Unable to change group of $dst!"; fi 1857b66cf61Sopenharmony_ci if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst || exit 1; fi 1867b66cf61Sopenharmony_cielse 1877b66cf61Sopenharmony_ci # Install a file... 1887b66cf61Sopenharmony_ci dstfile="`basename $dst`" 1897b66cf61Sopenharmony_ci 1907b66cf61Sopenharmony_ci # Check the destination file - for libraries just use the "-x" option 1917b66cf61Sopenharmony_ci # to strip... 1927b66cf61Sopenharmony_ci case "$dstfile" in 1937b66cf61Sopenharmony_ci *.a | *.dylib | *.sl | *.sl.* | *.so | *.so.*) 1947b66cf61Sopenharmony_ci stripopt="-x" 1957b66cf61Sopenharmony_ci ;; 1967b66cf61Sopenharmony_ci *) 1977b66cf61Sopenharmony_ci stripopt="" 1987b66cf61Sopenharmony_ci ;; 1997b66cf61Sopenharmony_ci esac 2007b66cf61Sopenharmony_ci 2017b66cf61Sopenharmony_ci # Make a temp file name in the proper directory. 2027b66cf61Sopenharmony_ci dsttmp="$dstdir/#inst.$$#" 2037b66cf61Sopenharmony_ci 2047b66cf61Sopenharmony_ci # Move or copy the file name to the temp name 2057b66cf61Sopenharmony_ci $doit $instcmd $src $dsttmp || exit 1 2067b66cf61Sopenharmony_ci 2077b66cf61Sopenharmony_ci # Update permissions and strip as needed, then move to the final name. 2087b66cf61Sopenharmony_ci # If the chmod, strip, rm, or mv commands fail, remove the installed 2097b66cf61Sopenharmony_ci # file... 2107b66cf61Sopenharmony_ci if [ x"$stripcmd" != x ]; then $doit $stripcmd $stripopt "$dsttmp" || echo "warning: Unable to strip $dst!"; fi 2117b66cf61Sopenharmony_ci if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dsttmp" || echo "warning: Unable to change owner of $dst!"; fi 2127b66cf61Sopenharmony_ci if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dsttmp" || echo "warning: Unable to change group of $dst!"; fi 2137b66cf61Sopenharmony_ci 2147b66cf61Sopenharmony_ci trap "rm -f ${dsttmp}" 0 && 2157b66cf61Sopenharmony_ci if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dsttmp"; fi && 2167b66cf61Sopenharmony_ci $doit $rmcmd -f "$dstdir/$dstfile" && 2177b66cf61Sopenharmony_ci $doit $mvcmd "$dsttmp" "$dstdir/$dstfile" 2187b66cf61Sopenharmony_cifi 2197b66cf61Sopenharmony_ci 2207b66cf61Sopenharmony_ciexit 0 221