kopia lustrzana https://github.com/weetmuts/wmbusmeters
More work on packaging as deb.
rodzic
69cf31ace0
commit
ca79c0063a
12
Makefile
12
Makefile
|
@ -29,7 +29,7 @@ ifeq "$(HOST)" "arm"
|
||||||
DEBARCH=armhf
|
DEBARCH=armhf
|
||||||
else
|
else
|
||||||
CXX=g++
|
CXX=g++
|
||||||
STRIP=strip
|
STRIP=strip --strip-unneeded --remove-section=.comment --remove-section=.note
|
||||||
BUILD=build
|
BUILD=build
|
||||||
DEBARCH=amd64
|
DEBARCH=amd64
|
||||||
endif
|
endif
|
||||||
|
@ -79,15 +79,15 @@ all: $(BUILD)/wmbusmeters $(BUILD)/testinternals
|
||||||
dist: wmbusmeters_$(VERSION)_$(DEBARCH).deb
|
dist: wmbusmeters_$(VERSION)_$(DEBARCH).deb
|
||||||
|
|
||||||
install: $(BUILD)/wmbusmeters
|
install: $(BUILD)/wmbusmeters
|
||||||
@./install.sh $(BUILD)/wmbusmeters
|
@./install.sh $(BUILD)/wmbusmeters /
|
||||||
|
|
||||||
|
uninstall:
|
||||||
|
@./uninstall.sh /
|
||||||
|
|
||||||
wmbusmeters_$(VERSION)_$(DEBARCH).deb:
|
wmbusmeters_$(VERSION)_$(DEBARCH).deb:
|
||||||
@rm -rf $(BUILD)/debian/wmbusmeters
|
@rm -rf $(BUILD)/debian/wmbusmeters
|
||||||
@mkdir -p $(BUILD)/debian/wmbusmeters/DEBIAN
|
@mkdir -p $(BUILD)/debian/wmbusmeters/DEBIAN
|
||||||
@mkdir -p $(BUILD)/debian/wmbusmeters/usr/bin
|
@./install.sh --no-adduser $(BUILD)/wmbusmeters $(BUILD)/debian/wmbusmeters
|
||||||
@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
|
|
||||||
@rm -f $(BUILD)/debian/wmbusmeters/DEBIAN/control
|
@rm -f $(BUILD)/debian/wmbusmeters/DEBIAN/control
|
||||||
@echo "Package: wmbusmeters" >> $(BUILD)/debian/wmbusmeters/DEBIAN/control
|
@echo "Package: wmbusmeters" >> $(BUILD)/debian/wmbusmeters/DEBIAN/control
|
||||||
@echo "Version: $(VERSION)" >> $(BUILD)/debian/wmbusmeters/DEBIAN/control
|
@echo "Version: $(VERSION)" >> $(BUILD)/debian/wmbusmeters/DEBIAN/control
|
||||||
|
|
75
install.sh
75
install.sh
|
@ -2,10 +2,18 @@
|
||||||
|
|
||||||
if [ "$1" = "" ]
|
if [ "$1" = "" ]
|
||||||
then
|
then
|
||||||
echo Usage: install.sh build/wmbusmeters
|
echo Usage: install.sh [binary] [root]
|
||||||
|
echo Example: install.sh build/wmbusmeters /
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
ADDUSER=true
|
||||||
|
if [ "$1" = "--no-adduser" ]
|
||||||
|
then
|
||||||
|
ADDUSER=false
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
|
||||||
if [ ! $(basename "$1") = "wmbusmeters" ]
|
if [ ! $(basename "$1") = "wmbusmeters" ]
|
||||||
then
|
then
|
||||||
echo Oups, please only try to install wmbusmeters using this script.
|
echo Oups, please only try to install wmbusmeters using this script.
|
||||||
|
@ -18,61 +26,67 @@ then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$EUID" -ne 0 ]
|
if [ ! -d "$2" ]
|
||||||
then echo "Please run as root."
|
then
|
||||||
exit
|
echo Oups, please supply a valid root directory.
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rm -f /usr/bin/wmbusmeters /usr/sbin/wmbusmetersd
|
ROOT="${2%/}"
|
||||||
cp "$1" /usr/bin/wmbusmeters
|
|
||||||
ln -s /usr/bin/wmbusmeters /usr/sbin/wmbusmetersd
|
|
||||||
|
|
||||||
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)
|
ID=$(id -u wmbusmeters 2>/dev/null)
|
||||||
|
|
||||||
if [ "$ID" == "" ]
|
if [ "$ADDUSER" = "true" ]
|
||||||
then
|
then
|
||||||
|
if [ "$ID" = "" ]
|
||||||
|
then
|
||||||
# Create the wmbusmeters user
|
# Create the wmbusmeters user
|
||||||
adduser --no-create-home --shell /usr/sbin/nologin --disabled-login --gecos "" wmbusmeters
|
adduser --no-create-home --shell $ROOT/usr/sbin/nologin --disabled-login --gecos "" wmbusmeters
|
||||||
echo user: added wmbusmeters
|
echo user: added wmbusmeters
|
||||||
else
|
else
|
||||||
echo user: wmbusmeters unmodified
|
echo user: wmbusmeters unmodified
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -f /etc/wmbusmeters.conf ]
|
if [ ! -f $ROOT/etc/wmbusmeters.conf ]
|
||||||
then
|
then
|
||||||
# Create default configuration
|
# Create default configuration
|
||||||
cat <<EOF > /etc/wmbusmeters.conf
|
mkdir -p $ROOT/etc/
|
||||||
|
cat <<EOF > $ROOT/etc/wmbusmeters.conf
|
||||||
loglevel=normal
|
loglevel=normal
|
||||||
device=auto
|
device=auto
|
||||||
logtelegrams=false
|
logtelegrams=false
|
||||||
meterfiles=/tmp/wmbusmeters
|
meterfiles=/tmp/wmbusmeters
|
||||||
EOF
|
EOF
|
||||||
chown root:root /etc/wmbusmeters.conf
|
chmod 644 $ROOT/etc/wmbusmeters.conf
|
||||||
chmod 644 /etc/wmbusmeters.d
|
echo conf file: created $ROOT/etc/wmbusmeters.conf
|
||||||
echo conf file: created /etc/wmbusmeters.conf
|
|
||||||
else
|
else
|
||||||
echo conf file: /etc/wmbusmeters.conf unchanged
|
echo conf file: $ROOT/etc/wmbusmeters.conf unchanged
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -d /etc/wmbusmeters.d ]
|
if [ ! -d $ROOT/etc/wmbusmeters.d ]
|
||||||
then
|
then
|
||||||
# Create the configuration directory
|
# Create the configuration directory
|
||||||
mkdir -p /etc/wmbusmeters.d
|
mkdir -p $ROOT/etc/wmbusmeters.d
|
||||||
chown -R root:root /etc/wmbusmeters.d
|
chmod -R 644 $ROOT/etc/wmbusmeters.d
|
||||||
chmod -R 644 /etc/wmbusmeters.d
|
echo conf dir: created $ROOT/etc/wmbusmeters.d
|
||||||
echo conf dir: created /etc/wmbusmeters.d
|
|
||||||
else
|
else
|
||||||
echo conf dir: /etc/wmbusmeters.d unchanged
|
echo conf dir: $ROOT/etc/wmbusmeters.d unchanged
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -d /etc/systemd/system ]
|
if [ ! -f $ROOT/etc/systemd/system/wmbusmeters.service ]
|
||||||
then
|
then
|
||||||
if [ ! -f /etc/systemd/system/wmbusmeters.service ]
|
mkdir -p $ROOT/etc/systemd/system/
|
||||||
then
|
|
||||||
# Create service file
|
# Create service file
|
||||||
cat <<EOF > /etc/systemd/system/wmbusmeters.service
|
cat <<EOF > $ROOT/etc/systemd/system/wmbusmeters.service
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=wmbusmeters service
|
Description=wmbusmeters service
|
||||||
After=network.target
|
After=network.target
|
||||||
|
@ -88,8 +102,7 @@ ExecStart=/usr/sbin/wmbusmetersd
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
echo systemd: installed /etc/systemd/system/wmbusmeters.service
|
echo systemd: installed $ROOT/etc/systemd/system/wmbusmeters.service
|
||||||
else
|
else
|
||||||
echo systemd: /etc/systemd/system/wmbusmeters.service unchanged
|
echo systemd: $ROOT/etc/systemd/system/wmbusmeters.service unchanged
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Start wmbusmeters service
|
|
@ -0,0 +1,3 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# More cleanup?
|
|
@ -0,0 +1,3 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Shutdown wmbusmeters service if it is running.
|
|
@ -0,0 +1,3 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Stop the service
|
|
@ -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
|
Ładowanie…
Reference in New Issue