#!/bin/bash # # mkkpkg: make new configured kernel package from kernel-xx-xx.src.rpm # # [Version 2.3.2] Jul 10 2000 # Modified by sagami@pc.highway.ne.jp # - see Chgangelog # # [Version 2.3.0] Apr 20 2000 # Modified by SAGAMI # - renewed srpm checking process # - renewed RPMDIR checking precess # - and more... # # [Version 2.2.5] Mar 3 2000 # Modified by Jun Nishii # - bug fix: set ARCH as i386 (i586 does not make pcmcia now) # # [Version 2.2.4] Feb 29 2000 # Modified by Jun Nishii # - fix a small bug: patch from Shoji Matsumoto # # [Version 2.2.3] Feb 29 2000 # Modified by Jun Nishii # - mkkpkg-2.2.3 # - fix a bug and typo by Toru Sagami, thanks. # # [Version 2.2.2] Feb 25 2000 # Modified by Jun Nishii # - fix a bug: wrong path for SRPMS # # [Version 2.2.1] Feb 25 2000 # Modified by Jun Nishii # - fix a bug: lost definition of RPMRC # # [Version 2.2] Feb 24 2000 # Modified by SAGAMI # - fixed some bugs # - 2.1 exits -1 in anyways :-p # - BUILDMODE -> RPMBUILDMODE # - Some ENV value needs {,}? # - RPMDIR sometimes NULL # - moved /usr/bin/mkkpkg to /usr/sbin/mkkpkg # - tweaken, using --showrc --rmspec # - dont include packager tag in new spec file, because rpm will include it # if defined in rpmmacros # - awk ARGV problems in parser # # [Version 2.1] Jan 30 2000 # Modified by Jun Nishii # - merge patch from SAGAMI # + bug fix for processing .rpmmacros # + use --target # + added Packager, Vendor, Distribution in new spec file # + --clean, --rmsource # + use new revision number for new spec file name # + modify messages # - clean up script # # [Version 2.0] # Modified by Jun Nishii Jan 10 2000 # - use parsespec to remove smp, BOOT, BOOTsmp entry # # Modified by Yasuhide OOMORI # - Quick hack about rpmdir. # - Modified for mistyping of new revision: # -- remove control character # - Modified to quickly make one kernel: # -- no compile for smp or BOOT kernel. # # [Verion 1.0] # Written by MATSUMOTO Shoji # This script must be distributed by Project Vine . # The responsibility of any trouble with this script is on you. # ############################################################ MKKPKGVERSION=2.5.3 CMDNAME=`basename $0` RETVAL=0 ############################################################ ### some functions showUsage(){ echo "$CMDNAME: make new configured kernel package from kernel-xx-xx.src.rpm" echo "usage: $CMDNAME [-v] [config|menuconfig|xconfig]" echo "Try \`$CMDNAME --help' for more" } showHelp(){ echo "$CMDNAME:" echo " make new configured kernel package from kernel SRPM." echo "" echo " usage:" echo " $CMDNAME --version : show version and exit" echo " $CMDNAME --help : print this message and exit" echo "" echo " $CMDNAME [-v] [config|menuconfig|xconfig] [...]" echo " [-v|--verbose] : be a little verbose" echo " : kernel SOURCE RPM (SRPM) to use" echo " [config] : execute \`make config'" echo " [menuconfig] : execute \`make menuconfig' (default)" echo " [xconfig] : execute \`make xconfig'" echo " [gconfig] : execute \`make gconfig' (for 2.6.x)" echo " [--release=RELEASE]: RELEASE for user's release number" echo " [--buildmode=MODE] : rpm build mode MODE [-ba|-bb]" echo " [--rpmarg=RPMARG] : additional rpm arguments RPMARG for building" echo " [--english] : show Configure.help in English (if available)" echo " [--tmpdir=TMPDIR] : directory to which log message goes" echo " [--output=FILENAME]: log message to FILENAME in TMPDIR" #echo " [--fetch] : fetch SRPM via apt-get" #echo " [--disable-edit] : disable to edit SPEC file with EDITOR" echo " [--target=ARCH] : build target architecture ARCH" echo " [--enable-smp] : create smp/BOOT packages as well" #echo " [--fast] : build rpm without \"nice\"" #echo " [--fastest] : build rpm with \"nice --19\" (root privileged)" #echo " [--devel] : assuming --smp --fast --verbose..." #echo " [--rebuild] : just rebuild SRPM (what for?)" echo "" } showbuildnotice(){ if [ $QUIET != "true" ] ; then echo "" echo " Log output goes to $TMPDIR/$LOGFILE." echo " You can read it by following sequence:" echo " 1. Push \"Ctrl+Z\" to suspend the next long process" echo " 2. Type \"bg\" to continue background" echo " 3. Use \"less\" to print $TMPDIR/$LOGFILE" echo " 3.1 Push \"Shift+F\" to \"Forward forever; like tail -f\"" echo " 3.2 If you want to stop reading, Push \"Ctrl+C\"" echo " 4. Type \"fg\" to get back to $CMDNAME" echo " X. If you are using X, you can read log thru another term window" echo "" echo " It takes about 10-240 minutes depending on your configuration and also" echo -e " depending on your machine: It's \\033[1;31mnot freezing!\\033[0;39m" echo "" echo "Ready for Action?" fi } checkDir(){ if [ ! -d $1 ] ; then echo "directory not found: $1" return 1 elif [ ! -w $1 ] ; then echo "permission denied: $1" return 1 fi return 0 } checkFile(){ if [ ! -f $1 ] ; then echo "file not found: $1" return 1 fi return 0 } #rpm3var () { # var=`rpm --showrc | sed -e "s/%{name}/$NAME/" \ # | awk "/-[0-9]+[:=][[:blank:]]+$1[[:blank:]]/ {print \\$3}"` # while test -n "`echo $var | egrep '%\{[_a-zA-Z]+\}'`"; do # v=`echo $var | sed 's/.*%{\([_a-zA-Z]\+\)}.*/\1/'` # w="`rpm3var $v`" # var=`echo $var | sed "s,%{\\([_a-zA-Z]\\+\\)},$w,g"` # done # echo $var #} rpm3var () { var=$(rpm --eval "%$1" | sed -e "s|%{name}|$NAME|" -e "s|\${HOME}|$HOME|") echo $var } getrpmmacro () { macro=`rpm --showrc | grep ^.*[0-9][:=][[:space:]]"$1" \ | sed "s/^.*$1[[:space:]]//"` echo $macro } askyesno () { yesno="" while [ -z "$yesno" ] ; do echo -n "$1 [y/n] " read yesno yesno=`echo $yesno | tr -d '[:cntrl:]' | tr '[:upper:]' '[:lower:]'` [ "$yesno" = "y" ] && return 1 [ "$yesno" = "n" ] && return 0 yesno="" done } checkTMPdir () { if [ -f $TMPDIR/$LOGFILE ] ; then echo "$CMDNAME found: $TMPDIR/$LOGFILE" LANG=C ls -l $TMPDIR/$LOGFILE echo "" echo "The log might be that of previous attempt, but we don't override it" echo "even if you are root or owner. Delete it and try again. Also check if" echo "someone else (including you) is running $CMDNAME." exit -1 fi return 0 } listbuilddir (){ find $1 -maxdepth 1 -type d -printf "%f\n" >$2 } rpmqueryformat(){ rpm -qp $1 --queryformat "%{$2}" 2>/dev/null } ############################################################ ### runtime environment LANGUAGE= ############################################################ ### process arguments MARCH=`uname -m` case "$MARCH" in *86) ARCH=i686 ;; x86_64) ARCH=x86_64 ;; *) ARCH=$MARCH ;; esac # ARCH=`uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/` TMPDIR=${TMPDIR:=/tmp} DISTRIBUTION=${DISTRIBUTION:-Local} LOGFILE=kernel-mkkpkg.log CONFMETHOD=menuconfig MESG=true QUIET=echo NICE=nice CONFIGURED= HELP= SMP= ############################################################ while [ $# -gt 0 ] ; do case "$1" in ####### experts only ####### # Yes, SMP actually means that we(who?) also build BOOT/mol packages. --clean) CLEAN="1" ;; --noclean) CLEAN="" ;; --devel|--develo|--develop) DEVEL="1" # assuming --fast --smp --verbose --eng { NICE="" ; SMP="1" ; MESG=echo ; HELP=en ; } #DATE=`date +'%Y%m%d%I%M'` #LOGFILE="kernel-mkkpkg-"${DATE}.log ;; --disable-smp|--without-smp|--nosmp|--smp=n*) SMP="" ;; --noenv|--noenvc|--noenvch|--noenvche|--noenvchec|--noenvcheck) NOENVCHEKCK="1" ;; --enable-smp|--with-smp|--smp|--smp=y*) # SMP other than == 1 have no meanings SMP="1" ;; --fast|--disable-nice|--without-nice) NICE="" ;; --fastest) NICE="" [ "`id -u`" = "0" ] && NICE="nice --19" ;; --reb|--rebu|--rebui|--rebuil|--rebuild) CONFMETHOD=[none] REBUILD="1" ;; ####### experts only ####### ####### experimental ####### --apt-get|--aptget|--fetch) if [ -x ${APTGET:=/usr/bin/apt-get} ] ; then FETCH="LC_MESSAGES=C $APTGET -qq source kernel" FETCHFILE=`eval $FETCH --no-act | awk '{print $3}'` if [ ! -z "$FETCHFILE" ] ; then $QUIET "fetching source file $FETCHFILE via apt-get..." eval $FETCH if [ $? -ne 0 ] ; then $QUIET "fetching source file via apt-get faild." else $QUIET "fetched $FETCHFILE" [ -f "$FETCHFILE" ] || $QUIET ", but not found" fi else $QUIET "fetching source file via apt-get failed." fi [ -f "$FETCHFILE" ] && SRPM=$FETCHFILE fi ;; ####### experimental ####### --arg=*|--rpmarg=*) RPMARG=`echo $1 | sed 's/.*=//'` [ "$RPMARG" = "--nobuild" -o "$RPMARG" = "--test" ] && RPMARG="" ;; --edit|--enable-edit) EDIT=y ;; --noedit|--disable-edit) EDIT="n" ;; --en|--eng|--english) HELP=en ;; --ja|--jp|--japan|--japanese) HELP=ja ;; -h|--h|--he|--hel|--help) showHelp && exit 0 ;; --mode=*|--buildmode=*|--rpmbuildmode=*) RPMBUILDMODE=`echo $1 | sed 's/.*=//'` case "$RPMBUILDMODE" in --rebuild|rebuild) REBUILD="1" ;; -bs|bs|-ba|ba) RPMBUILDMODE="-ba" ;; -bb|bb) RPMBUILDMODE="-bb" ;; # -bc|bc) RPMBUILDMODE="-bc" ;; # -bi|bi) RPMBUILDMODE="-bi" ;; *) RPMBUILDMODE="" ;; esac ;; --output=*) LOGFILE=`echo $1 | sed 's/.*=//' | xargs basename` ;; --q|--qu|--qui|--quie|--quiet|--silent) QUIET=true MESG=true ;; --rel=*|--release=*|--rev=*|--revision=*) NREV=`echo $1 | sed 's/.*=//' | sed -e 's/.*smp.*//' -e 's/.*mol.*//'` ;; --skip|--skipconfig|--skip-config|--config=skip) CONFIGURED=y CONFMETHOD=[skipped] ;; --specfile=*) SPEC=`echo $1 | sed 's/.*=//'` if [ ! -f "$SPEC" ] ; then echo "$CMDNAME: missing SPECFILE $SPEC" && exit 1 fi SRPMDIR=`rpm3var _srcrpmdir` NVR=`rpm -q --specfile $SPEC \ --qf '%{NAME}-%{VERSION}-%{RELEASE}\n' | head -1` if [ -z "$NVR" ] ; then echo "$CMDNAME: failed to query $SPEC" exit 1 fi rpmbuild -bs $SPEC >/dev/null 2>&1 if [ $? -ne 0 ] ; then echo "$CMDNAME: failed to build $SPEC" exit 1 fi SRPM="${SRPMDIR}/${NVR}.src.rpm" if [ ! -f "$SRPM" ] ; then echo "$CMDNAME: missing SRPM $SRPM" exit 1 fi [ -z "$RPMBUILDMODE" ] && RPMBUILDMODE="-ba" ;; --target=*|--target|--arch=*) ARCH=`echo $1 | sed 's/.*=//' | sed 's/.*noarch.*//'` if [ "$1" = "--target" -a ! -f "$2" ] ; then ARCH=`echo $2 | sed 's/.*=//' | sed 's/.*noarch.*//'` fi COMPAT=`LANG=C rpm --showrc | grep "^compatible build archs:" | \ sed 's/compatible build archs://'` MATCHED="" for i in $COMPAT ; do [ "$ARCH" = "$i" ] && MATCHED="y" done [ ! "$MATCHED" = "y" ] && ARCH="" [ "$1" = "--target" -a -n "$ARCH" ] && shift ;; --tmpdir=*|--tmp=*) TMPDIR=`echo $1 | sed 's/.*=//'` if [ ! -d "$TMPDIR" -o ! -w "$TMPDIR" ] ; then echo "$CMDNAME: can't write in $TMPDIR" && exit 1 fi ;; --config|config) CONFMETHOD=config ;; --old|--oldconfig|oldconfig) CONFMETHOD=oldconfig ;; --menu|--menuconfig|menuconfig) CONFMETHOD=menuconfig ;; --xconfig|--Xconfig|xconfig|Xconfig) CONFMETHOD=xconfig [ -z "$DISPLAY" ] && CONFMETHOD=menuconfig ;; --gconfig|gconfig) CONFMETHOD=gconfig [ -z "$DISPLAY" ] && CONFMETHOD=menuconfig ;; -v|--verb|--verbo|--verbos|--verbose) MESG=echo QUIET=echo ;; --vers|--versi|--versio|--version) echo "$CMDNAME: version $MKKPKGVERSION" exit 0 ;; *) [ -f $1 ] && SRPM=$1 if [ -z "$SRPM" ] ; then echo "$CMDNAME error: invalid option $1" showUsage && exit 1 fi ;; esac shift done # with no arguments if [ -z "$SRPM" ] ; then showUsage && exit fi ############################################################ # Print first banner. Can you read? # 34 blue 32 green 35 purple 31 red 33 yellow $MESG -e "\\033[1;34m$CMDNAME\\033[0;39m verbose mode" $MESG "$CMDNAME will execute \"make $CONFMETHOD\"" ############################################################ ## check SRPM and get KVER KREV from it # checking its signiture... rpm -K $SRPM >/dev/null if [ $? -ne 0 ] ; then echo "`basename $SRPM`: didn't pass \"rpm -K\"" exit -1 fi # checking if it's srpm... if [ "`file -L $SRPM | cut -d" " -f4`" != "src" ] ; then echo "`basename $SRPM`: does not appear to be src rpm" exit -1 fi NAME=`rpmqueryformat $SRPM NAME` KVER=`rpmqueryformat $SRPM VERSION` KREV=`rpmqueryformat $SRPM RELEASE` SRPMNAME=${NAME}-${KVER}-${KREV} #SRPMNAME=`file -L $SRPM | cut -d" " -f6` ############################################################ ## rebuild SRPM and exit (experts only) ## do nothing other than rebuild: what for? -- It's for logged and timed. if [ "$REBUILD" = "1" ] ; then LOGFILE=kernel-$KVER-$KREV-$ARCH.log $QUIET "`LANG=C date '+%c'`" $QUIET -n "$CMDNAME: rebuilding `basename $SRPM` for $ARCH..." KSTARTTIME=`LANG=C date '+%s'` eval LANG=C $NICE rpmbuild --rebuild $SRPM --target $ARCH $RPMARG \ >$TMPDIR/$LOGFILE 2>&1 RETVAL=$? $QUIET "exit $RETVAL" KENDTIME=`LANG=C date '+%s'` BUILDLAPSE=`expr $KENDTIME - $KSTARTTIME` $QUIET "Lapse: `expr $BUILDLAPSE / 60` min `expr $BUILDLAPSE % 60` sec" \ | tee -a $TMPDIR/$LOGFILE gzip --force --best --quiet $TMPDIR/$LOGFILE exit $RETVAL fi ############################################################ ## set and check RPMDIR PACKAGER=`getrpmmacro packager` [ -z "$PACKAGER" ] && PACKAGER="$(whoami) <$(whoami)@$(hostname)>" TOPDIR=`rpm3var _topdir` BUILDDIR=`rpm3var _builddir` RPMDIR=`rpm3var _rpmdir` SPECDIR=`rpm3var _specdir` SRCDIR=`rpm3var _sourcedir` SRPMDIR=`rpm3var _srcrpmdir` if [ "$NOENVCHEKCK" != "1" ] ;then for dir in $TOPDIR $BUILDDIR $RPMDIR $SPECDIR \ $SRCDIR $SRPMDIR $RPMDIR/${ARCH}; do checkDir $dir || { mkdir -p $dir || exit -1 } done #checkDir $RPMDIR/noarch || exit -1 $MESG Using rpmdir: $TOPDIR fi ############################################################ # checking if it's kernel and version is supported case "$NAME" in kernel30|kernel26) # random guess (will be examined later) BUILDLINUXDIR=${BUILDDIR}/${NAME}-${KVER}/linux-${KVER} ;; kernel25) # random guess (will be examined later) BUILDLINUXDIR=${BUILDDIR}/${NAME}-${KVER}/linux ;; kernel24) # support for 2.4.x BUILDLINUXDIR=${BUILDDIR}/linux-${KVER} ;; kernel22) # random guess (will be examined later) BUILDLINUXDIR=${BUILDDIR}/linux ;; kernel) case "$KVER" in 2.6*|3.*) # support for 2.6.x/3.x BUILDLINUXDIR=${BUILDDIR}/${NAME}-${KVER}/linux-${KVER} ;; 2.4*) # support for 2.4.x BUILDLINUXDIR=${BUILDDIR}/linux-${KVER} ;; 2.2*) # as of 2.2.17, it is OK. BUILDLINUXDIR=${BUILDDIR}/linux ;; *) echo "`basename $SRPM`: version $KVER package is not supported" BUILDLINUXDIR=${BUILDDIR}/${NAME}-${KVER}/linux echo "try to detect \"linux\" directory to build..." ;; esac ;; *) echo "`basename $SRPM`: does not appear to be kernel package" exit -1 ;; esac $MESG Using buildlinuxdir: $BUILDLINUXDIR ############################################################ ## extract file names from SRPM # first $TMPFILE is made here TMPFILE=`mktemp $TMPDIR/$CMDNAME.XXXXXX` || \ { echo "could not create temporary file" ; exit 1 ; } rpm -qlp $SRPM >$TMPFILE SPEC="$SPECDIR/`grep '.spec$' $TMPFILE`" KCFG="`grep \"$ARCH.config\" $TMPFILE | tail -1`" # this is unusual, almost impossible if [ -z "$SPEC" ] ; then echo "can't find SPEC file" rm -f $TMPFILE && exit -1 fi # as for now, srpm must have "$ARCH.config" if [ -z "$KCFG" ] ; then echo "can't find default configuration file for $ARCH" rm -f $TMPFILE && exit -1 fi $MESG Using SPEC file: $SPEC $MESG Using kernel config file: $KCFG ############################################################ ## install SRPM: "rpm -i" by root is thought to be a hole... $MESG "Executing \"rpm -ivh $SRPM\"" rpm -ivh $SRPM >/dev/null 2>&1 sync && sleep 1 # checking files in source dir not only for nosrc, but also for src if [ "$NOENVCHEKCK" != "1" ] ;then $MESG -n "Checking files in SOURCES..." for file in `cat $TMPFILE | grep -v '\.spec$'` ; do checkFile $SRCDIR/$file if [ $? -ne 0 ] ; then echo "It must be placed in or symbolic linked from ${SRCDIR}" rm -f $TMPFILE && exit -1 fi done $MESG "done." fi # first $TMPFILE is removed here rm -f $TMPFILE ############################################################ ## before expand SRPM: it costs a while and overrides BUILD ## check if exists kernel-mkkpkg.log ($LOGFILE) ## perhaps someone else is running mkkpkg, really? checkTMPdir ############################################################ ## expand SRPM and find BUILDLINUXDIR (kind of ugly...) # print second -for "panpie"- banner if [ "$MESG" != "echo" ] ; then $QUIET -e "Welcome to \\033[1;35m$CMDNAME\\033[0;39m" $QUIET "" && sleep 1 fi $QUIET "Please wait for a while \"make $CONFMETHOD\" to be executed..." # first, we clean up existing BUILDLINUXDIR (if any) by executing -bs mkdir -p $SRPMDIR/.${CMDNAME}.tmp rpmbuild -bs --clean $SPEC --define "_srcrpmdir $SRPMDIR/.${CMDNAME}.tmp" >/dev/null 2>&1 rm -rf $SRPMDIR/.${CMDNAME}.tmp TMPPRE=`mktemp $TMPDIR/$CMDNAME.XXXXXX` || \ { echo "could not create temporary file" ; exit 1 ; } listbuilddir $BUILDDIR $TMPPRE # then, we expand $QUIET -n "Executing \"rpmbuild -bp $SPEC\"..." if ! rpmbuild -bp $SPEC >/dev/null 2>&1 ; then echo "" && echo "Failed to expand sources/patches." rm -f $TMPPRE && exit -1 else sync && sleep 3 fi $QUIET "done." # afterwards, we examine and detect buildlinuxdir TMPPOST=`mktemp $TMPDIR/$CMDNAME.XXXXXX` || \ { echo "could not create temporary file" ; exit 1 ; } listbuilddir $BUILDDIR $TMPPOST TMPDIFF=`mktemp $TMPDIR/$CMDNAME.XXXXXX` || \ { echo "could not create temporary file" ; exit 1 ; } diff -B $TMPPRE $TMPPOST | grep "^> " | sed 's,^> ,,' >$TMPDIFF rm -f $TMPPRE $TMPPOST $MESG -n "Examining and detecting buildlinuxdir..." if [ ! -d "$BUILDLINUXDIR" ] ; then BUILDLINUXDIR="" KMAJOR=`echo $KVER | cut -f1,2 -d.` for i in `cat $TMPDIFF` ; do # kernel-2.2 if [ "$i" = "linux" -a -d "$BUILDDIR/linux" ] ; then BUILDLINUXDIR="$BUILDDIR/linux" # kernel-2.4, 2.6 elif [ -d "$BUILDDIR/$i/linux" ] ; then BUILDLINUXDIR="$BUILDDIR/$i/linux" # kernel-3.x elif [ -d "$BUILDDIR/$i/linux-$KMAJOR" ] ; then BUILDLINUXDIR="$BUILDDIR/$i/linux-$KMAJOR" fi done if [ -z "$BUILDLINUXDIR" ] ; then echo "Can't detect RPM_BUILD_ROOT/linux directory" rm -f $TMPDIFF && exit -1 fi fi $MESG "done." $MESG Using buildlinuxdir: $BUILDLINUXDIR rm -f $TMPDIFF ############################################################ ## get release(revision) number while [ "$NREV" = "" ] ; do echo -n "Input your kernel Revision [SRPM = $KREV]: " read NREV # remove control character in string # string "smp" is bad thing for kernel-headers and /boot/kernel.h NREV=`echo $NREV | tr -d '[:cntrl:]' | sed 's/.*smp.*//'` if [ -f ${RPMDIR}/${ARCH}/kernel-${KVER}-${NREV}.${ARCH}.rpm ] ; then echo "${RPMDIR}/${ARCH}/kernel-${KVER}-${NREV}.${ARCH}.rpm found." askyesno " Override?" [ $? = 0 ] && NREV="" elif [ "${KVER}-${NREV}" = "`uname -r`" ] ; then echo "${KVER}-${NREV} is same as currently running." askyesno " Override?" [ $? = 0 ] && NREV="" # Confirmation of kernel release(revision) elif [ -n "$NREV" ] ; then askyesno " kernel Revision [yours = $NREV]. OK?" [ $? = 0 ] && NREV="" fi done ############################################################ ## make spec file NSPEC=${SPECDIR}/kernel-${KVER}-${NREV}.spec if [ "$NSPEC" = "$SPEC" ] ; then mv -f $SPEC ${SPEC}.${CMDNAME} SPEC=${SPEC}.${CMDNAME} fi ### poor spec type detection (new type has build* macros) newtypespec="" for i in buildsmp buildBOOT buildenterprise ; do grep -q "^[[:space:]]*%define[[:space:]]$i" $SPEC && newtypespec="1" done if [ "$SMP" = "1" -o "$newtypespec" = "1" ] ; then [ ! "$SMP" = "1" ] && SMP="0" cp -f $SPEC $NSPEC TMPOUT=`mktemp $TMPDIR/.specout.XXXXXX` || \ { echo "could not create temporary file" ; exit 1 ; } # we leave buildenterprise as it is (might be 0 by default) # for i in buildsmp buildBOOT buildmol buildenterprise; do for i in buildsmp buildBOOT buildmol ; do sed -e "s/^[[:space:]]*\(%define[[:space:]]$i\).*/\1 $SMP/" < $NSPEC > $TMPOUT mv -f $TMPOUT $NSPEC done else # oldtype without smp (default) PARSESPEC=/usr/share/mkkpkg/parsespec if [ ! -x $PARSESPEC ] ; then echo "can't execute: $PARSESPEC" && exit -1 fi $PARSESPEC $SPEC > $NSPEC fi if [ ! "$DEVEL" = "1" ] ; then # common substitution TMPOUT=`mktemp $TMPDIR/.specout.XXXXXX` || \ { echo "could not create temporary file" ; exit 1 ; } sed -e "s/^Release.*/Release: $NREV/" \ -e "s/^Vendor.*/Vendor: mkkpkg ($SRPMNAME)/" \ -e "s/^Distribution.*/Distribution: $DISTRIBUTION/" \ -e "s/^Packager.*/Packager: $PACKAGER/" < $NSPEC >$TMPOUT mv -f $TMPOUT $NSPEC else # we do not want filename and tags above to be changed! mv -f $NSPEC $SPEC NSPEC=$SPEC fi $MESG "created new SPEC file: " $NSPEC $MESG " from \"Release: $KREV\" to \"Release: $NREV\"" # dont rm -f $SPEC now ############################################################ ## run editor $QUIET "" && sleep 1 cp -f $NSPEC $NSPEC.$$ if [ ! "$EDIT" = "y" -a ! "$EDIT" = "n" ] ; then askyesno "Do you want to edit `basename $NSPEC`?" [ $? = 1 ] && EDIT="y" fi while [ "$EDIT" = "y" ] ; do echo -n "Push \"enter\" to edit SPEC file [${EDITOR:=vi}]: " read TMPEDITOR [ "$TMPEDITOR" ] && EDITOR=$TMPEDITOR $EDITOR $NSPEC \ || { echo "can't start editor. Continue..." ; EDITOR="" ; } askyesno "Have you finished editting `basename $NSPEC`?" [ $? = 1 ] && EDIT="" done if ! diff -bB $NSPEC.$$ $NSPEC >/dev/null ; then echo "detected modified SPEC file" rpm -q --specfile $NSPEC >/dev/null if [ $? -ne 0 ] ; then echo "You made a mistake while editing $NSPEC" rm -f $NSPEC.$$ && exit -1 fi UREV="`rpm -q --queryformat "%{RELEASE}\n" --specfile $NSPEC | uniq`" UVER="`rpm -q --queryformat "%{VERSION}\n" --specfile $NSPEC | uniq`" if [ "$UREV" != "$NREV" ] ; then echo "Change detected after edit:" UREV=`echo $UREV | sed 's/.*smp.*//'` if [ -z "$UREV" ] ; then echo "$CMDNAME error: still \"smp\" string in RELEASE." rm -f $NSPEC.$$ && exit -1 fi echo " from \"Release: $NREV\" to \"Release: $UREV\"" NREV=$UREV fi # BTW, how come you persist in using mkkpkg? if [ "$UVER" != "$KVER" ] ; then echo " from \"Version: $KVER\" to \"Version: $UVER\"" KVER=$UVER fi askyesno "Do you want to re-expand sources/patches with new SPEC file?" if [ $? = 1 ] ; then echo "Executing \"rpmbuild -bp $NSPEC\"" TMPOUT=`mktemp $TMPDIR/${CMDNAME}-expand.XXXXXX` || \ { echo "could not create temporary file" ; exit 1 ; } if rpmbuild -bp $NSPEC >$TMPOUT 2>&1 ; then sync && sleep 3 echo "Succeeded in expanding sources/patches." rm -f $TMPOUT else echo "Failed to expand sources/patches." echo "See $TMPOUT." rm -f $NSPEC.$$ && exit -1 fi fi fi rm -f $NSPEC.$$ [ "$NSPEC" != "$SPEC" ] && rm -f $SPEC ############################################################ ## asking whether to build srpm if [ -z "$RPMBUILDMODE" ] ; then askyesno "Do you want to build SRPM? (If no, only RPMs are built)" if [ $? = 1 ] ; then RPMBUILDMODE="-ba" $MESG " OK, SRPM and RPMs will be built." else RPMBUILDMODE="-bb" $MESG " OK, only RPMs will be built." fi fi ############################################################ ## now make config checkDir $BUILDLINUXDIR || exit -1 if [ "$HELP" = "en" ] ; then if [ "$NOENVCHEKCK" != "1" ] ;then if [ -L $BUILDLINUXDIR/Documentation/Configure.help \ -a -f $BUILDLINUXDIR/Documentation/Configure.help.en ] ; then pushd $BUILDLINUXDIR/linux/Documentation >/dev/null 2>&1 $MESG "Using Configure.help.en ..." ln -sf Configure.help.en Configure.help popd >/dev/null 2>&1 fi fi fi # make sure EXTRAVERSION says what we want it to say, but... perl -pi -e "s/^EXTRAVERSION.*/EXTRAVERSION = -${NREV}/" \ $BUILDLINUXDIR/Makefile || : if [ "$SMP" = "1" ] ; then if [ ! "$ARCH" = "ppc" ] ; then CONFFILE="`set +f; echo $BUILDLINUXDIR/configs/{*-$ARCH,*-$ARCH-smp,*-$ARCH-BOOT}.config`" else CONFFILE="`set +f; echo $BUILDLINUXDIR/configs/{*-$ARCH,*-$ARCH-smp,*-$ARCH-mol,*-$ARCH-BOOT}.config`" fi else CONFFILE="`set +f; echo $BUILDLINUXDIR/configs/*-$ARCH.config`" fi while [ -z "$CONFIGURED" ] ; do for file in $CONFFILE ; do if [ -f $file ] ; then KCFG=`basename $file` $MESG "Copying $KCFG into source tree for $ARCH" cp -f $file $BUILDLINUXDIR/.config elif [ "$SMP" != "1" ] ; then # Could this sentence be evalueted?! $MESG "Missing?! `basename $file`, using default?!" else $MESG -n "Ignoring... " $MESG "`basename $file` seems to be BOOT on non-base architecture" KCFG="" fi if [ -n "$KCFG" ] ; then echo "Ready for make \"$CONFMETHOD\" by $KCFG" echo -n "[Push enter to continue] " read make -s $CONFMETHOD -C $BUILDLINUXDIR if [ $? -ne 0 ] ; then askyesno "Something wrong with \"make $CONFMETHOD\". Continue?" [ $? = 0 ] && exit -1 fi checkFile $BUILDLINUXDIR/.config || \ { echo "$BUILDLINUXDIR/.config is missing " ; exit -1 ; } ## leaving original and user-configured .configs in SOURCES $MESG "mv $SRCDIR/${KCFG}{,.mkkpkg}" mv -f $SRCDIR/${KCFG}{,.mkkpkg} $MESG "Copying .config into $SRCDIR/${KCFG}" ## ad-hoc fix (20050621) case "$ARCH" in *86) echo "# i386" > $SRCDIR/${KCFG} ;; ppc) echo "# powerpc" > $SRCDIR/${KCFG} ;; *) echo "# $ARCH" > $SRCDIR/${KCFG} ;; esac cat $BUILDLINUXDIR/.config >> $SRCDIR/${KCFG} ## cp -f $BUILDLINUXDIR/.config $SRCDIR/${KCFG} fi echo "" && sleep 1 done CONFIGURED="y" done # it will create these binaries, but some of them are only for base arch. TMPFILE=`mktemp $TMPDIR/$CMDNAME.XXXXXX` || \ { echo "could not create temporary file" ; exit 1 ; } rpm -q --specfile $NSPEC | sed "s/$/\.$ARCH\.rpm/g" | sort > $TMPFILE ############################################################ ## now build rpm package ## test $RPMARG if [ -n "$RPMARG" ] ; then if ! rpmbuild -bp $NSPEC --target=$ARCH $RPMARG --nobuild >/dev/null 2>&1 then RPMARG="" fi fi RPMBUILDCMD="rpmbuild $RPMBUILDMODE $NSPEC --target=$ARCH $RPMARG >$TMPDIR/$LOGFILE 2>&1" ADDITIONALFLAGS="smp=$SMP build=${NICE:-fast}" # output lines should be less than 24 lines. clear if [ $QUIET != "true" ] ;then echo "" echo -e "\\033[1;32m$CMDNAME\\033[0;39m" echo "" echo "Now we are prepared for executing:" echo " rpmbuild $RPMBUILDMODE $NSPEC --target=$ARCH $RPMARG" fi if [ ! "$DEVEL" = "1" ] ; then [ "$SMP" = "1" -o ! "$NICE" = "nice" ] && echo "With: $ADDITIONALFLAGS" showbuildnotice echo -n "[Push enter to continue] " read fi $QUIET "Started: `LANG=C date '+%c'`" echo -n "Building..." ## Build KSTARTTIME=`LANG=C date '+%s'` if checkTMPdir ; then eval $NICE $RPMBUILDCMD RETVAL=$? fi ############################################################ ## check return value and whether package are made KENDTIME=`LANG=C date '+%s'` BUILDLAPSE=`expr $KENDTIME - $KSTARTTIME` # echo "EXIT $RETVAL" | mail -s "$COMNAME finised on `hostname`" `whoami` if [ $RETVAL -ne 0 ] ; then echo "" && echo "Errored: `LANG=C date '+%c'`" echo -n "[Push enter] " read echo "Some errors were occurred with non-zero status $RETVAL." echo "Please check $TMPDIR/$LOGFILE." rm -f $TMPFILE && exit -1 fi echo "" $QUIET "Finished: `LANG=C date '+%c'`" $MESG "Lapse: `expr $BUILDLAPSE / 60` min `expr $BUILDLAPSE % 60` sec" echo -n "[Push enter] " read NEWRPM=${RPMDIR}/${ARCH}/${NAME}-${KVER}-${NREV}.${ARCH}.rpm if [ -f $NEWRPM ] ; then echo "Created:" for i in `cat $TMPFILE` ; do [ -f $RPMDIR/${ARCH}/$i ] && LANG=C ls $RPMDIR/${ARCH}/$i done else echo "$NEWRPM does not seem to have been created." echo "Please check $TMPDIR/$LOGFILE." rm -f $TMPFILE && exit -1 fi NEWSRPM="${SRPMDIR}/`rpmqueryformat $NEWRPM SOURCERPM`" if [ "$RPMBUILDMODE" = "-ba" ] ; then if [ -f $NEWSRPM ] ; then # echo "Created:" LANG=C ls $NEWSRPM else echo "$NEWSRPM does not seem to have been created." # dont exit! it is trivial fi fi ############################################################ ## clean up if [ "$CLEAN" != "1" ] ;then echo "How do you want $LOGFILE in $TMPDIR?" echo -n "m)move to $HOME r)remove *)leave in $TMPDIR : " read yn yn=`echo $yn | tr -d '[:cntrl:]' | tr '[:upper:]' '[:lower:]'` else yn=r fi if [ "$yn" = "r" ] ; then rm -f $TMPDIR/$LOGFILE elif [ "$yn" = "m" ] ; then if [ -n "$HOME" ] ; then [ "$HOME" != "$TMPDIR" ] && mv -f $TMPDIR/$LOGFILE $HOME gzip --quiet --force --best $HOME/$LOGFILE fi fi askyesno "Do you want to clean up BUILD tree and files in SOURCES?" [ $? = 1 ] && CLEAN=1 if [ "$CLEAN" = "1" ] ;then rpmbuild --rmsource --rmspec --clean --force $NSPEC >/dev/null 2>&1 rm -f $SPEC rm -f $SRCDIR/*.config.mkkpkg fi ############################################################ ## terminates rm -f $TMPFILE exit 0 # vim6: ts=4 tw=0 nolist ai laststatus=2 statusline=%<%f%h%m%r%y%=%l,%c%V\ %P # $Id: mkkpkg,v 1.22 2007/08/09 02:50:53 shaolin Exp $