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