|
|
This study creates a database file at the time of installation and saves a copy of the database when the package is removed.
This case study shows examples of the following techniques:
To create a database file at the time of installation and save a copy on removal, you must:
This package requires three classes:
Notice in the sample prototype(4) file that none of the pathnames begin with a slash or a variable. This indicates that they are collectively relocatable.
The sample script initializes a database using the data files belonging to the admin class. To perform this task, it:
No special action is required for the admin class at removal time so no removal class action script is created. This means that all files and directories in the admin class will simply be removed from the system.
The sample removal script makes a copy of the database file before it is deleted during package removal. No special action is required for this class at installation time, so no installation class action script is needed.
Remember that the input to a removal script is a list of pathnames to remove. Pathnames always appear in lexical order with the directories appearing first. This script captures directory names so that they can be acted upon later and copies any files to a directory named /tmp. When all of the pathnames have been processed, the script then goes back and removes all directories and files associated with the cfgdata class.
The outcome of this removal script is to copy config.data to /tmp and then remove the config.data file and the data directory.
PKG='krazy' NAME='KrAzY Applications' CATEGORY='applications' ARCH='3b2' VERSION='Version 1' CLASSES='none cfgdata admin'
i pkginfo i i.admin i r.cfgdata d none bin 555 root sys f none bin/process1 555 root other f none bin/process2 555 root other f none bin/process3 555 root other f none bin/config 500 root sys d admin cfg 555 root sys f admin cfg/datafile1 444 root sys f admin cfg/datafile2 444 root sys f admin cfg/datafile3 444 root sys f admin cfg/datafile4 444 root sys d cfgdata data 555 root sys
# extra space required by config data which is # dynamically loaded onto the system data 500 1
# PKGINST parameter provided by installation service # BASEDIR parameter provided by installation servicewhile read src dest do # the installation service provides '/dev/null' as the # pathname for directories, pipes, special devices, etc # which it knows how to create [ "$src" = /dev/null ] && continue
cp $src $dest || exit 2 done
# if this is the last time this script will # be executed during the installation, do additional # processing here if [ "$1" = ENDOFCLASS ] then # our config process will create a data file based on any changes # made by installing files in this class; make sure # the data file is in class 'cfgdata' so special rules can apply # to it during package removal installf -c cfgdata $PKGINST $BASEDIR/data/config.data f 444 root sys || exit 2 $BASEDIR/bin/config > $BASEDIR/data/config.data || exit 2 installf -f -c cfgdata $PKGINST || exit 2 fi exit 0
# the product manager for this package has suggested that # the configuration data is so valuable that it should be # backed up to /tmp before it is removed!while read path do # pathnames appear in lexical order, thus directories # will appear first; you cannot operate on directories # until done, so just keep track of names until # later if [ -d $path ] then dirlist="$dirlist $path" continue fi mv $path /tmp || exit 2 done if [ -n "$dirlist" ] then rm -rf $dirlist || exit 2 fi exit 0