build 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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. chmod 0700 misc/id_dsa
  122. remotedate="`ssh -q -i misc/id_dsa bryan@endurance.quadspeedi.net ls -al public_html/nightly/${os}-current.tar.gz | \
  123. sed -e 's/.*\-> \([0-1][0-2]\.[0-3][0-9]\.[0-9][0-9][0-9][0-9]\)\-.*/\1/'`"
  124. if [ "${remotedate}" = "${builddate}" ]; then
  125. exit 0
  126. fi
  127. fi
  128. if [ $compile = "1" ]; then
  129. echo "[*] Building ${PACKNAME}::${type} for $os"
  130. MAKE="`which gmake`"
  131. if test -z "${MAKE}"; then
  132. MAKE="`which make`"
  133. fi
  134. if [ $clean = "2" ]; then
  135. if test -f Makefile; then
  136. echo "[*] DistCleaning old files..."
  137. ${MAKE} distclean > /dev/null
  138. fi
  139. fi
  140. # Run ./configure, then verify it's ok
  141. echo "[*] Configuring..."
  142. umask 077 >/dev/null
  143. ./configure --silent
  144. if [ $clean = "1" ]; then
  145. echo "[*] Cleaning up old binaries/files..."
  146. ${MAKE} clean > /dev/null
  147. fi
  148. fi
  149. if test -n "$d"; then
  150. d="-debug"
  151. fi
  152. _build()
  153. {
  154. if [ $[${tb}] = "1" ]; then
  155. if [ $compile = "1" ]; then
  156. echo "[*] Building ${d}${tb}..."
  157. ${MAKE} ${d}${tb}
  158. if ! test -f ${tb}; then
  159. echo "[!] ${d}${tb} build failed"
  160. exit 1
  161. fi
  162. fi
  163. if [ $nopkg = "0" -o $pkg = "1" ]; then
  164. echo "[*] Hashing and initializing settings in binary"
  165. cp ${tb} ${tb}.$os-$ver${d} > /dev/null 2>&1
  166. ./${tb}.$os-$ver${d} -p ${pack}
  167. rm=1
  168. elif [ $nopkg = "0" ]; then
  169. mv ${tb} ${tb}.$os-$ver${d} > /dev/null 2>&1
  170. fi
  171. fi
  172. }
  173. if [ -f stamp.hub ]; then
  174. tb="hub"
  175. _build
  176. tb="leaf"
  177. else
  178. tb="leaf"
  179. _build
  180. tb="hub"
  181. fi
  182. _build
  183. if [ $bzip = "1" ]; then
  184. zip="j"
  185. ext="bz2"
  186. else
  187. zip="z"
  188. ext="gz"
  189. fi
  190. # Wrap it nicely up into an archive
  191. if [ $nopkg = "0" -o $pkg = "1" ]; then
  192. echo "[*] Packaging..."
  193. #This MALLOC business is to not Abort 'tar' due to some bug it has.
  194. tmp=${MALLOC_CHECK_}
  195. unset MALLOC_CHECK_
  196. tar -c${zip}f ${PACKNAME}.$os-$ver${d}.tar.${ext} hub.$os-$ver${d} leaf.$os-$ver${d}
  197. chmod 0644 ${PACKNAME}.$os-$ver${d}.tar.${ext}
  198. if test -n "$tmp"; then
  199. declare -x MALLOC_CHECK_=$tmp
  200. fi
  201. if [ $rm = "1" ]; then
  202. rm -f *$os-$ver${d}
  203. fi
  204. echo "Binaries are now in '${PACKNAME}.$os-$ver${d}.tar.${ext}'."
  205. if ! [ $scp = 0 ]; then
  206. chmod 0700 misc/id_dsa
  207. scp -i misc/id_dsa -B -p -C ${PACKNAME}.$os-$ver${d}.tar.${ext} $scp
  208. fi
  209. elif ! [ $scp = "0" ]; then
  210. cp hub hub.$os-$ver${d}-${builddate} > /dev/null 2>&1
  211. cp leaf leaf.$os-$ver${d}-${builddate} > /dev/null 2>&1
  212. #This MALLOC business is to not Abort 'tar' due to some bug it has.
  213. tmp=${MALLOC_CHECK_}
  214. unset MALLOC_CHECK_
  215. tar -c${zip}f ${builddate}-$os-$ver${d}.tar.${ext} hub.$os-$ver${d}-${builddate} leaf.$os-$ver${d}-${builddate}
  216. chmod 0644 ${builddate}-$os-$ver${d}.tar.${ext}
  217. if test -n "$tmp"; then
  218. declare -x MALLOC_CHECK_=$tmp
  219. fi
  220. chmod 0700 misc/id_dsa
  221. scp -i misc/id_dsa -B -p -C ${builddate}-$os-$ver${d}.tar.${ext} $scp
  222. rm -rf ${builddate}-$os-$ver${d}.tar.${ext} hub.$os-$ver${d}-${builddate} leaf.$os-$ver${d}-${builddate}
  223. ssh -i misc/id_dsa bryan@endurance.quadspeedi.net ln -fs ${builddate}-$os-$ver${d}.tar.${ext} public_html/nightly/${os}-current.tar.gz
  224. fi
  225. exit 0