-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinstall.sh
executable file
·73 lines (58 loc) · 1.42 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/sh
set -eu
# Add system user zytempmqtt
SRVNAME="zytempmqtt"
ID=$(id -u ${SRVNAME} 2>/dev/null || true)
if [ -f /usr/sbin/nologin ]; then
USERSHELL="/usr/sbin/nologin"
elif [ -f /sbin/nologin ]; then
USERSHELL="/sbin/nologin"
else
USERSHELL="/bin/false"
fi
if [ ! $(getent group ${SRVNAME}) ]; then
groupadd -f ${SRVNAME}
echo "group: added ${SRVNAME}"
fi
if [ -z "$ID" ]; then
useradd --system --shell $USERSHELL -g ${SRVNAME} ${SRVNAME}
echo "user: added ${SRVNAME}"
fi
# Install udev rule
if grep -qa container=lxc /proc/1/environ; then
echo "Skipping udev rules in lxc"
else
cp -a udev/90-usb-zytemp-permissions.rules /etc/udev/rules.d/
udevadm control --reload-rules
udevadm trigger
fi
# Create default config
mkdir -p /etc/zytempmqtt
cat <<'EOF' > /etc/zytempmqtt/config.yaml
mqtt_host: homeassistant.local
mqtt_username: user
mqtt_password: pass
friendly_name: aircontrol-mini
EOF
# Add systemd service
SERVICE_PATH=/lib/systemd/system/${SRVNAME}.service
cat <<'EOF' > $SERVICE_PATH
[Unit]
Description="zytempmqtt service"
Documentation=https://github.com/patrislav1/zytemp_mqtt
After=network.target
StopWhenUnneeded=false
StartLimitIntervalSec=10
StartLimitInterval=10
StartLimitBurst=3
[Service]
Type=simple
User=zytempmqtt
Group=zytempmqtt
Restart=always
RestartSec=10
ExecStart=/usr/bin/python3 -m zytempmqtt
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload