Files
starburst/v2/arch-chadwm.sh
T
2026-05-13 23:35:12 +02:00

146 lines
4.3 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
##########################
# Color helpers (printf-safe, no tput)
##########################
RED="\033[0;31m"
GREEN="\033[0;32m"
YELLOW="\033[0;33m"
CYAN="\033[0;36m"
GRAY="\033[0;37m"
BOLD="\033[1m"
RESET="\033[0m"
# Disable colors if output is not a terminal
if [ ! -t 1 ]; then
RED="" GREEN="" YELLOW="" CYAN="" GRAY="" BOLD="" RESET=""
fi
say_red() { printf "\n"; printf "%b%s%b\n" "$RED" "$*" "$RESET"; }
say_green() { printf "\n"; printf "%b%s%b\n" "$GREEN" "$*" "$RESET"; }
say_yellow() { printf "\n"; printf "%b%s%b\n" "$YELLOW" "$*" "$RESET"; }
say_cyan() { printf "\n"; printf "%b%s%b\n" "$CYAN" "$*" "$RESET"; }
say_gray() { printf "\n"; printf "%b%s%b\n" "$GRAY" "$*" "$RESET"; }
say_bold() { printf "\n"; printf "%b%s%b\n" "$BOLD" "$*" "$RESET"; }
##########################
# Use exported variables from main detection script
##########################
OS="${DETECTED_OS}"
DDE="${DETECTED_DE}"
DE="${SELECTED_DE}"
TWM="${SELECTED_TWM}"
INSTALL_LEVEL="${INSTALL_LEVEL}"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
##########################
# Helper functions
##########################
install_packages() { sudo pacman -Sy; sudo pacman -S --noconfirm --needed "$@"; }
is_package_installed() { pacman -Qi "$@" &>/dev/null; }
remove_packages() {
local packages_to_remove=()
# 1. Identify which packages are actually installed
for pkg in "$@"; do
if is_package_installed "$pkg"; then
packages_to_remove+=("$pkg")
else
say_gray "Package '$pkg' not found. Skipping removal."
fi
done
# 2. Only run pacman if there are packages to remove
if [ ${#packages_to_remove[@]} -gt 0 ]; then
say_cyan "Removing packages: ${packages_to_remove[*]}"
sudo pacman -Rs --noconfirm "${packages_to_remove[@]}" || true
else
say_gray "No packages to remove from the list."
fi
}
detect_de() {
if command -v xfce4-session >/dev/null 2>&1; then
echo "xfce"
else
echo ""
fi
}
detect_display_manager() {
if [ -f /etc/systemd/system/display-manager.service ]; then
basename "$(readlink /etc/systemd/system/display-manager.service)"
else
echo ""
fi
}
enable_graphical_target() {
sudo systemctl enable sddm
sudo systemctl set-default graphical.target
}
#########################
# Start installation
##########################
say_yellow "Starting Chadwm setup..."
# 1. FIX: Identify the correct user correctly
# If running via sudo, we want the actual user, not root.
ACTUAL_USER=${SUDO_USER:-$(whoami)}
# 2. LOGIC FIX:
# If you want Chadwm to install even if XFCE is present,
# we should check if Chadwm is already installed instead of checking for a DE.
if [ ! -f "/usr/local/bin/chadwm" ]; then
say_cyan "Installing Chadwm..."
install_packages sddm picom feh acpi rofi dash imlib2 xsetroot git base-devel
enable_graphical_target
# Use absolute path to avoid home directory confusion
USER_HOME="/home/$ACTUAL_USER"
CHAD_DIR="$USER_HOME/.config/chadwm"
# Clone as the actual user so permissions are correct
if [ ! -d "$CHAD_DIR" ]; then
sudo -u "$ACTUAL_USER" git clone https://github.com/siduck/chadwm --depth 1 "$CHAD_DIR"
fi
# Move to the source directory and build
cd "$CHAD_DIR/chadwm"
sudo make install
# 3. Ensure the target directory actually exists
TARGET_DIR="/usr/share/xsessions"
TARGET_FILE="$TARGET_DIR/chadwm.desktop"
sudo mkdir -p "$TARGET_DIR"
# 4. Create the .desktop file
# Use the ACTUAL_USER variable here
cat <<EOF | sudo tee $TARGET_FILE > /dev/null
[Desktop Entry]
Name=chadwm
Comment=dwm made beautiful
Exec=$CHAD_DIR/scripts/run.sh
Type=Application
EOF
sudo chmod 644 $TARGET_FILE
say_green "Chadwm with SDDM installed successfully."
else
say_cyan "Chadwm binary already detected. Skipping build."
fi
# 5. Handle Display Manager replacement separately
CURRENT_DM="$(detect_display_manager)"
if [[ "$CURRENT_DM" == "lightdm.service" ]]; then
say_yellow "LightDM is active. Switching to SDDM..."
sudo systemctl disable lightdm
sudo pacman -Rs --noconfirm lightdm lightdm-gtk-greeter || true
sudo systemctl enable sddm
fi
say_green "Chadwm / SDDM setup completed."