I have some common code that I would like to execute in the %pre and %post section of my rpm spec file. When I place a subroutine in the %pre section, I need to add the same subroutine to the %post section of the RPM. It sucks maintaining the same subroutine twice. Here is an example:
RPM spec file %pre and %post sections:
%pre
log_file=/var/log/myrpminstall.log
#-------------------------------------
# Send text log_file
#-------------------------------------
log_it() {
log_msg=$1
echo -e $log_msg >> $log_file
}
log_it "pre section log information"
%post
log_it "Post section log informations"
Currently, when the %post section of the rpm executes during an install, I receive an error message:
/var/tmp/rpm-tmp.36557: line 5: log_it: command not found
So, is there a way to make a subroutine like log_it accessible to all sections (global function) of the RPM?? Currently, I have to place the log_it function in the %post section if I want to use it there.