1
0

build 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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]"
  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. clean=0
  42. nopkg=0
  43. bzip=0
  44. pkg=0
  45. scp=0
  46. nightly=0
  47. pack=pack/pack.cfg
  48. while getopts bCcdhnNPp:s: opt ; do
  49. case "$opt" in
  50. b) bzip=1 ;;
  51. c) clean=1 ;;
  52. C) clean=2 ;;
  53. d) debug=1 ;;
  54. h) usage; exit 0 ;;
  55. n) nopkg=1 ;;
  56. N) nightly=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. fi
  72. rm=1
  73. compile=1
  74. if [ $pkg = "1" ]; then
  75. rm=0
  76. compile=0
  77. fi
  78. if [ $debug = "1" ]; then
  79. dmake="d"
  80. d="-debug"
  81. else
  82. dmake=""
  83. d=""
  84. fi
  85. # Figure what bins we're making
  86. case `uname` in
  87. Linux) os=Linux;;
  88. FreeBSD) os=FreeBSD;;
  89. # FreeBSD) case `uname -r` in
  90. # 5*) os=FreeBSD5;;
  91. # 4*) os=FreeBSD4;;
  92. # 3*) os=FreeBSD3;;
  93. # esac;;
  94. OpenBSD) os=OpenBSD;;
  95. NetBSD) os=NetBSD;;
  96. SunOS) os=Solaris;;
  97. CYGWIN*) os=Cygwin;;
  98. esac
  99. if test -z $os
  100. then
  101. echo "[!] Automated packaging disabled, `uname` isn't recognized"
  102. fi
  103. if [ $nightly = "1" ]; then
  104. chmod 0700 misc/id_dsa
  105. remotedate="`ssh -q -i misc/id_dsa bryan@endurance.quadspeedi.net ls -al public_html/nightly/${os}-current.tar.gz | \
  106. sed -e 's/.*\-> \([0-1][0-2]\.[0-3][0-9]\.[0-9][0-9][0-9][0-9]\)\-.*/\1/'`"
  107. if [ "${remotedate}" = "${builddate}" ]; then
  108. exit 0
  109. fi
  110. fi
  111. if [ $compile = "1" ]; then
  112. echo "[*] Building ${PACKNAME} for $os"
  113. MAKE="`which gmake`"
  114. if test -z "${MAKE}"; then
  115. MAKE="`which make`"
  116. fi
  117. if [ $clean = "2" ]; then
  118. if test -f Makefile; then
  119. echo "[*] DistCleaning old files..."
  120. ${MAKE} distclean > /dev/null
  121. fi
  122. fi
  123. # Run ./configure, then verify it's ok
  124. echo "[*] Configuring..."
  125. umask 077 >/dev/null
  126. ./configure --silent
  127. if [ $clean = "1" ]; then
  128. echo "[*] Cleaning up old binaries/files..."
  129. ${MAKE} clean > /dev/null
  130. fi
  131. fi
  132. _build()
  133. {
  134. if [ $compile = "1" ]; then
  135. echo "[*] Building ${dmake}${tb}..."
  136. ${MAKE} ${dmake}${tb}
  137. if ! test -f ${tb}; then
  138. echo "[!] ${dmake}${tb} build failed"
  139. exit 1
  140. fi
  141. fi
  142. if [ $nopkg = "0" -o $pkg = "1" ]; then
  143. echo "[*] Hashing and initializing settings in binary"
  144. cp ${tb} ${tb}.$os-$ver${d} > /dev/null 2>&1
  145. ./${tb}.$os-$ver${d} -p ${pack}
  146. rm=1
  147. elif [ $nopkg = "0" ]; then
  148. mv ${tb} ${tb}.$os-$ver${d} > /dev/null 2>&1
  149. fi
  150. }
  151. tb="wraith"
  152. _build
  153. if [ $bzip = "1" ]; then
  154. zip="j"
  155. ext="bz2"
  156. else
  157. zip="z"
  158. ext="gz"
  159. fi
  160. # Wrap it nicely up into an archive
  161. if [ $nopkg = "0" -o $pkg = "1" ]; then
  162. echo "[*] Packaging..."
  163. #This MALLOC business is to not Abort 'tar' due to some bug it has.
  164. tmp=${MALLOC_CHECK_}
  165. unset MALLOC_CHECK_
  166. tar -c${zip}f ${PACKNAME}.$os-$ver${d}.tar.${ext} wraith.$os-$ver${d}
  167. chmod 0644 ${PACKNAME}.$os-$ver${d}.tar.${ext}
  168. if test -n "$tmp"; then
  169. declare -x MALLOC_CHECK_=$tmp
  170. fi
  171. if [ $rm = "1" ]; then
  172. rm -f *$os-$ver${d}
  173. fi
  174. echo "Binaries are now in '${PACKNAME}.$os-$ver${d}.tar.${ext}'."
  175. if ! [ $scp = 0 ]; then
  176. chmod 0700 misc/id_dsa
  177. scp -i misc/id_dsa -B -p -C ${PACKNAME}.$os-$ver${d}.tar.${ext} $scp
  178. fi
  179. elif ! [ $scp = "0" ]; then
  180. cp wraith wraith.$os-$ver${d} > /dev/null 2>&1
  181. cp ChangeLog ChangeLog-${builddate}
  182. gzip -9 ChangeLog-${builddate}
  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 ${builddate}-$os-$ver${d}.tar.${ext} wraith.$os-$ver${d} ChangeLog-${builddate}.gz
  187. chmod 0644 ${builddate}-$os-$ver${d}.tar.${ext}
  188. if test -n "$tmp"; then
  189. declare -x MALLOC_CHECK_=$tmp
  190. fi
  191. chmod 0700 misc/id_dsa
  192. scp -i misc/id_dsa -B -p -C ${builddate}-$os-$ver${d}.tar.${ext} $scp
  193. rm -rf ${builddate}-$os-$ver${d}.tar.${ext} wraith.$os-$ver${d} ChangeLog-${builddate}.gz
  194. ssh -i misc/id_dsa bryan@endurance.quadspeedi.net ln -fs ${builddate}-$os-$ver${d}.tar.${ext} public_html/nightly/${os}-current.tar.gz
  195. fi
  196. exit 0