slackbuilds/ap/skopeo/skopeo.SlackBuild

126 lines
3.5 KiB
Bash
Executable File

#!/bin/sh
# Set initial variables:
CWD=$(pwd)
APP=skopeo
VERSION=$(ls $APP-*.tar.?z* | sed -e 's/\.tar\..z.*//' | rev | cut -d- -f1 | rev)
ARCH=${ARCH:-x86_64}
BUILD=${BUILD:-1}
TAG=${TAG:-micu}
TMP=${TMP:-/tmp}
OUTDIR=${OUTDIR:-$TMP}
# The domain part of the go package name, usually the hosting platform
DOMAIN=github.com
# The name of the organization/owner of the package
ORG=containers
# The name of the repository
REPONAME=$APP
LIBSUFFIX=""
if [ "$ARCH" = "x86_64" ]; then
LIBSUFFIX=${LIBSUFFIX:-64}
fi
PKG=$TMP/package-$APP
rm -rf $PKG
mkdir -p $TMP $PKG
cd $TMP || exit 1
rm -rf $APP-$VERSION
mkdir -p $APP-$VERSION/src/$DOMAIN/$ORG
cd $APP-$VERSION/src/$DOMAIN/$ORG || exit 1
tar xvf $CWD/$APP-$VERSION.tar.?z* || exit 1
mv $APP-$VERSION $REPONAME
cd $REPONAME || exit 1
chown -R root:root .
find . -perm 444 -exec chmod 644 {} \;
find . -perm 777 -exec chmod 755 {} \;
find . -perm 666 -exec chmod 644 {} \;
# Fresh build usually requires very recent 'go' version, newer than
# system (gcc)go. So let's be brave, invest some time and build
# a dedicated environment (or use the one already built there):
GODEVDIR=${GODEVDIR:-$TMP/go-devel}
if [ ! -x $GODEVDIR/go/bin/go ]; then
echo "Development go not found at $GODEVDIR, building it."
mkdir -p $GODEVDIR
cd $GODEVDIR || exit 1
git clone https://go.googlesource.com/go
export GOPATH=$GODEVDIR/go
cd $GOPATH
cd src || exit 1
./all.bash || exit 1
cd $TMP/$APP-$VERSION/src/$DOMAIN/$ORG/$REPONAME || exit 1
else
echo "Development go found at $GODEVDIR, using it."
fi
export PATH=$GODEVDIR/go/bin:$PATH
# Point go to the location of the source tree
export GOPATH="$TMP/$APP-$VERSION"
make bin/skopeo docs PREFIX="/usr" MANDIR="/usr/man" BUILDTAGS="containers_image_ostree_stub" || exit 1
make install DESTDIR="$PKG" PREFIX="/usr" MANDIR="/usr/man" || exit 1
( cd $PKG/etc/containers
mv policy.json policy.json.new
mv registries.d/default.yaml registries.d/default.yaml.new
)
# Don't ship .la files:
rm -f $PKG/{,usr/}lib${LIBSUFFIX}/*.la
chown -R root:bin $PKG/usr/bin $PKG/usr/sbin
( cd $PKG
find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
find . | xargs file | grep "current ar archive" | grep ELF | cut -f 1 -d : | xargs strip -g 2> /dev/null
)
# Compress and if needed symlink the man pages:
if [ -d $PKG/usr/info ]; then
rm -f $PKG/usr/info/dir
gzip -9 $PKG/usr/info/*
fi
if [ -d $PKG/usr/man ]; then
( cd $PKG/usr/man
for manpagedir in $(find . -type d -name "man*") ; do
( cd $manpagedir
for eachpage in $( find . -type l -maxdepth 1) ; do
ln -s $( readlink $eachpage ).gz $eachpage.gz
rm $eachpage
done
gzip -9 *.?
)
done
)
fi
mkdir -p $PKG/usr/doc/$APP-$VERSION
cp -a LICENSE *.md $PKG/usr/doc/$APP-$VERSION
mkdir -p $PKG/install
[ -f $CWD/doinst.sh ] && cat $CWD/doinst.sh > $PKG/install/doinst.sh
[ -f $CWD/doinst.sh.gz ] && zcat $CWD/doinst.sh.gz > $PKG/install/doinst.sh
cat $CWD/slack-desc > $PKG/install/slack-desc
# Allow to run as non-root until now:
if [ $(id -u) -ne 0 ]; then
echo "*** Running as non-root, skipping makepkg."
echo "*** Package contents is in $PKG directory."
exit 0
fi
cd $PKG
makepkg -l y -c n $OUTDIR/$APP-$VERSION-$ARCH-${BUILD}${TAG}.txz
# Clean up the extra stuff:
if [ "$1" = "--cleanup" ]; then
rm -rf $TMP/$APP-$VERSION
rm -rf $PKG
rm -rf $GODEVDIR
fi