mkdist 3.7 KB

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