build 5.8 KB

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