#!/bin/bash # Version: 1.6 GSB SlackBuild. # Copyright (c) 2007 Darren 'Tadgy' Austin # # Licenced under the terms of the GNU General Public Licence version 3. # # Make sure we are in the right directory (you can never trust users..) cd $( cd ${BASH_SOURCE%/*} ; pwd ) # If the user created an options file, read it. [ -r ./gsb.options ] && { . ./gsb.options export OPTIONSREAD=1 } # The default list of GSB sections, in the order they should be processed. SECTIONS="${GSB_SECTIONS:- tools libraries platform desktop bindings applications accessibility administration office mono extras themes compiz networking ooo meta testing }" # Usage. function usage() { cat << EOF Usage: ${0##*/} [options] Options: --help Show this help screen. --list List the packages which will be built in this section. --force A package will not be built if a package of the same name is already installed, or any of the pre-requisite packages are not installed. This option over-rides the checks and attempts a build (which will probably fail) anyway. --no-cleanup By default, any source, temporary build and package directories will be deleted once the package is built. This option prevents those files from being removed. --no-patchesdir When rebuilding packages which already exist in the main package directory, the default is to put the new packages in the patches directory. Using this option completely disables the use of a patches directory. --no-skip During the build process, packages that are up to date (ie, the package version and build numbers match the coresponding SlackBuild) will not be rebuilt. This option forces packages to be rebuilt regardless of the version and build numbers. This option doesn't affect the pre-build checks for installed packages (see the --force option). This option implies --no-patchesdir. --no-prune Normally, when a package is built and copied to the destination directory (whether it be the main package directory or the patches directory), any previous package(s) of the same name in that directory are deleted - it is assumed the new package is to replace any which are already present. This option prevents previous packages being deleted, possibly leaving more than one package of the same name (but with different version or build numbers) laying around. --no-install Build the packages but don't install them afterwards. This should only be used for testing as it WILL cause serious problems - most builds rely on other GSB packages being automatically installed first. --no-metafiles Do not create the package's .txt and .md5 meta files which would usually be produced during a build. Options are passed down to the next level SlackBuild where appropriate. EOF } function list_packages() { echo "The sections and packages listed below (in processing order) will be built." for SECTION in $SECTIONS do echo echo " $SECTION:" echo "$( $SECTION/gsb.$SECTION.SlackBuild --list | cut -d$'\n' -f2- )" done } function runtime() { # $1 = Number of seconds to convert to readable text [required] [ -z "$1" ] && return 1 local D=$(( $1 / 86400 )) local H=$(( ($1 - ($D * 86400)) / 3600 )) local M=$(( ($1 - ($D * 86400) - ($H * 3600)) / 60 )) local S=$(( $1 - ($D * 86400) - ($H * 3600) - ($M * 60) )) if [ $D -gt 0 ]; then echo -n "${D}d, ${H}h ${M}m ${S}s" else echo -n "${H}h, ${M}m ${S}s" fi return 0 } function gen_packages_txt() { # $1 = Sub-directory to process [required] # $2 = Sub-directory to put PACKAGES.TXT in, or empty for current directory [ -z "$1" ] && return 1 { echo -e "PACKAGES.TXT; $( date )\n\n" for FILE in $( find ./$1 -name \*.tgz \( -type f -o -type l \) \ -printf "%f %p\n" | sort -k1 -f | cut -d' ' -f2 ) do SIZES="$( gunzip -l $FILE | tail -n 1 | tr -s ' ' )" echo "PACKAGE NAME: $( echo $FILE | rev | cut -d/ -f1 | rev )" echo "PACKAGE LOCATION: $( echo $FILE | rev | cut -d/ -f2- | rev )" echo "PACKAGE SIZE (compressed): $(( $( echo \"$SIZES\" | cut -d' ' -f2 ) / 1024 )) K" echo "PACKAGE SIZE (uncompressed): $(( $( echo \"$SIZES\" | cut -d' ' -f3 ) / 1024 )) K" echo "PACKAGE REQUIRED: $( tar zxOf $FILE --occurrence=1 install/slack-required 2>/dev/null | tr '\n' ',' | sed -e 's/,$//' )" echo "PACKAGE CONFLICTS: $( tar zxOf $FILE --occurrence=1 install/slack-conflicts 2>/dev/null | tr '\n' ',' | sed -e 's/,$//' )" echo "PACKAGE SUGGESTS: $( tar zxOf $FILE --occurrence=1 install/slack-suggests 2>/dev/null | tr '\n' ' ' )" echo "PACKAGE DESCRIPTION:" tar xzOf $FILE --occurrence=1 install/slack-desc 2>/dev/null | grep -v "^#" | egrep "[[:alnum:]\+]+\:" echo done } >${2:-.}/PACKAGES.TXT 2>/dev/null cat ${2:-.}/PACKAGES.TXT | gzip -9c >${2:-.}/PACKAGES.TXT.gz 2>/dev/null } function gen_filelist_txt() { # $1 = Sub-directory to process [required] # $2 = Sub-directory to put FILELIST.TXT in, or empty for current directory [ -z "$1" ] && return 1 ( cd $1 echo -e "FILELIST.TXT; $( date )\n\n" find . ! -wholename ./FILELIST.TXT ! -wholename ./FILELIST.TXT.gz \ ! -wholename ./CHECKSUMS.md5 ! -wholename ./CHECKSUMS.md5.gz | \ sort | xargs ls -ld ) >${2:-.}/FILELIST.TXT 2>/dev/null cat ${2:-.}/FILELIST.TXT | gzip -9c >${2:-.}/FILELIST.TXT.gz 2>/dev/null } function gen_checksums_md5() { # $1 = Sub-directory to process [required] # $2 = Sub-directory to put CHECKSUMS.md5 in, or empty for current directory [ -z "$1" ] && return 1 ( cd $1 echo -e "CHECKSUMS.md5; $( date )\n\n" echo "MD5 Filename" find . ! -wholename ./CHECKSUMS.md5 ! -wholename ./CHECKSUMS.md5.gz \ ! -name \*.tgz.md5 \( -type f -o -type l \) -exec md5sum {} \; | \ sort -k2 -f ) >${2:-.}/CHECKSUMS.md5 2>/dev/null cat ${2:-.}/CHECKSUMS.md5 | gzip -9c >${2:-.}/CHECKSUMS.md5.gz 2>/dev/null } # Environment. export TMP=${TMP:-/tmp} if [ "$ARCH" = "x86_64" ]; then export PKGDEST=${PKGDEST:-$TMP/gsb64-tree} export LOGSDIR=${LOGSDIR:-$TMP/gsb64-buildlogs} else export PKGDEST=${PKGDEST:-$TMP/gsb-tree} export LOGSDIR=${LOGSDIR:-$TMP/gsb-buildlogs} fi export GSBDIR=${GSBDIR:-gsb} export PATCHESDIR=${PATCHESDIR:-patches} export TESTINGDIR=${TESTINGDIR:-testing} export PACKAGESDIR=${PACKAGESDIR:-packages} export SOURCEDIR=${SOURCEDIR:-source} # Option defaults. NOMETAFILES=0 # Parse command line arguments. while [ $# -gt 0 ]; do if [ "$1" = "-help" ] || [ "$1" = "--help" ]; then usage exit 0 elif [ "$1" = "-list" ] || [ "$1" = "--list" ]; then list_packages exit 0 elif [ "$1" = "-force" ] || [ "$1" = "--force" ]; then SLACKBUILD_ARGS="${SLACKBUILD_ARGS:+"$SLACKBUILD_ARGS "}--force" shift elif [ "$1" = "-no-cleanup" ] || [ "$1" = "--no-cleanup" ]; then SLACKBUILD_ARGS="${SLACKBUILD_ARGS:+"$SLACKBUILD_ARGS "}--no-cleanup" shift elif [ "$1" = "-no-patchesdir" ] || [ "$1" = "--no-patchesdir" ]; then SLACKBUILD_ARGS="${SLACKBUILD_ARGS:+"$SLACKBUILD_ARGS "}--no-patchesdir" shift elif [ "$1" = "-no-skip" ] || [ "$1" = "--no-skip" ]; then SLACKBUILD_ARGS="${SLACKBUILD_ARGS:+"$SLACKBUILD_ARGS "}--no-skip" shift elif [ "$1" = "-no-prune" ] || [ "$1" = "--no-prune" ]; then SLACKBUILD_ARGS="${SLACKBUILD_ARGS:+"$SLACKBUILD_ARGS "}--no-prune" shift elif [ "$1" = "-no-install" ] || [ "$1" = "--no-install" ]; then SLACKBUILD_ARGS="${SLACKBUILD_ARGS:+"$SLACKBUILD_ARGS "}--no-install" shift elif [ "$1" = "-no-metafiles" ] || [ "$1" = "--no-metafiles" ]; then SLACKBUILD_ARGS="${SLACKBUILD_ARGS:+"$SLACKBUILD_ARGS "}--no-metafiles" NOMETAFILES=1 shift else echo "${0##*/}: Unknown option: $1" echo "Try: $0 --help" exit 1 fi done # Temporary space, package and log file storage. mkdir -p $TMP mkdir -p $PKGDEST mkdir -p $LOGSDIR # Make sure /usr/include/db.h points to the db4 header. ( cd /usr/include && rm -f db.h && ln -s db4/db.h db.h ) || { echo "${0##*/}: Could not set db.h header" exit 1 } # Do the build. ( echo echo "*********************************************************************" echo "* Building GSB - this will take a while..." echo "*********************************************************************" for SECTION in $SECTIONS do ( cd $SECTION && ./gsb.$SECTION.SlackBuild $SLACKBUILD_ARGS 2>&1 ) || { echo echo "*********************************************************************" echo "* Build aborted: error building in section '$SECTION'." echo "* Check the build logs in:" echo "* $LOGSDIR" echo "* and try again after correcting the error." echo "*********************************************************************" echo "* Build failed after $( runtime $SECONDS )." echo "*********************************************************************" exit 1 } done cp ../{COPYING,CREDITS,README} $PKGDEST # cp ../{COPYING,CREDITS,README,UPGRADING} $PKGDEST cp testing/README $PKGDEST/testing if [ "$ARCH" = "x86_64" ]; then cp ../ChangeLog.slamd64 $PKGDEST/ChangeLog cp ../VERSIONS.slamd64 $PKGDEST/VERSIONS else cp ../ChangeLog.slackware $PKGDEST/ChangeLog cp ../VERSIONS.slackware $PKGDEST/VERSIONS fi ( cd $PKGDEST && ln -sf ChangeLog ChangeLog.txt ) if [ "$NOMETAFILES" = "0" ]; then echo echo "*********************************************************************" echo "* Generating final meta files - this may take a while..." echo "*********************************************************************" echo "* If you like our GNOME desktop, plan to use it for a commercial" echo "* product/service or just want to spread some goodwill, please visit" echo "* the GNOME SlackBuild website: and" echo "* make a paypal donation to the project. Thanks! :) ~The GSB team" echo "*********************************************************************" ( cd $PKGDEST && for DIR in $GSBDIR $PATCHESDIR $TESTINGDIR do [ -d $DIR ] && { gen_packages_txt $DIR/$PACKAGESDIR $DIR gen_filelist_txt $DIR $DIR gen_checksums_md5 $DIR $DIR } done ln -sf $GSBDIR/PACKAGES.TXT PACKAGES.TXT ln -sf $GSBDIR/PACKAGES.TXT.gz PACKAGES.TXT.gz gen_filelist_txt . gen_checksums_md5 . ) else echo echo "*********************************************************************" echo "*** Warning: not creating final meta files." echo "*********************************************************************" fi echo echo "*********************************************************************" echo "* Finished building GSB!" echo "* GSB was sucessfully built and installed on the system." echo "* See the README file for details on how to start GNOME." echo "*********************************************************************" echo "* The complete GSB binary tree can be found in:" echo "* $PKGDEST" echo "* Build logs can be found in:" echo "* $LOGSDIR" echo "* The binary tree and build logs can be deleted if not required." echo "*********************************************************************" echo "* Complete build time was $( runtime $SECONDS )." echo "*********************************************************************" ) 2>&1 | tee $LOGSDIR/$( basename $0 .SlackBuild )-$( date +%Y%m%d-%H%M%S ).log # Return the exit status from the sub-shell, not the tee command. exit ${PIPESTATUS[0]}