More work on packaging as deb.

pull/22/head
weetmuts 2019-02-23 19:49:30 +01:00
rodzic 69cf31ace0
commit ca79c0063a
7 zmienionych plików z 107 dodań i 41 usunięć

Wyświetl plik

@ -29,7 +29,7 @@ ifeq "$(HOST)" "arm"
DEBARCH=armhf
else
CXX=g++
STRIP=strip
STRIP=strip --strip-unneeded --remove-section=.comment --remove-section=.note
BUILD=build
DEBARCH=amd64
endif
@ -79,15 +79,15 @@ all: $(BUILD)/wmbusmeters $(BUILD)/testinternals
dist: wmbusmeters_$(VERSION)_$(DEBARCH).deb
install: $(BUILD)/wmbusmeters
@./install.sh $(BUILD)/wmbusmeters
@./install.sh $(BUILD)/wmbusmeters /
uninstall:
@./uninstall.sh /
wmbusmeters_$(VERSION)_$(DEBARCH).deb:
@rm -rf $(BUILD)/debian/wmbusmeters
@mkdir -p $(BUILD)/debian/wmbusmeters/DEBIAN
@mkdir -p $(BUILD)/debian/wmbusmeters/usr/bin
@mkdir -p $(BUILD)/debian/wmbusmeters/usr/sbin
@cp $(BUILD)/wmbusmeters $(BUILD)/debian/wmbusmeters/usr/bin/wmbusmeters
@ln $(BUILD)/debian/wmbusmeters/usr/bin/wmbusmeters $(BUILD)/debian/wmbusmeters/usr/sbin/wmbusmetersd
@./install.sh --no-adduser $(BUILD)/wmbusmeters $(BUILD)/debian/wmbusmeters
@rm -f $(BUILD)/debian/wmbusmeters/DEBIAN/control
@echo "Package: wmbusmeters" >> $(BUILD)/debian/wmbusmeters/DEBIAN/control
@echo "Version: $(VERSION)" >> $(BUILD)/debian/wmbusmeters/DEBIAN/control

Wyświetl plik

