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.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. # determine file's type
  35. if [ -h "$FILE" ] ; then
  36. #echo $FILE is a symlink
  37. # Unfortunately, cp -d isn't universal so we have to
  38. # use a work-around.
  39. # Use ls -l to find the target that the link points to
  40. LL=`ls -l "$FILE"`
  41. for L in $LL ; do
  42. TARGET=$L
  43. done
  44. #echo $FILE is a symlink pointing to $TARGET
  45. FILE=`basename "$FILE"`
  46. # Go to $DEST and make the link
  47. PWDSAVE="$PWD"
  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. $RM "$DEST/`basename $FILE`"
  55. cp "$FILE" "$DEST"
  56. if [ $MODE ] ; then
  57. FILE=`basename "$FILE"`
  58. chmod $MODE "$DEST/$FILE"
  59. fi
  60. else
  61. echo "Unknown type of argument: " "$FILE"
  62. exit 1
  63. fi
  64. I=`expr $I + 1`
  65. done
  66. exit 0
  67. fi
  68. # If we get here, we didn't find anything to do
  69. echo "Usage:"
  70. echo " install -d dir Create named directory"
  71. echo " install [-m mode] file [...] dest Install files in destination"