mkdist 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. #!/bin/sh
  2. # $Source$
  3. # $State$
  4. # Set up default variables.
  5. destdir=
  6. srcdir=`pwd`
  7. aal=/usr/local/bin/aal
  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|--aal)
  31. aal="$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 --aal <path> Where the ACK 'aal' 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. $aal 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 $aal points to the right thing.
  101. if !(strings $aal | grep archiver > /dev/null); then
  102. echo "$aal does not seem to point at the ACK archiver tool."
  103. echo ""
  104. echo "Press RETURN to go ahead anyway, or CTRL+C to abort."
  105. read ignored
  106. fi
  107. # Actually do the work.
  108. echo "Creating distribution from CVS tree: $srcdir"
  109. echo " into destination tree: $destdir"
  110. echo ""
  111. if [ -e $destdir ]; then
  112. if [ "$delete" = "yes" ]; then
  113. echo "Press RETURN to erase $destdir and its contents, or CTRL+C to abort."
  114. read _ _
  115. echo "Erasing..."
  116. rm -rf "$destdir"
  117. else
  118. echo "$destdir exists. Aborting."
  119. exit 1
  120. fi
  121. fi
  122. echo "Working..."
  123. mkdir -p $destdir
  124. process_dir $srcdir
  125. echo "Done."
  126. # Revision history
  127. # $Log$
  128. # Revision 1.5 2007-04-24 19:48:41 dtrg
  129. # Removed bashish.
  130. #
  131. # Revision 1.4 2007/02/25 20:56:41 dtrg
  132. # Performed major renovations to make the script work on OpenBSD.
  133. #
  134. # Revision 1.3 2007/02/24 02:05:56 dtrg
  135. # Removed some bashish; added comment support; removed the make
  136. # distr functionality, as nothing was using it any more and it was
  137. # causing problems.
  138. #
  139. # Revision 1.2 2005/06/24 23:19:23 dtrg
  140. # Added new mkdist tool.
  141. #
  142. # Revision 1.1 2005/06/24 22:13:57 dtrg
  143. # Created new tool to generate distributions.