install_newt_v2.sh aktualisiert

This commit is contained in:
2025-09-30 22:19:24 +02:00
parent 320044f3f9
commit b2308b356e

View File

@@ -6,6 +6,8 @@ INSTALL_DIR="/opt/newt"
SERVICE_NAME="PVE-MGNT" SERVICE_NAME="PVE-MGNT"
SYMLINK="${INSTALL_DIR}/newt_latest" SYMLINK="${INSTALL_DIR}/newt_latest"
SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service" SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service"
UPDATER_SERVICE="/etc/systemd/system/newt-updater.service"
UPDATER_TIMER="/etc/systemd/system/newt-updater.timer"
GREEN='\033[0;32m' GREEN='\033[0;32m'
YELLOW='\033[1;33m' YELLOW='\033[1;33m'
@@ -29,27 +31,27 @@ download_newt() {
x86_64) file="newt_linux_amd64" ;; x86_64) file="newt_linux_amd64" ;;
aarch64) file="newt_linux_arm64" ;; aarch64) file="newt_linux_arm64" ;;
armv7l) file="newt_linux_arm32" ;; armv7l) file="newt_linux_arm32" ;;
*) error "Nicht unterstützte Architektur: $arch" ;; *) error "Unsupported architecture: $arch" ;;
esac esac
local url="https://github.com/${REPO}/releases/download/${version}/${file}" local url="https://github.com/${REPO}/releases/download/${version}/${file}"
local target="${INSTALL_DIR}/newt_${version}" local target="${INSTALL_DIR}/newt_${version}"
mkdir -p "$INSTALL_DIR" mkdir -p "$INSTALL_DIR"
info "⬇️ Lade $url herunter" info "⬇️ Downloading $url"
curl -fsSL "$url" -o "${target}.tmp" || error "Download fehlgeschlagen." curl -fsSL "$url" -o "${target}.tmp" || error "Download failed."
chmod +x "${target}.tmp" chmod +x "${target}.tmp"
mv "${target}.tmp" "$target" mv "${target}.tmp" "$target"
ln -sf "$target" "$SYMLINK" ln -sf "$target" "$SYMLINK"
info "✅ newt ${version} installiert als ${target}" info " Installed newt ${version} at ${target}"
} }
setup_systemd_service() { setup_systemd_service() {
echo "🆔 Bitte gib die Pangolin-ID ein: " echo "🆔 Please enter the Pangolin ID: "
read -r PANGOLIN_ID read -r PANGOLIN_ID
echo "🔑 Bitte gib das Secret ein: " echo "🔑 Please enter the Secret: "
read -r PANGOLIN_SECRET read -r PANGOLIN_SECRET
echo "🌐 Bitte gib den Endpoint (z.B. https://pangolin.domain.de) ein: " echo "🌐 Please enter the Endpoint (e.g. https://pangolin.domain.com): "
read -r PANGOLIN_ENDPOINT read -r PANGOLIN_ENDPOINT
cat > "$SERVICE_FILE" <<EOF cat > "$SERVICE_FILE" <<EOF
@@ -69,51 +71,121 @@ EOF
systemctl daemon-reload systemctl daemon-reload
systemctl enable "$SERVICE_NAME" systemctl enable "$SERVICE_NAME"
systemctl restart "$SERVICE_NAME" systemctl restart "$SERVICE_NAME"
info "🛠️ systemd-Dienst ${SERVICE_NAME} eingerichtet und gestartet." info "🛠️ Systemd service ${SERVICE_NAME} has been set up and started."
}
setup_update_timer() {
if [[ -f "$UPDATER_SERVICE" && -f "$UPDATER_TIMER" ]]; then
info "⏳ Update timer already exists skipping."
return
fi
info "⚙️ Creating systemd timer for daily updates …"
cat > "$UPDATER_SERVICE" <<EOF
[Unit]
Description=Automatic update for Newt installer
[Service]
Type=oneshot
ExecStart=/bin/bash -c 'curl -fsSL https://gitea.vmd55888.de/manuel.maier/update-install-newt/raw/branch/main/install_newt_v2.sh | bash -s -- --update'
EOF
cat > "$UPDATER_TIMER" <<EOF
[Unit]
Description=Run newt-updater.service daily
[Timer]
OnCalendar=03:00
Persistent=true
[Install]
WantedBy=timers.target
EOF
systemctl daemon-reload
systemctl enable --now newt-updater.timer
info "✅ Update timer created (runs daily at 03:00)."
} }
mode_install() { mode_install() {
local version local version
version=$(get_latest_version) version=$(get_latest_version)
version=${version#v} version=${version#v}
info "📦 Neueste Version: $version" info "📦 Latest version: $version"
if [ -f "${INSTALL_DIR}/newt_${version}" ]; then if [ -f "${INSTALL_DIR}/newt_${version}" ]; then
warn "⚠️ Version $version ist bereits installiert. Installation wird übersprungen." warn "⚠️ Version $version is already installed. Skipping installation."
warn "👉 Falls du eine Neuinstallation erzwingen möchtest, verwende '--reinstall'." warn "👉 Use '--reinstall' if you want to force a reinstall."
setup_update_timer
exit 0 exit 0
fi fi
download_newt "$version" download_newt "$version"
setup_systemd_service setup_systemd_service
info "🚀 Installation abgeschlossen!" setup_update_timer
info "🚀 Installation completed!"
} }
mode_update() { mode_update() {
local version local version
version=$(get_latest_version) version=$(get_latest_version)
version=${version#v} version=${version#v}
info "📦 Neueste Version: $version" info "📦 Latest version: $version"
if [ -f "${INSTALL_DIR}/newt_${version}" ]; then if [ -f "${INSTALL_DIR}/newt_${version}" ]; then
info "✅ Version $version ist bereits installiert. Kein Update nötig." info "✅ Version $version is already installed. No update required."
setup_update_timer
exit 0 exit 0
fi fi
download_newt "$version" download_newt "$version"
systemctl restart "$SERVICE_NAME" systemctl restart "$SERVICE_NAME"
info "🚀 Update abgeschlossen!" setup_update_timer
info "🚀 Update completed!"
} }
mode_reinstall() { mode_reinstall() {
local version local version
version=$(get_latest_version) version=$(get_latest_version)
version=${version#v} version=${version#v}
info "📦 Neueste Version: $version" info "📦 Latest version: $version"
download_newt "$version" download_newt "$version"
setup_systemd_service setup_systemd_service
info "🚀 Reinstallation abgeschlossen!" setup_update_timer
info "🚀 Reinstallation completed!"
}
mode_uninstall() {
warn "⚠️ Uninstalling newt and removing all systemd entries …"
# Stop and remove service
if systemctl is-active --quiet "$SERVICE_NAME"; then
systemctl stop "$SERVICE_NAME"
fi
systemctl disable "$SERVICE_NAME" 2>/dev/null || true
rm -f "$SERVICE_FILE"
# Remove updater
if systemctl is-active --quiet newt-updater.timer; then
systemctl stop newt-updater.timer
fi
systemctl disable newt-updater.timer 2>/dev/null || true
rm -f "$UPDATER_SERVICE" "$UPDATER_TIMER"
systemctl daemon-reload
# Delete installation dir (ask first)
if [ -d "$INSTALL_DIR" ]; then
read -p "❓ Do you want to remove ${INSTALL_DIR} and all versions? (y/N): " yn
case $yn in
[Yy]*) rm -rf "$INSTALL_DIR"; info "📂 ${INSTALL_DIR} was removed." ;;
*) warn "📂 ${INSTALL_DIR} was NOT removed." ;;
esac
fi
info "🧹 Uninstallation completed!"
} }
main() { main() {
@@ -127,8 +199,11 @@ main() {
--reinstall) --reinstall)
mode_reinstall mode_reinstall
;; ;;
--uninstall)
mode_uninstall
;;
*) *)
error "❌ Unbekannter Parameter: $1 (verwende --install, --update oder --reinstall)" error "❌ Unknown parameter: $1 (use --install, --update, --reinstall or --uninstall)"
;; ;;
esac esac
} }