After many hours of fiddling with a 'project' computer (which is really just a better way of saying spare parts that were laying around the house and turned into a working machine), I installed way too many slackbuild packages which became very time consuming. Mythtv can be named the main culprit behind this, because it has a lot of packages that it depends on (and those packages depend on a lot of packages and so on). So I began to ask myself this question of 'Can I make slackbuilds easier?' and in the spirit of B0b the Builder I answered 'Yes we can!'.
So I give to you, my fellow slackers, a small script that takes a file (for some reason too many cmd line arguments won't register) of package names and slackbuild names and then does the rest of the work for you. This will work for most all packages that follow the usual layout: pkgName-0.1.2.extension or even pkg-Name-0.1.2.extension or even pkg-Name-0.1.2rc3.extension. Note it will break if the package is a snapshot that includes the date in the version number or other weird formats. Also note that it will not pass arguments to the slackbuilds for you (though I'd imagine you can just set them before you run the script and all will turn out ok). Anyway feel free to do anything you like with these scripts (use it, modify it, post it on the web, print it out and set it on fire) so long as you don't claim credit for the work you didn't do.
Code:
root@multimedia:/make# cat /usr/sbin/installsbo
#!/bin/bash
#
# Takes <file>
# Creates and installs the slackbuild and then cleans up
if [[ $# < 1 ]]; then
echo "Usage: $0 </path/to/listOfPackages>"
exit
fi
list=`cat $1`
isSB=0
for x in $list; do
if [[ $isSB == 0 ]]; then
package=$x
if [[ -n `echo $package | grep ".tar.bz2" ` ]]; then
pkgflags="-xjf"
pkgreplace=".tar.bz2"
elif [[ -n `echo $package | grep ".tar.gz" ` ]]; then
pkgflags="-xf"
pkgreplace=".tar.gz"
elif [[ -n `echo $package | grep ".tgz" ` ]]; then
pkgflags="-xf"
pkgreplace=".tgz"
else
echo "unanticipated package extension: $package"
exit
fi
isSB=1
else
SB=$x
if [[ -n `echo $SB | grep ".tar.bz2" ` ]]; then
sbflags="-xjf"
sbreplace=".tar.bz2"
elif [[ -n `echo $SB | grep ".tar.gz" ` ]]; then
sbflags="-xf"
sbreplace=".tar.gz"
elif [[ -n `echo $SB | grep ".tgz" ` ]]; then
sbflags="-xf"
sbreplace=".tgz"
else
echo "unanticipated slackbuild extension: $SB"
exit
fi
buildDir=`echo $SB | sed s/$sbreplace// `
packageName=`echo $package | sed -r 's/(.*)[-_]([0-9a-zA-Z].*)/\1/' `
regex="s/(.*)[-_]([0-9a-zA-Z].*)$pkgreplace/\2/"
packageVers=`echo $package | sed -r $regex `
echo "unpackaging slackbuild ..."
tar $sbflags $SB
echo "moving package ..."
mv $package $buildDir/
echo "moving to $buildDir ..."
pushd $buildDir
regex="s/VERSION=(.*)/VERSION=$packageVers/"
sed -rs $regex $buildDir.SlackBuild > a
mv a $buildDir.SlackBuild
chmod +x $buildDir.SlackBuild
if [[ -n `cat $buildDir.SlackBuild | grep "PKGNAME"` ]]; then
varName="\$PKGNAME"
elif [[ -n `cat $buildDir.SlackBuild | grep "PRGNAM"` ]]; then
varName="\$PRGNAM"
fi
addtoscript="/sbin/installpkg \"\$OUTPUT/$varName-\$VERSION-\$ARCH-\$BUILD\$TAG.\${PKGTYPE:-tgz}\"\n
checkpkg \"\$OUTPUT/$varName-\$VERSION-\$ARCH-\$BUILD\$TAG.\${PKGTYPE:-tgz}\"\n
exit \$?"
echo "adding to script ..."
echo -e $addtoscript >> ./$buildDir.SlackBuild
echo "running slackbuild ..."
./$buildDir.SlackBuild
if [[ $? != 1 ]]; then
echo "Failed to install: $package";
exit
fi
isSB=0
popd
rm -R $buildDir $SB
fi
done
root@multimedia:/make# cat /usr/sbin/checkpkg
#!/bin/bash
#
# Checks if a slackbuild was made into a package
# We can assume if this returns 1 then it was also installed
echo "Checking: $1 ..."
if [[ `ls $1` == $1 ]]; then
exit 1
else
exit 0
fi
So an example file would look like either of the following:
Code:
example-1.2.3.tar.bz2 example.tar.gz helloWorld.4.5.6.tar.bz2 helloWorld.tar.gz
or
Code:
example-1.2.3.tar.bz2 example.tar.gz
helloWorld.4.5.6.tar.bz2 helloWorld.tar.gz
Note: yeah I know this could use some cleaning up, but it's been a long day and I coded this this morning give me a break haha.