1
0

build 5.9 KB

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