Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

minstall 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/bin/sh
  2. # A minimal replacement for 'install' that supports installing symbolic links.
  3. # Only a limited number of options are supported:
  4. # -d dir Create a directory
  5. # -m mode Sets a file's mode when installing
  6. # If these commands aren't portable, we'll need some "if (arch)" type stuff
  7. SYMLINK="ln -s"
  8. MKDIR="mkdir -p"
  9. RM="rm -f"
  10. MODE=""
  11. if [ "$1" = "-d" ] ; then
  12. # make a directory path
  13. $MKDIR "$2"
  14. exit 0
  15. fi
  16. if [ "$1" = "-m" ] ; then
  17. # set file mode
  18. MODE=$2
  19. shift 2
  20. fi
  21. # install file(s) into destination
  22. if [ $# -ge 2 ] ; then
  23. # Last cmd line arg is the dest dir
  24. for FILE in $@ ; do
  25. DEST="$FILE"
  26. done
  27. # Loop over args, moving them to DEST directory
  28. I=1
  29. for FILE in $@ ; do
  30. if [ $I = $# ] ; then
  31. # stop, don't want to install $DEST into $DEST
  32. exit 0
  33. fi
  34. PWDSAVE=`pwd`
  35. # determine file's type
  36. if [ -h "$FILE" ] ; then
  37. #echo $FILE is a symlink
  38. # Unfortunately, cp -d isn't universal so we have to
  39. # use a work-around.
  40. # Use ls -l to find the target that the link points to
  41. LL=`ls -l "$FILE"`
  42. for L in $LL ; do
  43. TARGET=$L
  44. done
  45. #echo $FILE is a symlink pointing to $TARGET
  46. FILE=`basename "$FILE"`
  47. # Go to $DEST and make the link
  48. cd "$DEST" # pushd
  49. $RM "$FILE"
  50. $SYMLINK "$TARGET" "$FILE"
  51. cd "$PWDSAVE" # popd
  52. elif [ -f "$FILE" ] ; then
  53. #echo "$FILE" is a regular file
  54. # Only copy if the files differ
  55. if ! cmp -s $FILE $DEST/`basename $FILE`; then
  56. $RM "$DEST/`basename $FILE`"
  57. cp "$FILE" "$DEST"
  58. fi
  59. if [ $MODE ] ; then
  60. FILE=`basename "$FILE"`
  61. chmod $MODE "$DEST/$FILE"
  62. fi
  63. else
  64. echo "Unknown type of argument: " "$FILE"
  65. exit 1
  66. fi
  67. I=`expr $I + 1`
  68. done
  69. exit 0
  70. fi
  71. # If we get here, we didn't find anything to do
  72. echo "Usage:"
  73. echo " install -d dir Create named directory"
  74. echo " install [-m mode] file [...] dest Install files in destination"