Create separate deb creation script.

pull/303/head
Fredrik Öhrström 2021-06-26 17:49:21 +02:00
rodzic 67f01cdc50
commit 3ee42c6fdb
7 zmienionych plików z 307 dodań i 34 usunięć

Wyświetl plik

@ -216,40 +216,7 @@ uninstall:
@./uninstall.sh / @./uninstall.sh /
wmbusmeters_$(DEBVERSION)_$(DEBARCH).deb: wmbusmeters_$(DEBVERSION)_$(DEBARCH).deb:
@rm -rf $(BUILD)/debian/wmbusmeters @./deb/create_deb.sh $(BUILD) $@ $(DEBVERSION) $(DEBARCH)
@mkdir -p $(BUILD)/debian/wmbusmeters/DEBIAN
@./install.sh $(BUILD)/wmbusmeters $(BUILD)/debian/wmbusmeters --no-adduser
# Remove the conf files, they are to be installed by postinst.
@rm $(BUILD)/debian/wmbusmeters/etc/wmbusmeters.conf
@rm -rf $(BUILD)/debian/wmbusmeters/etc/wmbusmetersd
# Build the control file
@echo "Package: wmbusmeters" >> $(BUILD)/debian/wmbusmeters/DEBIAN/control
@echo "Version: $(DEBVERSION)" >> $(BUILD)/debian/wmbusmeters/DEBIAN/control
@echo "Maintainer: Fredrik Öhrström <oehrstroem@gmail.com>" >> $(BUILD)/debian/wmbusmeters/DEBIAN/control
@echo "Architecture: $(DEBARCH)" >> $(BUILD)/debian/wmbusmeters/DEBIAN/control
@echo "Installed-Size: 1" >> $(BUILD)/debian/wmbusmeters/DEBIAN/control
@echo "Depends: libc6 (>= 2.27)" >> $(BUILD)/debian/wmbusmeters/DEBIAN/control
@echo "Section: kernel" >> $(BUILD)/debian/wmbusmeters/DEBIAN/control
@echo "Priority: optional" >> $(BUILD)/debian/wmbusmeters/DEBIAN/control
@echo "Homepage: https://github.com/weetmuts/wmbusmeters" >> $(BUILD)/debian/wmbusmeters/DEBIAN/control
@echo "Description: A tool to read wireless mbus telegrams from utility meters." >> $(BUILD)/debian/wmbusmeters/DEBIAN/control
@mkdir -p $(BUILD)/debian/wmbusmeters/usr/share/doc/wmbusmeters
# Install the changelog
@cp deb/changelog $(BUILD)/debian/wmbusmeters/usr/share/doc/wmbusmeters/changelog.Debian
@gzip -v9 $(BUILD)/debian/wmbusmeters/usr/share/doc/wmbusmeters/changelog.Debian
# Collect copyright information
@./deb/collect_copyrights.sh
@cp /tmp/copyright $(BUILD)/debian/wmbusmeters/usr/share/doc/wmbusmeters/copyright
# Install the install/remove scripts.
@for x in preinst postinst prerm postrm ; do \
cp deb/$$x $(BUILD)/debian/wmbusmeters/DEBIAN/ ; \
chmod 555 $(BUILD)/debian/wmbusmeters/DEBIAN/$$x ; \
done
# Package the deb
@(cd $(BUILD)/debian; dpkg-deb --build wmbusmeters .)
@mv $(BUILD)/debian/wmbusmeters_$(DEBVERSION)_$(DEBARCH).deb .
@echo Built package $@
@echo But the deb package is not yet working correctly! Work in progress.
snapcraft: snapcraft:
snapcraft snapcraft

65
deb/create_deb.sh 100755
Wyświetl plik

