From 34aec6d7a17cd11ecdf2f94d2cfcb0f6b1e50a07 Mon Sep 17 00:00:00 2001 From: Matthew Wall Date: Mon, 6 Jul 2015 14:25:53 -0400 Subject: [PATCH] fixed rpm upgrade process --- pkg/weewx.spec.in | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/pkg/weewx.spec.in b/pkg/weewx.spec.in index 8f00ab85..cad2d272 100644 --- a/pkg/weewx.spec.in +++ b/pkg/weewx.spec.in @@ -111,25 +111,32 @@ ln -s ../share/weewx/wee_reports %{buildroot}%{_bindir}/wee_reports # pre-compile the python code python -m compileall %{buildroot}%{dst_bin_dir} +%pre +if [ "$1" = "2" ]; then + # this is an upgrade + if [ -f %{cfg_file} ]; then + echo saving previous config as %{cfg_file}.prev + cp -p %{cfg_file} %{cfg_file}.prev + fi +fi + %post python -m compileall %{dst_bin_dir} if [ "$1" = "1" ]; then # this is a new installation - /usr/share/weewx/wee_config --install --dist-config=/etc/weewx/weewx.conf --output=/etc/weewx/weewx.conf --driver=weewx.drivers.simulator --no-prompt --no-backup + # create a sane configuration file with simulator as the station type + /usr/share/weewx/wee_config --install --dist-config=/etc/weewx/weewx.conf.dist --output=/etc/weewx/weewx.conf --driver=weewx.drivers.simulator --no-prompt --no-backup chkconfig weewx on %{initdir}/weewx start elif [ "$1" = "2" ]; then # this is an upgrade - # merge changes to weewx.conf - if [ -f %{cfg_file}.dist ]; then - NEWVER=`/usr/share/weewx/wee_config --version` - OLDVER=`grep version %{cfg_file} | sed -e 's/\s*version\s*=\s*//'` - echo saving previous config file as %{cfg_file}-$OLDVER - mv %{cfg_file} %{cfg_file}-$OLDVER - echo saving distribution config file as %{cfg_file}-$NEWVER - cp -p %{cfg_file}.dist %{cfg_file}-$NEWVER - echo merging previous and distribution into %{cfg_file} - /usr/share/weewx/wee_config --upgrade --config=%{cfg_file}-$OLDVER --dist-config=%{cfg_file}-$NEWVER --output=%{cfg_file} --no-prompt --no-backup + # update previous config and merge with dist into to weewx.conf + if [ -f %{cfg_file}.dist -a -f %{cfg_file}.prev ]; then + OLDVER=`grep version %{cfg_file}.prev | sed -e 's/\s*version\s*=\s*//'` + echo saving previous config as %{cfg_file}-$OLDVER + mv %{cfg_file}.prev %{cfg_file}-$OLDVER + echo merging configs into %{cfg_file} + /usr/share/weewx/wee_config --upgrade --config=%{cfg_file}-$OLDVER --dist-config=%{cfg_file}.dist --output=%{cfg_file} --no-prompt --no-backup fi # do a full restart not just a HUP %{initdir}/weewx stop