LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Blogs > psionl0
User Name
Password

Notices



Rate this Entry

Automating Slackware's Package Management

Posted 02-20-2013 at 02:45 AM by psionl0
Updated 02-20-2013 at 03:04 AM by psionl0

In my previous blog, I explained how even if you are only installing a couple of files on the system, there were advantages to creating a Slackware package to do so. The example I gave was the files I needed to disable nouveau and use nvidia instead.

This policy paid dividends when I upgraded to Slackware 14.0. The nvidia drivers wouldn't work and I faced the task of upgrading them for 14.0 (which meant remembering stuff I had done 18 months ago). Before doing that, it seemed prudent to just remove the files I had installed for nvidia (where/what were they again?) and see if the new kernel was up to the task. All I had to do was enter the command: "removepkg nvidiaenabled-1.0-noarch-1_gs.tgz" and it was done. The new kernel proved to be up to task so hours of work had been spared.

The problem is that creating a Slackware package by hand can be an involved process (as shown by the steps in my previous blog). I had previously created a package called "moreicons" which added a couple of icons somewhere for use in wbar or idesk. It installed and worked but it wouldn't copy the "slack-desc" so pkgtools had no information to reveal about it (apart from the files). It turns out that "makepkg" is rather fussy about both the structure of the directory you are making a package out of and the name of the package. I couldn't see where I was going wrong so, since it was a minor package, I just left things as they were.

Since that time, I have gained some experience in writing SlackBuild scripts so I decided it was time to make a proper "moreicons" package by writing a script to do so. Slackwiki has a good tutorial on writing SlackBuild scripts to convert a source to a package and SlackBuilds.org has a number of templates you can use to make your own script. Of course, since the main reason for writing a SlackBuild script is that src2pkg has failed to create the package for you, it is not really a task for n00bs. However, for just installing a few files, writing a script is well within the realm of anybody who can use an editor and Slackware's package management tools.

This is a breakdown of the script I wrote for moreicons. The first part just sets up some variables that the script will use. This makes it easy to use the script as a template for installing other files. The usual SlackBuild script uses the /tmp or /tmp/SBo directories to do its work but I saw no advantage of this for such a minor task and kept everything in the current working directory. Note that the build is 2 because it is fixing up build 1.
Code:
#!/bin/sh

# Slackware build script for moreicons


PRGNAM=moreicons
VERSION=${VERSION:-1.0}
ARCH=noarch
BUILD=${BUILD:-2}
TAG=${TAG:-_gs}
CWD=$(pwd)
PKG=$CWD/package-$PRGNAM

set -e # Exit on most errors
The next section is the main part of the script. It deletes the old package directory and creates a new directory structure where the files I want installed will be placed. Note that this script assumes that the icons are present in the current working directory.
Code:
rm -rf $PKG
mkdir -p $PKG

# Create the subdirectories and copy the icons into the $PKG directory
mkdir -p $PKG/usr/share/pixmaps
cp -a $CWD/home.png $PKG/usr/share/pixmaps
cp -a $CWD/sw.png $PKG/usr/share/pixmaps
DOCUMENTATION: Since this package is only installing a couple of files, there is strictly no need for any documentation other than the slack-desc. If you are creating the package by hand it is tempting to skip the documentation altogether. However, it is no extra work for the script and by creating a directory for documentation, you avoid the need to hang on to the files you used when creating the script/package. It is usual to keep a copy of the SlackBuild in the documents folder and it is also a good idea to add a README file there too. The README file is basically just the slack-desc without the "moreicons:" bits but I also have the option of adding some extra instructions for my future self. The README is actually created within the script itself so no extra files are involved.
Code:
# Copy program documentation into the package
mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild

# Create a README file
cat > $PKG/usr/doc/$PRGNAM-$VERSION/README << _EOG
moreicons (extra icons) 

Puts a couple of extra icons into
/usr/share/pixmaps directory
sw.png, home.png 

Used in wbar, idesk etc.

SlackBuild created 19 Feb 2013
_EOG
Just as the script creates a README file, it also creates the slack-desc. The use of the generic $PRGNAM variable makes this more useful as a template.
Code:
# Create a slack-desc file and put it in the install directory
mkdir -p $PKG/install
cat > $PKG/install/slack-desc <<_EOF
$PRGNAM: moreicons (extra icons) 
$PRGNAM:
$PRGNAM: Puts a couple of extra icons into
$PRGNAM: /usr/share/pixmaps directory
$PRGNAM: sw.png, home.png
$PRGNAM:
$PRGNAM: Used in wbar, idesk etc.
$PRGNAM:
$PRGNAM:
$PRGNAM: SlackBuild created 19 Feb 2013
$PRGNAM:
_EOF
Finally, we build the package.
Code:
# Make the package
cd $PKG
/sbin/makepkg -l y -c n $CWD/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.${PKGTYPE:-tgz}
I have included the moreicons.SlackBuild.txt as an attachment in case anybody would like to use it as a template.
Attached Files
File Type: txt moreicons.SlackBuild.txt (1.2 KB, 7 views)
Posted in Uncategorized
Views 390 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 05:23 PM.

Main Menu
Advertisement

Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration