#! /bin/sh # We want to use BASH, not whatever /bin/sh points to. if test -z "$BASH"; then PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin bash="`which bash`" ${bash} $0 ${1+"$@"} exit 0 fi # Awk out the version from source AWK="`which awk`" if test -z "${AWK}"; then AWK="`which gawk`" fi ver="?.?.?" ver=`grep "char" src/main.c | $AWK '/egg_version/ {print $5}' | sed -e 's/\"//g' | sed -e 's/\;//g'` BUILDTS=`cat src/build.h | $AWK '{print $3}'` builddate=`perl -e "use POSIX 'strftime';print strftime(\"%m.%d.%Y\n\",gmtime(${BUILDTS}));"` clear #Display a banner bt=`grep -A 5 "char \*wbanner(void) {" src/misc.c | grep "switch" | sed -e "s/.*switch (randint(\(.\))) {/\1/"` bn=$[($RANDOM % ${bt})] banner=`grep -A 15 "char \*wbanner(void) {" src/misc.c | grep "case ${bn}:" | sed -e "s/.*case ${bn}: return STR(\"\(.*\)\");/\1/"` echo -e "${banner}" echo -e "Version: ${ver}\nBuild: ${builddate}" usage() { echo echo "Usage: $0 [-bcCdnP] [-p FILE] [all|hub|leaf]" echo echo " The options are as follows:" echo " -b Use bzip2 instead of gzip when packaging." echo " -c Cleans up old binaries/files before compile." echo " -C Preforms a distclean before making." echo " -d Builds a debug package." echo " -n Do not package the binaries." echo " -p FILE What file to use as the cfg file." echo " -P For development (Don't compile/rm binaries)" echo " -s scp target." } debug=0 all=0 hub=0 leaf=0 clean=0 type= nopkg=0 bzip=0 pkg=0 scp=0 nightly=0 pack=pack/pack.cfg while getopts bCcdhnNPp:s: opt ; do case "$opt" in b) bzip=1 ;; c) clean=1 ;; C) clean=2 ;; d) debug=1 ;; h) usage; exit 0 ;; n) nopkg=1 ;; N) nightly=1 ;; p) pack="$OPTARG" ;; P) pkg=1 ;; s) scp="$OPTARG" ;; *) usage; exit 1 ;; esac done shift $(($OPTIND - 1)) PACKNAME=`grep "PACKNAME " ${pack} | $AWK '/PACKNAME/ {print $2}'` echo "Packname: ${PACKNAME} (${pack})" echo -e `grep -r "http://" src/misc.c | sed -e "s/.*\- \(.*\) \-.*/\1/"` echo if test -z "$1"; then usage exit 1 else if [ $1 = "all" ]; then all=1 elif [ $1 = "leaf" ]; then leaf=1 type="leaf" elif [ $1 = "hub" ]; then hub=1 type="hub" else all=1 fi fi rm=1 compile=1 if [ $pkg = "1" ]; then rm=0 compile=0 fi if [ $debug = "1" ]; then d="d" else d="" fi if [ $all = "1" ]; then type="all" leaf=1 hub=1 fi # Figure what bins we're making case `uname` in Linux) os=Linux;; FreeBSD) os=FreeBSD;; # FreeBSD) case `uname -r` in # 5*) os=FreeBSD5;; # 4*) os=FreeBSD4;; # 3*) os=FreeBSD3;; # esac;; OpenBSD) os=OpenBSD;; NetBSD) os=NetBSD;; SunOS) os=Solaris;; CYGWIN*) os=Cygwin;; esac if test -z $os then echo "[!] Automated packaging disabled, `uname` isn't recognized" fi if [ $nightly = "1" ]; then chmod 0700 misc/id_dsa remotedate="`ssh -q -i misc/id_dsa bryan@endurance.quadspeedi.net ls -al public_html/nightly/${os}-current.tar.gz | \ sed -e 's/.*\-> \([0-1][0-2]\.[0-3][0-9]\.[0-9][0-9][0-9][0-9]\)\-.*/\1/'`" if [ "${remotedate}" = "${builddate}" ]; then exit 0 fi fi if [ $compile = "1" ]; then echo "[*] Building ${PACKNAME}::${type} for $os" MAKE="`which gmake`" if test -z "${MAKE}"; then MAKE="`which make`" fi if [ $clean = "2" ]; then if test -f Makefile; then echo "[*] DistCleaning old files..." ${MAKE} distclean > /dev/null fi fi # Run ./configure, then verify it's ok echo "[*] Configuring..." umask 077 >/dev/null ./configure --silent if [ $clean = "1" ]; then echo "[*] Cleaning up old binaries/files..." ${MAKE} clean > /dev/null fi fi if test -n "$d"; then d="-debug" fi _build() { if [ $[${tb}] = "1" ]; then if [ $compile = "1" ]; then echo "[*] Building ${d}${tb}..." ${MAKE} ${d}${tb} if ! test -f ${tb}; then echo "[!] ${d}${tb} build failed" exit 1 fi fi if [ $nopkg = "0" -o $pkg = "1" ]; then echo "[*] Hashing and initializing settings in binary" cp ${tb} ${tb}.$os-$ver${d} > /dev/null 2>&1 ./${tb}.$os-$ver${d} -p ${pack} rm=1 elif [ $nopkg = "0" ]; then mv ${tb} ${tb}.$os-$ver${d} > /dev/null 2>&1 fi fi } if [ -f stamp.hub ]; then tb="hub" _build tb="leaf" else tb="leaf" _build tb="hub" fi _build if [ $bzip = "1" ]; then zip="j" ext="bz2" else zip="z" ext="gz" fi # Wrap it nicely up into an archive if [ $nopkg = "0" -o $pkg = "1" ]; then echo "[*] Packaging..." #This MALLOC business is to not Abort 'tar' due to some bug it has. tmp=${MALLOC_CHECK_} unset MALLOC_CHECK_ tar -c${zip}f ${PACKNAME}.$os-$ver${d}.tar.${ext} hub.$os-$ver${d} leaf.$os-$ver${d} chmod 0644 ${PACKNAME}.$os-$ver${d}.tar.${ext} if test -n "$tmp"; then declare -x MALLOC_CHECK_=$tmp fi if [ $rm = "1" ]; then rm -f *$os-$ver${d} fi echo "Binaries are now in '${PACKNAME}.$os-$ver${d}.tar.${ext}'." if ! [ $scp = 0 ]; then chmod 0700 misc/id_dsa scp -i misc/id_dsa -B -p -C ${PACKNAME}.$os-$ver${d}.tar.${ext} $scp fi elif ! [ $scp = "0" ]; then cp hub hub.$os-$ver${d} > /dev/null 2>&1 cp leaf leaf.$os-$ver${d} > /dev/null 2>&1 cp ChangeLog ChangeLog-${builddate} gzip -9 ChangeLog-${builddate} #This MALLOC business is to not Abort 'tar' due to some bug it has. tmp=${MALLOC_CHECK_} unset MALLOC_CHECK_ tar -c${zip}f ${builddate}-$os-$ver${d}.tar.${ext} hub.$os-$ver${d} leaf.$os-$ver${d} ChangeLog-${builddate}.gz chmod 0644 ${builddate}-$os-$ver${d}.tar.${ext} if test -n "$tmp"; then declare -x MALLOC_CHECK_=$tmp fi chmod 0700 misc/id_dsa scp -i misc/id_dsa -B -p -C ${builddate}-$os-$ver${d}.tar.${ext} $scp rm -rf ${builddate}-$os-$ver${d}.tar.${ext} hub.$os-$ver${d} leaf.$os-$ver${d} ChangeLog-${builddate}.gz ssh -i misc/id_dsa bryan@endurance.quadspeedi.net ln -fs ${builddate}-$os-$ver${d}.tar.${ext} public_html/nightly/${os}-current.tar.gz fi exit 0