| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- #! /bin/sh
- PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:${HOME}/bin
- if [ -d .git ]; then
- BUILDTS=$(git log -1 --pretty=format:%ct HEAD)
- ver=$(git describe --candidates=2)
- else
- ver=$(awk '/^VERSION/ {print $3}' Makefile.in)
- BUILDTS=`grep -m 1 "BUILDTS = " Makefile.in | awk '{print $3}'`
- fi
- # Convert timestamp into readable format
- rm -f ts > /dev/null 2>&1
- cc -o ts src/timestamp.c > /dev/null 2>&1
- builddate=`./ts ${BUILDTS}`
- rm -f ts > /dev/null 2>&1
- #Display banner
- clear
- head -n 8 README
- echo -e "Version: ${ver}\nBuild: ${builddate}"
- echo ""
- usage()
- {
- echo "Usage: $0 [-bcCdnP] pack.cfg"
- 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 For development (Don't compile/rm binaries)"
- }
- debug=0
- clean=0
- nopkg=0
- bzip=0
- pkg=0
- while getopts bCcdhnP: opt ; do
- case "$opt" in
- b) bzip=1 ;;
- c) clean=1 ;;
- C) clean=2 ;;
- d) debug=1 ;;
- h) usage; exit 0 ;;
- n) nopkg=1 ;;
- P) pkg=1 ;;
- *) usage; exit 1 ;;
- esac
- done
- shift $(($OPTIND - 1))
- pack=$1
- if ! [ -f $pack ]; then
- echo "Cannot read $pack" >&2
- exit 1
- fi
- if test -z "$1"; then
- usage
- exit 1
- fi
- PACKNAME=`grep "PACKNAME " ${pack} | awk '/PACKNAME/ {print $2}'`
- rm=1
- compile=1
- if [ $pkg = "1" ]; then
- rm=0
- compile=0
- fi
- if [ $debug = "1" ]; then
- dmake="d"
- d="-debug"
- else
- dmake=""
- d=""
- 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;;
- esac
- if test -z $os
- then
- echo "[!] Automated packaging disabled, `uname` isn't recognized"
- fi
- if [ $compile = "1" ]; then
- echo "[*] Building ${PACKNAME} for $os"
- 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
- _build()
- {
- if [ $compile = "1" ]; then
- echo "[*] Building ${dmake}${tb}..."
- make ${dmake}${tb}
- if ! test -f ${tb}; then
- echo "[!] ${dmake}${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} -q ${pack}
- rm=1
- elif [ $nopkg = "0" ]; then
- mv ${tb} ${tb}.$os-$ver${d} > /dev/null 2>&1
- fi
- }
- tb="wraith"
- _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..."
- tar -c${zip}f ${PACKNAME}.$os-$ver${d}.tar.${ext} wraith.$os-$ver${d}
- chmod 0644 ${PACKNAME}.$os-$ver${d}.tar.${ext}
- if [ $rm = "1" ]; then
- rm -f *$os-$ver${d}
- fi
- echo "Binaries are now in '${PACKNAME}.$os-$ver${d}.tar.${ext}'."
- fi
|