#!/bin/bash # src2pkg-bootstrap.src2pkg ## This script builds the src2pkg/src2pkg package, ## including the libsentry libraries. Once you ## have built the src2pkg package, install it using ## the 'installpkg' command. Then you can build other ## packages from source using the src2pkg/src2pkg tools. CWD=$(pwd) # use /tmp if you can't write to the current working directory TEMP_DIR=$CWD NAME="src2pkg" VERSION="1.9" BUILD="1" LIBSENTRY_VERSION="0.6.7.3" TAR_VERSION=1.13 BB_VERSION=1.2.1 # sign the package with the kernel version number if [[ $(uname -r |cut -f1,2 -d.) = "2.4" ]] ; then SIG=_K24 else SIG=_K26 fi NORMAL="" # RED: Failure or error message RED="" # GREEN: Success message GREEN="" # BLUE: Summary messages BLUE="" # ARCH= # If you don't have uname set the ARCH above if ! [[ $ARCH ]] ; then if [[ "$(uname -m)" = "ppc" ]] ; then ARCH="powerpc" elif [[ "$(uname -m)" = "s390" ]] ; then ARCH="s390" elif [[ "$(uname -m)" = "s390x" ]] ; then ARCH="s390x" elif [[ "$(uname -m)" = "x86_64" ]] ; then ARCH="x86_64" elif [[ "$(uname -m |grep 86)" != "" ]] ; then ARCH="i486" fi fi PKG_DIR=$TEMP_DIR/$NAME-$VERSION-$ARCH-$BUILD$SIG PACKAGE=$TEMP_DIR/$NAME-$VERSION-$ARCH-$BUILD$SIG.tgz [[ -d $PKG_DIR ]] && echo "Removing existing PKG_DIR" && rm -rf $PKG_DIR [[ -e $PACKAGE ]] && echo "Removing existing package" && rm -rf $PACKAGE # clean up stale files and start fresh if [[ $BOOT_STRAP ]] ; then echo "Running 'make clean' in libsentry, tar and busybox sources" ( cd $TEMP_DIR/libsentry-$LIBSENTRY_VERSION && make clean &> /dev/null ) ( cd $TEMP_DIR/tar-$TAR_VERSION && make clean &> /dev/null ) ( cd $TEMP_DIR/busybox-$BB_VERSION && make clean &> /dev/null ) else echo "Removing old source directories" ( cd $TEMP_DIR && rm -rf libsentry-$LIBSENTRY_VERSION ) ( cd $TEMP_DIR && rm -rf tar-$TAR_VERSION ) ( cd $TEMP_DIR && rm -rf busybox-$BB_VERSION ) fi echo "src2pkg uses statically-linked binaries for some critical operations." echo "Most are supplied by the busybox program, but we also install a" echo "separate static copy of the tar program which is used throughout." echo "" cd $TEMP_DIR ; if ! [[ $BOOT_STRAP ]] ; then echo "Unpacking busybox" tar xjf $CWD/busybox-$BB_VERSION.tar.bz2 rm -f busybox-$BB_VERSION/.config cp -a $CWD/busybox-static.config busybox-$BB_VERSION/.config fi cd busybox-$BB_VERSION ; echo "Configuring busybox" make oldconfig 1> /dev/null printf "Compiling busybox..." if [[ $ARCH = "x86_64" ]] ; then CFLAGS='-O2 -fPIC' make &> /dev/null elif [[ $ARCH = "i486" ]] ; then CFLAGS='-O2' make &> /dev/null else make &> /dev/null fi if [[ $? -eq 0 ]] ; then printf $GREEN"Done\n"$NORMAL else echo "busybox failed to compile... exiting." exit fi echo "Creating busybox links" make install &> /dev/null # build and use our own static copy of tar for consistent results and safety #! [[ -d $TEMP_DIR/tar ]] && mkdir -p $TEMP_DIR/tar cd $TEMP_DIR ; if ! [[ $BOOT_STRAP ]] ; then echo "Unpacking tar..." tar xjf $CWD/tar-$TAR_VERSION.tar.bz2 if [[ "$TAR_VERSION" = "1.13" ]] ; then ( cd tar-$TAR_VERSION echo "patching tar..." echo "This adds support for bzip2:" patch -p1 < $CWD/tar-$TAR_VERSION-bzip2.diff ) fi fi cd tar-$TAR_VERSION ; printf "configuring tar..." if [[ $ARCH = "x86_64" ]] ; then CFLAGS="-O2 -fPIC -static -s" ./configure --disable-nls --with-ncursesw --enable-widec &> /dev/null elif [[ $ARCH = "i486" ]] ; then CFLAGS='-O2' ./configure --disable-nls --with-ncursesw --enable-widec &> /dev/null else ./configure --disable-nls --with-ncursesw --enable-widec &> /dev/null fi if [[ $? -eq 0 ]] ; then printf $GREEN"Done\n"$NORMAL else echo "tar failed to configure... exiting." exit fi printf "compiling tar..." if [[ $ARCH = "x86_64" ]] ; then CFLAGS='-O2 -fPIC' LDFLAGS="-static -s" make &> /dev/null elif [[ $ARCH = "i486" ]] ; then CFLAGS='-O2' LDFLAGS="-static -s" make &> /dev/null else LDFLAGS="-static -s" make &> /dev/null fi if [[ $? -eq 0 ]] ; then printf $GREEN"Done\n"$NORMAL else echo "tar failed to compile... exiting." exit fi # build the libsentry library cd $TEMP_DIR ; echo "Unpacking sources..." ! [[ $BOOT_STRAP ]] && tar xjf $CWD/libsentry-$LIBSENTRY_VERSION.tar.bz2 echo "Compiling libsentry..." cd libsentry-$LIBSENTRY_VERSION ; if [[ $ARCH = "x86_64" ]] ; then CFLAGS='-O2 -fPIC' make 1> /dev/null 2> /dev/null elif [[ $ARCH = "i486" ]] ; then CFLAGS='-O2' make 1> /dev/null 2> /dev/null else make 1> /dev/null 2> /dev/null fi if [[ -e $TEMP_DIR/libsentry-$LIBSENTRY_VERSION/libsentry.so ]] ; then echo "libsentry Libraries successfully built." else echo "libsentry Libraries build Failed!" && exit 1 fi # build the package echo "Creating Package Tree..." mkdir -p $PKG_DIR chown root:root $PKG_DIR chmod 755 $PKG_DIR mkdir -p $PKG_DIR/usr/libexec/src2pkg chmod 755 $PKG_DIR/usr/libexec/src2pkg cp -a $CWD/Resources/libexec/* $PKG_DIR/usr/libexec/src2pkg cp -a $TEMP_DIR/libsentry-$LIBSENTRY_VERSION/libsentry.so $PKG_DIR/usr/libexec/src2pkg chown root:root $PKG_DIR/usr/libexec/src2pkg/* chmod 644 $PKG_DIR/usr/libexec/src2pkg/* chmod 755 $PKG_DIR/usr/libexec/src2pkg/libsentry.so # Install static tar mkdir -p $PKG_DIR/usr/libexec/src2pkg/static cp -a $TEMP_DIR/tar-$TAR_VERSION/src/tar $PKG_DIR/usr/libexec/src2pkg/static # busybox cp -a $TEMP_DIR/busybox-$BB_VERSION/_install/bin/busybox $PKG_DIR/usr/libexec/src2pkg/static # fix perms chown root:root $PKG_DIR/usr/libexec/src2pkg/static/* chmod 755 $PKG_DIR/usr/libexec/src2pkg/static/* # src2pkg mkdir -p $PKG_DIR/usr/bin cp -a $CWD/Resources/bin/src2pkg $PKG_DIR/usr/bin chown root:root $PKG_DIR/usr/bin/src2pkg chmod 755 $PKG_DIR/usr/bin/src2pkg # trackinstall cp -a $CWD/Resources/bin/trackinstall $PKG_DIR/usr/bin chown root:root $PKG_DIR/usr/bin/trackinstall chmod 755 $PKG_DIR/usr/bin/trackinstall # disrpm mkdir -p $PKG_DIR/usr/bin cp -a $CWD/Resources/bin/disrpm $PKG_DIR/usr/bin chown root:root $PKG_DIR/usr/bin/disrpm chmod 755 $PKG_DIR/usr/bin/disrpm # tracklist can be run by non-root users so place it in /usr/bin #mkdir -p $PKG_DIR/usr/bin cp -a $CWD/Resources/bin/tracklist $PKG_DIR/usr/bin chown root:root $PKG_DIR/usr/bin/tracklist chmod 755 $PKG_DIR/usr/bin/tracklist # install the libsentry wrapper cp -a $CWD/Resources/bin/sentry $PKG_DIR/usr/bin chown root:root $PKG_DIR/usr/bin/sentry chmod 755 $PKG_DIR/usr/bin/sentry # config files mkdir -p $PKG_DIR/etc/src2pkg cp -a $CWD/Resources/etc/* $PKG_DIR/etc/src2pkg chown root:root $PKG_DIR/etc/src2pkg/* chmod 755 $PKG_DIR/etc/src2pkg chmod 644 $PKG_DIR/etc/src2pkg/* # docs mkdir -p $PKG_DIR/usr/doc/$NAME-$VERSION cp -a $CWD/Resources/doc/* $PKG_DIR/usr/doc/$NAME-$VERSION cp -a $TEMP_DIR/libsentry-$LIBSENTRY_VERSION/README $PKG_DIR/usr/doc/$NAME-$VERSION/README if [[ -e ../$CWD/ChangeLog ]] ; then rm -f $PKG_DIR/usr/doc/$NAME-$VERSION/ChangeLog cp -a ../$CWD/ChangeLog $PKG_DIR/usr/doc/$NAME-$VERSION/ fi chown -R root:root $PKG_DIR/usr/doc/$NAME-$VERSION cd $PKG_DIR/usr/doc/$NAME-$VERSION ; find . -type f -exec chmod 644 {} \; # manpage(s) mkdir -p $PKG_DIR/usr/man/man1 cp -a $CWD/Resources/man/* $PKG_DIR/usr/man/man1 cp -a $CWD/libsentry-$LIBSENTRY_VERSION/sentry.1 $PKG_DIR/usr/man/man1 gzip $PKG_DIR/usr/man/man1/* # slack-desc and doinst.sh mkdir -p $PKG_DIR/install cp -a $CWD/slack-desc $PKG_DIR/install cp $CWD/doinst.sh $PKG_DIR/install echo "Creating Package..." cd $PKG_DIR ; # use our new tar-1.13 so the package is created properly $TEMP_DIR/tar-1.13/src/tar cvf $NAME-$VERSION-$ARCH-$BUILD$SIG.tar . gzip -9 $NAME-$VERSION-$ARCH-$BUILD$SIG.tar mv $NAME-$VERSION-$ARCH-$BUILD$SIG.tar.gz ../$NAME-$VERSION-$ARCH-$BUILD$SIG.tgz echo "Finished Package is located in:" echo "$PACKAGE" echo "" echo "Use 'installpkg $NAME-$VERSION-$ARCH-$BUILD$SIG.tgz' to install the package." echo "Then you can use the 'src2pkg' program to build sources and/or generate" echo "src2pkg scripts for build customization." if [[ $1 = "--cleanup" ]] ; then cd $TEMP_DIR ; rm -rf $NAME-$VERSION-$ARCH-$BUILD$SIG rm -rf busybox-$BB_VERSION rm -rf libsentry-$LIBSENTRY_VERSION rm -rf tar-$TAR_VERSION fi