Files
workstation-config/temp-cleanup/install.sh
T

55 lines
1.6 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.
#!/usr/bin/env bash
set -e
echo "📦 Installiere Temp Cleanup System..."
# 🧠 Verzeichnisse bestimmen
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TARGET_DIR="$HOME/workstation-config/temp-cleanup"
SYSTEMD_USER_DIR="$HOME/.config/systemd/user"
SERVICE_NAME="cleanup-temp.service"
TIMER_NAME="cleanup-temp.timer"
SCRIPT_NAME="cleanup_temp.sh"
echo "📁 Script-Verzeichnis: $SCRIPT_DIR"
echo "📁 Ziel-Verzeichnis: $TARGET_DIR"
# 🧱 Zielstruktur sicherstellen
mkdir -p "$TARGET_DIR"
mkdir -p "$SYSTEMD_USER_DIR"
# 🚨 KEIN SELF-COPY (wichtigster Fix)
if [ "$SCRIPT_DIR" != "$TARGET_DIR" ]; then
echo "📄 Kopiere Dateien ins Ziel..."
cp "$SCRIPT_DIR/$SCRIPT_NAME" "$TARGET_DIR/"
cp "$SCRIPT_DIR/systemd/$SERVICE_NAME" "$TARGET_DIR/"
cp "$SCRIPT_DIR/systemd/$TIMER_NAME" "$TARGET_DIR/"
else
echo "️ Bereits im Zielverzeichnis Kopieren übersprungen"
fi
# 🔐 Script ausführbar machen
chmod +x "$TARGET_DIR/$SCRIPT_NAME"
# 🔧 Service erstellen (Pfad dynamisch setzen)
echo "⚙️ Erstelle systemd Service..."
sed "s|ExecStart=.*|ExecStart=$TARGET_DIR/$SCRIPT_NAME|" \
"$TARGET_DIR/systemd/$SERVICE_NAME" > "$SYSTEMD_USER_DIR/$SERVICE_NAME"
# ⏱ Timer installieren
cp "$TARGET_DIR/systemd/$TIMER_NAME" "$SYSTEMD_USER_DIR/$TIMER_NAME"
# 🔄 systemd reload
echo "🔄 Reload systemd..."
systemctl --user daemon-reload
# 🚀 Aktivieren & starten
systemctl --user enable "$TIMER_NAME" >/dev/null 2>&1 || true
systemctl --user start "$TIMER_NAME" >/dev/null 2>&1 || true
echo "✅ Installation abgeschlossen!"
echo "🧹 Temp-Cleanup läuft jetzt automatisch"