jpayne@68: #!/bin/sh jpayne@68: # install - install a program, script, or datafile jpayne@68: jpayne@68: scriptversion=2018-03-11.20; # UTC jpayne@68: jpayne@68: # This originates from X11R5 (mit/util/scripts/install.sh), which was jpayne@68: # later released in X11R6 (xc/config/util/install.sh) with the jpayne@68: # following copyright and license. jpayne@68: # jpayne@68: # Copyright (C) 1994 X Consortium jpayne@68: # jpayne@68: # Permission is hereby granted, free of charge, to any person obtaining a copy jpayne@68: # of this software and associated documentation files (the "Software"), to jpayne@68: # deal in the Software without restriction, including without limitation the jpayne@68: # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or jpayne@68: # sell copies of the Software, and to permit persons to whom the Software is jpayne@68: # furnished to do so, subject to the following conditions: jpayne@68: # jpayne@68: # The above copyright notice and this permission notice shall be included in jpayne@68: # all copies or substantial portions of the Software. jpayne@68: # jpayne@68: # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR jpayne@68: # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, jpayne@68: # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE jpayne@68: # X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN jpayne@68: # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- jpayne@68: # TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. jpayne@68: # jpayne@68: # Except as contained in this notice, the name of the X Consortium shall not jpayne@68: # be used in advertising or otherwise to promote the sale, use or other deal- jpayne@68: # ings in this Software without prior written authorization from the X Consor- jpayne@68: # tium. jpayne@68: # jpayne@68: # jpayne@68: # FSF changes to this file are in the public domain. jpayne@68: # jpayne@68: # Calling this script install-sh is preferred over install.sh, to prevent jpayne@68: # 'make' implicit rules from creating a file called install from it jpayne@68: # when there is no Makefile. jpayne@68: # jpayne@68: # This script is compatible with the BSD install script, but was written jpayne@68: # from scratch. jpayne@68: jpayne@68: tab=' ' jpayne@68: nl=' jpayne@68: ' jpayne@68: IFS=" $tab$nl" jpayne@68: jpayne@68: # Set DOITPROG to "echo" to test this script. jpayne@68: jpayne@68: doit=${DOITPROG-} jpayne@68: doit_exec=${doit:-exec} jpayne@68: jpayne@68: # Put in absolute file names if you don't have them in your path; jpayne@68: # or use environment vars. jpayne@68: jpayne@68: chgrpprog=${CHGRPPROG-chgrp} jpayne@68: chmodprog=${CHMODPROG-chmod} jpayne@68: chownprog=${CHOWNPROG-chown} jpayne@68: cmpprog=${CMPPROG-cmp} jpayne@68: cpprog=${CPPROG-cp} jpayne@68: mkdirprog=${MKDIRPROG-mkdir} jpayne@68: mvprog=${MVPROG-mv} jpayne@68: rmprog=${RMPROG-rm} jpayne@68: stripprog=${STRIPPROG-strip} jpayne@68: jpayne@68: posix_mkdir= jpayne@68: jpayne@68: # Desired mode of installed file. jpayne@68: mode=0755 jpayne@68: jpayne@68: chgrpcmd= jpayne@68: chmodcmd=$chmodprog jpayne@68: chowncmd= jpayne@68: mvcmd=$mvprog jpayne@68: rmcmd="$rmprog -f" jpayne@68: stripcmd= jpayne@68: jpayne@68: src= jpayne@68: dst= jpayne@68: dir_arg= jpayne@68: dst_arg= jpayne@68: jpayne@68: copy_on_change=false jpayne@68: is_target_a_directory=possibly jpayne@68: jpayne@68: usage="\ jpayne@68: Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE jpayne@68: or: $0 [OPTION]... SRCFILES... DIRECTORY jpayne@68: or: $0 [OPTION]... -t DIRECTORY SRCFILES... jpayne@68: or: $0 [OPTION]... -d DIRECTORIES... jpayne@68: jpayne@68: In the 1st form, copy SRCFILE to DSTFILE. jpayne@68: In the 2nd and 3rd, copy all SRCFILES to DIRECTORY. jpayne@68: In the 4th, create DIRECTORIES. jpayne@68: jpayne@68: Options: jpayne@68: --help display this help and exit. jpayne@68: --version display version info and exit. jpayne@68: jpayne@68: -c (ignored) jpayne@68: -C install only if different (preserve the last data modification time) jpayne@68: -d create directories instead of installing files. jpayne@68: -g GROUP $chgrpprog installed files to GROUP. jpayne@68: -m MODE $chmodprog installed files to MODE. jpayne@68: -o USER $chownprog installed files to USER. jpayne@68: -s $stripprog installed files. jpayne@68: -t DIRECTORY install into DIRECTORY. jpayne@68: -T report an error if DSTFILE is a directory. jpayne@68: jpayne@68: Environment variables override the default commands: jpayne@68: CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG jpayne@68: RMPROG STRIPPROG jpayne@68: " jpayne@68: jpayne@68: while test $# -ne 0; do jpayne@68: case $1 in jpayne@68: -c) ;; jpayne@68: jpayne@68: -C) copy_on_change=true;; jpayne@68: jpayne@68: -d) dir_arg=true;; jpayne@68: jpayne@68: -g) chgrpcmd="$chgrpprog $2" jpayne@68: shift;; jpayne@68: jpayne@68: --help) echo "$usage"; exit $?;; jpayne@68: jpayne@68: -m) mode=$2 jpayne@68: case $mode in jpayne@68: *' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*) jpayne@68: echo "$0: invalid mode: $mode" >&2 jpayne@68: exit 1;; jpayne@68: esac jpayne@68: shift;; jpayne@68: jpayne@68: -o) chowncmd="$chownprog $2" jpayne@68: shift;; jpayne@68: jpayne@68: -s) stripcmd=$stripprog;; jpayne@68: jpayne@68: -t) jpayne@68: is_target_a_directory=always jpayne@68: dst_arg=$2 jpayne@68: # Protect names problematic for 'test' and other utilities. jpayne@68: case $dst_arg in jpayne@68: -* | [=\(\)!]) dst_arg=./$dst_arg;; jpayne@68: esac jpayne@68: shift;; jpayne@68: jpayne@68: -T) is_target_a_directory=never;; jpayne@68: jpayne@68: --version) echo "$0 $scriptversion"; exit $?;; jpayne@68: jpayne@68: --) shift jpayne@68: break;; jpayne@68: jpayne@68: -*) echo "$0: invalid option: $1" >&2 jpayne@68: exit 1;; jpayne@68: jpayne@68: *) break;; jpayne@68: esac jpayne@68: shift jpayne@68: done jpayne@68: jpayne@68: # We allow the use of options -d and -T together, by making -d jpayne@68: # take the precedence; this is for compatibility with GNU install. jpayne@68: jpayne@68: if test -n "$dir_arg"; then jpayne@68: if test -n "$dst_arg"; then jpayne@68: echo "$0: target directory not allowed when installing a directory." >&2 jpayne@68: exit 1 jpayne@68: fi jpayne@68: fi jpayne@68: jpayne@68: if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then jpayne@68: # When -d is used, all remaining arguments are directories to create. jpayne@68: # When -t is used, the destination is already specified. jpayne@68: # Otherwise, the last argument is the destination. Remove it from $@. jpayne@68: for arg jpayne@68: do jpayne@68: if test -n "$dst_arg"; then jpayne@68: # $@ is not empty: it contains at least $arg. jpayne@68: set fnord "$@" "$dst_arg" jpayne@68: shift # fnord jpayne@68: fi jpayne@68: shift # arg jpayne@68: dst_arg=$arg jpayne@68: # Protect names problematic for 'test' and other utilities. jpayne@68: case $dst_arg in jpayne@68: -* | [=\(\)!]) dst_arg=./$dst_arg;; jpayne@68: esac jpayne@68: done jpayne@68: fi jpayne@68: jpayne@68: if test $# -eq 0; then jpayne@68: if test -z "$dir_arg"; then jpayne@68: echo "$0: no input file specified." >&2 jpayne@68: exit 1 jpayne@68: fi jpayne@68: # It's OK to call 'install-sh -d' without argument. jpayne@68: # This can happen when creating conditional directories. jpayne@68: exit 0 jpayne@68: fi jpayne@68: jpayne@68: if test -z "$dir_arg"; then jpayne@68: if test $# -gt 1 || test "$is_target_a_directory" = always; then jpayne@68: if test ! -d "$dst_arg"; then jpayne@68: echo "$0: $dst_arg: Is not a directory." >&2 jpayne@68: exit 1 jpayne@68: fi jpayne@68: fi jpayne@68: fi jpayne@68: jpayne@68: if test -z "$dir_arg"; then jpayne@68: do_exit='(exit $ret); exit $ret' jpayne@68: trap "ret=129; $do_exit" 1 jpayne@68: trap "ret=130; $do_exit" 2 jpayne@68: trap "ret=141; $do_exit" 13 jpayne@68: trap "ret=143; $do_exit" 15 jpayne@68: jpayne@68: # Set umask so as not to create temps with too-generous modes. jpayne@68: # However, 'strip' requires both read and write access to temps. jpayne@68: case $mode in jpayne@68: # Optimize common cases. jpayne@68: *644) cp_umask=133;; jpayne@68: *755) cp_umask=22;; jpayne@68: jpayne@68: *[0-7]) jpayne@68: if test -z "$stripcmd"; then jpayne@68: u_plus_rw= jpayne@68: else jpayne@68: u_plus_rw='% 200' jpayne@68: fi jpayne@68: cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; jpayne@68: *) jpayne@68: if test -z "$stripcmd"; then jpayne@68: u_plus_rw= jpayne@68: else jpayne@68: u_plus_rw=,u+rw jpayne@68: fi jpayne@68: cp_umask=$mode$u_plus_rw;; jpayne@68: esac jpayne@68: fi jpayne@68: jpayne@68: for src jpayne@68: do jpayne@68: # Protect names problematic for 'test' and other utilities. jpayne@68: case $src in jpayne@68: -* | [=\(\)!]) src=./$src;; jpayne@68: esac jpayne@68: jpayne@68: if test -n "$dir_arg"; then jpayne@68: dst=$src jpayne@68: dstdir=$dst jpayne@68: test -d "$dstdir" jpayne@68: dstdir_status=$? jpayne@68: else jpayne@68: jpayne@68: # Waiting for this to be detected by the "$cpprog $src $dsttmp" command jpayne@68: # might cause directories to be created, which would be especially bad jpayne@68: # if $src (and thus $dsttmp) contains '*'. jpayne@68: if test ! -f "$src" && test ! -d "$src"; then jpayne@68: echo "$0: $src does not exist." >&2 jpayne@68: exit 1 jpayne@68: fi jpayne@68: jpayne@68: if test -z "$dst_arg"; then jpayne@68: echo "$0: no destination specified." >&2 jpayne@68: exit 1 jpayne@68: fi jpayne@68: dst=$dst_arg jpayne@68: jpayne@68: # If destination is a directory, append the input filename. jpayne@68: if test -d "$dst"; then jpayne@68: if test "$is_target_a_directory" = never; then jpayne@68: echo "$0: $dst_arg: Is a directory" >&2 jpayne@68: exit 1 jpayne@68: fi jpayne@68: dstdir=$dst jpayne@68: dstbase=`basename "$src"` jpayne@68: case $dst in jpayne@68: */) dst=$dst$dstbase;; jpayne@68: *) dst=$dst/$dstbase;; jpayne@68: esac jpayne@68: dstdir_status=0 jpayne@68: else jpayne@68: dstdir=`dirname "$dst"` jpayne@68: test -d "$dstdir" jpayne@68: dstdir_status=$? jpayne@68: fi jpayne@68: fi jpayne@68: jpayne@68: case $dstdir in jpayne@68: */) dstdirslash=$dstdir;; jpayne@68: *) dstdirslash=$dstdir/;; jpayne@68: esac jpayne@68: jpayne@68: obsolete_mkdir_used=false jpayne@68: jpayne@68: if test $dstdir_status != 0; then jpayne@68: case $posix_mkdir in jpayne@68: '') jpayne@68: # Create intermediate dirs using mode 755 as modified by the umask. jpayne@68: # This is like FreeBSD 'install' as of 1997-10-28. jpayne@68: umask=`umask` jpayne@68: case $stripcmd.$umask in jpayne@68: # Optimize common cases. jpayne@68: *[2367][2367]) mkdir_umask=$umask;; jpayne@68: .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; jpayne@68: jpayne@68: *[0-7]) jpayne@68: mkdir_umask=`expr $umask + 22 \ jpayne@68: - $umask % 100 % 40 + $umask % 20 \ jpayne@68: - $umask % 10 % 4 + $umask % 2 jpayne@68: `;; jpayne@68: *) mkdir_umask=$umask,go-w;; jpayne@68: esac jpayne@68: jpayne@68: # With -d, create the new directory with the user-specified mode. jpayne@68: # Otherwise, rely on $mkdir_umask. jpayne@68: if test -n "$dir_arg"; then jpayne@68: mkdir_mode=-m$mode jpayne@68: else jpayne@68: mkdir_mode= jpayne@68: fi jpayne@68: jpayne@68: posix_mkdir=false jpayne@68: case $umask in jpayne@68: *[123567][0-7][0-7]) jpayne@68: # POSIX mkdir -p sets u+wx bits regardless of umask, which jpayne@68: # is incompatible with FreeBSD 'install' when (umask & 300) != 0. jpayne@68: ;; jpayne@68: *) jpayne@68: # Note that $RANDOM variable is not portable (e.g. dash); Use it jpayne@68: # here however when possible just to lower collision chance. jpayne@68: tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ jpayne@68: jpayne@68: trap 'ret=$?; rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null; exit $ret' 0 jpayne@68: jpayne@68: # Because "mkdir -p" follows existing symlinks and we likely work jpayne@68: # directly in world-writeable /tmp, make sure that the '$tmpdir' jpayne@68: # directory is successfully created first before we actually test jpayne@68: # 'mkdir -p' feature. jpayne@68: if (umask $mkdir_umask && jpayne@68: $mkdirprog $mkdir_mode "$tmpdir" && jpayne@68: exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1 jpayne@68: then jpayne@68: if test -z "$dir_arg" || { jpayne@68: # Check for POSIX incompatibilities with -m. jpayne@68: # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or jpayne@68: # other-writable bit of parent directory when it shouldn't. jpayne@68: # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. jpayne@68: test_tmpdir="$tmpdir/a" jpayne@68: ls_ld_tmpdir=`ls -ld "$test_tmpdir"` jpayne@68: case $ls_ld_tmpdir in jpayne@68: d????-?r-*) different_mode=700;; jpayne@68: d????-?--*) different_mode=755;; jpayne@68: *) false;; jpayne@68: esac && jpayne@68: $mkdirprog -m$different_mode -p -- "$test_tmpdir" && { jpayne@68: ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"` jpayne@68: test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" jpayne@68: } jpayne@68: } jpayne@68: then posix_mkdir=: jpayne@68: fi jpayne@68: rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" jpayne@68: else jpayne@68: # Remove any dirs left behind by ancient mkdir implementations. jpayne@68: rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null jpayne@68: fi jpayne@68: trap '' 0;; jpayne@68: esac;; jpayne@68: esac jpayne@68: jpayne@68: if jpayne@68: $posix_mkdir && ( jpayne@68: umask $mkdir_umask && jpayne@68: $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" jpayne@68: ) jpayne@68: then : jpayne@68: else jpayne@68: jpayne@68: # The umask is ridiculous, or mkdir does not conform to POSIX, jpayne@68: # or it failed possibly due to a race condition. Create the jpayne@68: # directory the slow way, step by step, checking for races as we go. jpayne@68: jpayne@68: case $dstdir in jpayne@68: /*) prefix='/';; jpayne@68: [-=\(\)!]*) prefix='./';; jpayne@68: *) prefix='';; jpayne@68: esac jpayne@68: jpayne@68: oIFS=$IFS jpayne@68: IFS=/ jpayne@68: set -f jpayne@68: set fnord $dstdir jpayne@68: shift jpayne@68: set +f jpayne@68: IFS=$oIFS jpayne@68: jpayne@68: prefixes= jpayne@68: jpayne@68: for d jpayne@68: do jpayne@68: test X"$d" = X && continue jpayne@68: jpayne@68: prefix=$prefix$d jpayne@68: if test -d "$prefix"; then jpayne@68: prefixes= jpayne@68: else jpayne@68: if $posix_mkdir; then jpayne@68: (umask=$mkdir_umask && jpayne@68: $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break jpayne@68: # Don't fail if two instances are running concurrently. jpayne@68: test -d "$prefix" || exit 1 jpayne@68: else jpayne@68: case $prefix in jpayne@68: *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; jpayne@68: *) qprefix=$prefix;; jpayne@68: esac jpayne@68: prefixes="$prefixes '$qprefix'" jpayne@68: fi jpayne@68: fi jpayne@68: prefix=$prefix/ jpayne@68: done jpayne@68: jpayne@68: if test -n "$prefixes"; then jpayne@68: # Don't fail if two instances are running concurrently. jpayne@68: (umask $mkdir_umask && jpayne@68: eval "\$doit_exec \$mkdirprog $prefixes") || jpayne@68: test -d "$dstdir" || exit 1 jpayne@68: obsolete_mkdir_used=true jpayne@68: fi jpayne@68: fi jpayne@68: fi jpayne@68: jpayne@68: if test -n "$dir_arg"; then jpayne@68: { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && jpayne@68: { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && jpayne@68: { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || jpayne@68: test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 jpayne@68: else jpayne@68: jpayne@68: # Make a couple of temp file names in the proper directory. jpayne@68: dsttmp=${dstdirslash}_inst.$$_ jpayne@68: rmtmp=${dstdirslash}_rm.$$_ jpayne@68: jpayne@68: # Trap to clean up those temp files at exit. jpayne@68: trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 jpayne@68: jpayne@68: # Copy the file name to the temp name. jpayne@68: (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && jpayne@68: jpayne@68: # and set any options; do chmod last to preserve setuid bits. jpayne@68: # jpayne@68: # If any of these fail, we abort the whole thing. If we want to jpayne@68: # ignore errors from any of these, just make sure not to ignore jpayne@68: # errors from the above "$doit $cpprog $src $dsttmp" command. jpayne@68: # jpayne@68: { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && jpayne@68: { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && jpayne@68: { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && jpayne@68: { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && jpayne@68: jpayne@68: # If -C, don't bother to copy if it wouldn't change the file. jpayne@68: if $copy_on_change && jpayne@68: old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && jpayne@68: new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && jpayne@68: set -f && jpayne@68: set X $old && old=:$2:$4:$5:$6 && jpayne@68: set X $new && new=:$2:$4:$5:$6 && jpayne@68: set +f && jpayne@68: test "$old" = "$new" && jpayne@68: $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 jpayne@68: then jpayne@68: rm -f "$dsttmp" jpayne@68: else jpayne@68: # Rename the file to the real destination. jpayne@68: $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || jpayne@68: jpayne@68: # The rename failed, perhaps because mv can't rename something else jpayne@68: # to itself, or perhaps because mv is so ancient that it does not jpayne@68: # support -f. jpayne@68: { jpayne@68: # Now remove or move aside any old file at destination location. jpayne@68: # We try this two ways since rm can't unlink itself on some jpayne@68: # systems and the destination file might be busy for other jpayne@68: # reasons. In this case, the final cleanup might fail but the new jpayne@68: # file should still install successfully. jpayne@68: { jpayne@68: test ! -f "$dst" || jpayne@68: $doit $rmcmd -f "$dst" 2>/dev/null || jpayne@68: { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && jpayne@68: { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } jpayne@68: } || jpayne@68: { echo "$0: cannot unlink or rename $dst" >&2 jpayne@68: (exit 1); exit 1 jpayne@68: } jpayne@68: } && jpayne@68: jpayne@68: # Now rename the file to the real destination. jpayne@68: $doit $mvcmd "$dsttmp" "$dst" jpayne@68: } jpayne@68: fi || exit 1 jpayne@68: jpayne@68: trap '' 0 jpayne@68: fi jpayne@68: done jpayne@68: jpayne@68: # Local variables: jpayne@68: # eval: (add-hook 'before-save-hook 'time-stamp) jpayne@68: # time-stamp-start: "scriptversion=" jpayne@68: # time-stamp-format: "%:y-%02m-%02d.%02H" jpayne@68: # time-stamp-time-zone: "UTC0" jpayne@68: # time-stamp-end: "; # UTC" jpayne@68: # End: