BSD DevCenter
oreilly.comSafari Books Online.Conferences.

advertisement


Building Binary PC-BSD Packages
Pages: 1, 2, 3, 4, 5

Step 3: Prepare the Tarball and Install/Uninstall Scripts

Packages are really compressed tarballs, so start by uncompressing them:



# bunzip2 *.tbz

As you untar each package, you can remove the original tarball:

# tar xvf digikam-0.7.2.tbz && rm digikam-0.7.2.tar
# tar xvf libltdl-1.5.10.tbz && rm libltdl-1.5.10.tar
<snip 10 other untars>

Notice that this created several subdirectories, one of which is bin/. The PBI you create will be a compressed snapshot of this bin/ directory. The rest of this article will show you how to put all the required pieces into it.

The first piece will be a new tarball named base_changes.tar, which contains everything except the contents of bin:

# tar cv --exclude bin -f bin/base_changes.tar .

Next, create an install script and set it as executable:

# vi bin/PBI.SetupScript.sh
#!/bin/sh
cd /usr/local/MyPrograms/$1
tar xvjpf base_changes.tar
rm base_changes.tar

# chmod +x bin/PBI.SetupScript.sh

Then create an uninstall script:

# vi bin/PBI.RemoveScript.sh
#!/bin/sh
cd /usr/local/MyPrograms
rm -Rf $1

# chmod +x bin/PBI.RemoveScript.sh

Notice that when the PBI installs, everything it needs (base_changes.tar) untars into /usr/local/MyPrograms/$1, where $1 represents the name of the PBI. Uninstalling the PBI removes that entire directory.

Because you can use these scripts with any PBI, I keep a copy in my pbi/ directory so I don't have to re-create them:

# cp bin/PBI.* ~dru/pbi

Step 4: Copy Libraries

Now it's time to create a lib/ directory in your staging area's bin/ directory:

# pwd
/home/dru/pbi/digikam/bin
# mkdir lib

Unless you have a very simple application, there can be many dozens of libraries that you need to locate and copy into that custom lib/ directory. ldd will give you the names, but you don't want to spend hours copying pathnames when a script will do it in under a second. This script will work every time, so ~user_account/pbi/ is a good place to keep it. (I've put --- at the beginning and end of the script to make it easy to cut and paste.)

# more ~dru/pbi/lib.sh

---

#!/bin/sh

# this script requires you to input the name of an executable 
# which is referred to as $1 in the script

# copy the output of ldd into a file
# ldd gives the paths to required libraries

ldd $1 > $1_lib.sh

# these statements clean up the output of ldd
# and transforms it into a series of "cp path lib" statements

cat $1_lib.sh | cut -d = -f 2 | cut -d '(' -f 1 > $1_tmp1
sed 's/\>/cp/g' $1_tmp1 > $1_tmp2 ; mv $1_tmp2 $1_tmp1
sed 's/$/ lib/g' $1_tmp1 > $1_tmp2 ; mv $1_tmp2 $1_lib.sh

# this transforms the first non-path line
# into a shebang

sed 's/.*\:.*/\#\!\/bin\/sh/'g $1_lib.sh > $1_tmp1 ; mv $1_tmp1 $1_lib.sh

# this makes the resulting file executable

chmod +x $1_lib.sh

echo "Run the script $1_lib.sh to copy the required libraries"

---

Pages: 1, 2, 3, 4, 5

Next Pagearrow





Sponsored by: