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