#!/bin/bash # eup - by Blake Barnett (blake@soulmachine.net) # getoptex functions by Grigoriy Strokin (grg@philol.msu.ru) # In order to use this script, you need to have an intial checkout of the # enlightenment CVS tree, currently eup only supports building libs, apps # and certain misc apps for e17. Support for e16 will be added if it seems # useful enough. # See the enlightenment CVS notes for more details: # http://enlightenment.org/pages/cvsnotes.html # DISCLAIMER: Use at your own risk, no guarantees, blah blah blah. # LICENSE: Creative Commons attribution license # http://creativecommons.org/licenses/by/2.0/ #This is the default build list and default order, add what you want here. LIBBUILDLIST="imlib2 edb eet evas ecore \ epeg embryo edje epsilon esmart emotion \ engrave etox ewl imlib2_loaders" APPBUILDLIST="iconbar entice entrance \ elicit elation examine e e_utils e_modules \ enscribe express eclair" MISCBUILDLIST="elapse erss engage enotes" ETERMBUILDLIST="libast Eterm" EVIDENCEBUILDLIST="evidence" E16BUILDLIST="e epplets e16keyedit e16menuedit" #Declare our variables. #FIXME: Probably didn't get all of them... CDIR="${PWD##/*/}" SUDOBIN="`which sudo`" NOPROMPT=0 NOUPDATE=0 DOINSTALL=0 DOBUILD=0 FORCEOVER=0 PREFIX="" LOGFILE="$PWD/${0##/*/}-`date +%F`.log" BLUE="" CYAN="" GREEN="" OFF="" RED="" #Some voodoo to handle long options and other cool stuff. function getoptex() { let $# || return 1 local optlist="${1#;}" let OPTIND || OPTIND=1 [ $OPTIND -lt $# ] || return 1 shift $OPTIND if [ "$1" != "-" -a "$1" != "${1#-}" ] then OPTIND=$[OPTIND+1]; if [ "$1" != "--" ] then local o o="-${1#-$OPTOFS}" for opt in ${optlist#;} do OPTOPT="${opt%[;.:]}" unset OPTARG local opttype="${opt##*[^;:.]}" [ -z "$opttype" ] && opttype=";" if [ ${#OPTOPT} -gt 1 ] then # long-named option case $o in "--$OPTOPT") if [ "$opttype" != ":" ]; then return 0; fi OPTARG="$2" if [ -z "$OPTARG" ]; then # error: must have an agrument let OPTERR && echo "$0: error: $OPTOPT must have an argument" >&2 OPTARG="$OPTOPT"; OPTOPT="?" return 1; fi OPTIND=$[OPTIND+1] # skip option's argument return 0 ;; "--$OPTOPT="*) if [ "$opttype" = ";" ]; then # error: must not have arguments let OPTERR && echo "$0: error: $OPTOPT must not have arguments" >&2 OPTARG="$OPTOPT" OPTOPT="?" return 1 fi OPTARG=${o#"--$OPTOPT="} return 0 ;; esac else # short-named option case "$o" in "-$OPTOPT") unset OPTOFS [ "$opttype" != ":" ] && return 0 OPTARG="$2" if [ -z "$OPTARG" ] then echo "$0: error: -$OPTOPT must have an argument" >&2 OPTARG="$OPTOPT" OPTOPT="?" # return 1 exit 1 fi OPTIND=$[OPTIND+1] # skip option's argument return 0 ;; "-$OPTOPT"*) if [ $opttype = ";" ] then # an option with no argument is in a chain of options OPTOFS="$OPTOFS?" # move to the next option in the chain OPTIND=$[OPTIND-1] # the chain still has other options return 0 else unset OPTOFS OPTARG="${o#-$OPTOPT}" return 0 fi ;; esac fi done echo "$0: error: invalid option: $o" fi; fi OPTOPT="?" unset OPTARG return 1 } #magical thingies. function optlistex { local l="$1" local m # mask local r # to store result while [ ${#m} -lt $[${#l}-1] ]; do m="$m?"; done # create a "???..." mask while [ -n "$l" ] do r="${r:+"$r "}${l%$m}" # append the first character of $l to $r l="${l#?}" # cut the first charecter from $l m="${m#?}" # cut one "?" sign from m if [ -n "${l%%[^:.;]*}" ] then # a special character (";", ".", or ":") was found r="$r${l%$m}" # append it to $r l="${l#?}" # cut the special character from l m="${m#?}" # cut one more "?" sign fi done echo $r } #Wrapper for bash's built-in function to use getoptex function getopt() { local optlist=`optlistex "$1"` shift getoptex "$optlist" "$@" 2>>$LOGFILE return $? } #Duh function usage() { echo "${GREEN}Usage:${OFF} $0 ${CYAN}[options]${CYAN}" echo "${BLUE}------------------------------------------------------- " echo " ${CYAN}-i --install${OFF} Automagically install each build (requires sudo" echo " ${CYAN}-n --noprompt${OFF} Don't prompt (always assume es to prompts)" echo " ${CYAN}-d --dir${OFF} Build only " echo " ${CYAN}-F --force-overwrite${OFF} Force overwriting of existing packages" echo " ${CYAN}-p --prefix${OFF} Optional path to install each build to." echo " (default=/usr/local)" echo " ${CYAN}-l --log${OFF} Log path and filename." echo " (default=$LOGFILE" echo " ${CYAN}-u --noupdate${OFF} Don't do a CVS update for each build." echo " ${CYAN}-c --coloroff${OFF} Disable colors" echo " ${CYAN}-h --help${OFF} Show this help info" } #Convenience function for turning off ascii colors. function coloroff() { BLUE="" CYAN="" GREEN="" OFF="" RED="" } #This pulls the current target build version. NASTY! #FIXME: If there is a better way to do this, change me. function getvers() { ver=`grep AM_INIT_AUTOMAKE configure.in | awk '{print $2}'| sed 's/)//'` #is the version returned an integer? if [ `echo $ver | grep [[:digit:]]` ]; then echo "$ver" else ./autogen.sh >>$LOGFILE 2>&1 if [ -r config.h ]; then ver=`grep "#define VERSION" config.h | awk '{print $3}'` else echo "No config.h, running configure." >>$LOGFILE ./configure >>$LOGFILE 2>&1 ver=`grep "#define VERSION" config.h | awk '{print $3}'` fi echo ${ver} | cut -d \" -f 2 fi } #This creates a generic debian/changelog. #FIXME: Change to use dpkg-buildpackage option to overried changelog source. function updatechlog() { CHLOGDATE=`date "+%a, %d %b %G %T %z"` CHLOGIDENT="-- Blake Barnett (shadoi) " CHLOGVER="$1 ($version-0cvs`date "+%G%m%d"`) unstable; urgency=low" cd debian 2>>$LOGFILE rm changelog.in 2>>$LOGFILE echo $CHLOGVER >> changelog.in echo "" >> changelog.in echo " * a CVS snapshot release." >> changelog.in echo "" >> changelog.in echo " $CHLOGIDENT $CHLOGDATE" >> changelog.in echo "" >> changelog.in cp changelog.in changelog cd .. } #Convenience function for error checking. #FIXME: is $? reliable? function errorcheck() { if [ $? -gt 0 ]; then echo "$1 $2 ${RED}failed!${OFF}" echo "$1 $2 failed!" 2>&1 >>$LOGFILE tail $LOGFILE exit 1 else return 0 fi } #Just a convenience function for output and logging. function notifyem() { #once for stdout echo "${GREEN} $1:${OFF} $2" #once for log with no colors echo "$1: $2" 2>&1 >>$LOGFILE } #Do all our fancy option parsing and stuff while getoptex "b; build; i; install; n; noprompt; c; coloroff; d: dir: F; force-overwrite; u; noupdate; h; help; p: prefix: l: log:" "$@" do case $OPTOPT in i|install) DOINSTALL=i ;; b|build) DOBUILD=b ;; n|noprompt) NOPROMPT=n ;; p|prefix) PREFIX="$OPTARG" ;; l|log) LOGFILE="$OPTARG" ;; u|noupdate) NOUPDATE=u ;; c|coloroff) coloroff ;; d|dir) FORCEBUILD="$OPTARG" ;; F|force-overwrite) FORCEOVER=F ;; h|help) usage exit 1 ;; esac done #Figure out what we're going to build #FIXME: Allow more elegant target selection # such as a CVS path (ie. CVSROOT/e17/libs/blah) case $CDIR in evcvs) BUILDLIST=$EVIDENCEBUILDLIST ;; eterm) BUILDLIST=$ETERMBUILDLIST ;; misc) BUILDLIST=$MISCBUILDLIST ;; libs) BUILDLIST=$LIBBUILDLIST ;; apps) BUILDLIST=$APPBUILDLIST ;; e16) BUILDLIST=$E16BUILDLIST ;; *) echo "${RED}ERROR${OFF}: You should be in e17/libs, e17/apps, e16, evidence or misc from enlightenment CVS to run this script!" exit 1 ;; esac if [ ! -z "${FORCEBUILD}" ]; then #FIXME: This is a horribly hackish way to do this BUILDLIST="${FORCEBUILD} $3 $4 $5 $6 $7 $8 $9" fi #If we're going to install check to see if sudo is available. if [ $DOINSTALL = "i" ]; then if [ -z $SUDOBIN ]; then echo "This script requires sudo for installation." exit 2 fi fi #Show what we're going to build and prompt to continue unless $NOPROMPT is set. if [ $NOPROMPT = 0 ]; then echo "The following modules will be built: $BUILDLIST" read -n 2 -p "${GREEN}Continue? ${OFF}[Yy|Nn]: " GO case $GO in Y|y) echo "${GREEN}WEEEEEEEEEEE${OFF}!!!" ;; N|n) echo "FINE!" exit 2 ;; *) echo "Don't sass me." exit 2 ;; esac fi #Begin looping through the $BUIDLIST ask to do a CVS checkout if the directory #doesn't exist. #FIXME - More options for fresh checkouts? for thing in $BUILDLIST; do echo "-------------------------------------------------" if [ ! -d $thing ]; then echo "WARNING: $thing doesn't exist" if [ $NOPROMPT = n ]; then cvs -z3 co -d $thing e17/$CDIR/$thing >>$LOGFILE 2>&1 else read -n 2 -p "Do CVS checkout for $thing? [Yy|Nn]: " RESP case $RESP in Y|y) cvs -z3 co -d $thing e17/$CDIR/$thing \ 2>&1 >>$LOGFILE ;; N|n) echo "FINE!" exit 2 ;; esac fi fi #Go into the target build directory. cd $thing #Do an update unless $NOUPDATE is set. if [ $NOUPDATE = 0 ]; then notifyem "Updating" "$thing" cvs up -dAP >>$LOGFILE 2>&1 errorcheck "Updating" "$thing" fi #Get the version using our built-in version=`getvers $thing` notifyem "Building debs for" "$thing v$version" if [ $thing = "imlib2_loaders" ]; then thing="imlib2-loaders" elif [ $thing = "e" ]; then thing="enlightenment" elif [ $thing = "Eterm" ]; then thing="eterm" elif [ $thing = "e_utils" ]; then thing="eutils" elif [ $thing = "e_modules" ]; then thing="emodules" fi #Check if we've already built packages for this sucker. if [ $FORCEOVER = 0 ]; then ls -1 "../${thing}_${version}-0cvs`date +%G%m%d`_i386.changes" >/dev/null 2>&1 if [ $? -eq 0 ]; then notifyem "Found package built today" "$thing" notifyem "Skipping" "$thing" cd .. continue fi else notifyem "Overwriting package built today" "$thing" fi #This updates the debian/changelog file using our built-in. updatechlog $thing errorcheck "Updating debian/changelog for" "$thing" #Begin building the debian package. if [ $DOBUILD = 0 ]; then fakeroot dpkg-buildpackage -sd >>$LOGFILE 2>&1 errorcheck "Building" "$thing" else notifyem "Skipping build for" "$thing" fi #Install the package if $DOINSTALL is set. if [ $DOINSTALL = i ]; then notifyem "Installing" "$thing" sudo dpkg -i ../*$thing*`date "+%G%m%d"`*.deb >>$LOGFILE 2>&1 errorcheck "Installing" "$thing" if [ $thing = e ]; then sudo dpkg -i ../libe*`date "+%G%m%d"`*.deb >>$LOGFILE 2>&1 fi fi echo "-------------------------------------------------" #Make sure we're back out of the target build dir. cd .. done