#!/usr/bin/env bash # Omeron - Modular System Setup Framework # Usage: ./install.sh [--fresh] [--modules m1,m2] [--skip-packages] [--with-sddm] [--help] set -euo pipefail OMERON_ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" export OMERON_ROOT export OMERON_PROJECT_DIR="$OMERON_ROOT" source "$OMERON_ROOT/lib/log.sh" source "$OMERON_ROOT/lib/tui.sh" source "$OMERON_ROOT/lib/utils.sh" source "$OMERON_ROOT/lib/config.sh" source "$OMERON_ROOT/lib/modules.sh" OMERON_FRESH_INSTALL="${OMERON_FRESH_INSTALL:-0}" export OMERON_FRESH_INSTALL DEFAULT_MODULES=( "core/preflight" "core/packages" "core/dotfiles" "core/services" "homelab/setup" "optional/install" "core/sddm" "post/apply-theme" ) FRESH_MODULES=( "core/packages" "core/dotfiles" "core/services" "core/sddm" "post/apply-theme" ) RUN_MODULES=() SKIP_MODULES=() WITH_SDDM=0 usage() { cat </dev/null && declare -F "module_description" >/dev/null 2>&1; then description="$(module_description)" fi printf " %-30s %s\n" "$rel_path" "$description" done exit 0 } parse_args() { while [[ $# -gt 0 ]]; do case "$1" in --fresh) OMERON_FRESH_INSTALL=1 shift ;; --modules) IFS=',' read -ra RUN_MODULES <<< "$2" shift 2 ;; --skip) IFS=',' read -ra SKIP_MODULES <<< "$2" shift 2 ;; --skip-packages) SKIP_MODULES+=("core/packages") shift ;; --with-sddm) WITH_SDDM=1 shift ;; --list-modules) list_modules ;; -h|--help) usage ;; *) echo "Unknown option: $1" >&2 usage ;; esac done } collect_modules() { if ((${#RUN_MODULES[@]})); then local result=() for mod in "${RUN_MODULES[@]}"; do result+=("$OMERON_MODULE_DIR/$mod.sh") done printf '%s\n' "${result[@]}" return fi local modules=() if ((OMERON_FRESH_INSTALL)); then modules=("${FRESH_MODULES[@]}") else modules=("${DEFAULT_MODULES[@]}") fi local module_order=() for mod in "${modules[@]}"; do local skip=0 for skipped in "${SKIP_MODULES[@]}"; do if [[ "$mod" == "$skipped" || "$mod" == "core/$skipped" ]]; then skip=1 break fi done [[ "$mod" == "core/sddm" && "$WITH_SDDM" -eq 0 && "$OMERON_FRESH_INSTALL" -eq 0 ]] && skip=1 ((skip)) && continue local module_file="$OMERON_MODULE_DIR/$mod.sh" [[ -f "$module_file" ]] && module_order+=("$module_file") done printf '%s\n' "${module_order[@]}" } collect_all_interactive() { local modules=() if ((OMERON_FRESH_INSTALL)); then modules=("${FRESH_MODULES[@]}") else modules=("${DEFAULT_MODULES[@]}") fi local total=${#modules[@]} local idx=1 local module_order=() for mod in "${modules[@]}"; do local module_file="$OMERON_MODULE_DIR/$mod.sh" [[ -f "$module_file" ]] || continue local description="" if source "$module_file" 2>/dev/null && declare -F "module_description" >/dev/null 2>&1; then description="$(module_description)" fi printf '\n' log_step "$idx" "$total" "${description:-$mod}" if declare -F "module_required" >/dev/null 2>&1; then source "$module_file" if module_required; then log_info "Required module - will run" module_order+=("$module_file") ((idx++)) continue fi fi if tui_confirm "Run this step?"; then module_order+=("$module_file") else log_info "Skipped" fi ((idx++)) done printf '%s\n' "${module_order[@]}" } show_banner() { tui_header " Ꮎ Ꮇ Ꭼ Ꮢ Ꮎ Ꮑ " tui_format "" tui_format "#{bold}Modular System Setup Framework#{normal}" tui_format "#{italic}Arch / Hyprland / CachyOS#{normal}" tui_format "" if ((OMERON_FRESH_INSTALL)); then tui_format "#{bold}#{yellow}⚡ FRESH INSTALL MODE#{normal}" tui_format "Will install Hyprland, GPU drivers, and all dependencies." tui_format "" fi } show_summary() { local modules=("$@") tui_format "" tui_format "#{bold}Installation Summary:#{normal}" tui_format " Modules to run: ${#modules[@]}" local gpu gpu="$(detect_gpu)" tui_format " Detected GPU: ${gpu}" if ((${#modules[@]})); then tui_format "" tui_format "#{bold}Steps:#{normal}" local i=1 for mod in "${modules[@]}"; do local name name="$(basename "$mod" .sh)" tui_format " $i. ${name}" ((i++)) done fi tui_format "" if ! tui_confirm "Proceed with installation?"; then tui_format "#{bold}Installation cancelled by user.#{normal}" exit 0 fi } main() { OMERON_LOG_FILE="${OMERON_LOG_FILE:-$HOME/.local/share/omeron/install-$(date +%Y%m%d-%H%M%S).log}" export OMERON_LOG_FILE parse_args "$@" tui_style show_banner mkdir -p "$(dirname "$OMERON_LOG_FILE")" log_info "Omeron installation started" log_info "Log file: $OMERON_LOG_FILE" log_info "Project: $OMERON_ROOT" log_info "Fresh install: $OMERON_FRESH_INSTALL" if ((!OMERON_FRESH_INSTALL)) && ((${#RUN_MODULES[@]} == 0)); then log_info "Checking for fresh install..." if is_fresh_install; then OMERON_FRESH_INSTALL=1 export OMERON_FRESH_INSTALL log_info "Fresh system detected — switching to full setup mode" fi fi local modules_to_run=() if ((${#RUN_MODULES[@]})); then mapfile -t modules_to_run < <(collect_modules) else mapfile -t modules_to_run < <(collect_all_interactive) fi if ((${#modules_to_run[@]} == 0)); then log_warn "No modules selected. Nothing to do." exit 0 fi show_summary "${modules_to_run[@]}" local total=${#modules_to_run[@]} local idx=1 for module_path in "${modules_to_run[@]}"; do local description="" if source "$module_path" 2>/dev/null && declare -F "module_description" >/dev/null 2>&1; then description="$(module_description)" fi printf '\n' log_step "$idx" "$total" "${description:-$(basename "$module_path" .sh)}" module_run "$module_path" || { local rc=$? if declare -F "module_required" >/dev/null 2>&1; then source "$module_path" if module_required 2>/dev/null; then log_error "Required module failed. Aborting." exit $rc fi fi log_warn "Module completed with warnings" } ((idx++)) done printf '\n' tui_header " Ꮎ Ꮇ Ꭼ Ꮢ Ꮎ Ꮑ " tui_format "" tui_format "#{bold}#{green}Installation Complete!#{normal}" tui_format "" tui_format "Log: ${OMERON_LOG_FILE}" tui_format "" if ((OMERON_FRESH_INSTALL)); then tui_format "#{bold}Your system is ready for Hyprland!#{normal}" tui_format "" tui_format " Start Hyprland: Hyprland" tui_format " Or enable SDDM: sudo systemctl enable --now sddm" tui_format " Reload config: hyprctl reload" else tui_format "What next?" tui_format " - Reload config with: hyprctl reload" tui_format " - Re-run installer: ./install.sh" fi tui_format "" if have notify-send; then notify-send "Omeron" "Installation complete! ✨" >/dev/null 2>&1 || true fi } main "$@"