#!/bin/bash # Build a package source `which ttPM-funcs` 2>/dev/null || exit 1 # The arguments have to be atleast 2. if [ $# -lt 2 ] then printMsg warning "Usage `basename $0` [-s|-b] [-i] package version" printMsg warning "-s: Perform a Pass 1 bootstrap build" printMsg warning "-b: Perform a Pass 2 bootstrap build" printMsg warning "-i: Complete Installation" printMsg warning "Note: Options should be before the package name" error "Incorrect arguments" fi # Set build type based on the passed options BUILD_TYPE="standard" # Build Type TT_DO_NOT_INSTALL=true # Whether to install into / PACKAGE=${1} # Package Name VERSION=${2} # Package Version until [ -z "$1" ] do case "$1" in -s) BUILD_TYPE="static" shift ;; -b) BUILD_TYPE="bootstrap" shift ;; -i) TT_DO_NOT_INSTALL=false shift ;; -*) shift ;; *) PACKAGE="${1}" VERSION="${2}" break ;; esac done # Do not run as root (allow root operating during bootstrap) if [ "$BUILD_TYPE" = "standard" ] then checkNotRoot fi # Convinience vars with PACKAGE, VERSION and BUILD combos PV="$PACKAGE-$VERSION" PB="$PACKAGE-$BUILD_TYPE" PVB="$PACKAGE-$VERSION-$BUILD_TYPE" # Source all the functions in build dir for F in $(find $TT_ETC_DIR/buildFunctions -maxdepth 1 -mindepth 1) do source $F 2>/dev/null done # Function to calculate execution time elapsedTime() { if [ $1 = 1 ] then END_TIME=`date +%s` let ELAPSED_TIME=END_TIME-START_TIME else START_TIME=`date +%s` fi } # Function to add configure options addConfigOpt() { PKG_CONFIG="${PKG_CONFIG} $@" } # Function to add make options addMakeOpt() { PKG_MAKE="${PKG_MAKE} $@" } # Function to extract the src archive and change to the directory. xtractPkg() { # Create build dir and change to that directory cd ${BUILD_DIR} # Xtract the src archive file. There may be multiple archives. for F in ${SRC_FILE} do doTrace $BASH extract ${SOURCE_DIR}/${F} || error "Xtract ${F}" done unset F } # Apply the patches for the particular version patchPkg() { # If the function is called with a parameter, then figure out patches for the supplied parameter if [ $# != 0 ] then PATCH_EXP=${1} else PATCH_EXP="${PV}" fi # Apply all patches matching the expression for P in $(find ${PATCH_DIR} -name "${PATCH_EXP}-*.patch.bz2" -maxdepth 1 2>/dev/null | sort ) do printMsg info "Applying patch `basename ${P}`" # If -p1 fails, try -p0 before giving up #doTrace bzcat ${P} | patch -Np1 -f || doTrace bzcat ${P} | patch -Np0 -f || error Patch doTrace bzcat ${P} | patch -Np1 -f || error Patch done unset PATCH_EXP P } # Install configuration files installConfigPkg() { N=0 while [ "x${CFG_FILE[N]}" != "x" -a "x${CFG_DIR[N]}" != "x" -a "x${CFG_PERM[N]}" != "x" ] do install -d $INSTALL_DIR/${CFG_DIR[N]} if [ -e "${CFG_DIR[N]}/${CFG_FILE[N]}" ] then cp -p ${CFG_DIR[N]}/${CFG_FILE[N]} $INSTALL_DIR/${CFG_DIR[N]} fi if [ ! -e "${INSTALL_DIR}${CFG_DIR[N]}/${CFG_FILE[N]}" ] then install -m ${CFG_PERM[N]} $CONFIG_DIR/${CFG_FILE[N]} $INSTALL_DIR/${CFG_DIR[N]} fi let N=N+1 done unset N } # Compile the package. compilePkg() { : } # Test/Check the package. testPkg() { : } # Install the compiled version of the package. installPkg() { : } # Backup the compiled version of the package backupPkg() { install -d $TT_PKG_BACKUP_DIR cd $TT_PKG_BUILD_DIR tar -cjf $TT_PKG_BACKUP_DIR/install-$PV.tar.bz2 `basename $INSTALL_DIR` if [ "$TT_BACKUP_BUILD" = "build" ] then cd $TT_PKG_BUILD_DIR tar -cjf $TT_PKG_BACKUP_DIR/build-$PV.tar.bz2 `basename $BUILD_DIR` fi } # Relocate pkg from fake root to / relocPkg() { touch ~/.Loggedin sleep 2 cd $INSTALL_DIR tar cf - . | (cd / ; tar xf - 2>&1 | grep -v "Cannot utime" | grep -v "Error exit delayed" ) return 0 } # Remove the build dir cleanPkg() { cd BUILD_SIZE=`du -sh ${BUILD_DIR} | cut -f 1,1` INSTALL_SIZE=`du -sh ${INSTALL_DIR} | cut -f 1,1` rm -rf ${BUILD_DIR} rm -rf ${INSTALL_DIR} } # Things to be done before pkg is relocated preInstallPkg() { : } # Things to be done after pkg is relocated to / postInstallPkg() { : } # Define vars for locations where we can find the neccessary files if [ "$BUILD_TYPE" = "standard" ] then BUILD_FILE_DIR=${TT_PKG_DATA_DIR} PATCH_DIR=${TT_PKG_PATCH_DIR} SOURCE_DIR=${TT_PKG_SRC_DIR} CONFIG_DIR=${TT_PKG_CONFIG_DIR} PKG_CONFIG="--prefix=/usr --sysconfdir=/etc --mandir=/usr/share/man --infodir=/usr/share/info" PKG_MAKE="" PKG_PREFIX=/usr PKG_ETC=/etc else BUILD_FILE_DIR=$TT_HOME_DIR/$PACKAGE/data PATCH_DIR=$TT_HOME_DIR/$PACKAGE/patches SOURCE_DIR=$TT_HOME_DIR/$PACKAGE/src CONFIG_DIR=$TT_HOME_DIR/$PACKAGE/config # Ensure that TT_BOOTSTRAP_PREFIX is defined. checkEnvVar TT_BOOTSTRAP_PREFIX PKG_CONFIG="--prefix=$TT_BOOTSTRAP_PREFIX" PKG_MAKE="" PKG_PREFIX=$TT_BOOTSTRAP_PREFIX PKG_ETC=$TT_BOOTSTRAP_PREFIX/etc fi # Use version specific build file if it exists if [ -f "${BUILD_FILE_DIR}/${PACKAGE}.build" ] then printMsg warning "Using generic build file" BUILD_FILE="${BUILD_FILE_DIR}/${PACKAGE}.build" fi if [ -f "${BUILD_FILE_DIR}/${PV}.build" ] then printMsg warning "Using version specific build file" VERSION_SPECIFIC_BUILD="true" BUILD_FILE="${BUILD_FILE_DIR}/${PV}.build" fi if [ -z ${BUILD_FILE} ] then error "No Build file found, exiting..." fi # Previously installed version of the package (specific to the build type) if [ -f "${TT_PKG_LOCAL_DATA_DIR}/${PB}.version" ] then PREVIOUS=`cat ${TT_PKG_LOCAL_DATA_DIR}/${PB}.version` fi if [ "$BUILD_TYPE" != "standard" ] then PREVIOUS="NA" fi # Print Info. printMsg info "PACKAGE -----------> ${PACKAGE}" printMsg info "VERSION -----------> ${VERSION}" printMsg info "BUILD_TYPE --------> ${BUILD_TYPE}" printMsg info "PREVIOUS ----------> ${PREVIOUS}" printMsg info "BUILD_FILE --------> `basename ${BUILD_FILE}`" # Set the source file and dir # Most common incarnations specified. To override set in build file cd if [ -f "${SOURCE_DIR}/${PACKAGE}_${VERSION}.zip" ] then SRC_FILE=${PACKAGE}_${VERSION}.zip SRC_DIR=${PACKAGE}_${VERSION} fi if [ -f "${SOURCE_DIR}/${PACKAGE}_${VERSION}.tgz" ] then SRC_FILE=${PACKAGE}_${VERSION}.tgz SRC_DIR=${PACKAGE}_${VERSION} fi if [ -f "${SOURCE_DIR}/${PACKAGE}_${VERSION}.tar.gz" ] then SRC_FILE=${PACKAGE}_${VERSION}.tar.gz SRC_DIR=${PACKAGE}_${VERSION} fi if [ -f "${SOURCE_DIR}/${PACKAGE}_${VERSION}.tar.bz2" ] then SRC_FILE=${PACKAGE}_${VERSION}.tar.bz2 SRC_DIR=${PACKAGE}_${VERSION} fi if [ -f "${SOURCE_DIR}/${PACKAGE}${VERSION}.zip" ] then SRC_FILE=${PACKAGE}${VERSION}.zip SRC_DIR=${PACKAGE}${VERSION} fi if [ -f "${SOURCE_DIR}/${PACKAGE}${VERSION}.tgz" ] then SRC_FILE=${PACKAGE}${VERSION}.tgz SRC_DIR=${PACKAGE}${VERSION} fi if [ -f "${SOURCE_DIR}/${PACKAGE}${VERSION}.tar.gz" ] then SRC_FILE=${PACKAGE}${VERSION}.tar.gz SRC_DIR=${PACKAGE}${VERSION} fi if [ -f "${SOURCE_DIR}/${PACKAGE}${VERSION}.tar.bz2" ] then SRC_FILE=${PACKAGE}${VERSION}.tar.bz2 SRC_DIR=${PACKAGE}${VERSION} fi if [ -f "${SOURCE_DIR}/${PACKAGE}-${VERSION}.zip" ] then SRC_FILE=${PACKAGE}-${VERSION}.zip SRC_DIR=${PACKAGE}-${VERSION} fi if [ -f "${SOURCE_DIR}/${PACKAGE}-${VERSION}.tgz" ] then SRC_FILE=${PACKAGE}-${VERSION}.tgz SRC_DIR=${PACKAGE}-${VERSION} fi if [ -f "${SOURCE_DIR}/${PACKAGE}-${VERSION}.tar.gz" ] then SRC_FILE=${PACKAGE}-${VERSION}.tar.gz SRC_DIR=${PACKAGE}-${VERSION} fi if [ -f "${SOURCE_DIR}/${PACKAGE}-${VERSION}.tar.bz2" ] then SRC_FILE=${PACKAGE}-${VERSION}.tar.bz2 SRC_DIR=${PACKAGE}-${VERSION} fi # Set locations where pkgs will be built and installed BUILD_DIR="$TT_PKG_BUILD_DIR/build-${PVB}" INSTALL_DIR="$TT_PKG_BUILD_DIR/install-${PVB}" install -d $BUILD_DIR $INSTALL_DIR # Source the build script. . $BUILD_FILE # Print more info printMsg info "SRC_FILE(S) -------> ${SRC_FILE}" printMsg info "SRC_DIR -----------> ${SRC_DIR}" # See if the build file supports the type of build we are trying to perform. #eval isSupported=\$$BUILD_TYPE #if [ -z $isSupported ] #then #error Build type $BUILD_TYPE is not supported. #fi if [ "$BUILD_TYPE" != "standard" ] && [ -z "`echo $SUPPORTED_BUILD_TYPES | grep $BUILD_TYPE`" ] then error Build type $BUILD_TYPE is not supported. fi # Useful to know which files have been installed by the current version touch ${HOME}/.Loggedin # Sleep to aid packages that have nothing to compile, else installed files are not logged sleep 2 # If Tracing is on, do trace first and then do actual compilation ITERATIONS=1 if [ "z$TT_DO_TRACE" = "ztrue" ] then ITERATIONS="1 2" fi for N in `echo $ITERATIONS` do # Xtract the package if [ ! -f ${BUILD_DIR}/.xtract ] then printMsg fancy "Extracting source files..." FUNC="xtract" logFile xtractPkg || error "Error" unset FUNC touch ${BUILD_DIR}/.xtract fi # Apply patches if [ ! -f ${BUILD_DIR}/.patch ] then printMsg fancy "Applying patches..." cd ${BUILD_DIR}/${SRC_DIR} FUNC="patch" logFile patchPkg || error "Error" unset FUNC touch ${BUILD_DIR}/.patch fi # Compile the pkg if [ ! -f ${BUILD_DIR}/.compile ] then printMsg fancy "Compiling..." elapsedTime 0 cd ${BUILD_DIR}/${SRC_DIR} FUNC="compile" logFile compilePkg || error "Error" unset FUNC elapsedTime 1 echo "$ELAPSED_TIME" > ${BUILD_DIR}/.compile fi # Test the pkg if [ "$BUILD_TYPE" = "standard" -a ! -f "${BUILD_DIR}/.test" ] then printMsg fancy "Testing package..." cd ${BUILD_DIR}/${SRC_DIR} FUNC="test" logFile testPkg unset FUNC touch ${BUILD_DIR}/.test fi # Install the new version (activate wrapper for install, else wrapper scripts won't work) if [ ! -f ${BUILD_DIR}/.install ] then export TT_WRAPPER="true" printMsg fancy "Installing in fake root..." elapsedTime 0 cd ${BUILD_DIR}/${SRC_DIR} FUNC="install" logFile installPkg || error "Error" unset FUNC FUNC="installConfig" logFile installConfigPkg || error "Error" unset FUNC elapsedTime 1 unset TT_WRAPPER echo "$ELAPSED_TIME" > ${BUILD_DIR}/.install fi # If we are tracing clean out the build dir if [ "z$TT_DO_TRACE" = "ztrue" ] then printMsg fancy "Cleaning up..." cleanPkg TT_DO_TRACE="" fi done # Maintainence on INSTALL_DIR # Clean up static libraries and libtool files # Compress man and info pages # Clean unneeded documents # Clean up symlinks printMsg fancy "Trimming installation..." find $INSTALL_DIR | xargs chmod u+rw processLibs for D in $TT_PKG_DOC_DIRS $DOC_DIRS do compressDoc $INSTALL_DIR$D done cleanInstallDir for F in $(find $INSTALL_DIR -type f) do stripFile $F done checkInstallDir # Exit point if we need to verify the installation in fake root before installing. if [ "z$TT_DO_NOT_INSTALL" = "ztrue" ] then printMsg info "Fake installation is in $INSTALL_DIR" printMsg info "Rerun script to complete installation" makeNoise 2>/dev/null exit 0 fi # Backup the pkg # Only backup if we are not using a version specific build if [ "z$TT_BACKUP_BUILD" != "znone" ] && [ "$BUILD_TYPE" = "standard" ] && [ -z $VERSION_SPECIFIC_BUILD ] then printMsg fancy "Backing up..." backupPkg fi # Calculate elapsed time E_TIME=0 let E_TIME=${E_TIME}+`cat $BUILD_DIR/.compile 2>/dev/null`+0 2>/dev/null let E_TIME=${E_TIME}+`cat $BUILD_DIR/.install 2>/dev/null`+0 2>/dev/null # Perform pre-installation routines printMsg fancy "Performing pre-installation operations..." preInstallPkg || error "Error" # Relocate pkg from fake install root to its final destination printMsg fancy "Relocating pkg in its final location..." relocPkg || error "Error" # Perform post-installation routines printMsg fancy "Performing post-installation operations..." postInstallPkg || error "Error" # Clean the pkg printMsg fancy "Cleaning up..." cleanPkg printMsg info "Time required to install package: $E_TIME secs" printMsg info "Build Size: $BUILD_SIZE" printMsg info "Install Size: $INSTALL_SIZE" # If we are performing a bootstrap/static build, exit now. if [ "$BUILD_TYPE" != "standard" ] then # Create the log for the current version $BASH logInstalledFiles ${PVB} exit 0 fi # Store accumulated data DT=`date --utc +"%F %T"` echo "${PV} [${BUILD_TYPE}] [$DT]: $E_TIME secs" >> ${TT_PKG_LOCAL_DATA_DIR}/$PACKAGE.time echo "${PV} [${BUILD_TYPE}] [$DT]: $BUILD_SIZE" >> ${TT_PKG_LOCAL_DATA_DIR}/$PACKAGE.buildSize echo "${PV} [${BUILD_TYPE}] [$DT]: $INSTALL_SIZE" >> ${TT_PKG_LOCAL_DATA_DIR}/$PACKAGE.installSize # Store information of the current version if [ -z $VERSION_SPECIFIC_BUILD ] then echo "$VERSION" > ${TT_PKG_LOCAL_DATA_DIR}/${PB}.version fi # Update files printMsg info "Updating files & permissions..." ldconfig -X 2>/dev/null changeUser ldconfig -X changeUser changePerms 2>&1>/dev/null # Create the log for the current version $BASH logInstalledFiles ${PVB} # Recreate pkg files pkgFiles # Wind up makeNoise 2>/dev/null