kopia lustrzana https://github.com/weetmuts/wmbusmeters
commit
24561f8c90
137
install.sh
137
install.sh
|
@ -1,20 +1,18 @@
|
|||
#!/bin/bash
|
||||
|
||||
if [ "$1" = "" ]
|
||||
if [ "$1" == "" ] || [ "$1" == "-h" ]
|
||||
then
|
||||
echo Usage: install.sh [binary] [root]
|
||||
echo Example: install.sh build/wmbusmeters /
|
||||
echo "Usage: install.sh [binary] [root] [OPTIONS]
|
||||
Example: install.sh build/wmbusmeters /
|
||||
|
||||
Options:
|
||||
--no-adduser Do not add wmbusmeters user
|
||||
--no-udev-rules Do not add udev rules
|
||||
"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
ADDUSER=true
|
||||
if [ "$1" = "--no-adduser" ]
|
||||
then
|
||||
ADDUSER=false
|
||||
shift
|
||||
fi
|
||||
|
||||
if [ ! $(basename "$1") = "wmbusmeters" ]
|
||||
if [ ! "$(basename "$1")" = "wmbusmeters" ]
|
||||
then
|
||||
echo Oups, please only try to install wmbusmeters using this script.
|
||||
exit 1
|
||||
|
@ -32,31 +30,50 @@ then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
SRC=$1
|
||||
ROOT="${2%/}"
|
||||
ADDUSER=true
|
||||
ADDUDEVRULES=true
|
||||
|
||||
while [ $# -ne 0 ]
|
||||
do
|
||||
ARG="$1"
|
||||
shift
|
||||
case "$ARG" in
|
||||
--no-adduser)
|
||||
ADDUSER=false
|
||||
;;
|
||||
--no-udev-rules)
|
||||
ADDUDEVRULES=false
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
|
||||
####################################################################
|
||||
##
|
||||
## Intall binaries
|
||||
##
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
echo binaries: installed $ROOT/usr/bin/wmbusmeters and $ROOT/usr/sbin/wmbusmetersd
|
||||
echo binaries: installed "$ROOT"/usr/bin/wmbusmeters and "$ROOT"/usr/sbin/wmbusmetersd
|
||||
|
||||
####################################################################
|
||||
##
|
||||
## Intall wmbusmeters manual page
|
||||
##
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
echo man page: installed $ROOT/usr/share/man/man1/wmbusmeters.1.gz
|
||||
echo man page: installed "$ROOT"/usr/share/man/man1/wmbusmeters.1.gz
|
||||
|
||||
####################################################################
|
||||
##
|
||||
|
@ -65,12 +82,22 @@ echo man page: installed $ROOT/usr/share/man/man1/wmbusmeters.1.gz
|
|||
|
||||
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 [ "$ADDUSER" = "true" ]
|
||||
then
|
||||
if [ "$ID" = "" ]
|
||||
then
|
||||
# Create the wmbusmeters user
|
||||
adduser --no-create-home --shell $ROOT/usr/sbin/nologin --disabled-login --gecos "" wmbusmeters
|
||||
useradd --system --shell $USERSHELL --groups dialout wmbusmeters
|
||||
echo user: added wmbusmeters
|
||||
else
|
||||
echo user: wmbusmeters unmodified
|
||||
|
@ -82,10 +109,10 @@ fi
|
|||
## Prepare for /var/run/wmbusmeters.pid
|
||||
##
|
||||
|
||||
#if [ ! -d $ROOT/var/run ]
|
||||
#if [ ! -d "$ROOT"/var/run ]
|
||||
#then
|
||||
# # Create /var/run
|
||||
# mkdir -p $ROOT/var/run
|
||||
# mkdir -p "$ROOT"/var/run
|
||||
# echo pid store: created /var/run
|
||||
#fi
|
||||
|
||||
|
@ -94,12 +121,12 @@ fi
|
|||
## Prepare for /var/log/wmbusmeters and /var/log/wmbusmeters/meter_readings
|
||||
##
|
||||
|
||||
if [ ! -d $ROOT/var/log/wmbusmeters/meter_readings ]
|
||||
if [ ! -d "$ROOT"/var/log/wmbusmeters/meter_readings ]
|
||||
then
|
||||
# Create /var/run
|
||||
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
|
||||
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
|
||||
fi
|
||||
|
||||
####################################################################
|
||||
|
@ -107,11 +134,11 @@ fi
|
|||
## Install /etc/logrotate.d/wmbusmeters
|
||||
##
|
||||
|
||||
if [ ! -f $ROOT/etc/logrotate.d/wmbusmeters ]
|
||||
if [ ! -f "$ROOT"/etc/logrotate.d/wmbusmeters ]
|
||||
then
|
||||
mkdir -p $ROOT/etc/logrotate.d
|
||||
mkdir -p "$ROOT"/etc/logrotate.d
|
||||
# Create logrotate file
|
||||
cat <<EOF > $ROOT/etc/logrotate.d/wmbusmeters
|
||||
cat <<EOF > "$ROOT"/etc/logrotate.d/wmbusmeters
|
||||
/var/log/wmbusmeters/*.log {
|
||||
rotate 12
|
||||
weekly
|
||||
|
@ -121,7 +148,7 @@ then
|
|||
start-stop-daemon -K -p /var/run/wmbusmeters.pid -s HUP -x /usr/sbin/wmbusmeters -q
|
||||
endscript
|
||||
EOF
|
||||
echo logrotate: created $ROOT/etc/logrotate.d/wmbusmeters
|
||||
echo logrotate: created "$ROOT"/etc/logrotate.d/wmbusmeters
|
||||
fi
|
||||
|
||||
####################################################################
|
||||
|
@ -129,11 +156,11 @@ fi
|
|||
## Install /etc/wmbusmeters.conf
|
||||
##
|
||||
|
||||
if [ ! -f $ROOT/etc/wmbusmeters.conf ]
|
||||
if [ ! -f "$ROOT"/etc/wmbusmeters.conf ]
|
||||
then
|
||||
# Create default configuration
|
||||
mkdir -p $ROOT/etc/
|
||||
cat <<EOF > $ROOT/etc/wmbusmeters.conf
|
||||
mkdir -p "$ROOT"/etc/
|
||||
cat <<EOF > "$ROOT"/etc/wmbusmeters.conf
|
||||
loglevel=normal
|
||||
device=auto
|
||||
logtelegrams=false
|
||||
|
@ -142,10 +169,10 @@ 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
|
||||
chmod 644 "$ROOT"/etc/wmbusmeters.conf
|
||||
echo conf file: created "$ROOT"/etc/wmbusmeters.conf
|
||||
else
|
||||
echo conf file: $ROOT/etc/wmbusmeters.conf unchanged
|
||||
echo conf file: "$ROOT"/etc/wmbusmeters.conf unchanged
|
||||
fi
|
||||
|
||||
####################################################################
|
||||
|
@ -153,14 +180,14 @@ fi
|
|||
## Create /etc/wmbusmeters.d
|
||||
##
|
||||
|
||||
if [ ! -d $ROOT/etc/wmbusmeters.d ]
|
||||
if [ ! -d "$ROOT"/etc/wmbusmeters.d ]
|
||||
then
|
||||
# Create the configuration directory
|
||||
mkdir -p $ROOT/etc/wmbusmeters.d
|
||||
chmod -R 655 $ROOT/etc/wmbusmeters.d
|
||||
echo conf dir: created $ROOT/etc/wmbusmeters.d
|
||||
mkdir -p "$ROOT"/etc/wmbusmeters.d
|
||||
chmod -R 655 "$ROOT"/etc/wmbusmeters.d
|
||||
echo conf dir: created "$ROOT"/etc/wmbusmeters.d
|
||||
else
|
||||
echo conf dir: $ROOT/etc/wmbusmeters.d unchanged
|
||||
echo conf dir: "$ROOT"/etc/wmbusmeters.d unchanged
|
||||
fi
|
||||
|
||||
####################################################################
|
||||
|
@ -168,11 +195,11 @@ fi
|
|||
## Create /etc/systemd/system/wmbusmeters.service
|
||||
##
|
||||
|
||||
if [ ! -f $ROOT/etc/systemd/system/wmbusmeters.service ]
|
||||
if [ ! -f "$ROOT"/etc/systemd/system/wmbusmeters.service ]
|
||||
then
|
||||
mkdir -p $ROOT/etc/systemd/system/
|
||||
mkdir -p "$ROOT"/etc/systemd/system/
|
||||
# Create service file
|
||||
cat <<EOF > $ROOT/etc/systemd/system/wmbusmeters.service
|
||||
cat <<EOF > "$ROOT"/etc/systemd/system/wmbusmeters.service
|
||||
[Unit]
|
||||
Description=wmbusmeters service
|
||||
After=network.target
|
||||
|
@ -204,9 +231,9 @@ PIDFile=/var/run/wmbusmeters/wmbusmeters.pid
|
|||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
echo systemd: installed $ROOT/etc/systemd/system/wmbusmeters.service
|
||||
echo systemd: installed "$ROOT"/etc/systemd/system/wmbusmeters.service
|
||||
else
|
||||
echo systemd: $ROOT/etc/systemd/system/wmbusmeters.service unchanged
|
||||
echo systemd: "$ROOT"/etc/systemd/system/wmbusmeters.service unchanged
|
||||
fi
|
||||
|
||||
|
||||
|
@ -214,17 +241,19 @@ fi
|
|||
##
|
||||
## Create /etc/udev/rules.d/99-wmbus-usb-serial.rules
|
||||
##
|
||||
|
||||
if [ ! -f $ROOT/etc/udev/rules.d/99-wmbus-usb-serial.rules ]
|
||||
if [ "$ADDUDEVRULES" = "true" ]
|
||||
then
|
||||
mkdir -p $ROOT/etc/udev/rules.d
|
||||
if [ ! -f "$ROOT"/etc/udev/rules.d/99-wmbus-usb-serial.rules ]
|
||||
then
|
||||
mkdir -p "$ROOT"/etc/udev/rules.d
|
||||
# Create service file
|
||||
cat <<EOF > $ROOT/etc/udev/rules.d/99-wmbus-usb-serial.rules
|
||||
cat <<EOF > "$ROOT"/etc/udev/rules.d/99-wmbus-usb-serial.rules
|
||||
SUBSYSTEM=="tty", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60",SYMLINK+="im871a",MODE="0660", GROUP="wmbusmeters",TAG+="systemd",ENV{SYSTEMD_WANTS}="wmbusmeters.service"
|
||||
SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001",SYMLINK+="amb8465",MODE="0660", GROUP="wmbusmeters",TAG+="systemd",ENV{SYSTEMD_WANTS}="wmbusmeters.service"
|
||||
SUBSYSTEM=="usb", ATTRS{idVendor}=="0bda", ATTRS{idProduct}=="2838",SYMLINK+="rtlsdr",MODE="0660", GROUP="wmbusmeters",TAG+="systemd",ENV{SYSTEMD_WANTS}="wmbusmeters.service"
|
||||
EOF
|
||||
echo udev: installed $ROOT/etc/udev/rules.d/99-wmbus-usb-serial.rules
|
||||
echo udev: installed "$ROOT"/etc/udev/rules.d/99-wmbus-usb-serial.rules
|
||||
else
|
||||
echo systemd: $ROOT/etc/udev/rules.d/99-wmbus-usb-serial.rules unchanged
|
||||
echo udev: "$ROOT"/etc/udev/rules.d/99-wmbus-usb-serial.rules unchanged
|
||||
fi
|
||||
fi
|
||||
|
|
48
uninstall.sh
48
uninstall.sh
|
@ -8,10 +8,16 @@ fi
|
|||
|
||||
ROOT="${1%/}"
|
||||
|
||||
if [ -x $ROOT/usr/bin/wmbusmeters ] || [ -x $ROOT/usr/sbin/wmbusmeters ]
|
||||
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
|
||||
rm -f "$ROOT"/usr/bin/wmbusmeters "$ROOT"/usr/sbin/wmbusmetersd
|
||||
echo binaries: removed "$ROOT"/usr/bin/wmbusmeters and "$ROOT"/usr/sbin/wmbusmetersd
|
||||
fi
|
||||
|
||||
if [ -f "$ROOT"/usr/share/man/man1/wmbusmeters.1.gz ]
|
||||
then
|
||||
rm "$ROOT"/usr/share/man/man1/wmbusmeters.1.gz
|
||||
echo man page: removed "$ROOT"/usr/share/man/man1/wmbusmeters.1.gz
|
||||
fi
|
||||
|
||||
ID=$(id -u wmbusmeters 2>/dev/null)
|
||||
|
@ -22,20 +28,38 @@ then
|
|||
echo user: removed wmbusmeters
|
||||
fi
|
||||
|
||||
if [ -f $ROOT/etc/wmbusmeters.conf ]
|
||||
if [ -d "$ROOT"/var/log/wmbusmeters/ ]
|
||||
then
|
||||
rm $ROOT/etc/wmbusmeters.conf
|
||||
echo conf file: removed $ROOT/etc/wmbusmeters.conf
|
||||
rm -rf "$ROOT"/var/log/wmbusmeters/
|
||||
echo log dir: removed "$ROOT"/var/log/wmbusmeters/
|
||||
fi
|
||||
|
||||
if [ -d $ROOT/etc/wmbusmeters.d ]
|
||||
if [ -f "$ROOT"/etc/logrotate.d/wmbusmeters ]
|
||||
then
|
||||
rm -rf $ROOT/etc/wmbusmeters.d
|
||||
echo conf dir: removed $ROOT/etc/wmbusmeters.d
|
||||
rm "$ROOT"/etc/logrotate.d/wmbusmeters
|
||||
echo logrotate file: removed "$ROOT"/etc/logrotate.d/wmbusmeters
|
||||
fi
|
||||
|
||||
if [ -f $ROOT/etc/systemd/system/wmbusmeters.service ]
|
||||
if [ -f "$ROOT"/etc/wmbusmeters.conf ]
|
||||
then
|
||||
rm $ROOT/etc/systemd/system/wmbusmeters.service
|
||||
echo systemd: removed $ROOT/etc/systemd/system/wmbusmeters.service
|
||||
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
|
||||
|
||||
if [ -f "$ROOT"/etc/udev/rules.d/99-wmbus-usb-serial.rules ]
|
||||
then
|
||||
rm "$ROOT"/etc/udev/rules.d/99-wmbus-usb-serial.rules
|
||||
echo udev: removed "$ROOT"/etc/udev/rules.d/99-wmbus-usb-serial.rules
|
||||
fi
|
||||
|
|
Ładowanie…
Reference in New Issue