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