LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   Can we make slackbuilds easier? (https://www.linuxquestions.org/questions/slackware-14/can-we-make-slackbuilds-easier-856231/)

TheCrow33 01-13-2011 11:44 PM

Can we make slackbuilds easier?
 
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.

TL_CLD 01-14-2011 12:37 AM

I can kinda see where you're going with this, but why not just go with the excellent sbopkg and use its queue facility?

http://www.sbopkg.org/

TheCrow33 01-14-2011 12:40 AM

Quote:

Originally Posted by TL_CLD (Post 4223807)
I can kinda see where you're going with this, but why not just go with the excellent sbopkg and use its queue facility?

http://www.sbopkg.org/

Doh! It's been a long couple of days and I guess I just wanted to make it longer by failing to google for an existing solutions first haha. Eh, oh well, I enjoyed programming it anyway.

TL_CLD 01-14-2011 01:47 AM

Quote:

Originally Posted by TheCrow33 (Post 4223808)
...I enjoyed programming it anyway.

Hehe, I can relate to that. I've written _a lot_ of code simply for the sake of writing it. It relaxes the mind.

tallship 01-14-2011 03:42 AM

That's actually pretty neat :)

could be used for some other, more specific packaging routines, tested, and incorporated as a sort of favpack install.

Nice work!

lumak 01-14-2011 09:35 AM

Mmmm I did that for converting my CDs to mp3/flac... then I realized there was abcde which did everything I wanted except place the final files in separate directories.

It was really annoying to try and find software that named the files -exactly- how I wanted them.


But in regards to the topic; I personally don't like using SBo for too many things. I like creating my own build queues for things like inkscape that doesn't have a lot of shared dependencies with other packages that I install.


All times are GMT -5. The time now is 09:06 PM.