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