@ -0,0 +1,65 @@
#!/bin/sh
BUILD=$1
DEB=$2
DEBVERSION=$3
DEBARCH=$4
if [ -z "$BUILD" ]
then
echo You must supply a directory for the deb contents.
exit 1
fi
if [ -z "$DEB" ]
then
echo you must supply a name for the deb file.
exit 1
fi
if [ -z "$DEBVERSION" ]
then
echo you must supply deb version.
exit 1
fi
if [ -z "$DEBARCH" ]
then
echo you must supply a deb arch.
exit 1
fi
rm -rf $BUILD/debian/wmbusmeters
mkdir -p $BUILD/debian/wmbusmeters/DEBIAN
./install.sh $BUILD/wmbusmeters $BUILD/debian/wmbusmeters --no-adduser
# Remove the conf files, they are to be installed by postinst.
rm $BUILD/debian/wmbusmeters/etc/wmbusmeters.conf
rm -rf $BUILD/debian/wmbusmeters/etc/wmbusmetersd
# Build the control file
echo "Package: wmbusmeters" >> $BUILD/debian/wmbusmeters/DEBIAN/control
echo "Version: $DEBVERSION" >> $BUILD/debian/wmbusmeters/DEBIAN/control
echo "Maintainer: Fredrik Öhrström <oehrstroemgmail.com>" >> $BUILD/debian/wmbusmeters/DEBIAN/control
echo "Architecture: $DEBARCH" >> $BUILD/debian/wmbusmeters/DEBIAN/control
echo "Installed-Size: 1" >> $BUILD/debian/wmbusmeters/DEBIAN/control
echo "Depends: libc6 (>= 2.27)" >> $BUILD/debian/wmbusmeters/DEBIAN/control
echo "Section: kernel" >> $BUILD/debian/wmbusmeters/DEBIAN/control
echo "Priority: optional" >> $BUILD/debian/wmbusmeters/DEBIAN/control
echo "Homepage: https://github.com/weetmuts/wmbusmeters" >> $BUILD/debian/wmbusmeters/DEBIAN/control
echo "Description: A tool to read wireless mbus telegrams from utility meters." >> $BUILD/debian/wmbusmeters/DEBIAN/control
mkdir -p $BUILD/debian/wmbusmeters/usr/share/doc/wmbusmeters
# Install the changelog
cp deb/changelog $BUILD/debian/wmbusmeters/usr/share/doc/wmbusmeters/changelog.Debian
gzip -v9 $BUILD/debian/wmbusmeters/usr/share/doc/wmbusmeters/changelog.Debian
# Collect copyright information
./deb/collect_copyrights.sh
cp /tmp/copyright $BUILD/debian/wmbusmeters/usr/share/doc/wmbusmeters/copyright
# Install the install/remove scripts.
for x in preinst postinst prerm postrm ; do \
cp deb/$x $BUILD/debian/wmbusmeters/DEBIAN/ ; \
chmod 555 $BUILD/debian/wmbusmeters/DEBIAN/$x ; \
done
# Package the deb
(cd $BUILD/debian; dpkg-deb --build wmbusmeters .)
mv $BUILD/debian/wmbusmeters_${DEBVERSION}_${DEBARCH}.deb .
echo Built package $
echo But the deb package is not yet working correctly! Work in progress.

Wyświetl plik

@ -0,0 +1,72 @@
#!/bin/sh
ID=$(id -u wmbusmeters 2>/dev/null)
if [ -f "$ROOT"/usr/sbin/nologin ]
then
USERSHELL="$ROOT/usr/sbin/nologin"
elif [ -f "$ROOT"/sbin/nologin ]
then
USERSHELL="$ROOT/sbin/nologin"
else
USERSHELL="/bin/false"
fi
if [ $(getent group wmbusmeters) ]
then
echo "group: wmbusmeters unmodified"
else
groupadd -f wmbusmeters
echo "group: added wmbusmeters"
fi
if [ -z "$ID" ]
then
# Create the wmbusmeters user
useradd --system --shell $USERSHELL -g wmbusmeters wmbusmeters
echo "user: added wmbusmeters"
else
echo "user: wmbusmeters unmodified"
fi
if [ $(getent group dialout) ]
then
if [ "$(groups wmbusmeters | grep -o dialout)" = "" ]
then
# Add the wmbusmeters user to dialout
usermod -a -G dialout wmbusmeters
echo "user: added wmbusmeters to dialout group"
else
echo "user: wmbusmeters already added to dialout"
fi
else
echo "dialout group does not exist"
fi
if [ $(getent group uucp) ]
then
if [ "$(groups wmbusmeters | grep -o uucp)" = "" ]
then
# Add the wmbusmeters user to uucp
usermod -a -G uucp wmbusmeters
echo "user: added wmbusmeters to uucp group"
else
echo "user: wmbusmeters already added to uucp"
fi
else
echo "uucp group does not exist"
fi
if [ $(getent group plugdev) ]
then
if [ "$(groups wmbusmeters | grep -o plugdev)" = "" ]
then
# Add the wmbusmeters user to plugdev
usermod -a -G plugdev wmbusmeters
echo "user: added wmbusmeters to plugdev group"
else
echo user: wmbusmeters already added to plugdev
fi
else
echo "plugdev group does not exist"
fi

Wyświetl plik

@ -0,0 +1,40 @@
#!/bin/sh
####################################################################
##
## Install /etc/wmbusmeters.conf
##
if [ ! -f "$ROOT"/etc/wmbusmeters.conf ]
then
# Create default configuration
mkdir -p "$ROOT"/etc/
cat <<EOF > "$ROOT"/etc/wmbusmeters.conf
loglevel=normal
device=auto:t1
logtelegrams=false
format=json
meterfiles=/var/log/wmbusmeters/meter_readings
meterfilesaction=overwrite
logfile=/var/log/wmbusmeters/wmbusmeters.log
EOF
chmod 644 "$ROOT"/etc/wmbusmeters.conf
echo "conf file: created $ROOT/etc/wmbusmeters.conf"
else
echo "conf file: $ROOT/etc/wmbusmeters.conf unchanged"
fi
####################################################################
##
## Create /etc/wmbusmeters.d
##
if [ ! -d "$ROOT"/etc/wmbusmeters.d ]
then
# Create the configuration directory
mkdir -p "$ROOT"/etc/wmbusmeters.d
chmod -R 755 "$ROOT"/etc/wmbusmeters.d
echo "conf dir: created $ROOT/etc/wmbusmeters.d"
else
echo "conf dir: $ROOT/etc/wmbusmeters.d unchanged"
fi

