build 5.5 KB

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