Last active
August 29, 2015 14:24
-
-
Save tryone144/0794324a5b395ebbcbb0 to your computer and use it in GitHub Desktop.
build the most current bazaar tree of DXX-REBIRTH
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# dxx-autobuild - build the most current bazaar tree of DXX-REBIRTH | |
# Copyright (C) 2015 Bernd Busse | |
# | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
# | |
# usage: ./dxx-autobuild [OPTION] [PATH] | |
# | |
# let's start | |
echo -e "\033[1m\033[31m" | |
echo -e " DXX-REBIRTH baazar autobuild script v0.62 " | |
echo -e "================================================================================" | |
echo -e "\033[0m" | |
################################################################################ | |
# ENVIRONMENT VARIABLES | |
################################################################################ | |
# some important variables | |
lock="/tmp/dxx-autobuild.lck" | |
odir=`echo ${PWD}` | |
ddir="./" | |
instdir="/usr/local/bin" | |
pre="" | |
revno="" | |
trunk="" | |
superuser="false" | |
# path to the binarys | |
bzr=`which bzr` | |
scons=`which scons` | |
sudo=`which sudo` | |
gcc=`which gcc` | |
# set the commandline flags | |
inst="false" | |
dbg="false" | |
clean="false" | |
update="unset" | |
# set trap execution | |
trap abbort 2 | |
################################################################################ | |
# FUNCTIONS | |
################################################################################ | |
############################################################################ | |
# TRAP FUNCTION | |
############################################################################ | |
abbort () { | |
# OUCH, WHY??? restore defaults | |
cd ${odir} | |
rm -rf ${lock} | |
echo -e "\033[1m\033[33m" >&2 | |
echo -e "WOW! your keyboard supports [ctrl]+[c] :o" >&2 | |
echo -e "\033[31mINTERRUPTED\033[0m" >&2 | |
exit 2 | |
} | |
############################################################################ | |
# SUCESSFUL TEST | |
############################################################################ | |
sucessful () { | |
if [ $? -ne 0 ] ; then | |
# an error occured, abbort | |
cd ${odir} | |
rm -rf ${lock} | |
echo -e "\033[1m\033[31m" >&2 | |
echo -e "ABBORT BUILDING" >&2 | |
echo -e "SOME ERRORS OCCURED. SEE ABOVE." >&2 | |
echo -e "\033[33mSadly the build couldn't be completed ${USER}. :(\033[0m" >&2 | |
exit 1 | |
else | |
# all went fine, exit | |
cd ${odir} | |
rm -rf ${lock} | |
echo -e "\033[1m\033[33m" | |
echo -e "All is done. Have fun ${USER}! =)\033[0m" | |
exit 0 | |
fi | |
} | |
############################################################################ | |
# PRINT THE INFO MESSAGE | |
############################################################################ | |
printinfo () { | |
echo -e "\033[1mThis script will download and install the most" | |
echo -e "current revision of D1X-REBIRTH and D2X-REBIRTH from" | |
echo -e "the official DXX-REBIRTH bazaar development repository" | |
echo -e "inside (the current) directory.\033[0m" | |
} | |
########################################################################### | |
# PRINT USAGE | |
########################################################################### | |
printusage () { | |
echo -e "\033[1musage: $0 [OPTION] [PATH]\033[0m" | |
} | |
########################################################################### | |
# PRINT THE PARAMETER HELP MESSAGE | |
########################################################################### | |
printparams () { | |
echo -e "\033[1mbuild flags:" | |
echo -e " -h : --help - show this help message" | |
echo -e " -d ; --debug - build a debug binary" | |
echo -e " -i ; --install - install to /usr/local/bin" | |
echo -e " -c ; --clean - make a clean build" | |
echo -e "" | |
echo -e "build select:" | |
echo -e " --d1x - build d1x-rebirth" | |
echo -e " --d2x - build d2x-rebirth" | |
echo -e " --dxx, --both - build both games (d1x and d2x)" | |
echo -e "" | |
echo -e " PATH - Download the branch into PATH [./]\033[0m" | |
} | |
########################################################################### | |
# PRINT THE GAME HELP MESSAGE | |
########################################################################### | |
printhelp () { | |
echo -e "\033[1m h ; help - will show this help message" | |
echo -e " d1x - will build D1X-REBIRTH" | |
echo -e " d2x - will build D2X-REBIRTH" | |
echo -e " dxx ; both - will build D1X-REBIRTH and D2X-REBIRTH" | |
echo -e " q ; quit - will quit\033[0m" | |
} | |
########################################################################### | |
# MAIN COMPILING ROUTINE | |
########################################################################### | |
buildbzr () { | |
# goto the old dir for safe | |
cd ${odir} | |
# show what we will build | |
PRE=`echo "${pre}" | tr '[a-z]' '[A-Z]'` | |
echo -e "\033[1m\033[31m" | |
echo -e " BUILDING ${PRE}-REBIRTH " | |
echo -e "--------------------------------------------------------------------------------\033[0m" | |
# okay, start building our favorite game | |
echo -e "\033[1m\033[33m[`date +%T`] START BUILDING\033[0m" | |
echo -e "\033[34m" | |
############################################################## | |
# BRANCH UPDATING ROUTINE | |
############################################################## | |
# goto download dir | |
cd ${ddir} | |
# an error occured, abbort | |
if [ $? -ne 0 ] ; then return 1 ; fi | |
# check for the branch | |
if test -d ${pre}-rebirth ; then | |
# branch is there, updating | |
echo -e "\033[1m\033[33m[`date +%T`] ENTERING BRANCH ${ddir}/${pre}-rebirth\033[0m\033[34m" | |
cd ${pre}-rebirth | |
# an error occured, abbort | |
if [ $? -ne 0 ] ; then return 1 ; fi | |
echo -e "\033[0m\033[1m\033[33m[`date +%T`] CHECKING CURRENT REVISION\033[0m\033[34m" | |
# check the current revison number | |
trunk=`bzr revno bzr://dxx-rebirth.bzr.sourceforge.net/bzrroot/dxx-rebirth/${pre}-rebirth` >/dev/null | |
# an error occured, abbort | |
if [ $? -ne 0 ] ; then return 1 ; fi | |
revno=`bzr revno .` >/dev/null | |
# an error occured, abbort | |
if [ $? -ne 0 ] ; then return 1 ; fi | |
if test ${trunk} -gt ${revno} ; then | |
# new version available | |
update="true" | |
echo -e "\033[0m\033[1m\033[33m[`date +%T`] UPDATING BRANCH (r${trunk})\033[0m\033[34m" | |
bzr pull >/dev/null | |
# an error occured, abbort | |
if [ $? -ne 0 ] ; then return 1 ; fi | |
echo -e "\033[0m\033[1m\033[33m[`date +%T`] DONE UPDATING\033[0m\033[34m" | |
else | |
# no new version available | |
echo -e "\033[0m\033[1m\033[33m[`date +%T`] BRANCH STILL UP TO DATE (r${revno})\033[0m\033[34m" | |
update="false" | |
fi | |
# check if we should rebuild (commandline flag) | |
if test ${clean} = "true" ; then | |
if test ${update} = "false" ; then | |
# no new revision | |
echo -e "\033[0m\033[1m\033[31m[`date +%T`] WARNING: You want a clean build, but the build is still up to date\033[0m\033[34m" | |
fi | |
echo -e "\033[0m\033[1m\033[33m[`date +%T`] CLEANING OLD BUILD\033[0m" | |
echo -e "\033[34m" | |
scons -c >/dev/null | |
# an error occured, abbort | |
if [ $? -ne 0 ] ; then return 1 ; fi | |
else | |
if test ${update} = "false" ; then | |
# check if the branch really was updated -> no need to build | |
# exit | |
return 0 | |
fi | |
fi | |
else | |
# branch isn't there, creating | |
echo -e "\033[0m\033[1m\033[33m[`date +%T`] CRATE BRANCH ${ddir}/${pre}-rebirth\033[0m\033[34m" | |
bzr branch bzr://dxx-rebirth.bzr.sourceforge.net/bzrroot/dxx-rebirth/${pre}-rebirth | |
# an error occured, abbort | |
if [ $? -ne 0 ] ; then return 1 ; fi | |
echo -e "\033[0m\033[1m\033[33m[`date +%T`] DONE CREATING" | |
echo -e "[`date +%T`] ENTERING BRANCH ${ddir}/${pre}-rebirth\033[0m\033[34m" | |
cd ${ddir}/${pre}-rebirth | |
# an error occured, abbort | |
if [ $? -ne 0 ] ; then return 1 ; fi | |
revno=`bzr revno .` >/dev/null | |
# an error occured, abbort | |
if [ $? -ne 0 ] ; then return 1 ; fi | |
fi | |
############################################################## | |
# COMPILING ROUTINE | |
############################################################## | |
echo -e "\033[0m" | |
echo -e "\033[1m\033[33m[`date +%T`] START COMPILING...\033[0m" | |
echo -e "\033[34m" | |
# check for the commandline flag '-d' | |
if ${dbg} = "true" ; then | |
scons debug=1 | |
# an error occured, abbort | |
if [ $? -ne 0 ] ; then return 1 ; fi | |
else | |
scons | |
# an error occured, abbort | |
if [ $? -ne 0 ] ; then return 1 ; fi | |
fi | |
echo -e "\033[0m" | |
echo -e "\033[1m\033[33m[`date +%T`] DONE COMPILING\033[0m" | |
echo -e "\033[34m" | |
# rename compiled binary to *-bzr for parallel installation | |
mv ${pre}-rebirth ${pre}-rebirth-${revno} | |
# an error occured, abbort | |
if [ $? -ne 0 ] ; then return 1 ; fi | |
# check for the commandline flag '-i' | |
if ${inst} = "true" ; then | |
echo -e "\033[0m\033[1m\033[33m[`date +%T`] INSTALLING TO ${instdir}/${pre}-rebirth-${revno}\033[0m\033[34m" | |
# check if we are root | |
if test ${superuser} = "true" ; then | |
cp ${pre}-rebirth-${revno} ${instdir}/${pre}-rebirth-${revno} | |
else | |
sudo cp ${pre}-rebirth-${revno} ${instdir}/${pre}-rebirth-${revno} | |
fi | |
# an error occured, abbort | |
if [ $? -ne 0 ] ; then return 1 ; fi | |
echo -e "\033[0m\033[1m\033[33m[`date +%T`] CREAT SIMBOLIC LINK TO ${instdir}/${pre}-rebirth-bzr\033[0m\033[34m" | |
# check if we are root | |
if test ${superuser} = "true" ; then | |
ln -s ${instdir}/${pre}-rebirth-${revno} ${instdir}/${pre}-rebirth-bzr | |
else | |
sudo ln -s ${instdir}/${pre}-rebirth-${revno} ${instdir}/${pre}-rebirth-bzr | |
fi | |
# check if it was succesful | |
if [ $? -eq 0 ] ; then | |
echo -e "\033[0m\033[1m\033[33m[`date +%T`] DONE BUILDING\033[0m" | |
return 0 | |
else | |
echo -e "\033[0m\033[1m\033[31mABBORT BUILDING" >&2 | |
echo -e "ERROR: CANNOT INSTALL BINARY\033[0m" >&2 | |
return 1 | |
fi | |
else | |
echo -e "\033[0m\033[1m\033[33m[`date +%T`] DONE BUILDING" | |
echo -e "" | |
echo -e "INFO: Please move '${pre}-rebirth-${revno}' to" | |
echo -e " your favorite place and run it.\033[0m" | |
return 0 | |
fi | |
# why are we still here? Something strange must be happened | |
return 1 | |
} | |
################################################################################ | |
# CHECK FOR LOCKFILE | |
################################################################################ | |
if test -f ${lock} ; then | |
# we've more than one instace running, abbort | |
echo -e "\033[1m\033[31mABBORT BUILDING" >&2 | |
echo -e "ERROR: THIS SCRIPT RUNS ALLREADY!" >&2 | |
echo -e "Please stop the existing script in order to run this one.\033[0m" >&2 | |
exit 1 | |
else | |
# lockfile doesn't exist, create it | |
echo "${lock} created by ${USER} at `date +%T`" > ${lock} | |
fi | |
################################################################################ | |
# PARAMETER SELECTION | |
################################################################################ | |
OPTS=`getopt -q -o hdic -l help,debug,install,clean,d1x,d2x,dxx,both -n "$0" -- "$@"` | |
if [ $? -ne 0 ] ; then | |
# unknown param, show usage and abbort | |
echo -e "\033[31munknown parameter(s): \033[1m$@" >&2 | |
echo -e "\033[0m" >&2 | |
printusage >&2 | |
echo -e "\033[1m" >&2 | |
echo -e "all commandline parmeters with $0 --help" >&2 | |
echo -e "\033[0m" >&2 | |
rm -rf ${lock} | |
exit 1 | |
fi | |
eval set -- "${OPTS}" | |
while true ; do | |
case $1 in | |
-h|--help) | |
# '-h' / '--help' will show help message and exit | |
printusage | |
echo -e "" | |
printinfo | |
echo -e "" | |
printparams | |
echo -e "" | |
rm -rf ${lock} | |
exit 0 ;; | |
-d|--debug) | |
# '-d' will build a debug binary | |
dbg="true" | |
echo -e "\033[34m==> build debug binary\033[0m" | |
shift ;; | |
-i|--install) | |
# '-i' will install the binaray to /usr/local/bin | |
inst="true" | |
echo -e "\033[34m==> install binary to \033[1m'${instdir}'\033[0m" | |
shift ;; | |
-c|--clean) | |
# '-c' will made a complete clean rebuild | |
clean="true" | |
echo -e "\033[34m==> make clean build\033[0m" | |
shift ;; | |
--d1x) # '--d1x' will build d1x-rebirth | |
input="d1x" | |
shift ;; | |
--d2x) # '--d2x' will build d2x-rebirth | |
input="d2x" | |
shift ;; | |
--dxx|--both) | |
# '--dxx' will build both, d1x and d2x | |
input="dxx" | |
shift ;; | |
--) # '--' is getopt's seperator for nooption commands | |
case $2 in | |
"") shift 2 ; break ;; | |
*) # first noopt param is not empty | |
if test -d $2 ; then | |
# second param is a dir, set download path | |
ddir=$2 | |
shift 2 | |
else | |
# second param is not a dir, abbort | |
echo -e "\033[1m\033[31mABBORT BUILDING" >&2 | |
echo -e "ERROR: '$2' is not a directory" >&2 | |
echo -e "\033[0m" >&2 | |
rm -rf ${lock} | |
exit 1 | |
fi ;; | |
esac | |
shift 2 ; break ;; | |
*) exit 1 ;; | |
esac | |
done | |
################################################################################ | |
# SUPERUSER CHECK | |
################################################################################ | |
uid=`id -u` | |
if test ${uid} = "0" ; then | |
echo -e "\033[1m\033[31mRUNNING THE SCRIPT AS ROOT MY BE DANGEROUS!" >&2 | |
echo -e "\033[0m" >&2 | |
superuser="true" | |
fi | |
############################################################################### | |
# PRINT BUILD DIRECTORY | |
################################################################################ | |
echo -e "\033[34m==> download directory: \033[1m${ddir}\033[0m" | |
echo -e "" | |
################################################################################ | |
# CHECK FOR NEEDED BINARIES | |
################################################################################ | |
# check for BAAZAR | |
if test ! -x ${bzr} ; then | |
# BAAZAR is not installed, show error message and abbort | |
echo -e "\033[1m\033[31mABBORT BUILDING" >&2 | |
echo -e "ERROR: BAAZAR IS NOT INSTALLED" >&2 | |
echo -e "You need Bazaar (bzr) to download the trunk.\033[0m" >&2 | |
rm -rf ${lock} | |
exit 1 | |
fi | |
# check for SCONS | |
if test ! -x ${scons} ; then | |
# SCONS is not installed, show error message and abbort | |
echo -e "\033[1m\033[31mABBORT BUILDING" >&2 | |
echo -e "ERROR: SCONS IS NOT INSTALLED" >&2 | |
echo -e "You need Scons (scons) to build the trunk.\033[0m" >&2 | |
rm -rf ${lock} | |
exit 1 | |
fi | |
# check for the Gnu Compiler Collection | |
if test ! -x ${gcc} ; then | |
# the Gnu Compiler Collection is not installed, show error message and abbort | |
echo -e "\033[1m\033[31mABBORT BUILDING" >&2 | |
echo -e "ERROR: GCC IS NOT INSTALLED" >&2 | |
echo -e "You need the Gnu Compiler Collection (gcc)" >&2 | |
echo -e "to compile the trunk.\033[0m" >&2 | |
rm -rf ${lock} | |
exit 1 | |
fi | |
# check if we should install the binary | |
if test ${inst} = "true" -a ${superuser} = "false" ; then | |
# commandline '-i' -> we should install | |
# check for SUDO (only if install = true) | |
if test ! -x ${sudo} ; then | |
# SUDO is not installed, show error message and abbort | |
echo -e "\033[1m\033[31mABBORT BUILDING" >&2 | |
echo -e "ERROR: SUDO IS NOT INSTALLED" >&2 | |
echo -e "You need Sudo (sudo) to install the binary.\033[0m" >&2 | |
rm -rf ${lock} | |
exit 1 | |
fi | |
fi | |
################################################################################ | |
# MAIN LOOP | |
################################################################################ | |
# welcome message | |
case `date +%H` in | |
04|05) # time 4:00 AM < now < 6:00 AM | |
echo -e "\033[1m\033[33mYou're early up ${USER}. =)\033[0m" ;; | |
06|07|08|09) # time 6:00 AM < now < 10:00 AM | |
echo -e "\033[1m\033[33mGood Morning ${USER}! =)\033[0m" ;; | |
10|11|12|13) # time 10:00 AM < now < 2:00 PM | |
echo -e "\033[1m\033[33mHi ${USER}! =)\033[0m" ;; | |
14|15|16|17) # time 2:00 PM < now < 6:00 PM | |
echo -e "\033[1m\033[33mGood Afternoon ${USER}! =)\033[0m" ;; | |
18|19|20|21|22) # time 6:00 PM < now < 11:00 PM | |
echo -e "\033[1m\033[33mGood Evening ${USER}! =)\033[0m" ;; | |
23|00|01|02|03) # time 11:00 PM < now < 4:00 AM | |
echo -e "\033[1m\033[33mAren't you tired already, ${USER}? ;)\033[0m" ;; | |
*) # What happend now? | |
exit 1 ;; | |
esac | |
echo -e "\033[1m\033[33mWelcome to the dxx-rebirth bzr-autobuild-script!\033[0m" | |
# infinite while loop | |
while : ; do | |
# input already set -> we used the commandline flag | |
if test -z ${input} ; then | |
# ask which game should be build | |
echo -e "\033[1m\033[32mSo, which game do you want to build?" | |
echo -e -n "(d1x)-rebirth or (d2x)-rebirth: \033[0m" | |
read input | |
fi | |
# check the command | |
case ${input} in | |
d1x) # okay, we'll build D1X-REBIRTH | |
pre=${input} | |
buildbzr | |
# check the exit status | |
sucessful ;; | |
d2x) # okay, we'll build D2X-REBIRTH | |
pre=${input} | |
buildbzr | |
# check the exit status | |
sucessful ;; | |
dxx|both) | |
# build d1x- and d2x-rebirth | |
# build d1x-rebirth | |
pre="d1x" | |
buildbzr | |
# build d2x-rebirth | |
pre="d2x" | |
buildbzr | |
# check the exit status | |
sucessful ;; | |
h|help) # print the help message | |
echo -e "" | |
printinfo | |
echo -e "" | |
printhelp | |
echo -e "" | |
# start the loop again | |
input="" ; continue ;; | |
q|quit) # stop the loop and quit the script | |
echo -e "\033[1m\033[33mGoodbye ${USER}! =)\033[0m" | |
rm -rf ${lock} | |
exit 0 ;; | |
*) # every other command is wrong | |
echo -e "\033[31munknown command: \033[1m${input}\033[0m" >&2 | |
echo -e "" >&2 | |
# start the loop again | |
input="" ; continue ;; | |
esac | |
done | |
# We are done! :) Good bye. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment