#!/usr/bin/env bash # Called explicitly by install.sh. Also usable once on existing installations. set -euo pipefail cd "$(dirname "$0")" DEPLOY="$(pwd -P)" DATA="${PIPU_DATA:-$(sed -n 's/^PIPU_DATA=//p' .env)}" DATA="${DATA:-/srv/pipu}" command -v python3 >/dev/null || { echo 'Install python3 (>=3.10) first' >&2; exit 1; } python3 -c 'import sys; assert sys.version_info >= (3, 10), "Python >=3.10 required"' [ -d /etc/systemd/system ] || { echo 'systemd is required for server management' >&2; exit 1; } mkdir -p "$DATA/management" /var/lib/pipu-management /usr/local/lib/pipu chown 65532:65532 "$DATA/management" chmod 700 "$DATA/management" /var/lib/pipu-management # Copy outside the checkout: switching revisions must not replace a running worker. install -m 700 server-agent.py /usr/local/lib/pipu/server-agent.py touch config.local chmod 600 config.local if [ -n "${SUDO_USER:-}" ]; then chown "$SUDO_USER" config.local; fi # systemd quoted arguments escape backslashes, quotes and specifiers. quote_unit() { printf '%s' "$1" | sed 's/\\/\\\\/g; s/"/\\"/g; s/%/%%/g'; } DEPLOY_UNIT="$(quote_unit "$DEPLOY")" MAILBOX_UNIT="$(quote_unit "$DATA/management")" cat > /etc/systemd/system/pipu-management.service <