How the package system works 
Simon  18 Sep, 2000

1. How the package system works 

For people who write packages that are curious how it works, I've attached the
relevant portions of the /etc/utils script which contains the listpkg,
installpkg, and removepkg commands, so you can see how simple they really are.
The whole system is a scheme I came up with in the last week of development on
Freesco 0.2.7, so I make no appologies for the simplistic nature of it, and it
does place a lot of reliance on the package writer to get things right, as a
consequence. (On the flip side, no real limitations are placed on what you
can do)

Because of its open nature its taken a while to standardise on how things
should be done, but heres the basics:

The listpkg command just looks for a file called packages.txt and displays it
- either from a specific URL at the freesco site, or the specified URL.
It generally doesnt get used by people writing 3rd party packages, so I'll
ignore it here.

installpkg appends .sh to the filename/URL you specify, and attempts to
download the script into /tmp/install, it then asks if you want to view it,
and then executes it. Several command line arguments are passed to your
install script, they are, in this order:

$1 - BaseURL - this is the p directory the package was downloaded from,
     and by using this, the install script can be URL independant.
     (To allow mirrors of the package etc)

$2 - VER - Freesco version - eg 0.2.7. Currently only one version of freesco
     supports packages, but its important for the install script to check the
     version of freesco, since a number of assumptions are generally made about
     the layout of things in freesco which may (probably will) change in future
     versions. Currently (until another version comes out) you should just
     check for 0.2.7 and refuse to install otherwise, as a safety measure.

$3 - bootdev - this lets your install script know if the user is using a floppy
     disk or hard drive. Most packages are too big or arent suitable for a
     floppy drive, so if $3=fd0 then forget about installing Possible values at
     the moment are fd0, hda1, hda5, hdb1, hdb5.

$4 - freedisk - this is the amount of floppy/hard drive space free, in
     kilobytes. You should check this to make sure theres enough room for your
     expanded files, plus a "bit".

$5 - freeram(disk) - this is the amount of free space in the ramdisk. Most
     packages download their tgz file to /tmp/install, so there has to be
     enough room (plus a bit) to hold it until after it has been extracted
     and deleted.

Generally the install script checks the above values, attempts to download the
tgz using snarf, extracts the tgz by using zcat and star, and then performs
package specific things. (for example sshd then uses ssh-keygen to create a
host key before deleting the keygen program)

Finally it will print a message telling the user a bit about the package
(what directory to look in to find config files etc) and if applicable to the
type of package, even start it up straight away.

If your /rc/rcuser/rc_* script includes firewall rules, you should also run the
command rc_masq so that your firewall rules will come into effect immediately,
instead of after a reboot.

After your install script exits, the installpkg command cleans up the mess for
you - specifically, it deletes the /tmp/install directory, (which was your
initial current directory when your script started) so you dont need to worry
about deleting the tgz file if you downloaded it to the current directory.

Package removal is completely up to you - the removepkg command just looks in
the directory /rc/uninst for a script of the name specified with a .rm
extension. For example:


Generally, you want to stop the service you're removing first (if applicable)
then delete files you've installed, and directory if applicable. rm -f $0
deletes the uninstall script itself.

Because this is just a script, you could give the user the opertunity to
answer questions, for example for extremail you might want to ask them
whether they want to delete just the program, or delete the config files
and messages as well.

If you'd previously had firewall rules in your /rc/rcuser/rc_* script, then
you should run rc_masq as part of the uninstall process AFTER you've deleted
your rc_* file, so that the firewall rules will get removed immediately.


A directory /rc/rcuser was added in 0.2.7 specifically with packages in mind,
and it works like this:

Firstly, its in the path, so your script in here can be executed without typing
the full path. Secondly there are three places which search for scripts
beginning with rc_ and execute them - during bootup, during shutdown, and
during the execution of rc_masq. (The firewalling script)

Simply placing the correct script file in this directory allows your package
to start up and shut down automatically with the system, and add its own custom
firewall rules. The script should be able to handle the following command line
arguments, ($1)

stop     - this is called during shutdown. Your package should cleanly exit or shut
           down as applicable.
restart  - you should perform a shutdown, then start up again.
firewall - you should add your firewall rules, or exit immediately if you have none.
          (very important)

no command line argument means start - your package should start up.

How you go about things is up to you as long as your script responds to those
arguments. Generally you'd print messages saying

 "Starting xxxxx..............DONE" 
or similar, but its not a requirement. Looking at the script from oidentd or
sshd should give you the idea.

Where should you put your program ? If its a single executable which you want
in the path, you could put it in /rc/rcuser, otherwise you should make a
directory under /mnt/router

Date: 18 Sep, 2000 
freesco/howtos/package_system_027.txt (86418 views) · Last modified: 2005/09/14 00:49 (external edit)