diff options
Diffstat (limited to 'scripts/makepkg')
-rwxr-xr-x | scripts/makepkg | 190 |
1 files changed, 114 insertions, 76 deletions
diff --git a/scripts/makepkg b/scripts/makepkg index 10c1c2a0..977efdeb 100755 --- a/scripts/makepkg +++ b/scripts/makepkg @@ -20,8 +20,9 @@ # USA. # -myver='2.7' +myver='2.7.1' startdir=`pwd` +USE_COLOR="n" # source Arch's abs.conf if it's present [ -f /etc/abs/abs.conf ] && source /etc/abs/abs.conf @@ -37,8 +38,33 @@ fi ### SUBROUTINES ### +plain() { + if [ "$USE_COLOR" = "Y" -o "$USE_COLOR" = "y" ]; then + echo -e " \033[1;1m$1\033[1;0m" >&2 + else + echo " $1" >&2 + fi +} msg() { - echo "$1" >&2 + if [ "$USE_COLOR" = "Y" -o "$USE_COLOR" = "y" ]; then + echo -e "\033[1;32m==>\033[1;0m \033[1;1m$1\033[1;0m" >&2 + else + echo "==> $1" >&2 + fi +} +warning() { + if [ "$USE_COLOR" = "Y" -o "$USE_COLOR" = "y" ]; then + echo -e "\033[1;33m==> WARNING:\033[1;0m \033[1;1m$1\033[1;0m" >&2 + else + echo "==> WARNING: $1" >&2 + fi +} +error() { + if [ "$USE_COLOR" = "Y" -o "$USE_COLOR" = "y" ]; then + echo -e "\033[1;31m==> ERROR:\033[1;0m \033[1;1m$1\033[1;0m" >&2 + else + echo "==> ERROR: $1" >&2 + fi } strip_url() { @@ -53,7 +79,7 @@ checkdeps() { ret=$? if [ "$ret" != "0" ]; then if [ "$ret" = "127" ]; then - msg "==> Missing Dependencies:" + msg "Missing Dependencies:" msg "" nl=0 for dep in $missdep; do @@ -70,7 +96,7 @@ checkdeps() { done msg "" else - msg "==> ERROR: pacman returned a fatal error." + error "pacman returned a fatal error." exit 1 fi fi @@ -88,10 +114,10 @@ handledeps() { if [ "$deplist" != "" -a $haveperm -eq 1 ]; then if [ "$DEP_BIN" = "1" ]; then # install missing deps from binary packages (using pacman -S) - msg "==> Installing missing dependencies..." + msg "Installing missing dependencies..." pacman -D $deplist if [ "$?" = "127" ]; then - msg "==> ERROR: Failed to install missing dependencies." + error "Failed to install missing dependencies." exit 1 fi # TODO: check deps again to make sure they were resolved @@ -99,15 +125,15 @@ handledeps() { # install missing deps by building them from source. # we look for each package name in $ABSROOT and build it. if [ "$ABSROOT" = "" ]; then - msg "==> ERROR: The ABSROOT environment variable is not defined." + error "The ABSROOT environment variable is not defined." exit 1 fi # TODO: handle version comparators (eg, glibc>=2.2.5) - msg "==> Building missing dependencies..." + msg "Building missing dependencies..." for dep in $deplist; do candidates=`find $ABSROOT -type d -name "$dep"` if [ "$candidates" = "" ]; then - msg "==> ERROR: Could not find \"$dep\" under $ABSROOT" + error "Could not find \"$dep\" under $ABSROOT" exit 1 fi success=0 @@ -126,7 +152,7 @@ handledeps() { fi done if [ "$success" = "0" ]; then - msg "==> ERROR: Failed to build \"$dep\"" + error "Failed to build \"$dep\"" exit 1 fi done @@ -136,8 +162,8 @@ handledeps() { fi elif [ "$deplist" != "" -a $haveperm -eq 0 ]; then if [ "$DEP_SRC" = "1" -o "$DEP_BIN" = "1" ]; then - msg "==> WARNING: Cannot auto-install missing dependencies as a normal user!" - msg "==> Run makepkg as root to resolve dependencies automatically." + warning "Cannot auto-install missing dependencies as a normal user!" + plain "Run makepkg as root to resolve dependencies automatically." fi missingdeps=1 fi @@ -156,6 +182,7 @@ usage() { echo " -g, --genmd5 Generate MD5sums for source files" echo " -h, --help This help" echo " -i, --install Install package after successful build" + echo " -m, --nocolor Disable colorized output messages" echo " -n, --nostrip Do not strip binaries/libraries" echo " -p <buildscript> Use an alternate build script (instead of PKGBUILD)" echo " -r, --rmdeps Remove installed dependencies after a successful build" @@ -194,6 +221,7 @@ while [ "$#" -ne "0" ]; do --install) INSTALL=1 ;; --force) FORCE=1 ;; --nostrip) NOSTRIP=1 ;; + --nocolor) USE_COLOR="n" ;; --genmd5) GENMD5=1 ;; --rmdeps) RMDEPS=1 ;; --help) @@ -205,7 +233,7 @@ while [ "$#" -ne "0" ]; do exit 1 ;; -*) - while getopts "cCsbdhifgnrp:w:-" opt; do + while getopts "cCsbdhifgmnrp:w:-" opt; do case $opt in c) CLEANUP=1 ;; C) CLEANCACHE=1 ;; @@ -215,6 +243,7 @@ while [ "$#" -ne "0" ]; do i) INSTALL=1 ;; g) GENMD5=1 ;; f) FORCE=1 ;; + m) USE_COLOR="n" ;; n) NOSTRIP=1 ;; w) PKGDEST=$OPTARG ;; p) BUILDSCRIPT=$OPTARG ;; @@ -248,11 +277,11 @@ cd - if [ "$CLEANCACHE" = "1" ]; then if [ "`id -u`" = "0" -a "$INFAKEROOT" != "1" ]; then - msg "==> Cleaning up source files from the cache." + msg "Cleaning up source files from the cache." rm -rf /var/cache/pacman/src/* exit 0 else - msg "==> You must be root to clean the cache." + error "You must be root to clean the cache." exit 1 fi fi @@ -262,7 +291,7 @@ unset replaces depends conflicts backup source install build makedepends umask 0022 if [ ! -f $BUILDSCRIPT ]; then - msg "==> ERROR: $BUILDSCRIPT does not exist." + error "$BUILDSCRIPT does not exist." exit 1 fi @@ -270,21 +299,21 @@ source $BUILDSCRIPT # check for no-no's if [ `echo $pkgver | grep '-'` ]; then - msg "==> ERROR: pkgver is not allowed to contain hyphens." + error "pkgver is not allowed to contain hyphens." exit 1 fi if [ `echo $pkgrel | grep '-'` ]; then - msg "==> ERROR: pkgrel is not allowed to contain hyphens." + error "pkgrel is not allowed to contain hyphens." exit 1 fi if [ -f $PKGDEST/${pkgname}-${pkgver}-${pkgrel}.pkg.tar.gz -a "$FORCE" = "0" -a "$GENMD5" = "0" ]; then if [ "$INSTALL" = "1" ]; then - msg "==> WARNING: a package has already been built, installing existing package." + warning "a package has already been built, installing existing package." pacman --upgrade $PKGDEST/${pkgname}-${pkgver}-${pkgrel}.pkg.tar.gz exit $? else - msg "==> ERROR: a package has already been built. (use -f to overwrite)" + error "a package has already been built. (use -f to overwrite)" exit 1 fi fi @@ -294,86 +323,86 @@ fi if [ "`id -u`" != "0" ]; then if [ "$USE_FAKEROOT" = "y" -o "$USE_FAKEROOT" = "Y" ]; then if [ `type -p fakeroot` ]; then - msg "==> Entering fakeroot environment" + msg "Entering fakeroot environment" fakeroot -- $0 -F $ARGLIST exit $? else - msg "==> WARNING: Fakeroot is not installed. Building as an unprivileged user" - msg "==> will result in non-root ownership of the packaged files." - msg "==> Install the fakeroot package to correctly build as a non-root" - msg "==> user." - msg "" + warning "Fakeroot is not installed. Building as an unprivileged user" + plain "will result in non-root ownership of the packaged files." + plain "Install the fakeroot package to correctly build as a non-root" + plain "user." + plain "" sleep 1 fi else - msg "==> WARNING: Running makepkg as an unprivileged user will result in non-root" - msg "==> ownership of the packaged files. Try using the fakeroot" - msg "==> environment. (USE_FAKEROOT=y in makepkg.conf)" - msg "" + warning "Running makepkg as an unprivileged user will result in non-root" + plain "ownership of the packaged files. Try using the fakeroot" + plain "environment. (USE_FAKEROOT=y in makepkg.conf)" + plain "" sleep 1 fi fi -msg "==> Making package: $pkgname (`date`)" +msg "Making package: $pkgname (`date`)" unset deplist makedeplist if [ `type -p pacman` -a "$NODEPS" = "0" ]; then - msg "==> Checking Runtime Dependencies..." + msg "Checking Runtime Dependencies..." deplist=`checkdeps ${depends[@]}` handledeps $deplist if [ $? -gt 0 ]; then exit 1 fi - msg "==> Checking Buildtime Dependencies..." + msg "Checking Buildtime Dependencies..." makedeplist=`checkdeps ${makedepends[@]}` handledeps $makedeplist if [ $? -gt 0 ]; then exit 1 fi elif [ "$NODEPS" = "1" ]; then - msg "==> WARNING: skipping dependency checks." + warning "skipping dependency checks." else - msg "==> WARNING: pacman was not found in PATH. skipping dependency checks." + warning "pacman was not found in PATH. skipping dependency checks." fi cd $startdir # retrieve sources -msg "==> Retrieving Sources..." +msg "Retrieving Sources..." mkdir -p src cd $startdir/src for netfile in ${source[@]}; do file=`strip_url $netfile` if [ -f ../$file ]; then - msg " |=> Found $file in build dir" + msg " Found $file in build dir" cp ../$file . elif [ -f /var/cache/pacman/src/$file ]; then - msg " |=> Using local copy of $file" + msg " Using local copy of $file" cp /var/cache/pacman/src/$file . else # check for a download utility if [ -z "$FTPAGENT" ]; then - msg "==> ERROR: FTPAGENT is not configured. Check the /etc/makepkg.conf file." - msg "==> Aborting..." + error "FTPAGENT is not configured. Check the /etc/makepkg.conf file." + msg "Aborting..." exit 1 fi ftpclient=`echo $FTPAGENT | awk {'print $1'}` if [ ! -x $ftpclient ]; then - msg "==> ERROR: ftpclient `basename $ftpclient` is not installed." - msg "==> Aborting..." + error "ftpclient `basename $ftpclient` is not installed." + msg "Aborting..." exit 1 fi proto=`echo $netfile | sed 's|://.*||'` if [ "$proto" != "ftp" -a "$proto" != "http" ]; then - msg "==> ERROR: $netfile was not found in the build directory and is not a proper URL." - msg "==> Aborting..." + error "$netfile was not found in the build directory and is not a proper URL." + msg "Aborting..." exit 1 fi - msg " |=> Downloading $file" + msg " Downloading $file" $FTPAGENT $netfile 2>&1 if [ ! -f $file ]; then - msg "==> ERROR: Failed to download $file" - msg "==> Aborting..." + error "Failed to download $file" + msg "Aborting..." exit 1 fi if [ "`id -u`" = "0" -a "$INFAKEROOT" != "1" ]; then @@ -387,15 +416,15 @@ done if [ "$GENMD5" = "0" ]; then # MD5 validation if [ ${#md5sums[@]} -ne ${#source[@]} ]; then - msg "==> WARNING: MD5sums are missing or incomplete. Cannot verify source integrity." + warning "MD5sums are missing or incomplete. Cannot verify source integrity." #sleep 1 elif [ `type -p md5sum` ]; then - msg "==> Validating source files with MD5sums" + msg "Validating source files with MD5sums" errors=0 idx=0 for netfile in ${source[@]}; do file=`strip_url $netfile` - echo -n " |=> $file ... " >&2 + echo -n " $file ... " >&2 echo "${md5sums[$idx]} $file" | md5sum -c - >/dev/null 2>&1 if [ $? -ne 0 ]; then echo "FAILED" >&2 @@ -406,15 +435,15 @@ if [ "$GENMD5" = "0" ]; then idx=$(($idx+1)) done if [ $errors -gt 0 ]; then - msg "==> ERROR: One or more files did not pass the validity check!" + error "One or more files did not pass the validity check!" exit 1 fi else - msg "==> WARNING: The md5sum program is missing. Cannot verify source files!" + warning "The md5sum program is missing. Cannot verify source files!" sleep 1 fi # extract sources - msg "==> Extracting Sources..." + msg "Extracting Sources..." for netfile in ${source[@]}; do file=`strip_url $netfile` unset cmd @@ -433,11 +462,11 @@ if [ "$GENMD5" = "0" ]; then cmd="bunzip2 $file" ;; esac if [ "$cmd" != "" ]; then - msg " |=> $cmd" + msg " $cmd" $cmd if [ $? -ne 0 ]; then - msg "==> ERROR: Failed to extract $file" - msg "==> Aborting..." + error "Failed to extract $file" + msg "Aborting..." exit 1 fi fi @@ -445,12 +474,13 @@ if [ "$GENMD5" = "0" ]; then else # generate md5 hashes if [ ! `type -p md5sum` ]; then - msg "==> ERROR: Cannot find the md5sum program." + error "Cannot find the md5sum program." exit 1 fi - msg "==> Generating MD5sums for source files" - msg "" + msg "Generating MD5sums for source files" + plain "" ct=0 + newline=0 numsrc=${#source[@]} for netfile in ${source[@]}; do file=`strip_url $netfile` @@ -458,17 +488,25 @@ else if [ $ct -eq 0 ]; then echo -n "md5sums=(" else - echo -ne "\t" + if [ $newline -eq 0 ]; then + echo -n " " + fi fi echo -n "'$sum'" ct=$(($ct+1)) if [ $ct -eq $numsrc ]; then echo ')' else - echo ' \' + if [ $newline -eq 1 ]; then + echo '\' + newline=0 + else + echo -n ' ' + newline=1 + fi fi done - msg "" + plain "" exit 0 fi @@ -480,16 +518,16 @@ fi # check for existing pkg directory if [ -d $startdir/pkg ]; then - msg "==> Removing existing pkg directory..." + msg "Removing existing pkg directory..." rm -rf $startdir/pkg fi mkdir -p $startdir/pkg # build -msg "==> Starting build()..." +msg "Starting build()..." build 2>&1 if [ $? -gt 0 ]; then - msg "==> Build Failed. Aborting..." + error "Build Failed. Aborting..." exit 2 fi @@ -514,7 +552,7 @@ fi # compress man pages if [ -d pkg/usr/man ]; then - msg "==> Compressing man pages..." + msg "Compressing man pages..." for i in `find pkg/usr/man -type f`; do ext=`echo $i | sed 's|.*\.||g'` fn=`echo $i | sed 's|.*/||g'` @@ -534,9 +572,9 @@ cd $startdir # strip binaries if [ "$NOSTRIP" = "0" ]; then - msg "==> Stripping debugging symbols from libraries..." + msg "Stripping debugging symbols from libraries..." find pkg/{,usr,usr/local,opt/*}/lib -type f -exec /usr/bin/strip --strip-debug '{}' \; 2>&1 - msg "==> Stripping symbols from binaries..." + msg "Stripping symbols from binaries..." find pkg/{,usr,usr/local,opt/*}/{bin,sbin} -type f -exec /usr/bin/strip '{}' \; 2>&1 fi @@ -550,7 +588,7 @@ fi size=`du -cb $startdir/pkg | tail -1 | awk '{print $1}'` # write the .PKGINFO file -msg "==> Generating .PKGINFO file..." +msg "Generating .PKGINFO file..." cd $startdir/pkg echo "# Generated by makepkg $myver" >.PKGINFO echo -n "# " >>.PKGINFO @@ -584,17 +622,17 @@ done # check for an install script if [ "$install" != "" ]; then - msg "==> Copying install script..." + msg "Copying install script..." cp $startdir/$install $startdir/pkg/.INSTALL fi # build a filelist -msg "==> Generating .FILELIST file..." +msg "Generating .FILELIST file..." cd $startdir/pkg tar cvf /dev/null * | sort >.FILELIST # tar it up -msg "==> Compressing package..." +msg "Compressing package..." cd $startdir/pkg if [ -f $startdir/pkg/.INSTALL ]; then cmd="tar czvf $PKGDEST/$pkgname-$pkgver-$pkgrel.pkg.tar.gz .PKGINFO .FILELIST .INSTALL *" @@ -605,19 +643,19 @@ $cmd | sort >../filelist cd $startdir if [ "$CLEANUP" = "1" ]; then - msg "==> Cleaning up..." + msg "Cleaning up..." rm -rf src pkg filelist fi if [ "$RMDEPS" = "1" -a "`id -u`" = "0" -a "$INFAKEROOT" != "1" ]; then - msg "==> Removing installed dependencies..." + msg "Removing installed dependencies..." pacman -R $makedeplist $deplist fi -msg "==> Finished making: $pkgname (`date`)" +msg "Finished making: $pkgname (`date`)" if [ "$INSTALL" = "1" -a "`id -u`" = "0" -a "$INFAKEROOT" != "1" ]; then - msg "==> Running pacman --upgrade..." + msg "Running pacman --upgrade..." pacman --upgrade $PKGDEST/${pkgname}-${pkgver}-${pkgrel}.pkg.tar.gz exit $? fi |