#!/bin/sh # # Version 1.5 # # Download, patch, configure, build & install a new version of Samba like this: # # ./BUILD -V 4.9.4 -T liu install # # "-T liu" isn't technically necessary, it just adds a convenient "tag" to the version number for the # install directory (/liu/pkg/samba/4.9.4-liu) in the example above. # # Then you copy the whole tree to filifjonkan:/export/liupkg/samba/ and use it. # PATH=/usr/local/bin:/usr/bin:/bin export PATH NCPU=24 ROOT="/liu/pkg" BUILD="`basename $0`" TAG="" PWD="`pwd`" MAKE=gmake GETVER="latest" OPTLEVEL="" CC="" COMPILERS="gcc8 gcc7 gcc6 gcc cc" for C in $COMPILERS; do if [ -x "/usr/local/bin/$C" -o -x "/usr/bin/$C" -o -x "/bin/$C" ]; then CC="$C" break fi done MORE=yes while [ $MORE = yes ]; do case "$1" in -h|--help|-\?) echo "Usage: $0 [-h|--help] [-a|--auto] [-R|--root ] [-V|--version ] [-C|--compiler ] [-T|--tag ] [-O|--optimize ] " exit 0 ;; -C|--compiler) CC="$2" shift ;; -R|--root) ROOT="$2" shift ;; -O|--optimize) OPTLEVEL="$2" shift ;; -V|--version) GETVER="$2" shift ;; -T|--tag) TAG="$2" shift ;; -|--) shift MORE=no ;; -*) echo "$0: Error: $0: Invalid switch" >&2 exit 1 ;; *) MORE=no ;; esac if [ $MORE = yes ]; then shift fi done case "$GETVER" in latest) SOURCE="https://download.samba.org/pub/samba/samba-${GETVER}.tar.gz" ;; *rc*) SOURCE="https://download.samba.org/pub/samba/rc/samba-${GETVER}.tar.gz" ;; *) SOURCE="https://download.samba.org/pub/samba/stable/samba-${GETVER}.tar.gz" ;; esac PKGVER="`basename $PWD`" PKG="`echo $PKGVER | awk -F- '{print $1}'`" VER="`echo $PKGVER | awk -F- '{print $2}'`" if [ "$TAG" = "" ]; then NTAG="`echo $PKGVER | awk -F- '{print $3}'`" if [ "$NTAG" != "" ]; then TAG="$NTAG" fi fi if [ "$PKG" != "samba" -o "$VER" = "" ]; then OLDSUM="`sum samba-${GETVER}.tar.gz 2>/dev/null`" if ! wget -N -q --show-progress "$SOURCE"; then echo "$0: Error: $SOURCE: Unable to download ${GETVER} Samba source" >&2 exit 1 fi if [ ! -f "samba-${GETVER}.tar.gz" ]; then echo "$0: samba-${GETVER}.tar.gz not found" >&2 exit 1 fi NEWSUM="`sum samba-${GETVER}.tar.gz 2>/dev/null`" SAMBASRC="`tar ztf samba-${GETVER}.tar.gz | awk -F'/' '{print $1; exit 0}'`" if [ "$TAG" = "" ]; then SAMBADIR="${SAMBASRC}" else SAMBADIR="${SAMBASRC}-${TAG}" fi # Updated tar archive - force rebuild if [ -d "${SAMBADIR}" -a "$OLDSUM" != "$NEWSUM" ]; then rm -fr "${SAMBADIR}" fi if [ ! -d "${SAMBADIR}" ]; then echo "*** Unpacking SAMBA and renaming to ${SAMBADIR} ***" tar zxf "samba-${GETVER}.tar.gz" && mv "$SAMBASRC" "$SAMBADIR" fi if [ -d "${SAMBADIR}" ]; then echo "*** Running ${BUILD} $@ in ${SAMBADIR} ***" DIR="`pwd`" cd "${SAMBADIR}" && exec "${DIR}/${BUILD}" "$@" fi echo "$0: The BUILD script must be executed in the 'samba-VERSION' directory" >&2 exit 1 fi case "$VER" in 4.*) MAJOR="`echo $VER | awk -F. '{print $1}'`" MINOR="`echo $VER | awk -F. '{print $2}'`" PATCH="`echo $VER | awk -F. '{print $3}'`" ;; *) echo "$0: $VER: Invalid Samba major version" >&2 exit 1 ;; esac if [ "$TAG" = "" ]; then PREFIX="$ROOT/$PKG/${VER}" else PREFIX="$ROOT/$PKG/${VER}-${TAG}" fi CONFARGS="\ --sysconfdir=/etc/samba \ --localstatedir=/var/samba \ --mandir=${PREFIX}/share \ --without-ad-dc \ --disable-cups \ --with-shared-modules=nfs4_acls,vfs_zfsacl,vfs_dfs_samba4 \ --with-privatedir=/etc/samba/private \ --with-configdir=/etc/samba \ --with-logfilebase=/var/samba/logs" case "$OPTLEVEL" in no|none) CFLAGS="-g" ;; *) CFLAGS="-g -O$OPTLEVEL" ;; esac OS="`uname -s`" case "$OS" in SunOS) CC="$CC -lreadline -lncurses -lnsl -lsocket" CONFARGS="$CONFARGS --accel-aes=none --without-json-audit --without-libarchive" ;; FreeBSD) CONFARGS="$CONFARGS --accel-aes=intelaesni" ;; *) echo "$0: Error: $OS: Unknown operating system" >&2 exit 1 ;; esac if [ "$TAG" = "" ]; then echo "Building Samba version $VER" else echo "Building Samba version $VER ($TAG)" fi if [ "$CC" != "" ]; then export CC fi if [ "$CFLAGS" != "" ]; then export CFLAGS fi export MAKE build() { case "$1" in patch) if [ -d "../Patches/${MAJOR}.${MINOR}" ]; then for PF in `ls -1 "../Patches/$MAJOR.$MINOR"/*.patch`; do echo "Applying patch $PF" patch -s -p1 <$PF || exit 1 done touch .patched fi ;; conf*) if [ ! -e .patched ]; then build patch fi ./configure --prefix="$PREFIX" $CONFARGS && touch .configured ;; make|"") if [ -d "../Patches/${MAJOR}.${MINOR}" -a ! -e .patched ]; then build patch fi if [ ! -e .configured ]; then build configure fi gmake -j$NCPU && touch .built ;; install) if [ ! -e .configured ]; then build configure fi if [ ! -e .built ]; then build fi $MAKE install ;; install-man) for N in 1 5 7 8; do mkdir -p "$PREFIX/share/man/man$N" && cp docs/manpages/*.$N "$PREFIX/share/man/man$N" done ;; clean) $MAKE clean ;; distclean) $MAKE distclean rm -f .configured ;; all) build patch && build configure && build make ;; *) echo "$0: Error: $1: Invalid action" >&2 exit 1 ;; help) echo "Usage: $0 patch|configure|make|install|clean|distclean|all" exit 0 ;; esac } if [ "$*" != "" ]; then for A in "$@"; do build "$A" done else build fi exit 0