build 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. pack=pack/pack.cfg
  51. while getopts bCcdhnPp:s: opt ; do
  52. case "$opt" in
  53. b) bzip=1 ;;
  54. c) clean=1 ;;
  55. C) clean=2 ;;
  56. d) debug=1 ;;
  57. h) usage; exit 0 ;;
  58. n) nopkg=1 ;;
  59. p) pack="$OPTARG" ;;
  60. P) pkg=1 ;;
  61. s) scp="$OPTARG" ;;
  62. *) usage; exit 1 ;;
  63. esac
  64. done
  65. shift $(($OPTIND - 1))
  66. PACKNAME=`grep "PACKNAME " ${pack} | $AWK '/PACKNAME/ {print $2}'`
  67. echo "Packname: ${PACKNAME} (${pack})"
  68. echo -e `grep -r "http://" src/misc.c | sed -e "s/.*\- \(.*\) \-.*/\1/"`
  69. echo
  70. if test -z "$1"; then
  71. usage
  72. exit 1
  73. else
  74. if [ $1 = "all" ]; then
  75. all=1
  76. elif [ $1 = "leaf" ]; then
  77. leaf=1
  78. type="leaf"
  79. elif [ $1 = "hub" ]; then
  80. hub=1
  81. type="hub"
  82. else
  83. all=1
  84. fi
  85. fi
  86. rm=1
  87. compile=1
  88. if [ $pkg = "1" ]; then
  89. rm=0
  90. compile=0
  91. fi
  92. if [ $debug = "1" ]; then
  93. d="d"
  94. else
  95. d=""
  96. fi
  97. if [ $all = "1" ]; then
  98. type="all"
  99. leaf=1
  100. hub=1
  101. fi
  102. # Figure what bins we're making
  103. case `uname` in
  104. Linux) os=Linux;;
  105. FreeBSD) os=FreeBSD;;
  106. # FreeBSD) case `uname -r` in
  107. # 5*) os=FreeBSD5;;
  108. # 4*) os=FreeBSD4;;
  109. # 3*) os=FreeBSD3;;
  110. # esac;;
  111. OpenBSD) os=OpenBSD;;
  112. NetBSD) os=NetBSD;;
  113. SunOS) os=Solaris;;
  114. CYGWIN*) os=Cygwin;;
  115. esac
  116. if test -z $os
  117. then
  118. echo "[!] Automated packaging disabled, `uname` isn't recognized"
  119. fi
  120. if ! [ $scp = 0 ]; then
  121. remotedate="`ssh -q -i misc/id_dsa bryan@endurance.quadspeedi.net ls -al public_html/nightly/${os}-current.tar.gz | \
  122. sed -e 's/.*\-> \([0-1][0-2]\.[0-3][0-9]\.[0-9][0-9][0-9][0-9]\)\-.*/\1/'`"
  123. if [ ${remotedate} = ${builddate} ]; then
  124. exit 0
  125. fi
  126. fi
  127. if [ $compile = "1" ]; then
  128. echo "[*] Building ${PACKNAME}::${type} for $os"
  129. MAKE="`which gmake`"
  130. if test -z "${MAKE}"; then
  131. MAKE="`which make`"
  132. fi
  133. if [ $clean = "2" ]; then
  134. if test -f Makefile; then
  135. echo "[*] DistCleaning old files..."
  136. ${MAKE} distclean > /dev/null
  137. fi
  138. fi
  139. # Run ./configure, then verify it's ok
  140. echo "[*] Configuring..."
  141. umask 077 >/dev/null
  142. ./configure --silent
  143. if [ $clean = "1" ]; then
  144. echo "[*] Cleaning up old binaries/files..."
  145. ${MAKE} clean > /dev/null
  146. fi
  147. fi
  148. if test -n "$d"; then
  149. d="-debug"
  150. fi
  151. _build()
  152. {
  153. if [ $[${tb}] = "1" ]; then
  154. if [ $compile = "1" ]; then
  155. echo "[*] Building ${d}${tb}..."
  156. ${MAKE} ${d}${tb}
  157. if ! test -f ${tb}; then
  158. echo "[!] ${d}${tb} build failed"
  159. exit 1
  160. fi
  161. fi
  162. if [ $nopkg = "0" -o $pkg = "1" ]; then
  163. echo "[*] Hashing and initializing settings in binary"
  164. cp ${tb} ${tb}.$os-$ver${d} > /dev/null 2>&1
  165. ./${tb}.$os-$ver${d} -p ${pack}
  166. rm=1
  167. elif [ $nopkg = "0" ]; then
  168. mv ${tb} ${tb}.$os-$ver${d} > /dev/null 2>&1
  169. fi
  170. fi
  171. }
  172. if [ -f stamp.hub ]; then
  173. tb="hub"
  174. _build
  175. tb="leaf"
  176. else
  177. tb="leaf"
  178. _build
  179. tb="hub"
  180. fi
  181. _build
  182. if [ $bzip = "1" ]; then
  183. zip="j"
  184. ext="bz2"
  185. else
  186. zip="z"
  187. ext="gz"
  188. fi
  189. # Wrap it nicely up into an archive
  190. if [ $nopkg = "0" -o $pkg = "1" ]; then
  191. echo "[*] Packaging..."
  192. #This MALLOC business is to not Abort 'tar' due to some bug it has.
  193. tmp=${MALLOC_CHECK_}
  194. unset MALLOC_CHECK_
  195. tar -c${zip}f ${PACKNAME}.$os-$ver${d}.tar.${ext} hub.$os-$ver${d} leaf.$os-$ver${d}
  196. chmod 0644 ${PACKNAME}.$os-$ver${d}.tar.${ext}
  197. if test -n "$tmp"; then
  198. declare -x MALLOC_CHECK_=$tmp
  199. fi
  200. if [ $rm = "1" ]; then
  201. rm -f *$os-$ver${d}
  202. fi
  203. echo "Binaries are now in '${PACKNAME}.$os-$ver${d}.tar.${ext}'."
  204. if ! [ $scp = 0 ]; then
  205. chmod 0700 misc/id_dsa
  206. scp -i misc/id_dsa -B -p -C ${PACKNAME}.$os-$ver${d}.tar.${ext} $scp
  207. fi
  208. elif ! [ $scp = 0 ]; then
  209. cp hub hub.$os-$ver${d}-${builddate} > /dev/null 2>&1
  210. cp leaf leaf.$os-$ver${d}-${builddate} > /dev/null 2>&1
  211. #This MALLOC business is to not Abort 'tar' due to some bug it has.
  212. tmp=${MALLOC_CHECK_}
  213. unset MALLOC_CHECK_
  214. tar -c${zip}f ${builddate}-$os-$ver${d}.tar.${ext} hub.$os-$ver${d}-${builddate} leaf.$os-$ver${d}-${builddate}
  215. chmod 0644 ${builddate}-$os-$ver${d}.tar.${ext}
  216. if test -n "$tmp"; then
  217. declare -x MALLOC_CHECK_=$tmp
  218. fi
  219. chmod 0700 misc/id_dsa
  220. scp -i misc/id_dsa -B -p -C ${builddate}-$os-$ver${d}.tar.${ext} $scp
  221. rm -rf ${builddate}-$os-$ver${d}.tar.${ext} hub.$os-$ver${d}-${builddate} leaf.$os-$ver${d}-${builddate}
  222. ssh -i misc/id_dsa bryan@endurance.quadspeedi.net ln -fs ${builddate}-$os-$ver${d}.tar.${ext} public_html/nightly/${os}-current.tar.gz
  223. fi
  224. exit 0