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