Making PKGs for RaQ 3 and 4
From CobaltFAQs
This is meant to augment the docs available at http://developer.cobalt.com/, and gives a step-by-step on simple PKG making.
First, you need to know that a PKG file is nothing more than a compressed tar archive file, that's had the .tar.gz filetype changed to .pkg... you can "open" a PKG file on a Linux machine by typing
- tar zxf filename.pkg
Opening and inspecting the contents of a PKG will put you a long way down the path to understanding how to build them yourself.
A PKG file contains
- some content (usually one or more RPMS) to be installed on the server
- a manifest file describing version info for the PKG
- an installation script (that actually installs the content)
- an uninstallation script (that can be executed to remove the PKG contents from the server)
Let's take a look at a specific example. I will retrace the steps I used to make my rsync PKG.
First, establish a shell session on your Linux server/workstation. Note: you do not need to be root to build a PKG file! Then set up a working directory. I will call it build
mkdir ~/build cd ~/build
I will be installing an RPM, so I need a directory to hold it
mkdir RPMS
I already built the rsync RPM, so I'll just copy it to the RPM directory
cp /usr/src/redhat/RPMS/i386/rsync-2.5.7-1.i386.rpm RPMS
Now make the manifest file, generally named packing_list, and put the following content inside
Package: YourName rsync Version: 2.5.7-1 List File: YourName-rsync-RaQ34-2.5.7-1 REBOOT: no SCRIPT: upgrade_me UNINSTALL: uninstall_me URL: ></A> <A HREF="http://www.example.com/" TARGET="_new" RPM: rsync 2.5.7 1 9550e5087f2d66cc11216e4bc9c55b1a
- Package
- This is the name that will appear in the list of installed programs in the Control Panel.
Important to note: there needs to be a trailing space after all the text to make the spacing show up properly in the Cobalt UI. - Version
- Should be self explanatory
- List file
- This will be the name of the files (with .md5lst or .uninst appended) in /var/lib/cobalt/ and /var/lib/cobalt/uninstallers/
- REBOOT
- Can be yes or no. If yes, admin will be prompted to reboot the server after PKG installation.
- SCRIPT
- The name of the install script. upgrade_me is the conventional/traditional name; call it whatever you want.
- UNINSTALL
- The name of the uninstall script. uninstall_me is the conventional/traditional name; call it whatever you want.
- URL
- The HTML "trick" shown is a way around a problem in the UI code. In order to show an actual hyperlink, you need to close the default anchor tag, then make another one. Otherwise, just the text of the link will appear.
- RPM
- One line for each RPM you plan to install. This PKG only contains one, so there's only one RPM line. The order the RPM lines are in will determine the installation order. Plan accordingly if some RPMS are prerequisites for others. Each line contains the name of the RPM, the major version, the minor version, and the MD5SUM of the RPM.
Now we'll make the upgrade_me script and put content in it
#!/bin/bash
# Cobalt PKG (c) 2004 Your Name <email@example.com> # http://www.example.com/ # Rsync software from http://rsync.samba.org/
RPMS=`/bin/ls $UPGRADE_DIR/RPMS`
# Verify proper product
if [ -e /etc/build ]; then /bin/egrep -q "(3000R|3100R|3001R)" /etc/build if [ $? != 0 ]; then /bin/echo "4015 This package for RaQ 3 and RaQ 4 only." exit 1 fi else /bin/echo "4015 Can't find /etc/build." exit 1 fi
# Create fake "installed RPMS" list file /bin/echo -n "YourName-rsync" > $UPGRADE_DIR/.installed_rpms
# Perform the installation for rpm in $RPMS; do /bin/rpm -U $UPGRADE_DIR/RPMS/$rpm > /dev/null 2>&1 if [ $? != 0 ]; then /bin/echo "4015 Problem installing package component: $rpm" exit 1 else /bin/echo $rpm >> $UPGRADE_DIR/.installed_rpms fi done
# Delete md5lst files for any existing (older) version # (Not sure if this should be here after the RPM install # or not; need to check install.cgi and see when the new # md5lst files are created...) if [ -e /var/lib/cobalt/*rsync* ]; then /bin/rm -rf /var/lib/cobalt/*rsync* fi
if [ -e /var/lib/cobalt/uninstallers/*rsync* ]; then /bin/rm -rf /var/lib/cobalt/uninstallers/*rsync* fi
exit 0
Most of the comments and explanations are inline, but I'll recap
- First, you grab all the filenames in the RPMS directory and save them into a variable for later.
- Then you check /etc/build to make sure this is the proper server type for this PKG.
- The "fake RPM" file is a workaround I saw in another PKG file. I'm not sure exactly what it does, but if you take it out, the install fails. More notes welcome by anyone with more of a clue than me.
- Install any RPMS listed in the RPMS directory of the PKG. Use the "upgrade" option so RPM will overwrite older versions of an RPM with any newer one that's in the PKG.
- Remove the old PKG md5lst files (used to display installed PKG info in the UI)
- Exit with code 0 so the Cobalt installer knows everything went ok.
Now we just have to make the uninstall script
#!/bin/sh # Cobalt PKG build (c) 2004 Your Name <email@example.com> # http://www.example.com/ # rsync software from http://rsync.samba.org/
# First, actually uninstall the software (duh) # The output could be redirected to a file in /tmp if you wanted to # trap and use it in case of failure /bin/rpm -e rsync > /dev/null 2>&1
# Delete the md5lst 'marker' files so the UI won't show # the stuff as still being installed /bin/rm -rf /var/lib/cobalt/YourName-rsync* /bin/rm -rf /var/lib/cobalt/uninstallers/YourName-rsync*
# Reset the 'Installed Software' list /usr/admserv/cgi-bin/.cobalt/install/install.cgi < /dev/null > /dev/null
# Outta here exit 0
Comments included should be sufficient.
Now we just have to make this all into a PKG file. So we're currently sitting in ~/build with an RPMS subdirectory containing our one RPM file. In ~/build are three files:
- packing_list
- upgrade_me
- uninstall_me
Make the whole directory tree into a compressed tar archive with the filename you want, and put the resulting file in ~
tar czvf ~/YourName-rsync-RaQ34-2.5.7-1.pkg .
That's all there is to it! Then put the PKG file onto a public webserver so you can install it with a URL, or else put a copy of it in /home/packages/ on your RaQ 3 or RaQ 4 and install it "locally" via the UI.
