Brian Paul | 464fcd0 | 2006-10-19 20:09:05 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | |
| 4 | # A minimal replacement for 'install' that supports installing symbolic links. |
| 5 | # Only a limited number of options are supported: |
| 6 | # -d dir Create a directory |
| 7 | # -m mode Sets a file's mode when installing |
| 8 | |
| 9 | |
| 10 | # If these commands aren't portable, we'll need some "if (arch)" type stuff |
| 11 | SYMLINK="ln -s" |
| 12 | MKDIR="mkdir -p" |
| 13 | RM="rm -f" |
| 14 | |
| 15 | MODE="" |
| 16 | |
| 17 | if [ "$1" = "-d" ] ; then |
| 18 | # make a directory path |
| 19 | $MKDIR "$2" |
| 20 | exit 0 |
| 21 | fi |
| 22 | |
| 23 | if [ "$1" = "-m" ] ; then |
| 24 | # set file mode |
| 25 | MODE=$2 |
| 26 | shift 2 |
| 27 | fi |
| 28 | |
| 29 | # install file(s) into destination |
| 30 | if [ $# -ge 2 ] ; then |
| 31 | |
| 32 | # Last cmd line arg is the dest dir |
| 33 | for FILE in $@ ; do |
Jon TURNEY | c55a8a7 | 2010-07-24 12:05:34 +0100 | [diff] [blame] | 34 | DESTDIR="$FILE" |
Brian Paul | 464fcd0 | 2006-10-19 20:09:05 +0000 | [diff] [blame] | 35 | done |
| 36 | |
| 37 | # Loop over args, moving them to DEST directory |
| 38 | I=1 |
| 39 | for FILE in $@ ; do |
| 40 | if [ $I = $# ] ; then |
| 41 | # stop, don't want to install $DEST into $DEST |
| 42 | exit 0 |
| 43 | fi |
| 44 | |
Jon TURNEY | c55a8a7 | 2010-07-24 12:05:34 +0100 | [diff] [blame] | 45 | DEST=$DESTDIR |
| 46 | |
| 47 | # On CYGWIN, because DLLs are loaded by the native Win32 loader, |
| 48 | # they are installed in the executable path. Stub libraries used |
| 49 | # only for linking are installed in the library path |
| 50 | case `uname` in |
| 51 | CYGWIN*) |
| 52 | case $FILE in |
| 53 | *.dll) |
| 54 | DEST="$DEST/../bin" |
| 55 | ;; |
| 56 | *) |
| 57 | ;; |
| 58 | esac |
| 59 | ;; |
| 60 | *) |
| 61 | ;; |
| 62 | esac |
| 63 | |
Alan Coopersmith | 1043a7c | 2008-06-06 16:09:10 -0700 | [diff] [blame] | 64 | PWDSAVE=`pwd` |
| 65 | |
Brian Paul | 464fcd0 | 2006-10-19 20:09:05 +0000 | [diff] [blame] | 66 | # determine file's type |
| 67 | if [ -h "$FILE" ] ; then |
| 68 | #echo $FILE is a symlink |
| 69 | # Unfortunately, cp -d isn't universal so we have to |
| 70 | # use a work-around. |
| 71 | |
| 72 | # Use ls -l to find the target that the link points to |
| 73 | LL=`ls -l "$FILE"` |
| 74 | for L in $LL ; do |
| 75 | TARGET=$L |
| 76 | done |
| 77 | #echo $FILE is a symlink pointing to $TARGET |
| 78 | |
| 79 | FILE=`basename "$FILE"` |
| 80 | # Go to $DEST and make the link |
Brian Paul | 464fcd0 | 2006-10-19 20:09:05 +0000 | [diff] [blame] | 81 | cd "$DEST" # pushd |
| 82 | $RM "$FILE" |
| 83 | $SYMLINK "$TARGET" "$FILE" |
| 84 | cd "$PWDSAVE" # popd |
| 85 | |
| 86 | elif [ -f "$FILE" ] ; then |
| 87 | #echo "$FILE" is a regular file |
Carl Worth | d2f4c2b | 2009-05-21 07:52:13 -0600 | [diff] [blame] | 88 | # Only copy if the files differ |
| 89 | if ! cmp -s $FILE $DEST/`basename $FILE`; then |
| 90 | $RM "$DEST/`basename $FILE`" |
| 91 | cp "$FILE" "$DEST" |
| 92 | fi |
Brian Paul | 464fcd0 | 2006-10-19 20:09:05 +0000 | [diff] [blame] | 93 | if [ $MODE ] ; then |
| 94 | FILE=`basename "$FILE"` |
| 95 | chmod $MODE "$DEST/$FILE" |
| 96 | fi |
| 97 | else |
| 98 | echo "Unknown type of argument: " "$FILE" |
| 99 | exit 1 |
| 100 | fi |
| 101 | |
| 102 | I=`expr $I + 1` |
| 103 | done |
| 104 | |
| 105 | exit 0 |
| 106 | fi |
| 107 | |
| 108 | # If we get here, we didn't find anything to do |
| 109 | echo "Usage:" |
| 110 | echo " install -d dir Create named directory" |
| 111 | echo " install [-m mode] file [...] dest Install files in destination" |
| 112 | |