build 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. #! /bin/sh
  2. # We want to use BASH, not whatever /bin/sh points to.
  3. if test -z "$BASH"; then
  4. bash $0 ${1+"$@"}
  5. exit 0
  6. fi
  7. # Awk out the version from source
  8. AWK="`which awk`"
  9. if test -z "${AWK}"; then
  10. AWK="`which gawk`"
  11. fi
  12. ver="?.?.?"
  13. ver=`grep "char" src/main.c | $AWK '/egg_version/ {print $5}' | sed -e 's/\"//g' | sed -e 's/\;//g'`
  14. BUILDTS=`cat src/build.h | $AWK '{print $3}'`
  15. builddate=`perl -e "use POSIX 'strftime';print strftime(\"%m.%d.%Y\n\",gmtime(${BUILDTS}));"`
  16. clear
  17. #Display a banner
  18. bt=`grep -A 5 "char \*wbanner(void) {" src/misc.c | grep "switch" | sed -e "s/.*switch (randint(\(.\))) {/\1/"`
  19. bn=$[($RANDOM % ${bt})]
  20. banner=`grep -A 15 "char \*wbanner(void) {" src/misc.c | grep "case ${bn}:" | sed -e "s/.*case ${bn}: return STR(\"\(.*\)\");/\1/"`
  21. echo -e "${banner}"
  22. echo -e "Version: ${ver}\nBuild: ${builddate}"
  23. usage()
  24. {
  25. echo
  26. echo "Usage: $0 [-bcCdnP] [-p FILE] [all|hub|leaf]"
  27. echo
  28. echo " The options are as follows:"
  29. echo " -b Use bzip2 instead of gzip when packaging."
  30. echo " -c Cleans up old binaries/files before compile."
  31. echo " -C Preforms a distclean before making."
  32. echo " -d Builds a debug package."
  33. echo " -n Do not package the binaries."
  34. echo " -p FILE What file to use as the cfg file."
  35. echo " -P For development (Don't compile/rm binaries)"
  36. echo " -s scp target."
  37. }
  38. debug=0
  39. all=0
  40. hub=0
  41. leaf=0
  42. clean=0
  43. type=
  44. nopkg=0
  45. bzip=0
  46. pkg=0
  47. scp=0
  48. pack=pack/pack.cfg
  49. while getopts bCcdhnPp:s: opt ; do
  50. case "$opt" in
  51. b) bzip=1 ;;
  52. c) clean=1 ;;
  53. C) clean=2 ;;
  54. d) debug=1 ;;
  55. h) usage; exit 0 ;;
  56. n) nopkg=1 ;;
  57. p) pack="$OPTARG" ;;
  58. P) pkg=1 ;;
  59. s) scp="$OPTARG" ;;
  60. *) usage; exit 1 ;;
  61. esac
  62. done
  63. shift $(($OPTIND - 1))
  64. PACKNAME=`grep "PACKNAME " ${pack} | $AWK '/PACKNAME/ {print $2}'`
  65. echo "Packname: ${PACKNAME} (${pack})"
  66. echo -e `grep -r "http://" src/misc.c | sed -e "s/.*\- \(.*\) \-.*/\1/"`
  67. echo
  68. if test -z "$1"; then
  69. usage
  70. exit 1
  71. else
  72. if [ $1 = "all" ]; then
  73. all=1
  74. elif [ $1 = "leaf" ]; then
  75. leaf=1
  76. type="leaf"
  77. elif [ $1 = "hub" ]; then
  78. hub=1
  79. type="hub"
  80. else
  81. all=1
  82. fi
  83. fi
  84. rm=1
  85. compile=1
  86. if [ $pkg = "1" ]; then
  87. rm=0
  88. compile=0
  89. fi
  90. if [ $debug = "1" ]; then
  91. d="d"
  92. else
  93. d=""
  94. fi
  95. if [ $all = "1" ]; then
  96. type="all"
  97. leaf=1
  98. hub=1
  99. fi
  100. # Figure what bins we're making
  101. case `uname` in
  102. Linux) os=Linux;;
  103. FreeBSD) os=FreeBSD;;
  104. # FreeBSD) case `uname -r` in
  105. # 5*) os=FreeBSD5;;
  106. # 4*) os=FreeBSD4;;
  107. # 3*) os=FreeBSD3;;
  108. # esac;;
  109. OpenBSD) os=OpenBSD;;
  110. NetBSD) os=NetBSD;;
  111. SunOS) os=Solaris;;
  112. CYGWIN*) os=Cygwin;;
  113. esac
  114. if test -z $os
  115. then
  116. echo "[!] Automated packaging disabled, `uname` isn't recognized"
  117. fi
  118. if [ $compile = "1" ]; then
  119. echo "[*] Building ${PACKNAME}::${type} for $os"
  120. MAKE="`which gmake`"
  121. if test -z "${MAKE}"; then
  122. MAKE="`which make`"
  123. fi
  124. if [ $clean = "2" ]; then
  125. if test -f Makefile; then
  126. echo "[*] DistCleaning old files..."
  127. ${MAKE} distclean > /dev/null
  128. fi
  129. fi
  130. # Run ./configure, then verify it's ok
  131. echo "[*] Configuring..."
  132. umask 077 >/dev/null
  133. ./configure --silent
  134. if [ $clean = "1" ]; then
  135. echo "[*] Cleaning up old binaries/files..."
  136. ${MAKE} clean > /dev/null
  137. fi
  138. fi
  139. if test -n "$d"; then
  140. d="-debug"
  141. fi
  142. _build()
  143. {
  144. if [ $[${tb}] = "1" ]; then
  145. if [ $compile = "1" ]; then
  146. echo "[*] Building ${d}${tb}..."
  147. ${MAKE} ${d}${tb}
  148. if ! test -f ${tb}; then
  149. echo "[!] ${d}${tb} build failed"
  150. exit 1
  151. fi
  152. fi
  153. if [ $nopkg = "0" -o $pkg = "1" ]; then
  154. echo "[*] Hashing and initializing settings in binary"
  155. cp ${tb} ${tb}.$os-$ver${d} > /dev/null 2>&1
  156. ./${tb}.$os-$ver${d} -p ${pack}
  157. rm=1
  158. elif [ $nopkg = "0" ]; then
  159. mv ${tb} ${tb}.$os-$ver${d} > /dev/null 2>&1
  160. fi
  161. fi
  162. }
  163. if [ -f stamp.hub ]; then
  164. tb="hub"
  165. _build
  166. tb="leaf"
  167. else
  168. tb="leaf"
  169. _build
  170. tb="hub"
  171. fi
  172. _build
  173. if [ $bzip = "1" ]; then
  174. zip="j"
  175. ext="bz2"
  176. else
  177. zip="z"
  178. ext="gz"
  179. fi
  180. # Wrap it nicely up into an archive
  181. if [ $nopkg = "0" -o $pkg = "1" ]; then
  182. echo "[*] Packaging..."
  183. #This MALLOC business is to not Abort 'tar' due to some bug it has.
  184. tmp=${MALLOC_CHECK_}
  185. unset MALLOC_CHECK_
  186. tar -c${zip}f ${PACKNAME}.$os-$ver${d}.tar.${ext} hub.$os-$ver${d} leaf.$os-$ver${d}
  187. chmod 0644 ${PACKNAME}.$os-$ver${d}.tar.${ext}
  188. if test -n "$tmp"; then
  189. declare -x MALLOC_CHECK_=$tmp
  190. fi
  191. if [ $rm = "1" ]; then
  192. rm -f *$os-$ver${d}
  193. fi
  194. echo "Binaries are now in '${PACKNAME}.$os-$ver${d}.tar.${ext}'."
  195. if ! [ $scp = 0 ]; then
  196. scp -i misc/id_dsa -B -p -C ${PACKNAME}.$os-$ver${d}.tar.${ext} $scp
  197. fi
  198. elif ! [ $scp = 0 ]; then
  199. cp hub hub.$os-$ver${d}-${builddate} > /dev/null 2>&1
  200. cp leaf leaf.$os-$ver${d}-${builddate} > /dev/null 2>&1
  201. #This MALLOC business is to not Abort 'tar' due to some bug it has.
  202. tmp=${MALLOC_CHECK_}
  203. unset MALLOC_CHECK_
  204. tar -c${zip}f $os-$ver${d}-${builddate}.tar.${ext} hub.$os-$ver${d}-${builddate} leaf.$os-$ver${d}-${builddate}
  205. chmod 0644 $os-$ver${d}-${builddate}.tar.${ext}
  206. if test -n "$tmp"; then
  207. declare -x MALLOC_CHECK_=$tmp
  208. fi
  209. scp -i misc/id_dsa -B -p -C $os-$ver${d}-${builddate}.tar.${ext} $scp
  210. rm -rf $os-$ver${d}-${builddate}.tar.${ext} hub.$os-$ver${d}-${builddate} leaf.$os-$ver${d}-${builddate}
  211. fi
  212. exit 0