This commit is contained in:
[yuri]
2025-11-11 15:58:40 +01:00
parent 44913f6027
commit e9ed98ddc8

View File

@@ -132,8 +132,10 @@ fi
SOURCE_DIR="$SCRIPT_DIR/config-files/debian"
DEST_DIR="$HOME"
AUTOSTART_DIR="$HOME/.config/autostart"
AUTOSTART_FILE="$AUTOSTART_DIR/xfce-config-apply.desktop"
HELPER_DIR="$HOME/.local/share/xfce-config-apply"
XFCE_SESSION_DIR="$HOME/.cache/sessions"
mkdir -p "$AUTOSTART_DIR" "$HOME/.local/bin"
# 1. Verify source directory exists
if [ ! -d "$SOURCE_DIR" ]; then
@@ -141,82 +143,54 @@ if [ ! -d "$SOURCE_DIR" ]; then
exit 1
fi
# 2. Detect running XFCE session
if pgrep -x "xfce4-panel" >/dev/null || pgrep -x "xfconfd" >/dev/null; then
say_yellow "XFCE session is currently active."
# Debian-based detection
if grep -qiE "debian|ubuntu|mint" /etc/os-release; then
say_yellow "Detected Debian-based system. Scheduling configuration for next login."
mkdir -p "$AUTOSTART_DIR" "$HELPER_DIR"
AUTOSTART_FILE="$AUTOSTART_DIR/xfce-config-apply.desktop"
HELPER_SCRIPT="$HELPER_DIR/run-once.sh"
# --- Create helper script ---
cat > "$HELPER_SCRIPT" <<EOF
# 2. Create helper script
cat > "$HELPER_SCRIPT" <<'EOF'
#!/usr/bin/env bash
set -e
RED="\033[0;31m"; GREEN="\033[0;32m"; YELLOW="\033[0;33m"; CYAN="\033[0;36m"; RESET="\033[0m"
say() { printf "%b%s%b\n" "$CYAN" "$*" "$RESET"; }
SOURCE_DIR="$HOME/config-files/debian"
DEST_DIR="$HOME"
if [ ! -d "\$SOURCE_DIR" ]; then
say "Source directory \$SOURCE_DIR not found; skipping."
exit 0
fi
say "Applying XFCE configuration early in session..."
shopt -s dotglob
cp -vrf "$SOURCE_DIR"/* "$DEST_DIR"/
cp -vrf "\$SOURCE_DIR"/* "\$DEST_DIR"/
shopt -u dotglob
rm -rf "$XFCE_SESSION_DIR"
rm -f "$AUTOSTART_FILE"
rm -rf "$HELPER_DIR"
echo "XFCE configuration applied and helper removed."
say "Clearing session cache..."
rm -rf "\$HOME/.cache/sessions/"
say "Configuration applied. Removing one-time autostart entry..."
rm -f "\$HOME/.config/autostart/xfce-config-apply.desktop"
exit 0
EOF
chmod +x "$HELPER_SCRIPT"
chmod +x "$HELPER_SCRIPT"
# --- Create autostart file ---
cat > "$AUTOSTART_FILE" <<EOF
# 3. Create autostart entry (early-phase)
cat > "$AUTOSTART_FILE" <<EOF
[Desktop Entry]
Type=Application
Name=Apply XFCE Config
Name=Apply XFCE Config (Early)
Comment=One-time XFCE configuration importer
Exec=$HELPER_SCRIPT
OnlyShowIn=XFCE;
X-GNOME-Autostart-enabled=true
X-XFCE-Autostart-Phase=Initialization
Hidden=false
NoDisplay=false
EOF
say_green "Created one-time autostart helper:"
say_gray " $AUTOSTART_FILE"
say_cyan "→ Log out and back in to apply your new XFCE configuration."
exit 0
else
say_cyan "Non-Debian system detected — applying configuration live."
fi
fi
# 3. Stop XFCE components (only for non-Debian)
say_yellow "Stopping XFCE daemons if running..."
pkill -x xfce4-panel || true
pkill -x xfconfd || true
pkill -x xfwm4 || true
sleep 1
# 4. Copy configuration files
say_yellow "Copying all configuration files from $SOURCE_DIR to $DEST_DIR ..."
shopt -s dotglob
cp -vrf "$SOURCE_DIR"/* "$DEST_DIR"/
shopt -u dotglob
# 5. Clear old XFCE session cache
say_yellow "Clearing XFCE session cache..."
rm -rf "$XFCE_SESSION_DIR"
# 6. Restart XFCE components (if applicable)
if pgrep -x "xfce4-session" >/dev/null; then
say_cyan "Restarting XFCE environment components..."
nohup xfconfd &>/dev/null &
nohup xfwm4 --replace &>/dev/null &
nohup xfce4-panel &>/dev/null &
disown
say_green "XFCE configuration reloaded successfully."
else
say_cyan "XFCE was not running. Configuration will load on next login."
fi
say_yellow "XFCE configuration will be applied at next login."
say_cyan "Autostart created at: $AUTOSTART_FILE"
say_cyan "Helper script: $HELPER_SCRIPT"
# End of script