Files
orderpy-bridge/debian/postinst
2026-03-14 13:01:24 +01:00

35 lines
1.1 KiB
Bash

#!/bin/bash
set -e
SERVICE_USER="orderpy-bridge"
SERVICE_GROUP="orderpy-bridge"
DATA_DIR="/var/lib/orderpy-bridge"
INSTALL_DIR="/opt/orderpy-bridge"
ENV_FILE="/etc/orderpy-bridge/orderpy-bridge.env"
if ! getent group "$SERVICE_GROUP" >/dev/null; then
groupadd --system "$SERVICE_GROUP"
fi
if ! getent passwd "$SERVICE_USER" >/dev/null; then
useradd --system --no-create-home --gid "$SERVICE_GROUP" "$SERVICE_USER"
fi
install -d -m 750 -o "$SERVICE_USER" -g "$SERVICE_GROUP" "$DATA_DIR"
if [[ ! -f "$ENV_FILE" ]]; then
install -m 640 -o root -g "$SERVICE_GROUP" /etc/orderpy-bridge/orderpy-bridge.env.example "$ENV_FILE"
echo "Created $ENV_FILE — please edit and set ORDERPY_CLOUD_URL, ORDERPY_ALLOWED_ORIGINS."
fi
chown -R "$SERVICE_USER:$SERVICE_GROUP" "$INSTALL_DIR"
if [[ ! -x "$INSTALL_DIR/venv/bin/uvicorn" ]]; then
python3 -m venv "$INSTALL_DIR/venv"
"$INSTALL_DIR/venv/bin/pip" install --disable-pip-version-check -r "$INSTALL_DIR/requirements.txt"
chown -R "$SERVICE_USER:$SERVICE_GROUP" "$INSTALL_DIR/venv"
fi
systemctl daemon-reload
echo "OrderPy Bridge installed. Edit $ENV_FILE then: systemctl enable --now orderpy-bridge"