dpl/scripts/node-onboarding/install-node.sh

38 lines
2.1 KiB
Bash

#!/bin/bash
set -euo pipefail
# Credential files are installed separately with mode 0600.
[[ $(id -u) == 0 ]] || exit 1
listen_port=''
tls_domain=''
for arg in "$@"; do
case "$arg" in
--listen-port=*) listen_port=${arg#*=} ;;
--tls-domain=*) tls_domain=${arg#*=} ;;
*) echo 'Usage: install-node.sh --listen-port=24443 --tls-domain=us01.example.com'; exit 1 ;;
esac
done
[[ $listen_port =~ ^[0-9]+$ && ${#listen_port} -le 5 ]] && (( 10#$listen_port >= 1024 && 10#$listen_port <= 65535 )) || { echo 'Explicit valid listen port required'; exit 1; }
[[ $tls_domain =~ ^[a-z0-9][a-z0-9.-]*\.[a-z]{2,}$ ]] || { echo 'Explicit TLS domain required'; exit 1; }
[[ -s /etc/dpl-node/config.yml && -s /etc/dpl-node/secret.env ]] || { echo 'Private node configuration missing'; exit 1; }
[[ ! -e /etc/systemd/system/dpl-node.service && ! -e /opt/dpl-node/xboard-node ]] || { echo 'DPL backend already installed; use a separately reviewed Git update'; exit 1; }
if ss -lntH "( sport = :$listen_port )" | grep -q .; then
echo "Port $listen_port already in use; inspect before deployment"; exit 1
fi
if systemctl list-unit-files XrayR.service --no-legend | grep -q '^XrayR.service'; then
systemctl is-active --quiet XrayR || { echo 'Existing XrayR is not active; investigate before installation'; exit 1; }
fi
printf '%s\n' "$tls_domain" > /etc/dpl-node/certificate-domain
chmod 644 /etc/dpl-node/certificate-domain
install -d -m 755 /opt/dpl-node
install -d -m 700 /var/lib/dpl-node /var/lib/dpl-node/kernel
curl --fail --location --silent --show-error \
https://github.com/cedar2025/Xboard-Node/releases/download/v1.13/xboard-node-linux-amd64 \
-o /opt/dpl-node/xboard-node.new
echo '55bf71fa9d9f2048d3255ae7c0af929a41897ca7743f6ead34132a6ca4c79043 /opt/dpl-node/xboard-node.new' | sha256sum --check
chmod 755 /opt/dpl-node/xboard-node.new
mv /opt/dpl-node/xboard-node.new /opt/dpl-node/xboard-node
/opt/dpl-node/xboard-node -v
install -m 644 "$(dirname "$0")/dpl-node.service" /etc/systemd/system/dpl-node.service
systemctl daemon-reload
echo 'Binary and independent unit installed. Obtain certificate before starting.'