mkdist 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. # Look for a LIST file and cache the first line.
  67. archivename=
  68. if [ -f LIST ]; then
  69. archivename=`head -1 LIST`
  70. fi
  71. for i in `cat $path/.distr`; do
  72. if [ -d $i ]; then
  73. # This is a directory. Recurse into it.
  74. ( process_dir $path/$i )
  75. elif [ -f $i ]; then
  76. # This is a file.
  77. addfile $path/$i
  78. elif [ "$i" = "$archivename" ]; then
  79. # Build the named archive.
  80. $arch cDr `cat LIST`
  81. addfile $path/$archivename
  82. else
  83. (
  84. PATH=$PATH:.
  85. export PATH
  86. make distr || make $i || (
  87. echo "Don't know what to do with $i, listed in $1/.distr."
  88. exit 1
  89. )
  90. if [ ! -f "$path/$i" ]; then
  91. echo "Make failed for $i, listed in $path/.distr"
  92. exit 1
  93. fi
  94. addfile $path/$i
  95. )
  96. fi
  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
  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.2 2005-06-24 23:19:23 dtrg
  131. # Added new mkdist tool.
  132. #
  133. # Revision 1.1 2005/06/24 22:13:57 dtrg
  134. # Created new tool to generate distributions.