22 lines
1.1 KiB
Bash
Executable File
22 lines
1.1 KiB
Bash
Executable File
#!/bin/bash
|
|
set -euo pipefail
|
|
cd "$(dirname "$0")"
|
|
PORT=6001
|
|
if [ "${1:-}" = --port ] && [ "$#" = 2 ]; then PORT="$2"; elif [ "$#" != 0 ]; then echo 'Usage: sudo ./install.sh [--port 6001]' >&2; exit 2; fi
|
|
[[ "$PORT" =~ ^[0-9]+$ ]] && (( PORT >= 1024 && PORT <= 65535 )) || { echo 'Invalid port' >&2; exit 2; }
|
|
for f in app/server.py web/index.html systemd/pigway-web-manager.service; do
|
|
[ -f "$f" ] || { echo "ERROR: required file missing: $f" >&2; exit 1; }
|
|
done
|
|
[ "$(id -u)" = 0 ] || { echo 'Run as root' >&2; exit 1; }
|
|
command -v python3 >/dev/null
|
|
mkdir -p /usr/local/lib/pigway-web-manager/{app,web}
|
|
install -m 0644 app/server.py /usr/local/lib/pigway-web-manager/app/
|
|
install -m 0644 web/index.html /usr/local/lib/pigway-web-manager/web/
|
|
sed "s/PIGWAY_PORT=6001/PIGWAY_PORT=$PORT/" systemd/pigway-web-manager.service > /etc/systemd/system/pigway-web-manager.service
|
|
systemctl daemon-reload
|
|
systemctl enable --now pigway-web-manager.service
|
|
systemctl restart pigway-web-manager.service
|
|
systemctl is-active --quiet pigway-web-manager.service
|
|
echo "Web Manager port: $PORT"
|
|
echo 'Token: sudo cat /var/lib/pigway-web-manager/manager.token'
|