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