-1

I'm Fairly new to packaging nodejs apps with rpm.

The requirement is that we always merge any changes we may have in the config file without wiping out any setting that may have been changed by the sys admin.

As you have guessed, config files for nodejs apps are in json.

I've investigated %config and %config(noreplace) in spec file, and noreplace is a better fit with the exception that if we have some new things added in the new config file then add those changes to the existing file without wiping out any changes that the sys admin may have done.

I've found few tools/ shell scripts that does that, but I'm not sure if there are more straight forward ways or best practices to follow to accomplish that?

nolimit
  • 814
  • 10
  • 19
  • I'm not sure I understand what you are asking for exactly but, in general, if there is an admin-editable configuration file in an rpm then it gets marked `%config(noreplace)` and it is up to the admin to compare it against new upstream configuration files and to manually merge in any changes. – Etan Reisner Apr 02 '15 at 19:02
  • I've updated the question. Requirement is to merge potential changes in config files. This is very basic, during development we sometimes add keys to the config, but with rpm (noreplace) those keys will never make it to the box where we are installing the software on. So what do you do in this case? – nolimit Apr 02 '15 at 19:37
  • to make it crystal clear, is there a way we can check and merge changes in the new rpm to the one already installed? or is it a common practice that it is up to the system admin to merge changes if any? – nolimit Apr 02 '15 at 19:41
  • As I said, for packages designed for general usage the general expectation is manual merging by the admin for upstream changes. Merging is possible (and also done) but requires more careful testing/etc. There isn't anything built-in for this though. You just get to do what you need to do in `%post`. – Etan Reisner Apr 02 '15 at 19:54

1 Answers1

0

What you needed is a way to detect .rpmsave files in the %post section of your spec. It could look something like this:

%post
# Check this during an update to the RPM $1 = 2
if [ "$1" = "2" ]
then
  ########################################################################
  # apply updates to config files, preserving any customizations
  #   1) restore original (customized) file if renamed to file.rpmsave
  #   2) run all config files through config_updates.pl
  ########################################################################
  #
  # RPM query will get config files from old and new rpm, so there will be dups
  # 
  IFS=$'\n'
  # Eliminate dups by passing query through sort -u %name is RPM name
  config_files=(`rpm -qc %name | sort -u`)
  unset IFS
  for AF in "${config_files[@]}"
  do
    # Search for config files with .rpmsave extension
    [ -f "$RF.rpmsave" ] && {
      # Save the new $RF file (cp -vf $RF $RF.new)
      # Copy the original rpm config file renamed during
      # the update with.rpmsave extension
      # back to $RF (cp -vf $RF.rpmsave $RF)
      # Launch another script to merge $RF.new into $RF.
      %dir_to_config_script/config_updates.pl -file=$RF
    }
  done
fi
GoinOff
  • 1,792
  • 1
  • 18
  • 37