#!/bin/bash ########################################################## #VBuild - Package build script for use on VectorLinux 5.8# ########################################################## #Eugene Suter # #You are free to modify this scrip under the terms of the# #GNU General Public License. # ########################################################## #Version 0.2 ########################################################## TMP=/tmp CWD=`pwd` NAME=powertop VERSION=1.2 ARCH=i586 RELEASE=1vl58 #CONFIG_FLAGS=" --prefix=/usr --sysconfdir=/etc --mandir=/usr/man --with-included-gettext" BUILD_DIR=$TMP/$NAME-package DESTDIR=$BUILD_DIR/dest REBUILD_DIR=$BUILD_DIR/rebuild TARBALL_NAME=$NAME-$VERSION.tar.* #Chose between tgz, tlz org tbz package formats here. PKG_FORMAT=tlz PKG_DEST=$TMP/finished-packages PKG=$NAME-$VERSION-$ARCH-$RELEASE.$PKG_FORMAT #Chose either Y or N USE_CHECKINSTALL=Y CLEANUP=Y #Packager name VL_PACKAGER=easuter ##Funtions go here: #See if requiredbuilder is installed #Check if script is being run with root privilages function authenticate() { if [ $UID != 0 ]; then echoc "You need to be root to run this script." red exit fi } #Make sure the package has a destination directory function chk_destination() { if [ ! -d $PKG_DEST ]; then mkdir -p $PKG_DEST fi } #Clean out any possible interfering files and directories # and create build directories function mk_build_dirs() { rm -rf $BUILD_DIR mkdir -p $BUILD_DIR mkdir -p $REBUILD_DIR mkdir -p $DESTDIR } #Get the source code prepared function prepare_src() { cd $BUILD_DIR cp $CWD/$TARBALL_NAME ./ tar xvf $BUILD_DIR/$TARBALL_NAME cd $NAME-$VERSION } #Do some custom stuff here (like headers hacking, custom makefiles, etc) #function do_custom() #{ # #} #Connfigure the source code function config_src() { #Start with an architecture breakdown: if [ $ARCH = "i586" ]; then export CFLAGS="-O2 -mtune=i686 -march=i586" fi if [ $ARCH = "i486" ]; then export CFLAGS="-O2 -mtune=i686 -march=i486" fi if [ $ARCH = "i386" ]; then export CFLAGS="-O2 -mtune=i686 -march=i386" fi export CXXFLAGS="$CFLAGS" #Give root ownership of the files: chown -R root.root ./ #Powertop does not use a configure script for its souces. #./configure $CONFIG_FLAGS } #Append configure switches and environment info to the package #description: function mk_config_info() { cp $CWD/slack-desc ./description-pak cat >> description-pak << EOF #---------------------------------------- BUILDDATE: `date` PACKAGER: $VL_PACKAGER HOST: `uname -srm` DISTRO: `cat /etc/vector-version` CFLAGS: $CFLAGS CONFIGURE: `awk "/\.\/configure\ /" config.log` EOF } #Build the sources and exit if it fails. function build() { make if ( ! make ); then echoc "Make failed!" red exit fi } #Build the package (checkinstall is the default option, but using the #"traditional" method is also available function mk_package() { if [ $USE_CHECKINSTALL = "Y" ]; then if [ $PKG_FORMAT = "tlz" ]; then CHKINST_TYPE="-L" elif [ $PKG_FORMAT = "tgz" ]; then CHKINST_TYPE="-G" else CHKINST_TYPE="-B" fi checkinstall $CHKINST_TYPE -y --pkgarch=$ARCH --pkgversion=$VERSION --pkgrelease=$RELEASE --pkgname=$NAME if [ ! -f $PKG ]; then echoc "Checkinstall failed to create the package!" exit fi else make DESTDIR=$DESTDIR install mkdir $DESTDIR/install cp ./description-pak $DESTDIR/install/slack-desc cd $DESTDIR requiredbuilder -v -y ./ #Strip debug code from executables and libraries (thanks P.Volkerding #for this bit of code) find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null makepkg -l y -c n $PKG fi } #If a package built with checkinstall needs to be exploded to include #extra files, then this function will do it function rebuild_pkg() { cp $PKG $REBUILD_DIR cd $REBUILD_DIR explodepkg $PKG rm $PKG #Do whatever you like here # # makepkg $PKG } ##The actual script only starts here :) if [ $USE_CHECKINSTALL = "N" ]; then if [ ! -e /usr/bin/requiredbuilder ]; then echoc "Requiredbuilder is not installed." red echoc "Sorry boss, won't build the package!" red exit fi fi authenticate chk_destination mk_build_dirs #do_custom prepare_src config_src mk_config_info build mk_package #rebuild_pkg cp $PKG $PKG_DEST echoc "$NAME package built successfully! It is in $PKG_DEST" green if [ $CLEANUP = "Y" ]; then rm -rf $BUILD_DIR fi #EOF