mkdist 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #!/bin/sh
  2. # $Source$
  3. # $State$
  4. # Set up default variables.
  5. destdir=
  6. srcdir=`pwd`
  7. arch=/usr/local/bin/arch
  8. delete=no
  9. copy=ln
  10. # --- Options parsing -------------------------------------------------------
  11. while [ "$1" != "" ]; do
  12. case "$1" in
  13. -s|--srcdir)
  14. srcdir="$2"
  15. shift
  16. ;;
  17. -d|--destdir)
  18. destdir="$2"
  19. shift
  20. ;;
  21. -x|--delete)
  22. delete=yes
  23. ;;
  24. -c|--copy)
  25. copy="cp -dp"
  26. ;;
  27. -a|--arch)
  28. arch="$2"
  29. shift
  30. ;;
  31. -h|--help)
  32. echo "mkdist [options]"
  33. echo "Options are:"
  34. echo " -s --srcdir <path> The CVS tree to read from. (default: CWD)"
  35. echo " -d --destdir <path> The directory to create the distribution in."
  36. echo " -x --delete Erase the destination directory first."
  37. echo " -c --copy Make physical copies of the files. (default: hardlink)"
  38. echo " -a --arch <path> Where the ACK 'arch' tool is."
  39. echo " -h --help Display this message."
  40. exit 0
  41. ;;
  42. *)
  43. echo "Unrecognised option. Try --help for help."
  44. exit 1
  45. esac
  46. shift
  47. done
  48. if [ "$destdir" == "" ]; then
  49. echo "You must specify a destination directory. (Try --help for help.)"
  50. exit 1
  51. fi
  52. # --- Main routines ---------------------------------------------------------
  53. # These two routines do the work of traversing the source tree and building
  54. # the distribution tree.
  55. addfile() {
  56. local f
  57. f="${1##$srcdir/}"
  58. mkdir -p $destdir/`dirname $f`
  59. $copy "$1" "$destdir/$f"
  60. }
  61. process_dir() {
  62. local path
  63. local archivename
  64. path=$1
  65. cd $path
  66. echo $PWD
  67. # Look for a LIST file and cache the first line.
  68. archivename=
  69. if [ -f LIST ]; then
  70. archivename=`head -1 LIST`
  71. fi
  72. for i in `cat $path/.distr`; do
  73. if [ "${i:0:1}" = "#" ]; then
  74. # Comment. Do nothing.
  75. true
  76. elif [ -d $i ]; then
  77. # This is a directory. Recurse into it.
  78. ( process_dir $path/$i )
  79. elif [ -f $i ]; then
  80. # This is a file.
  81. addfile $path/$i
  82. elif [ "$i" = "$archivename" ]; then
  83. # Build the named archive.
  84. $arch cDr `cat LIST`
  85. addfile $path/$archivename
  86. else
  87. echo "Don't know what to do with $i, listed in $PWD/.distr."
  88. exit 1
  89. fi
  90. done
  91. }
  92. # --- Main program ----------------------------------------------------------
  93. # Test to make sure that $arch points to the right thing.
  94. if !(strings $arch | grep archiver > /dev/null); then
  95. echo "$arch does not seem to point at the ACK archiver tool."
  96. echo "(Don't confuse this with the Linux tool for displaying your"
  97. echo "architecture.)"
  98. echo ""
  99. echo "Press RETURN to go ahead anyway, or CTRL+C to abort."
  100. read
  101. fi
  102. # Actually do the work.
  103. echo "Creating distribution from CVS tree: $srcdir"
  104. echo " into destination tree: $destdir"
  105. echo ""
  106. if [ -e $destdir ]; then
  107. if [ "$delete" == "yes" ]; then
  108. echo "Press RETURN to erase $destdir and its contents, or CTRL+C to abort."
  109. read
  110. echo "Erasing..."
  111. rm -rf "$destdir"
  112. else
  113. echo "$destdir exists. Aborting."
  114. exit 1
  115. fi
  116. fi
  117. echo "Working..."
  118. mkdir -p $destdir
  119. process_dir $srcdir
  120. echo "Done."
  121. # Revision history
  122. # $Log$
  123. # Revision 1.3 2007-02-24 02:05:56 dtrg
  124. # Removed some bashish; added comment support; removed the make
  125. # distr functionality, as nothing was using it any more and it was
  126. # causing problems.
  127. #
  128. # Revision 1.2 2005/06/24 23:19:23 dtrg
  129. # Added new mkdist tool.
  130. #
  131. # Revision 1.1 2005/06/24 22:13:57 dtrg
  132. # Created new tool to generate distributions.