| | |
| | | #!/bin/sh |
| | | # install - install a program, script, or datafile |
| | | |
| | | scriptversion=2011-11-20.07; # UTC |
| | | scriptversion=2014-09-12.12; # UTC |
| | | |
| | | # This originates from X11R5 (mit/util/scripts/install.sh), which was |
| | | # later released in X11R6 (xc/config/util/install.sh) with the |
| | |
| | | # This script is compatible with the BSD install script, but was written |
| | | # from scratch. |
| | | |
| | | tab=' ' |
| | | nl=' |
| | | ' |
| | | IFS=" "" $nl" |
| | | IFS=" $tab$nl" |
| | | |
| | | # set DOITPROG to echo to test this script |
| | | # Set DOITPROG to "echo" to test this script. |
| | | |
| | | # Don't use :- since 4.3BSD and earlier shells don't like it. |
| | | doit=${DOITPROG-} |
| | | if test -z "$doit"; then |
| | | doit_exec=exec |
| | | else |
| | | doit_exec=$doit |
| | | fi |
| | | doit_exec=${doit:-exec} |
| | | |
| | | # Put in absolute file names if you don't have them in your path; |
| | | # or use environment vars. |
| | |
| | | mvprog=${MVPROG-mv} |
| | | rmprog=${RMPROG-rm} |
| | | stripprog=${STRIPPROG-strip} |
| | | |
| | | posix_glob='?' |
| | | initialize_posix_glob=' |
| | | test "$posix_glob" != "?" || { |
| | | if (set -f) 2>/dev/null; then |
| | | posix_glob= |
| | | else |
| | | posix_glob=: |
| | | fi |
| | | } |
| | | ' |
| | | |
| | | posix_mkdir= |
| | | |
| | |
| | | dst_arg= |
| | | |
| | | copy_on_change=false |
| | | no_target_directory= |
| | | is_target_a_directory=possibly |
| | | |
| | | usage="\ |
| | | Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE |
| | |
| | | |
| | | -m) mode=$2 |
| | | case $mode in |
| | | *' '* | *' '* | *' |
| | | '* | *'*'* | *'?'* | *'['*) |
| | | *' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*) |
| | | echo "$0: invalid mode: $mode" >&2 |
| | | exit 1;; |
| | | esac |
| | |
| | | |
| | | -s) stripcmd=$stripprog;; |
| | | |
| | | -t) dst_arg=$2 |
| | | -t) |
| | | is_target_a_directory=always |
| | | dst_arg=$2 |
| | | # Protect names problematic for 'test' and other utilities. |
| | | case $dst_arg in |
| | | -* | [=\(\)!]) dst_arg=./$dst_arg;; |
| | | esac |
| | | shift;; |
| | | |
| | | -T) no_target_directory=true;; |
| | | -T) is_target_a_directory=never;; |
| | | |
| | | --version) echo "$0 $scriptversion"; exit $?;; |
| | | |
| | |
| | | esac |
| | | shift |
| | | done |
| | | |
| | | # We allow the use of options -d and -T together, by making -d |
| | | # take the precedence; this is for compatibility with GNU install. |
| | | |
| | | if test -n "$dir_arg"; then |
| | | if test -n "$dst_arg"; then |
| | | echo "$0: target directory not allowed when installing a directory." >&2 |
| | | exit 1 |
| | | fi |
| | | fi |
| | | |
| | | if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then |
| | | # When -d is used, all remaining arguments are directories to create. |
| | |
| | | # It's OK to call 'install-sh -d' without argument. |
| | | # This can happen when creating conditional directories. |
| | | exit 0 |
| | | fi |
| | | |
| | | if test -z "$dir_arg"; then |
| | | if test $# -gt 1 || test "$is_target_a_directory" = always; then |
| | | if test ! -d "$dst_arg"; then |
| | | echo "$0: $dst_arg: Is not a directory." >&2 |
| | | exit 1 |
| | | fi |
| | | fi |
| | | fi |
| | | |
| | | if test -z "$dir_arg"; then |
| | |
| | | # If destination is a directory, append the input filename; won't work |
| | | # if double slashes aren't ignored. |
| | | if test -d "$dst"; then |
| | | if test -n "$no_target_directory"; then |
| | | if test "$is_target_a_directory" = never; then |
| | | echo "$0: $dst_arg: Is a directory" >&2 |
| | | exit 1 |
| | | fi |
| | |
| | | dst=$dstdir/`basename "$src"` |
| | | dstdir_status=0 |
| | | else |
| | | # Prefer dirname, but fall back on a substitute if dirname fails. |
| | | dstdir=` |
| | | (dirname "$dst") 2>/dev/null || |
| | | expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ |
| | | X"$dst" : 'X\(//\)[^/]' \| \ |
| | | X"$dst" : 'X\(//\)$' \| \ |
| | | X"$dst" : 'X\(/\)' \| . 2>/dev/null || |
| | | echo X"$dst" | |
| | | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ |
| | | s//\1/ |
| | | q |
| | | } |
| | | /^X\(\/\/\)[^/].*/{ |
| | | s//\1/ |
| | | q |
| | | } |
| | | /^X\(\/\/\)$/{ |
| | | s//\1/ |
| | | q |
| | | } |
| | | /^X\(\/\).*/{ |
| | | s//\1/ |
| | | q |
| | | } |
| | | s/.*/./; q' |
| | | ` |
| | | |
| | | dstdir=`dirname "$dst"` |
| | | test -d "$dstdir" |
| | | dstdir_status=$? |
| | | fi |
| | |
| | | # is incompatible with FreeBSD 'install' when (umask & 300) != 0. |
| | | ;; |
| | | *) |
| | | # $RANDOM is not portable (e.g. dash); use it when possible to |
| | | # lower collision chance |
| | | tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ |
| | | trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 |
| | | trap 'ret=$?; rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null; exit $ret' 0 |
| | | |
| | | # As "mkdir -p" follows symlinks and we work in /tmp possibly; so |
| | | # create the $tmpdir first (and fail if unsuccessful) to make sure |
| | | # that nobody tries to guess the $tmpdir name. |
| | | if (umask $mkdir_umask && |
| | | exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 |
| | | $mkdirprog $mkdir_mode "$tmpdir" && |
| | | exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1 |
| | | then |
| | | if test -z "$dir_arg" || { |
| | | # Check for POSIX incompatibilities with -m. |
| | | # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or |
| | | # other-writable bit of parent directory when it shouldn't. |
| | | # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. |
| | | ls_ld_tmpdir=`ls -ld "$tmpdir"` |
| | | test_tmpdir="$tmpdir/a" |
| | | ls_ld_tmpdir=`ls -ld "$test_tmpdir"` |
| | | case $ls_ld_tmpdir in |
| | | d????-?r-*) different_mode=700;; |
| | | d????-?--*) different_mode=755;; |
| | | *) false;; |
| | | esac && |
| | | $mkdirprog -m$different_mode -p -- "$tmpdir" && { |
| | | ls_ld_tmpdir_1=`ls -ld "$tmpdir"` |
| | | $mkdirprog -m$different_mode -p -- "$test_tmpdir" && { |
| | | ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"` |
| | | test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" |
| | | } |
| | | } |
| | | then posix_mkdir=: |
| | | fi |
| | | rmdir "$tmpdir/d" "$tmpdir" |
| | | rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" |
| | | else |
| | | # Remove any dirs left behind by ancient mkdir implementations. |
| | | rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null |
| | | rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null |
| | | fi |
| | | trap '' 0;; |
| | | esac;; |
| | |
| | | *) prefix='';; |
| | | esac |
| | | |
| | | eval "$initialize_posix_glob" |
| | | |
| | | oIFS=$IFS |
| | | IFS=/ |
| | | $posix_glob set -f |
| | | set -f |
| | | set fnord $dstdir |
| | | shift |
| | | $posix_glob set +f |
| | | set +f |
| | | IFS=$oIFS |
| | | |
| | | prefixes= |
| | |
| | | if $copy_on_change && |
| | | old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && |
| | | new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && |
| | | |
| | | eval "$initialize_posix_glob" && |
| | | $posix_glob set -f && |
| | | set -f && |
| | | set X $old && old=:$2:$4:$5:$6 && |
| | | set X $new && new=:$2:$4:$5:$6 && |
| | | $posix_glob set +f && |
| | | |
| | | set +f && |
| | | test "$old" = "$new" && |
| | | $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 |
| | | then |