mine and postinstall

Stefan Fiedler <[email protected]>
Newsgroups gmane.linux.distributions.rock.devel
Message-ID <[email protected]>
Hi all,

I've just sent in two patches that add the postinstall (and postremove) 
feature to ROCK Linux. 
Comments, critics and suggestions are, as always, very welcome.

It basically works as follows:

- If the directory /var/adm/postinstall exists, mine writes a log file for 
each package installed or removed. The format of logs and flist files is the 
same. If this directory does not exist, no log will be written. Only files 
that have really been installed or removed will appear in the logs.

- The postinstall package contains the /usr/sbin/postinstall script. This 
script defines 6 helper functions: 
    + is_installed() and is_removed() check if a file exists (is installed) or 
does not exist (is removed), respectively.
    + any_installed() and any_removed() accept a grep pattern as their 
argument and return true if any files from the postinstall or postremove logs 
that match this pattern are installed or removed, respectively.
   + all_installed() and all_removed() also accept a grep pattern and return 
all files from the postinstall or postremove logs that match this pattern and 
are installed or removed, respectively.

- any_installed() and all_installed() only grep through the postinstall logs 
('<pkgname>-install.??????'),  any_removed() and all_removed() only grep 
through the postremove logs ('<pkgname>-remove.??????'). 
  This should prevent unexpected behaviour if a user installs _and_ removes a 
package with post-install/-remove actions before running 'postinstall', or if 
files of a package are accidentially deleted. 

- postinstall sources all postinstall scripts located in /etc/postinstall.

Now we can do the following in postinstall scripts, e.g. the one that comes 
with the postinstall package:

 # Print a helpful text when .so files have been installed or removed :)
 if any_installed ".*\.so"; then
  echo "dynamic libraries installed, run ldconfig!"
 fi

 if any_removed ".*\.so"; then
  echo "dynamic libraries removed, run ldconfig!"
 fi

 # Output each installed or removed file
 all_installed ".*" | while read M; do echo "Installed: $M"; done

 all_removed ".*" | while read M; do echo "Removed: $M"; done

- postinstall accepts the -a option which causes the any_installed() and 
is_installed() functions to always return true. The -r option does the same 
for any_removed() and is_removed(). Both options only affect the all_*()  
functions indirectly when these functions check with is_installed() or 
is_removed() if a file is installed or removed.

- to allow postremove actions, postinstall itself checks for installed 
postinstall scripts (/etc/postinstall/*.sh files) and backs them up 
in /etc/postinstall/postremove/. postinstall also checks for removed scripts, 
and for each removed script it sources the backup and then deletes it.

- as a last step, postinstall removes all /var/adm/postinstall/ log files.

--- Some notes: --- 

- mine writes the logs to the mine_root_dir hierarchy and not to the real root 
dir, in case they are different. This makes sense because only the 
mine_root_dir is known to be writeable (after all it's where packages are 
installed to or removed from), and you usually want to have installed/removed 
packages and the respective log files in the same hierarchy.

- there is no explicit check to see if a package was installed or removed 
completely. If you need to perform an action if a package is installed, use 
any_installed "<pkgname>: ".

- all_installed() and all_removed() only return file names, not the package 
names, simply because I think it's not needed.

Have fun,
 Stefan Fiedler
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.