move /etc/default/weewx to post

This commit is contained in:
Matthew Wall
2024-01-07 12:22:05 -05:00
parent 0c8ab8c699
commit f581efd8ba
4 changed files with 53 additions and 20 deletions

View File

@@ -5,8 +5,6 @@
- mw Check over the upgrade document for accuracy of package installs. More
detail would be useful.
- mw Do we want `weectl station upgrade --what config` to convert `WEEWX_ROOT =
/` to `WEEWX_ROOT = /etc/weewx`, or to delete `WEEWX_ROOT` entirely?
## deb/rpm installs

View File

@@ -248,6 +248,42 @@ get_user() {
fi
}
# create/modify the defaults file to match this installation
setup_defaults() {
dflts=/etc/default/weewx
if [ ! -f $dflts ]; then
echo "WEEWX_PYTHON=python3" > $dflts
echo "WEEWX_BINDIR=/usr/share/weewx" >> $dflts
else
grep -q "^WEEWX_PYTHON=" $dflts || \
echo "WEEWX_PYTHON=python3" >> $dflts
grep -q "^WEEWX_BINDIR=" $dflts || \
echo "WEEWX_BINDIR=/usr/share/weewx" >> $dflts
fi
# the SysV rc script uses additional variables, so set values for them
if [ "$1" = "init" ]; then
if [ ! -f $dflts ]; then
echo "WEEWX_CFGDIR=/etc/weewx" >> $dflts
echo "WEEWX_RUNDIR=/var/lib/weewx" >> $dflts
echo "WEEWX_USER=$WEEWX_USER" >> $dflts
echo "WEEWX_GROUP=$WEEWX_GROUP" >> $dflts
echo "WEEWX_INSTANCES=\"weewx\"" >> $dflts
else
grep -q "^WEEWX_CFGDIR=" $dflts || \
echo "WEEWX_CFGDIR=/etc/weewx" >> $dflts
grep -q "^WEEWX_RUNDIR=" $dflts || \
echo "WEEWX_RUNDIR=/var/lib/weewx" >> $dflts
grep -q "^WEEWX_USER=" $dflts || \
echo "WEEWX_USER=$WEEWX_USER" >> $dflts
grep -q "^WEEWX_GROUP=" $dflts || \
echo "WEEWX_GROUP=$WEEWX_GROUP" >> $dflts
grep -q "^WEEWX_INSTANCES=" $dflts || \
echo "WEEWX_INSTANCES=\"weewx\"" >> $dflts
fi
fi
}
# create the user that the daemon will run as, but only if not already exist
create_user() {
if ! getent group | grep -q "^$WEEWX_GROUP:"; then
@@ -368,6 +404,7 @@ fi
case "$1" in
configure)
get_user
setup_defaults $pid1
if [ "$2" != "" ]; then
# this is an upgrade so create a maintainers version by merging

View File

@@ -41,7 +41,6 @@ install:
mkdir -p $(DST_CFGDIR)
mkdir -p $(DST_DOCDIR)
mkdir -p $(DST)/usr/bin
mkdir -p $(DST)/etc/default
# copyright, license, and upstream changelog
cp docs_src/copyright.md $(DST_DOCDIR)/copyright
@@ -85,11 +84,6 @@ install:
$(SRC)/bin/$$f > $(DST)/usr/bin/$$f; \
done
# the defaults file indicates which python and weewx to use
sed \
-e 's%WEEWX_PYTHON=.*%WEEWX_PYTHON=$(PYTHON)%' \
$(SRC)/pkg/etc/default/weewx > $(DST)/etc/default/weewx
# additional debian control files that dpkg-buildpackage seems to ignore
mkdir -p $(DST)/DEBIAN
cp $(SRC)/debian/config $(DST)/DEBIAN

View File

@@ -84,7 +84,6 @@ mkdir -p %{buildroot}%{dst_code_dir}
mkdir -p %{buildroot}%{dst_cfg_dir}
mkdir -p %{buildroot}%{dst_doc_dir}
mkdir -p %{buildroot}%{_bindir}
mkdir -p %{buildroot}/etc/default
# rpm wants copyright and license even if no docs
cp docs_src/copyright.md %{buildroot}%{dst_doc_dir}/copyright
@@ -123,11 +122,6 @@ for f in %{entry_points}; do \
bin/$f > %{buildroot}%{_bindir}/$f; \
done
# configure defaults
sed \
-e 's%WEEWX_PYTHON=.*%WEEWX_PYTHON=%{python}%' \
pkg/etc/default/weewx > %{buildroot}/etc/default/weewx
%pre
# if there is already a database directory, then use ownership of that to
@@ -175,21 +169,32 @@ if [ -d /var/lib/weewx ]; then
WEEWX_GROUP=$(stat -c "%%G" /var/lib/weewx)
fi
# insert values into the defaults file (used by the entry points)
dflts=/etc/default/weewx
if [ ! -f $dflts ]; then
echo "WEEWX_PYTHON=python3" > $dflts
echo "WEEWX_BINDIR=/usr/share/weewx" >> $dflts
else
grep -q "^WEEWX_PYTHON=" $dflts || \
echo "WEEWX_PYTHON=python3" >> $dflts
grep -q "^WEEWX_BINDIR=" $dflts || \
echo "WEEWX_BINDIR=/usr/share/weewx" >> $dflts
fi
# see which init system (if any) is running
pid1=none
if [ -d /run/systemd/system ]; then
pid1=systemd
fi
# install the init files
if [ -d %{systemd_dir} ]; then
for f in weewx.service weewx@.service; do
sed \
-e "s/User=.*/User=${WEEWX_USER}/" \
-e "s/Group=.*/Group=${WEEWX_GROUP}/" \
%{dst_cfg_dir}/systemd/weewx.service > %{systemd_dir}/weewx.service
sed \
-e "s/User=.*/User=${WEEWX_USER}/" \
-e "s/Group=.*/Group=${WEEWX_GROUP}/" \
%{dst_cfg_dir}/systemd/weewx@.service > %{systemd_dir}/weewx@.service
%{dst_cfg_dir}/systemd/$f > %{systemd_dir}/$f
done
fi
# install the udev rules
@@ -322,7 +327,6 @@ rm -rf %{buildroot}
%attr(0755,root,root) %{_bindir}/weectl
%{dst_code_dir}/
%doc %{dst_doc_dir}/
%config(noreplace) %{_sysconfdir}/default/weewx
%config(noreplace) %{dst_cfg_dir}/
%changelog