blob: 8ee96089fa618d7d98866f5bb59420294501eb6b [file] [log] [blame]
Brian Paul464fcd02006-10-19 20:09:05 +00001#!/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
11SYMLINK="ln -s"
12MKDIR="mkdir -p"
13RM="rm -f"
14
15MODE=""
16
17if [ "$1" = "-d" ] ; then
18 # make a directory path
19 $MKDIR "$2"
20 exit 0
21fi
22
23if [ "$1" = "-m" ] ; then
24 # set file mode
25 MODE=$2
26 shift 2
27fi
28
29# install file(s) into destination
30if [ $# -ge 2 ] ; then
31
32 # Last cmd line arg is the dest dir
33 for FILE in $@ ; do
34 DEST="$FILE"
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
Alan Coopersmith1043a7c2008-06-06 16:09:10 -070045 PWDSAVE=`pwd`
46
Brian Paul464fcd02006-10-19 20:09:05 +000047 # determine file's type
48 if [ -h "$FILE" ] ; then
49 #echo $FILE is a symlink
50 # Unfortunately, cp -d isn't universal so we have to
51 # use a work-around.
52
53 # Use ls -l to find the target that the link points to
54 LL=`ls -l "$FILE"`
55 for L in $LL ; do
56 TARGET=$L
57 done
58 #echo $FILE is a symlink pointing to $TARGET
59
60 FILE=`basename "$FILE"`
61 # Go to $DEST and make the link
Brian Paul464fcd02006-10-19 20:09:05 +000062 cd "$DEST" # pushd
63 $RM "$FILE"
64 $SYMLINK "$TARGET" "$FILE"
65 cd "$PWDSAVE" # popd
66
67 elif [ -f "$FILE" ] ; then
68 #echo "$FILE" is a regular file
Michel Dänzer26626c02006-12-11 17:45:06 +010069 $RM "$DEST/`basename $FILE`"
Brian Paul464fcd02006-10-19 20:09:05 +000070 cp "$FILE" "$DEST"
71 if [ $MODE ] ; then
72 FILE=`basename "$FILE"`
73 chmod $MODE "$DEST/$FILE"
74 fi
75 else
76 echo "Unknown type of argument: " "$FILE"
77 exit 1
78 fi
79
80 I=`expr $I + 1`
81 done
82
83 exit 0
84fi
85
86# If we get here, we didn't find anything to do
87echo "Usage:"
88echo " install -d dir Create named directory"
89echo " install [-m mode] file [...] dest Install files in destination"
90