Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Application Packaging Developer's Guide
Previous Next

Creating a File at Installation and Saving It During Removal

This case study creates a database file at installation time and saves a copy of the database when the package is removed.

Techniques

This case study demonstrates the following techniques:

  • Using classes and class action scripts to perform special actions on different sets of objects

    For more information, see Writing Class Action Scripts.

  • Using the space file to inform the pkgadd command that extra space is required to install this package properly

    For more information on the space file, see Reserving Additional Space on a Target System.

  • Using the installf command to install a file not defined in the prototype and pkgmap files

Approach

To create a database file at installation and save a copy on removal for this case study, you must complete the following tasks:

  • Define three classes.

    The package in this case study requires the following three classes be defined in the CLASSES parameter:

    • The standard class of none, which contains a set of processes belonging in the subdirectory bin.

    • The admin class, which contains an executable file config and a directory containing data files.

    • The cfgdata class, which contains a directory.

  • Make the package collectively relocatable.

    Notice in the prototype file that none of the path names begins with a slash or an environment variable. This indicates that they are collectively relocatable.

  • Calculate the amount of space the database file requires and create a space file to deliver with the package. This file notifies the pkgadd command that the package requires extra space and specifies how much.

  • Create a class action script for the admin class (i.admin).

    The sample script initializes a database using the data files belonging to the admin class. To perform this task, it does the following:

    • Copies the source data file to its proper destination

    • Creates an empty file named config.data and assigns it to a class of cfgdata

    • Executes the bin/config command (delivered with the package and already installed) to populate the database file config.data using the data files belonging to the admin class

    • Executes the installf -f command to finalize installation of config.data

    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 are removed from the system.

  • Create a removal class action script for the cfgdata class (r.cfgdata).

    The removal script makes a copy of the database file before it is deleted. 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 path names to remove. Path names always appear in reverse alphabetical order. This removal script copies files to the directory named $PKGSAV. When all the path names 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 $PKGSAV and then remove the config.data file and the data directory.

Case Study Files

The pkginfo File
PKG=krazy
NAME=KrAzY Applications
CATEGORY=applications
BASEDIR=/opt
ARCH=SPARC
VERSION=Version 1
CLASSES=none cfgdata admin
The prototype File
i pkginfo
i request
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 admin 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
The space File
# extra space required by config data which is
# dynamically loaded onto the system
data 500 1
The i.admin Class Action Script
# PKGINST parameter provided by installation service
# BASEDIR parameter provided by installation service
while read src dest
do
   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

This illustrates a rare instance in which installf is appropriate in a class action script. Because a space file has been used to reserve room on a specific file system, this new file may be safely added even though it is not included in the pkgmap file.

The r.cfgdata Removal Script
# the product manager for this package has suggested that
# the configuration data is so valuable that it should be
# backed up to $PKGSAV before it is removed!
while read path
do
# path names appear in reverse lexical order.
   mv $path $PKGSAV || exit 2
   rm -f $path || exit 2
done
exit 0
Previous Next

 
 
  Published under the terms fo the Public Documentation License Version 1.01. Design by Interspire