Files
deskhub/DeskHub-Webseite/install.sh
T
2026-10-16 19:12:18 +00:00

179 lines
8.2 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# ═══════════════════════════════════════════════════════════════
# DeskHub Installer
# Verwendung: bash install.sh [Zielordner]
# Beispiel: bash install.sh /var/www/html/deskhub
# ═══════════════════════════════════════════════════════════════
set -e
# ── Farben ──────────────────────────────────────────────────────
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
BOLD='\033[1m'
NC='\033[0m'
# ── Konfiguration ───────────────────────────────────────────────
GITEA_TOKEN="bc90d44cf0d8adc61a30fec6fde4cbcc64cff429"
GITEA_BASE="https://git.viper.ipv64.net"
REPO="M_Viper/deskhub"
API_URL="$GITEA_BASE/api/v1/repos/$REPO/releases?limit=50&type=semver"
# ── Banner ──────────────────────────────────────────────────────
echo ""
echo -e "${CYAN}${BOLD}"
echo " ██████╗ ███████╗███████╗██╗ ██╗██╗ ██╗██╗ ██╗██████╗ "
echo " ██╔══██╗██╔════╝██╔════╝██║ ██╔╝██║ ██║██║ ██║██╔══██╗"
echo " ██║ ██║█████╗ ███████╗█████╔╝ ███████║██║ ██║██████╔╝"
echo " ██║ ██║██╔══╝ ╚════██║██╔═██╗ ██╔══██║██║ ██║██╔══██╗"
echo " ██████╔╝███████╗███████║██║ ██╗██║ ██║╚██████╔╝██████╔╝"
echo " ╚═════╝ ╚══════╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚═════╝ "
echo -e "${NC}"
echo -e "${BOLD} DeskHub Installer${NC}"
echo " ─────────────────────────────────────────────────────────"
echo ""
# ── Zielordner bestimmen ────────────────────────────────────────
INSTALL_DIR="${1:-/var/www/html/deskhub}"
echo -e " ${YELLOW}Installationsordner:${NC} $INSTALL_DIR"
echo ""
# ── Abhängigkeiten prüfen ───────────────────────────────────────
echo -e " ${BOLD}[1/5]${NC} Abhängigkeiten prüfen..."
for cmd in curl unzip php; do
if ! command -v $cmd &>/dev/null; then
echo -e " ${RED}✗ '$cmd' nicht gefunden. Bitte installieren:${NC}"
echo " apt install $cmd oder yum install $cmd"
exit 1
fi
done
echo -e " ${GREEN}✓ curl, unzip, php gefunden${NC}"
# ── Neuestes Release ermitteln ──────────────────────────────────
echo ""
echo -e " ${BOLD}[2/5]${NC} Neuestes Release von Gitea abrufen..."
RELEASE_JSON=$(curl -s --insecure \
-H "Authorization: token $GITEA_TOKEN" \
"$API_URL")
TAG_NAME=$(echo "$RELEASE_JSON" | php -r "
\$data = json_decode(file_get_contents('php://stdin'), true);
// Neueste Version per version_compare ermitteln
\$latest = '';
if (is_array(\$data)) {
foreach (\$data as \$r) {
\$tag = \$r['tag_name'] ?? '';
if (\$tag && (!\$latest || version_compare(ltrim(\$tag,'v'), ltrim(\$latest,'v'), '>'))) {
\$latest = \$tag;
}
}
}
echo \$latest;
")
if [ -z "$TAG_NAME" ]; then
echo -e " ${RED}✗ Konnte Release-Info nicht abrufen. Token oder Verbindung prüfen.${NC}"
exit 1
fi
echo -e " ${GREEN}✓ Neuestes Release: ${BOLD}$TAG_NAME${NC}"
# ── ZIP herunterladen ───────────────────────────────────────────
echo ""
echo -e " ${BOLD}[3/5]${NC} ZIP herunterladen..."
TMP_ZIP="/tmp/deskhub_${TAG_NAME}.zip"
ZIP_URL="$GITEA_BASE/$REPO/archive/${TAG_NAME}.zip"
curl -L --insecure --progress-bar \
-H "Authorization: token $GITEA_TOKEN" \
-o "$TMP_ZIP" \
"$ZIP_URL"
if [ ! -f "$TMP_ZIP" ] || [ ! -s "$TMP_ZIP" ]; then
echo -e " ${RED}✗ Download fehlgeschlagen.${NC}"
exit 1
fi
echo -e " ${GREEN}✓ Download abgeschlossen: $TMP_ZIP${NC}"
# ── Entpacken ───────────────────────────────────────────────────
echo ""
echo -e " ${BOLD}[4/5]${NC} Entpacken nach $INSTALL_DIR ..."
mkdir -p "$INSTALL_DIR"
TMP_EXTRACT="/tmp/deskhub_extract_$$"
mkdir -p "$TMP_EXTRACT"
unzip -q "$TMP_ZIP" -d "$TMP_EXTRACT"
# Unterordner-Prefix erkennen (z.B. deskhub-1.0.0/)
INNER=$(ls "$TMP_EXTRACT" | head -1)
if [ -d "$TMP_EXTRACT/$INNER" ]; then
cp -r "$TMP_EXTRACT/$INNER/." "$INSTALL_DIR/"
else
cp -r "$TMP_EXTRACT/." "$INSTALL_DIR/"
fi
rm -rf "$TMP_EXTRACT" "$TMP_ZIP"
echo -e " ${GREEN}✓ Dateien erfolgreich entpackt${NC}"
# ── Berechtigungen setzen ───────────────────────────────────────
chmod -R 755 "$INSTALL_DIR"
chmod -R 775 "$INSTALL_DIR/uploads" 2>/dev/null || true
chmod -R 775 "$INSTALL_DIR/assets/branding" 2>/dev/null || true
chmod -R 775 "$INSTALL_DIR/assets/avatars" 2>/dev/null || true
chmod -R 775 "$INSTALL_DIR/database" 2>/dev/null || true
# ── Datenbank einrichten ─────────────────────────────────────────
echo ""
echo -e " ${BOLD}[5/5]${NC} Datenbank einrichten..."
if [ -f "$INSTALL_DIR/database/setup_sqlite.php" ]; then
php "$INSTALL_DIR/database/setup_sqlite.php" && \
echo -e " ${GREEN}✓ SQLite-Datenbank eingerichtet${NC}" || \
echo -e " ${YELLOW}⚠ Datenbank-Setup fehlgeschlagen – bitte manuell ausführen${NC}"
fi
# ── Fertig ──────────────────────────────────────────────────────
echo ""
echo -e " ─────────────────────────────────────────────────────────"
echo -e " ${GREEN}${BOLD}✓ DeskHub $TAG_NAME erfolgreich installiert!${NC}"
echo ""
# Server-IP ermitteln
SERVER_IP=$(hostname -I 2>/dev/null | awk '{print $1}')
if [ -z "$SERVER_IP" ]; then
SERVER_IP=$(curl -s --max-time 3 ifconfig.me 2>/dev/null || echo "DEINE-IP")
fi
# Webroot-Pfad relativ zu /var/www/html oder /var/www ermitteln
WEB_PATH=""
for webroot in "/var/www/html" "/var/www" "/srv/www/htdocs" "/usr/share/nginx/html"; do
if [[ "$INSTALL_DIR" == "$webroot"* ]]; then
WEB_PATH="${INSTALL_DIR#$webroot}"
break
fi
done
echo -e " ${BOLD}Aufruf im Browser:${NC}"
if [ -n "$WEB_PATH" ]; then
echo -e " ${CYAN}${BOLD} http://$SERVER_IP$WEB_PATH${NC}"
echo -e " ${CYAN}${BOLD} http://$SERVER_IP$WEB_PATH/staff/login.php${NC} ← Admin-Login"
else
echo -e " ${CYAN}${BOLD} http://$SERVER_IP/${INSTALL_DIR##*/}${NC}"
echo -e " ${CYAN}${BOLD} http://$SERVER_IP/${INSTALL_DIR##*/}/staff/login.php${NC} ← Admin-Login"
fi
echo ""
echo -e " ${YELLOW}Nächste Schritte:${NC}"
echo " 1. Im Browser öffnen und Installation abschließen"
echo " 2. Admin-Konto unter /staff/login.php anlegen"
echo " 3. Einstellungen unter /staff/settings.php konfigurieren"
echo ""
echo " ─────────────────────────────────────────────────────────"
echo ""