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