Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Build slackware package from source - NOTE: I don't make any warranties that my script will work for you or won't fuck up your machine.
if [ $# -lt 4 ];
then
echo "4 args pls: SOURCEFILE SOURCEDIR DESTDIR PACKNAME (opt: LAYOUTFILE CON
FFLAGS)" && exit 1
fi
SOURCEFILE=$1
SOURCEDIR=$2
DESTDIR=$3
PACKNAME=$4
LAYOUTFILE=$5
CONFFLAGS=$6
DOCFILES=$7
echo "package builder for Slackware 13.37"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo "SOURCEFILE: $SOURCEFILE"
echo "SOURCEDIR: $SOURCEDIR"
echo "DESTDIR: $DESTDIR"
echo "PACKNAME: $PACKNAME"
echo "LAYOUTFILE: $LAYOUTFILE"
echo "CONFFLAGS: $CONFFLAGS"
echo "DOCFILES: $DOCFILES"
echo -n "Continue with that? [1/0] "
read start
# kill
if [ $start -ne 1 ]; then exit 0; else echo ""; fi
# measure execution time
time=$SECONDS
# remove old sources
echo -n "removing old sources............."
rm -r $SOURCEDIR &> /dev/null
if [ $? -eq 0 ]; then echo -e "\033[0;32;148m[OK]\033[39m"; else echo -e "\033[0
;32;148m[OK]\033[39m - no old source found"; fi
# remove old package
echo -n "removing old DESTDIR binaries...."
rm -r $DESTDIR &> /dev/null
if [ $? -eq 0 ]; then echo -e "\033[0;32;148m[OK]\033[39m"; else echo -e "\033[0
;32;148m[OK]\033[39m - no old binaries found"; fi
# extract archive
echo -n "extracting archive..............."
FILETYPE=`file -b $SOURCEFILE`
EXTENSION=${FILETYPE:0:4}
if [ "$EXTENSION" == "gzip" ]
then
tar xzf $SOURCEFILE &> /dev/null
elif [ "$EXTENSION" == "bzip" ]
then
tar xjf $SOURCEFILE &> /dev/null
else
echo "[FAIL] - wrong filetype"
exit 1
fi
if [ $? -eq 0 ]; then echo -e "\033[0;32;148m[OK]\033[39m"; else echo -e "\033[0;31;148m[FAIL]\033[39m - can't write or no archive
found"; exit 1; fi
# copying layout file
if [ $LAYOUTFILE ]
then
echo -n "copying layout file.............."
cp $LAYOUTFILE $SOURCEDIR
if [ $? -eq 0 ]; then echo -e "\033[0;32;148m[OK]\033[39m"; else echo -e "\033[0;31;148m[FAIL]\033[39m - can't write or file not
found"; exit 1; fi
fi
# configuring sources
echo -n "configuring sources.............."
cd $SOURCEDIR
./configure $CONFFLAGS &> /dev/null
if [ $? -eq 0 ]; then echo -e "\033[0;32;148m[OK]\033[39m"; else echo -e "\033[0;31;148m[FAIL]\033[39m"; exit 1; fi
# make install to DESTDIR
echo -n "make install to DESTDIR.........."
cd $SOURCEDIR
make DESTDIR=$DESTDIR install &> /dev/null
if [ $? -eq 0 ]; then echo -e "\033[0;32;148m[OK]\033[39m"; else echo -e "\033[0;31;148m[FAIL]\033[39m"; exit 1; fi
# make dir for documentation
echo -n "creating documentation dir......."
mkdir $DESTDIR/usr/doc && mkdir $DESTDIR/usr/doc/$PACKNAME/
if [ $? -eq 0 ]; then echo -e "\033[0;32;148m[OK]\033[39m"; else echo -e "\033[0;31;148m[FAIL]\033[39m"; exit 1; fi
if [ "$DOCFILES" ]
then
# copying documentation
echo -n "copying documentation............"
cp $DOCFILES $DESTDIR/usr/doc/$PACKNAME/
if [ $? -eq 0 ]; then echo -e "\033[0;32;148m[OK]\033[39m"; else echo -e "\033[0;31;148m[FAIL]\033[39m"; exit 1; fi
fi
# create pkg description file
# see: http://www.linuxpackages.net/howto.php?page=perfect-package&title=Perfect+Package#Slack-Desc
# change rights
echo -n "changing rights.................."
chown root.root $DESTDIR
if [ $? -eq 0 ]; then echo -e "\033[0;32;148m[OK]\033[39m"; else echo -e "\033[0;31;148m[FAIL]\033[39m"; exit 1; fi
# make pkg
echo -n "making slackware package........."
cd $DESTDIR
makepkg --chown y --linkadd y $DESTDIR/../$PACKNAME &> /dev/null
if [ $? -eq 0 ]; then echo -e "\033[0;32;148m[OK]\033[39m"; else echo -e "\033[0;31;148m[FAIL]\033[39m"; exit 1; fi
echo ""
echo "The package has been created successfully in $[$SECONDS-$time] seconds."
echo "You can install it with installpkg $DESTDIR/../$PACKNAME"
exit 0;
@mdix

This comment has been minimized.

Copy link
Owner Author

@mdix mdix commented Nov 19, 2011

NOTE: I don't make any warranties that my script will work for you or won't fuck up your machine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment