68 lines
1.8 KiB
Bash
68 lines
1.8 KiB
Bash
#!/usr/bin/env bash
|
|
# Install the Pit Log sync service on Debian or Ubuntu.
|
|
# The Proxmox helper runs this inside the new container.
|
|
set -euo pipefail
|
|
|
|
if [[ "$(id -u)" -ne 0 ]]; then
|
|
echo "Run this as root inside the container."
|
|
exit 1
|
|
fi
|
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
apt-get update
|
|
apt-get install -y python3 openssl ca-certificates
|
|
|
|
install -d -o root -g root -m 755 /opt/pitlog
|
|
if ! id pitlog >/dev/null 2>&1; then
|
|
useradd --system --home-dir /var/lib/pitlog --shell /usr/sbin/nologin pitlog
|
|
fi
|
|
install -d -o pitlog -g pitlog -m 750 /var/lib/pitlog /etc/pitlog
|
|
|
|
SOURCE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/pitlog_sync.py"
|
|
if [[ ! -f "$SOURCE" && -f /tmp/pitlog_sync.py ]]; then
|
|
SOURCE=/tmp/pitlog_sync.py
|
|
fi
|
|
if [[ ! -f "$SOURCE" ]]; then
|
|
echo "pitlog_sync.py was not next to this script."
|
|
exit 1
|
|
fi
|
|
install -o root -g pitlog -m 640 "$SOURCE" /opt/pitlog/pitlog_sync.py
|
|
|
|
if [[ ! -s /etc/pitlog/token ]]; then
|
|
openssl rand -hex 32 > /etc/pitlog/token
|
|
fi
|
|
chown root:pitlog /etc/pitlog/token
|
|
chmod 640 /etc/pitlog/token
|
|
|
|
PORT="${PITLOG_PORT:-8787}"
|
|
cat > /etc/systemd/system/pitlog-sync.service <<EOF
|
|
[Unit]
|
|
Description=Pit Log sync
|
|
After=network-online.target
|
|
Wants=network-online.target
|
|
|
|
[Service]
|
|
Type=simple
|
|
User=pitlog
|
|
Group=pitlog
|
|
Environment=PITLOG_TOKEN_FILE=/etc/pitlog/token
|
|
Environment=PITLOG_DB=/var/lib/pitlog/sync.db
|
|
Environment=PITLOG_PORT=${PORT}
|
|
ExecStart=/usr/bin/python3 /opt/pitlog/pitlog_sync.py
|
|
Restart=on-failure
|
|
RestartSec=2
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
|
|
systemctl daemon-reload
|
|
systemctl enable --now pitlog-sync.service
|
|
|
|
TOKEN="$(cat /etc/pitlog/token)"
|
|
echo
|
|
echo "Pit Log sync is running on port ${PORT}."
|
|
echo "Token: ${TOKEN}"
|
|
echo "On each phone, open Car and enter this address and the same token."
|
|
echo "Use http:// when the phone is on the same network. Use https:// if a reverse proxy serves the port."
|