Wyświetl plik

@ -0,0 +1,10 @@
####################################################################
##
## Intall wmbusmeters manual page
##
rm -f "$ROOT"/usr/share/man/man1/wmbusmeters.1.gz
mkdir -p "$ROOT"/usr/share/man/man1
gzip -v9 -c wmbusmeters.1 > "$ROOT"/usr/share/man/man1/wmbusmeters.1.gz
echo "man page: installed $ROOT/usr/share/man/man1/wmbusmeters.1.gz"

Wyświetl plik

@ -0,0 +1,79 @@
####################################################################
##
## Create /lib/systemd/system/wmbusmeters.service
##
SYSTEMD_NEEDS_RELOAD=false
mkdir -p "$ROOT"/lib/systemd/system/
OLD_WMBS=~/old.wmbusmeters.service.backup
CURR_WMBS="$ROOT"/lib/systemd/system/wmbusmeters.service
if [ -f $CURR_WMBS ]
then
echo "systemd: backing up $CURR_WMBS to here: $OLD_WMBS"
cp $CURR_WMBS $OLD_WMBS 2>/dev/null
fi
# Create service file for starting daemon without explicit device.
# This means that wmbusmeters will rely on the conf file device setting.
cat <<'EOF' > $CURR_WMBS
[Unit]
Description="wmbusmeters service"
Documentation=https://github.com/weetmuts/wmbusmeters
Documentation=man:wmbusmeters(1)
After=network.target
StopWhenUnneeded=false
StartLimitIntervalSec=10
StartLimitInterval=10
StartLimitBurst=3
[Service]
Type=forking
PrivateTmp=yes
User=wmbusmeters
Group=wmbusmeters
Restart=always
RestartSec=1
# Run ExecStartPre with root-permissions
PermissionsStartOnly=true
ExecStartPre=-/bin/mkdir -p /var/log/wmbusmeters/meter_readings
ExecStartPre=/bin/chown -R wmbusmeters:wmbusmeters /var/log/wmbusmeters
ExecStartPre=-/bin/mkdir -p /run/wmbusmeters
ExecStartPre=/bin/chown -R wmbusmeters:wmbusmeters /run/wmbusmeters
ExecStart=/usr/sbin/wmbusmetersd /run/wmbusmeters/wmbusmeters.pid
ExecReload=/bin/kill -HUP $MAINPID
PIDFile=/run/wmbusmeters/wmbusmeters.pid
[Install]
WantedBy=multi-user.target
EOF
if diff $OLD_WMBS $CURR_WMBS 1>/dev/null
then
echo "systemd: no changes to $CURR_WMBS"
else
echo "systemd: updated $CURR_WMBS"
SYSTEMD_NEEDS_RELOAD=true
fi
OLD_WMBAS=~/old.wmbusmeters@.service.backup
CURR_WMBAS="$ROOT"/lib/systemd/system/wmbusmeters@.service
if [ -f $CURR_WMBAS ]
then
echo "systemd: removing $CURR_WMBAS"
echo "systemd: backing up $CURR_WMBAS to here: $OLD_WMBAS"
cp $CURR_WMBAS $OLD_WMBAS 2>/dev/null
rm $CURR_WMBAS
SYSTEMD_NEEDS_RELOAD=true
fi
if [ "$SYSTEMD_NEEDS_RELOAD" = "true" ]
then
echo
echo
echo "You need to reload systemd configuration! Please do:"
echo "sudo systemctl daemon-reload"
fi

Wyświetl plik

@ -0,0 +1,40 @@
#!/bin/sh
####################################################################
##
## Prepare for /var/log/wmbusmeters and /var/log/wmbusmeters/meter_readings
##
if [ ! -d "$ROOT"/var/log/wmbusmeters/meter_readings ]
then
# Create the log directories
mkdir -p "$ROOT"/var/log/wmbusmeters/meter_readings
chown -R wmbusmeters:wmbusmeters "$ROOT"/var/log/wmbusmeters
echo "log: created $ROOT/var/log/wmbusmeters/meter_readings"
else
echo "log: $ROOT/var/log/wmbusmeters/meter_readings unchanged"
fi
####################################################################
##
## Install /etc/logrotate.d/wmbusmeters
##
if [ ! -f "$ROOT"/etc/logrotate.d/wmbusmeters ]
then
mkdir -p "$ROOT"/etc/logrotate.d
# Create logrotate file
cat <<EOF > "$ROOT"/etc/logrotate.d/wmbusmeters
/var/log/wmbusmeters/*.log {
rotate 12
weekly
compress
missingok
postrotate
/bin/kill -HUP `cat /run/wmbusmeters/wmbusmeters.pid 2> /dev/null` 2> /dev/null || true
endscript
EOF
echo "logrotate: created $ROOT/etc/logrotate.d/wmbusmeters"
else
echo "conf file: $ROOT/etc/logrotate.d/wmbusmeters unchanged"
fi