install_newt-msp-site_v2.sh hinzugefügt

This commit is contained in:
2025-09-03 23:17:29 +02:00
parent d7c02e91a2
commit c85730a34a

136
install_newt-msp-site_v2.sh Normal file
View File

@@ -0,0 +1,136 @@
#!/bin/bash
set -e
REPO="fosrl/newt"
INSTALL_DIR="/opt/me-msp-newt"
SERVICE_NAME="ME-MSP-Proxy-Client"
SYMLINK="${INSTALL_DIR}/newt_latest"
SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service"
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
info() { echo -e "${GREEN}[INFO]${NC} $1"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
error() { echo -e "${RED}[ERROR]${NC} $1"; exit 1; }
get_latest_version() {
curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" | grep -Po '"tag_name": *"\K[^"]+'
}
download_newt() {
local version="$1"
local arch=$(uname -m)
local file=""
case "$arch" in
x86_64) file="newt_linux_amd64" ;;
aarch64) file="newt_linux_arm64" ;;
armv7l) file="newt_linux_arm32" ;;
*) error "Nicht unterstützte Architektur: $arch" ;;
esac
local url="https://github.com/${REPO}/releases/download/${version}/${file}"
local target="${INSTALL_DIR}/newt_${version}"
mkdir -p "$INSTALL_DIR"
info "⬇️ Lade $url herunter …"
curl -fsSL "$url" -o "${target}.tmp" || error "Download fehlgeschlagen."
chmod +x "${target}.tmp"
mv "${target}.tmp" "$target"
ln -sf "$target" "$SYMLINK"
info "✅ newt ${version} installiert als ${target}"
}
setup_systemd_service() {
echo "🆔 Bitte gib die Pangolin-ID ein: "
read -r PANGOLIN_ID
echo "🔑 Bitte gib das Secret ein: "
read -r PANGOLIN_SECRET
echo "🌐 Bitte gib den Endpoint (z.B. https://pangolin.domain.de) ein: "
read -r PANGOLIN_ENDPOINT
cat > "$SERVICE_FILE" <<EOF
[Unit]
Description=Newt Client - ${SERVICE_NAME}
After=network.target
[Service]
ExecStart=${SYMLINK} --id ${PANGOLIN_ID} --secret ${PANGOLIN_SECRET} --endpoint ${PANGOLIN_ENDPOINT}
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable "$SERVICE_NAME"
systemctl restart "$SERVICE_NAME"
info "🛠️ systemd-Dienst ${SERVICE_NAME} eingerichtet und gestartet."
}
mode_install() {
local version
version=$(get_latest_version)
version=${version#v}
info "📦 Neueste Version: $version"
if [ -f "${INSTALL_DIR}/newt_${version}" ]; then
warn "⚠️ Version $version ist bereits installiert. Installation wird übersprungen."
warn "👉 Falls du eine Neuinstallation erzwingen möchtest, verwende '--reinstall'."
exit 0
fi
download_newt "$version"
setup_systemd_service
info "🚀 Installation abgeschlossen!"
}
mode_update() {
local version
version=$(get_latest_version)
version=${version#v}
info "📦 Neueste Version: $version"
if [ -f "${INSTALL_DIR}/newt_${version}" ]; then
info "✅ Version $version ist bereits installiert. Kein Update nötig."
exit 0
fi
download_newt "$version"
systemctl restart "$SERVICE_NAME"
info "🚀 Update abgeschlossen!"
}
mode_reinstall() {
local version
version=$(get_latest_version)
version=${version#v}
info "📦 Neueste Version: $version"
download_newt "$version"
setup_systemd_service
info "🚀 Reinstallation abgeschlossen!"
}
main() {
case "$1" in
--install|"")
mode_install
;;
--update)
mode_update
;;
--reinstall)
mode_reinstall
;;
*)
error "❌ Unbekannter Parameter: $1 (verwende --install, --update oder --reinstall)"
;;
esac
}
main "$@"