SlackBuild: best practices
Inviato: lun 31 ott 2005, 16:12
Ciao a tutti!
ero curioso di conoscere quali erano le abitudini/miglior pratiche di tutti noi nell'uso degli slackbuild..
Per esempio partendo dagli SlackBuild di NoCat e di Sukko, ne ho fatto uno mio
che fosse in grado di rilevare da solo i parametri più importanti, per esempio nome,
versione ...
che ne dite? idee? suggerimenti?
ero curioso di conoscere quali erano le abitudini/miglior pratiche di tutti noi nell'uso degli slackbuild..
Per esempio partendo dagli SlackBuild di NoCat e di Sukko, ne ho fatto uno mio
che fosse in grado di rilevare da solo i parametri più importanti, per esempio nome,
versione ...
Codice: Seleziona tutto
#!/bin/sh
# Get the current and temporary directories
CWD=`pwd`
if [ "$TMP" = "" ]; then
TMP=/tmp/pkg
fi
NAME=`basename $0 .SlackBuild`
PKG=$TMP/package-$NAME
SUFFIX=".tar.gz"
VERSION=`basename \`ls $NAME*$SUFFIX\` $SUFFIX | awk --field-separator - '{print $NF}'`
if [ ! -x SLCKARCH ] ; then
SLCKARCH="pentium-m"
fi
BUILD=1fab
# if tarname is different from program name
#TNAME=$NAME-src
#SOURCESLCKARCH=$TNAME-$VERSION
SOURCESLCKARCH=$NAME-$VERSION
# Set up working directories
if [ ! -d $TMP ]; then
mkdir -p $TMP
fi
if [ ! -d $PKG ]; then
mkdir -p $PKG
fi
# Set compilation flags according to the architecture
if [ ! -x SLCKFLAGS ] ; then
case $SLCKARCH in
"i686")
SLCKFLAGS="-O2 -march=i686"
;;
"celeron")
SLCKFLAGS="-Os -march=pentium3"
;;
"pentium3")
SLCKFLAGS="-O2 -march=pentium3"
;;
"pentium-m")
SLCKFLAGS="-O2 -march=pentium-m"
;;
"pentium4")
SLCKFLAGS="-O2 -march=pentium4"
;;
"duron"|"sempron")
SLCKFLAGS="-Os -march=athlon-xp"
;;
"athlonxp")
SLCKFLAGS="-O2 -march=athlon-xp"
;;
"sparc")
SLCKFLAGS="-O2"
;;
"supersparc")
SLCKFLAGS="-O2 -mcpu=supersparc"
;;
*|"i486")
SLCKFLAGS="-O2 -march=i486 -mtune=i686"
;;
esac
fi
# Print a welcome screen
# "+----------------+"
# "| $NAME-$VERSION |"
# "+----------------+"
BEGIN="+-"
END="-+"
BODY=""
for (( i = 1 ; i < `echo "$NAME-$VERSION" |wc -m` ; i++ )) ; do BODY="$BODY-" ; done
echo "$BEGIN$BODY$END"
echo "| $NAME-$VERSION |"
echo "$BEGIN$BODY$END"
if [ -d $PKG ] ;
then
if [ "$1" == "--clean" ] ;
then
# Clean up a previous build and go on
rm -rf $PKG $TMP/$NAME-$VERSION
echo "Removed previous build"
exit 1
fi
fi
echo "------------------------- Uncompressing source -------------------------"
cd $TMP
tar xzvf $CWD/$SOURCESLCKARCH.tar.gz
cd $SOURCESLCKARCH
chown -R root.root .
find . -perm 664 -exec chmod 644 {} \;
# Execute only the source
if [[ "$1" == "--source-only" || "$1" == "-s" ]] ;
then
echo "source extracted. I'm stopping ..."
exit 1
fi
# Patch
# echo "------------------------------- Patching -------------------------------"
# Build
echo "------------------------------ Configuring -----------------------------"
CFLAGS=$SLCKFLAGS \
CXXFLAGS=$SLCKFLAGS \
./configure --prefix=/usr \
--sysconfdir=/etc \
# --localstatedir=/var \
--with-preview=yes \
--program-prefix="" \
--program-suffix="" \
$SLCKARCH-slackware-linux
echo "------------------------------ Compiling -------------------------------"
make
res=$?
if [ $res -ne 0 ]
then
# make failed, we cannot continue
exit $res
fi
echo "------------------------------ Installing ------------------------------"
make install DESTDIR=$PKG
res=$?
if [ $res -ne 0 ]
then
# make install failed, we cannot continue
exit 1
fi
# Doc
echo "----------------- Copying documentation and other files ----------------"
mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a \
AUTHORS COPYING.LIB ChangeLog NEWS README \
$PKG/usr/doc/$NAME-$VERSION
# Gzip man pages
find $PKG/usr/man -name "*.[123456789]" -exec gzip -9 {} \;
# SlackBuild stuff
mkdir -p $PKG/usr/doc/$NAME-$VERSION/slackbuild
cp $CWD/{$0,$NAME.slack-desc,*.desktop} $PKG/usr/doc/$NAME-$VERSION/slackbuild
# Strip binaries.
# The commented one is an alternative version
#echo "--------------------------- Stripping binaries -------------------------"
#find $PKG -type f | xargs file | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded
( 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" | cut -f 1 -d : | xargs strip -g 2> /dev/null
)
# Set permissions
echo "--------------------------- Setting permissions ------------------------"
chown -R root.bin $PKG/usr/bin # $PKG/usr/sbin
chown -R root.root $PKG/usr/doc
chmod -R 755 $PKG/usr/doc/*
find $PKG/usr/doc -type f -exec chmod 644 {} \;
if [ -d $PKG/usr/share ]
then
chown -R root.root $PKG/usr/share
chmod -R 755 $PKG/usr/share/*
find $PKG/usr/share -type f -exec chmod 644 {} \;
fi
# Copy Slackware package files
echo "--------------------- Copying Slackware package files ------------------"
mkdir -p $PKG/install
cat $CWD/$NAME.slack-desc > $PKG/install/slack-desc
#ln -s $PKG/install/$NAME.slack-desc $PKG/install/slack-desc
#cat $CWD/slack-required > $PKG/install/slack-required
if [ -f $CWD/$NAME.doinst.sh ] ; then
cat $CWD/$NAME.doinst.sh > $PKG/install/doinst.sh
# ln -s $PKG/install/$NAME.doinst.sh $PKG/install/doinst.sh
fi
# Create package
echo "---------------------------- Creating package --------------------------"
echo "Creating package"
cd $PKG
makepkg -l y -c n $CWD/$NAME-$VERSION-$SLCKARCH-$BUILD.tgz
# Cleanup the temporary working directory
if [ "$1" = "--cleanup" ]; then
rm -rf $TMP/$NAME-$VERSION
rm -rf $PKG
fi