Files
starburst/v2/arch.sh
T
2026-05-07 21:35:53 +02:00

208 lines
5.9 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:-none}"
TWM="${SELECTED_TWM:-none}"
INSTALL_LEVEL="${INSTALL_LEVEL:-minimal}"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
echo
say_cyan "Starting Arch setup..."
echo
say_gray "DE: $DE, TWM: $TWM, Install Level: $INSTALL_LEVEL"
##########################
# Helper functions
##########################
install_packages() { 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
}
##########################
# 1. Add repositories if missing and update system
##########################
# Helper function to check and add a repository
add_repo_if_missing() {
local repo_name="$1"
local repo_config="$2"
if grep -q "\[$repo_name\]" /etc/pacman.conf; then
say_yellow "Repository [$repo_name] already exists. Skipping."
else
say_yellow "Adding [$repo_name] to /etc/pacman.conf..."
# Add a newline and the repo config to the end of the file
echo -e "\n$repo_config" | sudo tee -a /etc/pacman.conf > /dev/null
fi
}
say_yellow "Checking pacman.conf and sources..."
# 1. Create the backup
sudo cp /etc/pacman.conf "/etc/pacman.conf.bak.$(date +%s)"
# 2. Add yuku_repo
YUKU_BLOCK="[yuku_repo]
SigLevel = Never
Server = https://yurikuit.github.io/\$repo/\$arch"
add_repo_if_missing "yuku_repo" "$YUKU_BLOCK"
# 3. Add nemesis_repo
NEMESIS_BLOCK="[nemesis_repo]
SigLevel = Never
Server = https://erikdubois.github.io/\$repo/\$arch"
add_repo_if_missing "nemesis_repo" "$NEMESIS_BLOCK"
# 4. Refresh databases
sudo pacman -Sy
# Update the system
say_gray "Updating the system - sudo pacman -Syyu"
echo
sudo pacman -Syyu --noconfirm
##########################
# 2. Fix missing console font
##########################
say_yellow "Fix missing console font"
if grep -q FONT= /etc/vconsole.conf; then
say_green "Font is already set in /etc/vconsole.conf"
else
say_green "Setting console font in /etc/vconsole.conf"
echo 'FONT=gr737c-8x14' | sudo tee -a /etc/vconsole.conf
fi
##########################
# 3. Detected OS / DE / TWM info
##########################
say_yellow "Detected OS / Desktop Environment / Tiling Window Manager"
echo
say_gray "Installing OS-specific packages..."
say_gray "Selected DE: $DE"
say_gray "Selected TWM: $TWM"
say_gray "Installation Level: $INSTALL_LEVEL"
##########################
# 4. Desktop Environment installation
##########################
case "$DE" in
xfce|plasma|gnome)
say_yellow "Preparing to install $DE..."
SCRIPT_NAME="$SCRIPT_DIR/${OS}-${DE}.sh"
if [[ -f "$SCRIPT_NAME" ]]; then
say_cyan "Running $SCRIPT_NAME..."
bash "$SCRIPT_NAME"
else
say_red "Error: $SCRIPT_NAME not found!"
exit 1
fi
;;
none)
say_gray "No Desktop Environment selected, skipping DE installation."
;;
esac
##########################
# 5. Tiling Window Manager installation
##########################
case "$TWM" in
chadwm|hyprland)
say_yellow "Installing $TWM..."
SCRIPT_NAME="$SCRIPT_DIR/${OS}-${TWM}.sh"
if [[ -f "$SCRIPT_NAME" ]]; then
say_cyan "Running $SCRIPT_NAME..."
bash "$SCRIPT_NAME"
else
say_red "Error: $SCRIPT_NAME not found!"
exit 1
fi
;;
none)
say_gray "No tiling window manager selected."
;;
esac
##########################
# 6. Installation level handling
##########################
case "$INSTALL_LEVEL" in
minimal|full|workstation|server)
say_cyan "Installation level: $INSTALL_LEVEL"
SCRIPT_NAME="$SCRIPT_DIR/${OS}-${INSTALL_LEVEL}.sh"
if [[ -f "$SCRIPT_NAME" ]]; then
say_cyan "Running $SCRIPT_NAME..."
bash "$SCRIPT_NAME"
else
say_red "Error: $SCRIPT_NAME not found!"
exit 1
fi
;;
esac
say_green "Arch setup complete."
say_red "The installation has finished. A reboot is recommended."
# Reboots are dangerous to automate; we use a shorter timeout and default to No
if read -t 10 -rp "Reboot now? [y/N]: " reboot_choice; then
case "${reboot_choice,,}" in
y|yes)
say_red "Rebooting now."
sudo reboot
;;
*)
say_yellow "Skipping reboot."
exit 0
;;
esac
else
say_yellow "\nNo input detected. Skipping reboot for safety."
exit 0
fi