2019-02-23 17:30:16 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2019-04-25 20:29:15 +00:00
|
|
|
if [ "$1" == "" ] || [ "$1" == "-h" ]
|
2019-02-23 17:30:16 +00:00
|
|
|
then
|
2019-04-26 14:58:47 +00:00
|
|
|
echo "Usage: install.sh [binary] [root] [OPTIONS]
|
2019-04-25 20:29:15 +00:00
|
|
|
Example: install.sh build/wmbusmeters /
|
2019-05-21 12:19:54 +00:00
|
|
|
|
2019-04-25 20:29:15 +00:00
|
|
|
Options:
|
|
|
|
--no-adduser Do not add wmbusmeters user
|
|
|
|
--no-udev-rules Do not add udev rules
|
|
|
|
"
|
2019-02-23 17:30:16 +00:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2019-04-26 16:32:36 +00:00
|
|
|
if [ ! "$(basename "$1")" = "wmbusmeters" ]
|
2019-02-23 17:30:16 +00:00
|
|
|
then
|
|
|
|
echo Oups, please only try to install wmbusmeters using this script.
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -x "$1" ]
|
|
|
|
then
|
|
|
|
echo This is not an executable.
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-02-23 18:49:30 +00:00
|
|
|
if [ ! -d "$2" ]
|
|
|
|
then
|
|
|
|
echo Oups, please supply a valid root directory.
|
|
|
|
exit 1
|
2019-02-23 17:30:16 +00:00
|
|
|
fi
|
|
|
|
|
2019-04-26 14:58:47 +00:00
|
|
|
SRC=$1
|
2019-02-23 18:49:30 +00:00
|
|
|
ROOT="${2%/}"
|
2019-04-25 20:29:15 +00:00
|
|
|
ADDUSER=true
|
|
|
|
ADDUDEVRULES=true
|
|
|
|
|
|
|
|
while [ $# -ne 0 ]
|
|
|
|
do
|
|
|
|
ARG="$1"
|
2019-05-21 12:19:54 +00:00
|
|
|
shift
|
2019-04-25 20:29:15 +00:00
|
|
|
case "$ARG" in
|
|
|
|
--no-adduser)
|
|
|
|
ADDUSER=false
|
|
|
|
;;
|
|
|
|
--no-udev-rules)
|
|
|
|
ADDUDEVRULES=false
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2019-02-23 18:49:30 +00:00
|
|
|
|
2019-02-24 08:58:31 +00:00
|
|
|
####################################################################
|
|
|
|
##
|
|
|
|
## Intall binaries
|
|
|
|
##
|
|
|
|
|
2019-04-26 16:32:36 +00:00
|
|
|
rm -f "$ROOT"/usr/bin/wmbusmeters "$ROOT"/usr/sbin/wmbusmetersd
|
|
|
|
mkdir -p "$ROOT"/usr/bin
|
|
|
|
mkdir -p "$ROOT"/usr/sbin
|
|
|
|
cp "$SRC" "$ROOT"/usr/bin/wmbusmeters
|
|
|
|
ln -s "$ROOT"/usr/bin/wmbusmeters "$ROOT"/usr/sbin/wmbusmetersd
|
2019-02-23 17:30:16 +00:00
|
|
|
|
2019-04-26 16:32:36 +00:00
|
|
|
echo binaries: installed "$ROOT"/usr/bin/wmbusmeters and "$ROOT"/usr/sbin/wmbusmetersd
|
2019-02-23 17:30:16 +00:00
|
|
|
|
2019-02-26 21:19:16 +00:00
|
|
|
####################################################################
|
|
|
|
##
|
|
|
|
## Intall wmbusmeters manual page
|
|
|
|
##
|
|
|
|
|
2019-04-26 16:32:36 +00:00
|
|
|
rm -f "$ROOT"/usr/share/man/man1/wmbusmeters.1.gz
|
|
|
|
mkdir -p "$ROOT"/usr/share/man/man1
|
|
|
|
gzip -c wmbusmeters.1 > "$ROOT"/usr/share/man/man1/wmbusmeters.1.gz
|
2019-02-26 21:19:16 +00:00
|
|
|
|
2019-04-26 16:32:36 +00:00
|
|
|
echo man page: installed "$ROOT"/usr/share/man/man1/wmbusmeters.1.gz
|
2019-02-26 21:19:16 +00:00
|
|
|
|
2019-02-24 08:58:31 +00:00
|
|
|
####################################################################
|
|
|
|
##
|
|
|
|
## Create wmbusmeters user
|
|
|
|
##
|
|
|
|
|
2019-02-23 17:30:16 +00:00
|
|
|
ID=$(id -u wmbusmeters 2>/dev/null)
|
|
|
|
|
2019-04-26 16:32:36 +00:00
|
|
|
if [ -f "$ROOT"/usr/sbin/nologin ]
|
2019-04-25 20:29:15 +00:00
|
|
|
then
|
|
|
|
USERSHELL="$ROOT/usr/sbin/nologin"
|
2019-04-26 16:32:36 +00:00
|
|
|
elif [ -f "$ROOT"/sbin/nologin ]
|
2019-04-25 20:29:15 +00:00
|
|
|
then
|
|
|
|
USERSHELL="$ROOT/sbin/nologin"
|
|
|
|
else
|
|
|
|
USERSHELL="/bin/false"
|
|
|
|
fi
|
|
|
|
|
2019-02-23 18:49:30 +00:00
|
|
|
if [ "$ADDUSER" = "true" ]
|
2019-02-23 17:30:16 +00:00
|
|
|
then
|
2019-02-23 18:49:30 +00:00
|
|
|
if [ "$ID" = "" ]
|
|
|
|
then
|
|
|
|
# Create the wmbusmeters user
|
2019-04-25 20:29:15 +00:00
|
|
|
useradd --system --shell $USERSHELL --groups dialout wmbusmeters
|
2019-02-23 18:49:30 +00:00
|
|
|
echo user: added wmbusmeters
|
|
|
|
else
|
|
|
|
echo user: wmbusmeters unmodified
|
|
|
|
fi
|
2019-02-23 17:30:16 +00:00
|
|
|
fi
|
|
|
|
|
2019-02-24 08:58:31 +00:00
|
|
|
####################################################################
|
|
|
|
##
|
|
|
|
## Prepare for /var/run/wmbusmeters.pid
|
|
|
|
##
|
|
|
|
|
2019-04-26 16:32:36 +00:00
|
|
|
#if [ ! -d "$ROOT"/var/run ]
|
2019-02-24 08:58:31 +00:00
|
|
|
#then
|
|
|
|
# # Create /var/run
|
2019-04-26 16:32:36 +00:00
|
|
|
# mkdir -p "$ROOT"/var/run
|
2019-02-24 08:58:31 +00:00
|
|
|
# echo pid store: created /var/run
|
|
|
|
#fi
|
|
|
|
|
|
|
|
####################################################################
|
|
|
|
##
|
|
|
|
## Prepare for /var/log/wmbusmeters and /var/log/wmbusmeters/meter_readings
|
|
|
|
##
|
|
|
|
|
2019-04-26 16:32:36 +00:00
|
|
|
if [ ! -d "$ROOT"/var/log/wmbusmeters/meter_readings ]
|
2019-02-24 08:58:31 +00:00
|
|
|
then
|
2019-05-21 12:19:54 +00:00
|
|
|
# Create the log directories
|
2019-04-26 16:32:36 +00:00
|
|
|
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
|
2019-02-24 08:58:31 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
####################################################################
|
|
|
|
##
|
|
|
|
## Install /etc/logrotate.d/wmbusmeters
|
|
|
|
##
|
|
|
|
|
2019-04-26 16:32:36 +00:00
|
|
|
if [ ! -f "$ROOT"/etc/logrotate.d/wmbusmeters ]
|
2019-02-24 08:58:31 +00:00
|
|
|
then
|
2019-04-26 16:32:36 +00:00
|
|
|
mkdir -p "$ROOT"/etc/logrotate.d
|
2019-02-24 08:58:31 +00:00
|
|
|
# Create logrotate file
|
2019-04-26 16:32:36 +00:00
|
|
|
cat <<EOF > "$ROOT"/etc/logrotate.d/wmbusmeters
|
2019-02-24 08:58:31 +00:00
|
|
|
/var/log/wmbusmeters/*.log {
|
|
|
|
rotate 12
|
|
|
|
weekly
|
|
|
|
compress
|
|
|
|
missingok
|
|
|
|
postrotate
|
2019-06-13 14:42:00 +00:00
|
|
|
/bin/kill -HUP `cat /var/run/wmbusmeters/wmbusmeters.pid 2> /dev/null` 2> /dev/null || true
|
2019-02-24 08:58:31 +00:00
|
|
|
endscript
|
|
|
|
EOF
|
2019-04-26 16:32:36 +00:00
|
|
|
echo logrotate: created "$ROOT"/etc/logrotate.d/wmbusmeters
|
2019-06-13 14:42:00 +00:00
|
|
|
else
|
|
|
|
echo conf file: "$ROOT"/etc/logrotate.d/wmbusmeters unchanged
|
2019-02-24 08:58:31 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
####################################################################
|
|
|
|
##
|
|
|
|
## Install /etc/wmbusmeters.conf
|
|
|
|
##
|
|
|
|
|
2019-04-26 16:32:36 +00:00
|
|
|
if [ ! -f "$ROOT"/etc/wmbusmeters.conf ]
|
2019-02-23 17:30:16 +00:00
|
|
|
then
|
|
|
|
# Create default configuration
|
2019-04-26 16:32:36 +00:00
|
|
|
mkdir -p "$ROOT"/etc/
|
|
|
|
cat <<EOF > "$ROOT"/etc/wmbusmeters.conf
|
2019-02-24 16:31:32 +00:00
|
|
|
loglevel=normal
|
2019-02-23 17:30:16 +00:00
|
|
|
device=auto
|
|
|
|
logtelegrams=false
|
2019-02-26 21:19:16 +00:00
|
|
|
format=json
|
|
|
|
meterfiles=/var/log/wmbusmeters/meter_readings
|
2019-04-20 10:57:11 +00:00
|
|
|
meterfilesaction=overwrite
|
2019-02-24 14:20:55 +00:00
|
|
|
logfile=/var/log/wmbusmeters/wmbusmeters.log
|
2019-02-23 17:30:16 +00:00
|
|
|
EOF
|
2019-04-26 16:32:36 +00:00
|
|
|
chmod 644 "$ROOT"/etc/wmbusmeters.conf
|
|
|
|
echo conf file: created "$ROOT"/etc/wmbusmeters.conf
|
2019-02-23 17:30:16 +00:00
|
|
|
else
|
2019-04-26 16:32:36 +00:00
|
|
|
echo conf file: "$ROOT"/etc/wmbusmeters.conf unchanged
|
2019-02-23 17:30:16 +00:00
|
|
|
fi
|
|
|
|
|
2019-02-24 08:58:31 +00:00
|
|
|
####################################################################
|
|
|
|
##
|
|
|
|
## Create /etc/wmbusmeters.d
|
|
|
|
##
|
|
|
|
|
2019-04-26 16:32:36 +00:00
|
|
|
if [ ! -d "$ROOT"/etc/wmbusmeters.d ]
|
2019-02-23 17:30:16 +00:00
|
|
|
then
|
|
|
|
# Create the configuration directory
|
2019-04-26 16:32:36 +00:00
|
|
|
mkdir -p "$ROOT"/etc/wmbusmeters.d
|
|
|
|
chmod -R 655 "$ROOT"/etc/wmbusmeters.d
|
|
|
|
echo conf dir: created "$ROOT"/etc/wmbusmeters.d
|
2019-02-23 17:30:16 +00:00
|
|
|
else
|
2019-04-26 16:32:36 +00:00
|
|
|
echo conf dir: "$ROOT"/etc/wmbusmeters.d unchanged
|
2019-02-23 17:30:16 +00:00
|
|
|
fi
|
|
|
|
|
2019-02-24 08:58:31 +00:00
|
|
|
####################################################################
|
|
|
|
##
|
|
|
|
## Create /etc/systemd/system/wmbusmeters.service
|
|
|
|
##
|
|
|
|
|
2020-01-19 21:17:33 +00:00
|
|
|
if [ ! -f "$ROOT"/etc/systemd/system/wmbusmeters@.service ]
|
2019-02-23 17:30:16 +00:00
|
|
|
then
|
2019-04-26 16:32:36 +00:00
|
|
|
mkdir -p "$ROOT"/etc/systemd/system/
|
2019-02-23 18:49:30 +00:00
|
|
|
# Create service file
|
2020-01-19 21:17:33 +00:00
|
|
|
cat <<EOF > "$ROOT"/etc/systemd/system/wmbusmeters@.service
|
2019-02-23 17:30:16 +00:00
|
|
|
[Unit]
|
2020-01-19 21:17:33 +00:00
|
|
|
Description="wmbusmeters service on %i"
|
2019-02-23 17:30:16 +00:00
|
|
|
After=network.target
|
2019-02-24 15:51:18 +00:00
|
|
|
StopWhenUnneeded=true
|
2019-02-23 17:30:16 +00:00
|
|
|
|
|
|
|
[Service]
|
2019-02-24 08:58:31 +00:00
|
|
|
Type=forking
|
|
|
|
PrivateTmp=yes
|
2019-02-23 17:30:16 +00:00
|
|
|
User=wmbusmeters
|
2019-02-24 08:58:31 +00:00
|
|
|
Group=wmbusmeters
|
2019-04-03 15:31:51 +00:00
|
|
|
Restart=always
|
|
|
|
RestartSec=1
|
|
|
|
StartLimitIntervalSec=10
|
|
|
|
StartLimitInterval=10
|
|
|
|
StartLimitBurst=3
|
2019-02-24 08:58:31 +00:00
|
|
|
|
|
|
|
# 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 /var/run/wmbusmeters
|
|
|
|
ExecStartPre=/bin/chown -R wmbusmeters:wmbusmeters /var/run/wmbusmeters
|
|
|
|
|
2020-01-19 21:17:33 +00:00
|
|
|
ExecStart=/usr/sbin/wmbusmetersd --device=/dev/%i /var/run/wmbusmeters/wmbusmeters-%i.pid
|
|
|
|
ExecReload=/bin/kill -HUP `cat /var/run/wmbusmeters/wmbusmeters-%i.pid 2> /dev/null` 2> /dev/null || true
|
|
|
|
PIDFile=/var/run/wmbusmeters/wmbusmeters-%i.pid
|
2019-02-23 17:30:16 +00:00
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
EOF
|
|
|
|
|
2020-01-19 21:17:33 +00:00
|
|
|
echo systemd: installed "$ROOT"/etc/systemd/system/wmbusmeters@.service
|
2019-02-23 18:49:30 +00:00
|
|
|
else
|
2020-01-19 21:17:33 +00:00
|
|
|
echo systemd: "$ROOT"/etc/systemd/system/wmbusmeters@.service unchanged
|
2019-02-23 17:30:16 +00:00
|
|
|
fi
|
2019-02-24 08:58:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
####################################################################
|
|
|
|
##
|
|
|
|
## Create /etc/udev/rules.d/99-wmbus-usb-serial.rules
|
|
|
|
##
|
2019-04-25 20:29:15 +00:00
|
|
|
if [ "$ADDUDEVRULES" = "true" ]
|
2019-02-24 08:58:31 +00:00
|
|
|
then
|
2019-04-26 16:32:36 +00:00
|
|
|
if [ ! -f "$ROOT"/etc/udev/rules.d/99-wmbus-usb-serial.rules ]
|
2019-04-25 20:29:15 +00:00
|
|
|
then
|
2019-04-26 16:32:36 +00:00
|
|
|
mkdir -p "$ROOT"/etc/udev/rules.d
|
2019-04-25 20:29:15 +00:00
|
|
|
# Create service file
|
2019-04-26 16:32:36 +00:00
|
|
|
cat <<EOF > "$ROOT"/etc/udev/rules.d/99-wmbus-usb-serial.rules
|
2020-01-19 21:17:33 +00:00
|
|
|
SUBSYSTEM=="tty", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60",SYMLINK+="im871a",MODE="0660", GROUP="wmbusmeters",TAG+="systemd",ENV{SYSTEMD_WANTS}="wmbusmeters@%k.service"
|
|
|
|
SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001",SYMLINK+="amb8465",MODE="0660", GROUP="wmbusmeters",TAG+="systemd",ENV{SYSTEMD_WANTS}="wmbusmeters@%k.service"
|
|
|
|
SUBSYSTEM=="usb", ATTRS{idVendor}=="0bda", ATTRS{idProduct}=="2838",SYMLINK+="rtlsdr",MODE="0660", GROUP="wmbusmeters",TAG+="systemd",ENV{SYSTEMD_WANTS}="wmbusmeters@%k.service"
|
|
|
|
SUBSYSTEM=="usb", ATTRS{idVendor}=="2047", ATTRS{idProduct}=="0863",SYMLINK+="rfmrx2",MODE="0660", GROUP="wmbusmeters",TAG+="systemd",ENV{SYSTEMD_WANTS}="wmbusmeters@%k.service"
|
2019-02-24 08:58:31 +00:00
|
|
|
EOF
|
2019-04-26 16:32:36 +00:00
|
|
|
echo udev: installed "$ROOT"/etc/udev/rules.d/99-wmbus-usb-serial.rules
|
2019-04-25 20:29:15 +00:00
|
|
|
else
|
2019-04-26 16:32:36 +00:00
|
|
|
echo udev: "$ROOT"/etc/udev/rules.d/99-wmbus-usb-serial.rules unchanged
|
2019-04-25 20:29:15 +00:00
|
|
|
fi
|
2019-02-24 08:58:31 +00:00
|
|
|
fi
|