@ -2,10 +2,18 @@
if [ "$1" = "" ]
then
echo Usage: install.sh build/wmbusmeters
echo Usage: install.sh [binary] [root]
echo Example: install.sh build/wmbusmeters /
exit 0
fi
ADDUSER=true
if [ "$1" = "--no-adduser" ]
then
ADDUSER=false
shift
fi
if [ ! $(basename "$1") = "wmbusmeters" ]
then
echo Oups, please only try to install wmbusmeters using this script.
@ -18,61 +26,67 @@ then
exit 1
fi
if [ "$EUID" -ne 0 ]
then echo "Please run as root."
exit
if [ ! -d "$2" ]
then
echo Oups, please supply a valid root directory.
exit 1
fi
rm -f /usr/bin/wmbusmeters /usr/sbin/wmbusmetersd
cp "$1" /usr/bin/wmbusmeters
ln -s /usr/bin/wmbusmeters /usr/sbin/wmbusmetersd
ROOT="${2%/}"
echo binaries: installed /usr/bin/wmbusmeters and /usr/sbin/wmbusmetersd
rm -f $ROOT/usr/bin/wmbusmeters $ROOT/usr/sbin/wmbusmetersd
mkdir -p $ROOT/usr/bin
mkdir -p $ROOT/usr/sbin
cp "$1" $ROOT/usr/bin/wmbusmeters
ln -s $ROOT/usr/bin/wmbusmeters $ROOT/usr/sbin/wmbusmetersd
echo binaries: installed $ROOT/usr/bin/wmbusmeters and $ROOT/usr/sbin/wmbusmetersd
ID=$(id -u wmbusmeters 2>/dev/null)
if [ "$ID" == "" ]
if [ "$ADDUSER" = "true" ]
then
# Create the wmbusmeters user
adduser --no-create-home --shell /usr/sbin/nologin --disabled-login --gecos "" wmbusmeters
echo user: added wmbusmeters
else
echo user: wmbusmeters unmodified
if [ "$ID" = "" ]
then
# Create the wmbusmeters user
adduser --no-create-home --shell $ROOT/usr/sbin/nologin --disabled-login --gecos "" wmbusmeters
echo user: added wmbusmeters
else
echo user: wmbusmeters unmodified
fi
fi
if [ ! -f /etc/wmbusmeters.conf ]
if [ ! -f $ROOT/etc/wmbusmeters.conf ]
then
# Create default configuration
cat <<EOF > /etc/wmbusmeters.conf
mkdir -p $ROOT/etc/
cat <<EOF > $ROOT/etc/wmbusmeters.conf
loglevel=normal
device=auto
logtelegrams=false
meterfiles=/tmp/wmbusmeters
EOF
chown root:root /etc/wmbusmeters.conf
chmod 644 /etc/wmbusmeters.d
echo conf file: created /etc/wmbusmeters.conf
chmod 644 $ROOT/etc/wmbusmeters.conf
echo conf file: created $ROOT/etc/wmbusmeters.conf
else
echo conf file: /etc/wmbusmeters.conf unchanged
echo conf file: $ROOT/etc/wmbusmeters.conf unchanged
fi
if [ ! -d /etc/wmbusmeters.d ]
if [ ! -d $ROOT/etc/wmbusmeters.d ]
then
# Create the configuration directory
mkdir -p /etc/wmbusmeters.d
chown -R root:root /etc/wmbusmeters.d
chmod -R 644 /etc/wmbusmeters.d
echo conf dir: created /etc/wmbusmeters.d
mkdir -p $ROOT/etc/wmbusmeters.d
chmod -R 644 $ROOT/etc/wmbusmeters.d
echo conf dir: created $ROOT/etc/wmbusmeters.d
else
echo conf dir: /etc/wmbusmeters.d unchanged
echo conf dir: $ROOT/etc/wmbusmeters.d unchanged
fi
if [ -d /etc/systemd/system ]
if [ ! -f $ROOT/etc/systemd/system/wmbusmeters.service ]
then
if [ ! -f /etc/systemd/system/wmbusmeters.service ]
then
# Create service file
cat <<EOF > /etc/systemd/system/wmbusmeters.service
mkdir -p $ROOT/etc/systemd/system/
# Create service file
cat <<EOF > $ROOT/etc/systemd/system/wmbusmeters.service
[Unit]
Description=wmbusmeters service
After=network.target
@ -88,8 +102,7 @@ ExecStart=/usr/sbin/wmbusmetersd
WantedBy=multi-user.target
EOF
echo systemd: installed /etc/systemd/system/wmbusmeters.service
else
echo systemd: /etc/systemd/system/wmbusmeters.service unchanged
fi
echo systemd: installed $ROOT/etc/systemd/system/wmbusmeters.service
else
echo systemd: $ROOT/etc/systemd/system/wmbusmeters.service unchanged
fi

3
scripts/postinst 100644
Wyświetl plik

@ -0,0 +1,3 @@
#!/bin/sh
# Start wmbusmeters service

3
scripts/postrm 100644
Wyświetl plik

@ -0,0 +1,3 @@
#!/bin/bash
# More cleanup?

3
scripts/preinst 100644
Wyświetl plik

@ -0,0 +1,3 @@
#!/bin/sh
# Shutdown wmbusmeters service if it is running.

3
scripts/prerm 100644
Wyświetl plik

@ -0,0 +1,3 @@
#!/bin/bash
# Stop the service

41
uninstall.sh 100755
Wyświetl plik

@ -0,0 +1,41 @@
#!/bin/bash
if [ ! -d "$1" ]
then
echo Oups, please supply a valid root directory.
exit 1
fi
ROOT="${1%/}"
if [ -x $ROOT/usr/bin/wmbusmeters ] || [ -x $ROOT/usr/sbin/wmbusmeters ]
then
rm -f $ROOT/usr/bin/wmbusmeters $ROOT/usr/sbin/wmbusmetersd
echo binaries: removed $ROOT/usr/bin/wmbusmeters and $ROOT/usr/sbin/wmbusmetersd
fi
ID=$(id -u wmbusmeters 2>/dev/null)
if [ ! "$ID" = "" ]
then
deluser wmbusmeters
echo user: removed wmbusmeters
fi
if [ -f $ROOT/etc/wmbusmeters.conf ]
then
rm $ROOT/etc/wmbusmeters.conf
echo conf file: removed $ROOT/etc/wmbusmeters.conf
fi
if [ -d $ROOT/etc/wmbusmeters.d ]
then
rm -rf $ROOT/etc/wmbusmeters.d
echo conf dir: removed $ROOT/etc/wmbusmeters.d
fi
if [ -f $ROOT/etc/systemd/system/wmbusmeters.service ]
then
rm $ROOT/etc/systemd/system/wmbusmeters.service
echo systemd: removed $ROOT/etc/systemd/system/wmbusmeters.service
fi