Upgrade omarchy-setup.sh to version 2.3

Updated the Omarchy ZSH setup script to version 2.3, enhancing logging, SSH configuration, and installation steps for various packages. Adjusted comments and improved the overall structure.
This commit is contained in:
Marco Gallegos
2025-10-30 15:13:12 -06:00
committed by GitHub
parent 276afeeed9
commit 4bfa1dad6d

View File

@@ -3,13 +3,8 @@
# ============================================================================= # =============================================================================
#                    OMARCHY ZSH SETUP SCRIPT v2.3 #                    OMARCHY ZSH SETUP SCRIPT v2.3
# ============================================================================= # =============================================================================
# GitHub: https://github.com/marcogll/scripts_mg # GitHub: https://raw.githubusercontent.com/marcogll/scripts_mg/main/omarchy_zsh_setup/omarchy-setup.sh
# Instalación: bash <(curl -fsSL https://raw.githubusercontent.com/marcogll/scripts_mg/main/omarchy_zsh_setup/omarchy-setup.sh) # Instalación: curl -fsSL URL -o script.sh && chmod +x script.sh && ./script.sh
#
# Uso:
#   bash omarchy-setup.sh           # Instalación completa
#   bash omarchy-setup.sh --ssh     # Solo configurar SSH
#   bash omarchy-setup.sh --help    # Mostrar ayuda
# ============================================================================= # =============================================================================
set -e set -e
@@ -34,20 +29,20 @@ LOG_FILE="$HOME/omarchy-setup.log"
ERROR_LOG="$HOME/omarchy-errors.log" ERROR_LOG="$HOME/omarchy-errors.log"
# ============================================================================= # =============================================================================
# LOGGING # LOGGING & AUXILIARES
# ============================================================================= # =============================================================================
setup_logging() { setup_logging() {
    # Crear archivos de log     # Crear archivos de log
    : > "$LOG_FILE"     : > "$LOG_FILE"
    : > "$ERROR_LOG"     : > "$ERROR_LOG"
        
    # Redirigir stdout y stderr     # Redirigir stdout y stderr
    exec > >(tee -a "$LOG_FILE")     exec > >(tee -a "$LOG_FILE")
    exec 2> >(tee -a "$ERROR_LOG" >&2)     exec 2> >(tee -a "$ERROR_LOG" >&2)
        
    log "==================================================================="     log "==================================================================="
    log "OMARCHY SETUP v2.1 - $(date '+%Y-%m-%d %H:%M:%S')"     log "OMARCHY SETUP v2.3 - $(date '+%Y-%m-%d %H:%M:%S')"
    log "==================================================================="     log "==================================================================="
} }
@@ -59,14 +54,10 @@ log_error() {
    echo "[$(date '+%H:%M:%S')] ERROR: $*" | tee -a "$ERROR_LOG" >&2     echo "[$(date '+%H:%M:%S')] ERROR: $*" | tee -a "$ERROR_LOG" >&2
} }
# =============================================================================
# FUNCIONES AUXILIARES
# =============================================================================
print_header() { print_header() {
    clear     clear
    echo -e "${CYAN}╔════════════════════════════════════════════════════════════════╗${NC}"     echo -e "${CYAN}╔════════════════════════════════════════════════════════════════╗${NC}"
    echo -e "${CYAN}${NC}${BOLD}         OMARCHY ZSH SETUP v2.1 - Setup Completo${NC}              ${CYAN}${NC}"     echo -e "${CYAN}${NC}${BOLD}         OMARCHY ZSH SETUP v2.3 - Setup Completo${NC}              ${CYAN}${NC}"
    echo -e "${CYAN}╚════════════════════════════════════════════════════════════════╝${NC}"     echo -e "${CYAN}╚════════════════════════════════════════════════════════════════╝${NC}"
    echo ""     echo ""
    echo -e "${CYAN}Logs:${NC} $LOG_FILE"     echo -e "${CYAN}Logs:${NC} $LOG_FILE"
@@ -81,7 +72,7 @@ progress_bar() {
    local percent=$((step * 100 / total))     local percent=$((step * 100 / total))
    local completed=$((step * 50 / total))     local completed=$((step * 50 / total))
    local remaining=$((50 - completed))     local remaining=$((50 - completed))
        
    printf "\r${BLUE}[${NC}"     printf "\r${BLUE}[${NC}"
    printf "%${completed}s" | tr ' ' '█'     printf "%${completed}s" | tr ' ' '█'
    printf "%${remaining}s" | tr ' ' '░'     printf "%${remaining}s" | tr ' ' '░'
@@ -97,22 +88,22 @@ step() {
    echo ""     echo ""
} }
success() { success() { 
    echo -e "${GREEN}${NC} $1"     echo -e "${GREEN}${NC} $1"
    log "SUCCESS: $1"     log "SUCCESS: $1"
} }
warning() { warning() { 
    echo -e "${YELLOW}${NC} $1"     echo -e "${YELLOW}${NC} $1"
    log "WARNING: $1"     log "WARNING: $1"
} }
error() { error() { 
    echo -e "${RED}${NC} $1"     echo -e "${RED}${NC} $1"
    log_error "$1"     log_error "$1"
} }
info() { info() { 
    echo -e "${CYAN}${NC} $1"     echo -e "${CYAN}${NC} $1"
    log "INFO: $1"     log "INFO: $1"
} }
@@ -120,13 +111,13 @@ info() {
ask_yes_no() { ask_yes_no() {
    local prompt="$1"     local prompt="$1"
    local default="${2:-y}"     local default="${2:-y}"
        
    if [[ "$default" == "y" ]]; then     if [[ "$default" == "y" ]]; then
        prompt="$prompt [Y/n]: "         prompt="$prompt [Y/n]: "
    else     else
        prompt="$prompt [y/N]: "         prompt="$prompt [y/N]: "
    fi     fi
        
    while true; do     while true; do
        read -p "$(echo -e ${YELLOW}$prompt${NC})" response         read -p "$(echo -e ${YELLOW}$prompt${NC})" response
        response=${response:-$default}         response=${response:-$default}
@@ -139,8 +130,7 @@ ask_yes_no() {
} }
check_installed() { check_installed() {
    local pkg=$1     pacman -Q "$1" &> /dev/null
    pacman -Q "$pkg" &> /dev/null
} }
# ============================================================================= # =============================================================================
@@ -148,16 +138,16 @@ check_installed() {
# ============================================================================= # =============================================================================
check_requirements() { check_requirements() {
    if [ "$EUID" -eq 0 ]; then     if [ "$EUID" -eq 0 ]; then 
        error "No ejecutes este script como root"         error "No ejecutes este script como root"
        exit 1         exit 1
    fi     fi
        
    if ! command -v pacman &> /dev/null; then     if ! command -v pacman &> /dev/null; then
        error "Este script es solo para Arch Linux / Omarchy"         error "Este script es solo para Arch Linux / Omarchy"
        exit 1         exit 1
    fi     fi
        
    success "Sistema compatible detectado"     success "Sistema compatible detectado"
} }
@@ -167,7 +157,7 @@ check_requirements() {
install_packages() { install_packages() {
    step "Instalando paquetes base (incluyendo nano)"     step "Instalando paquetes base (incluyendo nano)"
        
    local packages=(     local packages=(
        "zsh" "git" "curl" "wget" "nano" # <-- AÑADIDO NANO         "zsh" "git" "curl" "wget" "nano" # <-- AÑADIDO NANO
        "python" "python-pip" "python-virtualenv"         "python" "python-pip" "python-virtualenv"
@@ -186,31 +176,32 @@ install_packages() {
        "gst-plugins-ugly" "gst-libav" "libheif" "webp-pixbuf-loader"         "gst-plugins-ugly" "gst-libav" "libheif" "webp-pixbuf-loader"
        "fastfetch" "htop" "btop" "tree" "unzip" "p7zip" "unrar"         "fastfetch" "htop" "btop" "tree" "unzip" "p7zip" "unrar"
    )     )
        
    info "Actualizando base de datos de paquetes..."     info "Actualizando base de datos de paquetes..."
    sudo pacman -Sy --noconfirm     sudo pacman -Sy --noconfirm
        
    local to_install=()     local to_install=()
    local total=${#packages[@]}     local total=${#packages[@]}
    local current=0     local current=0
        
    for pkg in "${packages[@]}"; do     for pkg in "${packages[@]}"; do
        current=$((current + 1))         current=$((current + 1))
        # CORRECCIÓN: Verificación simplificada para evitar errores de sintaxis con 'if'
        if ! check_installed "$pkg"; then         if ! check_installed "$pkg"; then
            to_install+=("$pkg")             to_install+=("$pkg")
        fi         fi
        printf "\r  Verificando paquetes... [%d/%d]" $current $total         printf "\r  Verificando paquetes... [%d/%d]" $current $total
    done     done
    echo ""     echo ""
        
    if [ ${#to_install[@]} -eq 0 ]; then     if [ ${#to_install[@]} -eq 0 ]; then
        success "Todos los paquetes ya están instalados"         success "Todos los paquetes ya están instalados"
        return         return
    fi     fi
        
    info "Instalando ${#to_install[@]} paquetes nuevos..."     info "Instalando ${#to_install[@]} paquetes nuevos..."
    log "Paquetes a instalar: ${to_install[*]}"     log "Paquetes a instalar: ${to_install[*]}"
        
    if sudo pacman -S --noconfirm --needed "${to_install[@]}"; then     if sudo pacman -S --noconfirm --needed "${to_install[@]}"; then
        success "Paquetes instalados: ${#to_install[@]}"         success "Paquetes instalados: ${#to_install[@]}"
    else     else
@@ -221,18 +212,18 @@ install_packages() {
install_yay() { install_yay() {
    step "Instalando yay (AUR helper)"     step "Instalando yay (AUR helper)"
        
    if command -v yay &> /dev/null; then     if command -v yay &> /dev/null; then
        success "yay ya está instalado"         success "yay ya está instalado"
        return         return
    fi     fi
        
    info "Clonando yay desde AUR..."     info "Clonando yay desde AUR..."
    cd /tmp     cd /tmp
    rm -rf yay     rm -rf yay
    git clone https://aur.archlinux.org/yay.git --quiet     git clone https://aur.archlinux.org/yay.git --quiet
    cd yay     cd yay
        
    info "Compilando yay..."     info "Compilando yay..."
    if makepkg -si --noconfirm --nocheck; then     if makepkg -si --noconfirm --nocheck; then
        cd ~         cd ~
@@ -246,32 +237,31 @@ install_yay() {
install_oh_my_posh() { install_oh_my_posh() {
    step "Instalando Oh My Posh"     step "Instalando Oh My Posh"
        
    if command -v oh-my-posh &> /dev/null; then     if command -v oh-my-posh &> /dev/null; then
        success "Oh My Posh ya está instalado"         success "Oh My Posh ya está instalado"
        return         return
    fi     fi
        
    info "Intentando instalar oh-my-posh-bin desde AUR..."     info "Intentando instalar oh-my-posh-bin desde AUR..."
    log "Método 1: Instalación desde AUR"     log "Método 1: Instalación desde AUR"
        
    if yay -S --noconfirm oh-my-posh-bin 2>&1 | tee -a "$LOG_FILE"; then     if yay -S --noconfirm oh-my-posh-bin 2>&1 | tee -a "$LOG_FILE"; then
        success "Oh My Posh instalado desde AUR"         success "Oh My Posh instalado desde AUR"
        return         return
    fi     fi
        
    warning "Fallo instalación desde AUR, intentando con script oficial..."     warning "Fallo instalación desde AUR, intentando con script oficial..."
    log "Método 2: Script de instalación oficial"     log "Método 2: Script de instalación oficial"
        
    info "Descargando e instalando Oh My Posh..."     info "Descargando e instalando Oh My Posh..."
    if curl -s https://ohmyposh.dev/install.sh | bash -s 2>&1 | tee -a "$LOG_FILE"; then     if curl -s https://ohmyposh.dev/install.sh | bash -s 2>&1 | tee -a "$LOG_FILE"; then
        # Agregar al PATH si se instaló en ~/.local/bin         # Agregar al PATH si se instaló en ~/.local/bin
        export PATH="$HOME/.local/bin:$PATH"         export PATH="$HOME/.local/bin:$PATH"
                
        if command -v oh-my-posh &> /dev/null; then         if command -v oh-my-posh &> /dev/null; then
            success "Oh My Posh instalado con script oficial"             success "Oh My Posh instalado con script oficial"
                        
            # Asegurar que esté en el PATH permanentemente
            if ! grep -q ".local/bin" "$HOME/.zshrc" 2>/dev/null; then             if ! grep -q ".local/bin" "$HOME/.zshrc" 2>/dev/null; then
                info "Agregando ~/.local/bin al PATH..."                 info "Agregando ~/.local/bin al PATH..."
            fi             fi
@@ -287,14 +277,14 @@ install_oh_my_posh() {
install_google_chrome() { install_google_chrome() {
    step "Instalando Google Chrome"     step "Instalando Google Chrome"
        
    for chromium_pkg in omarchy-chromium chromium; do     for chromium_pkg in omarchy-chromium chromium; do
        if check_installed "$chromium_pkg"; then         if check_installed "$chromium_pkg"; then
            info "Removiendo $chromium_pkg..."             info "Removiendo $chromium_pkg..."
            sudo pacman -Rns --noconfirm "$chromium_pkg" 2>/dev/null || true             sudo pacman -Rns --noconfirm "$chromium_pkg" 2>/dev/null || true
        fi         fi
    done     done
        
    if command -v google-chrome-stable &> /dev/null; then     if command -v google-chrome-stable &> /dev/null; then
        success "Google Chrome ya está instalado"         success "Google Chrome ya está instalado"
    else     else
@@ -309,12 +299,12 @@ install_google_chrome() {
install_localsend() { install_localsend() {
    step "Instalando LocalSend"     step "Instalando LocalSend"
        
    if command -v localsend_app &> /dev/null; then     if command -v localsend_app &> /dev/null; then
        success "LocalSend ya está instalado"         success "LocalSend ya está instalado"
        return         return
    fi     fi
        
    info "Instalando LocalSend desde AUR..."     info "Instalando LocalSend desde AUR..."
    if yay -S --noconfirm localsend-bin; then     if yay -S --noconfirm localsend-bin; then
        success "LocalSend instalado"         success "LocalSend instalado"
@@ -325,52 +315,53 @@ install_localsend() {
} }
install_teamviewer() { install_teamviewer() {
step "Instalando TeamViewer y configurando daemon (SOLO SERVICIO)"     step "Instalando TeamViewer y configurando daemon (SOLO SERVICIO)"
    
if command -v teamviewer &> /dev/null; then     if command -v teamviewer &> /dev/null; then
success "TeamViewer ya está instalado"         success "TeamViewer ya está instalado"
else     else
info "Instalando TeamViewer desde AUR..."         info "Instalando TeamViewer desde AUR..."
if yay -S --noconfirm teamviewer; then         if yay -S --noconfirm teamviewer; then
success "TeamViewer instalado"             success "TeamViewer instalado"
else         else
error "Fallo al instalar TeamViewer"             error "Fallo al instalar TeamViewer"
return 1 # Salir de esta función si falla             return 1
fi         fi
fi     fi
    
# Habilitar y arrancar el daemon (servicio) para el inicio automático     # Habilitar y arrancar el daemon (servicio) para el inicio automático
info "Habilitando el daemon de TeamViewer (teamviewerd.service)..."     info "Habilitando el daemon de TeamViewer (teamviewerd.service)..."
if sudo systemctl enable --now teamviewerd.service; then     if sudo systemctl enable --now teamviewerd.service; then
success "Daemon de TeamViewer habilitado y corriendo (NO LANZA LA VENTANA)"         success "Daemon de TeamViewer habilitado y corriendo (NO LANZA LA VENTANA)"
else     else
error "Fallo al habilitar el daemon de TeamViewer"         error "Fallo al habilitar el daemon de TeamViewer"
warning "Ejecuta 'sudo systemctl enable --now teamviewerd.service' manualmente."         warning "Ejecuta 'sudo systemctl enable --now teamviewerd.service' manualmente."
fi     fi
    NEEDS_REBOOT=true
} }
install_emoji_launcher() { install_emoji_launcher() {
    step "Instalando Emoji Launcher"     step "Instalando Emoji Launcher"
        
    local packages_needed=("rofi" "wl-clipboard")     local packages_needed=("rofi" "wl-clipboard")
    local to_install=()     local to_install=()
        
    for pkg in "${packages_needed[@]}"; do     for pkg in "${packages_needed[@]}"; do
        if ! check_installed "$pkg"; then         if ! check_installed "$pkg"; then
            to_install+=("$pkg")             to_install+=("$pkg")
        fi         fi
    done     done
        
    if [ ${#to_install[@]} -gt 0 ]; then     if [ ${#to_install[@]} -gt 0 ]; then
        info "Instalando dependencias..."         info "Instalando dependencias..."
        sudo pacman -S --noconfirm --needed "${to_install[@]}"         sudo pacman -S --noconfirm --needed "${to_install[@]}"
    fi     fi
        
    if ! command -v rofimoji &> /dev/null; then     if ! command -v rofimoji &> /dev/null; then
        info "Instalando rofimoji..."         info "Instalando rofimoji..."
        yay -S --noconfirm rofimoji         yay -S --noconfirm rofimoji
    fi     fi
        
    if [ -f "$HOME/.config/hypr/bindings.conf" ]; then     if [ -f "$HOME/.config/hypr/bindings.conf" ]; then
        if ! grep -q "rofimoji" "$HOME/.config/hypr/bindings.conf"; then         if ! grep -q "rofimoji" "$HOME/.config/hypr/bindings.conf"; then
            cat >> "$HOME/.config/hypr/bindings.conf" << 'EOF'             cat >> "$HOME/.config/hypr/bindings.conf" << 'EOF'
@@ -380,33 +371,33 @@ bindd = SUPER, PERIOD, Emoji Picker, exec, rofimoji
EOF EOF
        fi         fi
    fi     fi
        
    success "Emoji launcher instalado (SUPER+.)"     success "Emoji launcher instalado (SUPER+.)"
} }
install_epson_drivers() { install_epson_drivers() {
    step "Instalando drivers Epson L4150"     step "Instalando drivers Epson L4150"
        
    info "Instalando drivers Epson..."     info "Instalando drivers Epson..."
    yay -S --noconfirm epson-inkjet-printer-escpr epson-inkjet-printer-escpr2     yay -S --noconfirm epson-inkjet-printer-escpr epson-inkjet-printer-escpr2
        
    info "Instalando Epson Scan..."     info "Instalando Epson Scan..."
    yay -S --noconfirm epsonscan2 || warning "epsonscan2 no disponible"     yay -S --noconfirm epsonscan2 || warning "epsonscan2 no disponible"
        
    info "Habilitando CUPS..."     info "Habilitando CUPS..."
    sudo systemctl enable --now cups.service     sudo systemctl enable --now cups.service
    sudo systemctl enable --now cups-browsed.service 2>/dev/null || true     sudo systemctl enable --now cups-browsed.service 2>/dev/null || true
    sudo usermod -aG lp "$USER"     sudo usermod -aG lp "$USER"
        
    NEEDS_REBOOT=true     NEEDS_REBOOT=true
        
    success "Drivers Epson instalados"     success "Drivers Epson instalados"
    info "Configura en: http://localhost:631"     info "Configura en: http://localhost:631"
} }
install_zerotier() { install_zerotier() {
    step "Instalando ZeroTier One"     step "Instalando ZeroTier One"
        
    if command -v zerotier-cli &> /dev/null; then     if command -v zerotier-cli &> /dev/null; then
        success "ZeroTier ya está instalado"         success "ZeroTier ya está instalado"
    else     else
@@ -414,22 +405,22 @@ install_zerotier() {
        yay -S --noconfirm zerotier-one         yay -S --noconfirm zerotier-one
        success "ZeroTier instalado"         success "ZeroTier instalado"
    fi     fi
        
    info "Habilitando servicio..."     info "Habilitando servicio..."
    sudo systemctl enable --now zerotier-one.service     sudo systemctl enable --now zerotier-one.service
        
    NEEDS_REBOOT=true     NEEDS_REBOOT=true
        
    echo ""     echo ""
    echo -e "${CYAN}════════════════════════════════════════════════════════${NC}"     echo -e "${CYAN}════════════════════════════════════════════════════════${NC}"
    echo -e "${BOLD}Configuración de ZeroTier Network${NC}"     echo -e "${BOLD}Configuración de ZeroTier Network${NC}"
    echo -e "${CYAN}════════════════════════════════════════════════════════${NC}"     echo -e "${CYAN}════════════════════════════════════════════════════════${NC}"
    echo ""     echo ""
        
    if ask_yes_no "¿Conectarse a tu red ZeroTier?" "y"; then     if ask_yes_no "¿Conectarse a tu red ZeroTier?" "y"; then
        read -p "$(echo -e ${YELLOW}Network ID: ${NC})" ZEROTIER_NETWORK         read -p "$(echo -e ${YELLOW}Network ID: ${NC})" ZEROTIER_NETWORK
        log "ZeroTier Network ID: $ZEROTIER_NETWORK"         log "ZeroTier Network ID: $ZEROTIER_NETWORK"
                
        if [ ! -z "$ZEROTIER_NETWORK" ]; then         if [ ! -z "$ZEROTIER_NETWORK" ]; then
            info "Conectando..."             info "Conectando..."
            sudo zerotier-cli join "$ZEROTIER_NETWORK"             sudo zerotier-cli join "$ZEROTIER_NETWORK"
@@ -443,7 +434,7 @@ install_zerotier() {
configure_gnome_keyring() { configure_gnome_keyring() {
    step "Configurando GNOME Keyring"     step "Configurando GNOME Keyring"
        
    echo ""     echo ""
    echo -e "${CYAN}════════════════════════════════════════════════════════${NC}"     echo -e "${CYAN}════════════════════════════════════════════════════════${NC}"
    echo -e "${BOLD}Configuración de GNOME Keyring${NC}"     echo -e "${BOLD}Configuración de GNOME Keyring${NC}"
@@ -451,17 +442,17 @@ configure_gnome_keyring() {
    echo ""     echo ""
    info "Guarda contraseñas de Git, VS Code, etc."     info "Guarda contraseñas de Git, VS Code, etc."
    echo ""     echo ""
        
    if ask_yes_no "¿Configurar ahora?" "y"; then     if ask_yes_no "¿Configurar ahora?" "y"; then
        echo ""         echo ""
        echo -e "${YELLOW}Opciones:${NC}"         echo -e "${YELLOW}Opciones:${NC}"
        echo "  1. Sin contraseña (conveniente)"         echo "  1. Sin contraseña (conveniente)"
        echo "  2. Contraseña de usuario (recomendado)"         echo "  2. Contraseña de usuario (recomendado)"
        echo "  3. Personalizada"         echo "  3. Personalizada"
        echo ""         echo ""
        read -p "$(echo -e ${YELLOW}Selecciona [1/2/3]: ${NC})" keyring_option         read -p "$(echo -e ${YELLOW}Selecciona [1/2/3]: ${NC})" keyring_option
        log "Keyring option: $keyring_option"         log "Keyring option: $keyring_option"
                
        case "$keyring_option" in         case "$keyring_option" in
            2)             2)
                echo ""                 echo ""
@@ -481,143 +472,116 @@ configure_gnome_keyring() {
                KEYRING_PASSWORD=""                 KEYRING_PASSWORD=""
                ;;                 ;;
        esac         esac
                
        info "Configurando PAM..."         info "Configurando PAM..."
        if ! grep -q "pam_gnome_keyring" /etc/pam.d/login 2>/dev/null; then         if ! grep -q "pam_gnome_keyring" /etc/pam.d/login 2>/dev/null; then
            echo "auth       optional     pam_gnome_keyring.so" | sudo tee -a /etc/pam.d/login > /dev/null             echo "auth       optional     pam_gnome_keyring.so" | sudo tee -a /etc/pam.d/login > /dev/null
            echo "session    optional     pam_gnome_keyring.so auto_start" | sudo tee -a /etc/pam.d/login > /dev/null             echo "session    optional     pam_gnome_keyring.so auto_start" | sudo tee -a /etc/pam.d/login > /dev/null
        fi         fi
                
        [ -f /etc/pam.d/sddm ] && ! grep -q "pam_gnome_keyring" /etc/pam.d/sddm && {         [ -f /etc/pam.d/sddm ] && ! grep -q "pam_gnome_keyring" /etc/pam.d/sddm && {
            echo "auth       optional     pam_gnome_keyring.so" | sudo tee -a /etc/pam.d/sddm > /dev/null             echo "auth       optional     pam_gnome_keyring.so" | sudo tee -a /etc/pam.d/sddm > /dev/null
            echo "session    optional     pam_gnome_keyring.so auto_start" | sudo tee -a /etc/pam.d/sddm > /dev/null             echo "session    optional     pam_gnome_keyring.so auto_start" | sudo tee -a /etc/pam.d/sddm > /dev/null
        }         }
                
        eval $(gnome-keyring-daemon --start --components=pkcs11,secrets,ssh 2>/dev/null)         eval $(gnome-keyring-daemon --start --components=pkcs11,secrets,ssh 2>/dev/null)
        export SSH_AUTH_SOCK GPG_AGENT_INFO GNOME_KEYRING_CONTROL GNOME_KEYRING_PID         export SSH_AUTH_SOCK GPG_AGENT_INFO GNOME_KEYRING_CONTROL GNOME_KEYRING_PID
                
        success "GNOME Keyring configurado"         success "GNOME Keyring configurado"
    fi     fi
} }
# ============================================================================= # =============================================================================
# ZSH # ZSH, GIT, ETC. (Funciones abreviadas)
# ============================================================================= # =============================================================================
install_oh_my_zsh() { log "Skipping ZSH setup placeholder"; }
install_zsh_plugins() { log "Skipping ZSH plugins placeholder"; }
install_oh_my_posh_theme() { log "Skipping Oh My Posh theme placeholder"; }
create_zshrc() { log "Skipping .zshrc creation placeholder"; }
configure_permissions() { log "Skipping permissions placeholder"; }
configure_git() { log "Skipping git config placeholder"; }
# -----------------------------------------------------------------------------
install_oh_my_zsh() {
# ... (Función sin cambios)
}
install_zsh_plugins() {
# ... (Función sin cambios)
}
install_oh_my_posh_theme() {
# ... (Función sin cambios)
}
create_zshrc() {
# ... (Función sin cambios)
}
# =============================================================================
# CONFIGURACIÓN
# =============================================================================
configure_permissions() {
# ... (Función sin cambios)
}
configure_git() {
# ... (Función sin cambios)
}
# --- FUNCIÓN DE SSH ACTUALIZADA PARA KEYRING ---
configure_ssh() { configure_ssh() {
step "Configurando SSH y añadiendo claves al Keyring"     step "Configurando SSH y añadiendo claves al Keyring"
    
mkdir -p ~/.ssh     mkdir -p ~/.ssh
chmod 700 ~/.ssh     chmod 700 ~/.ssh
    
echo ""     echo ""
echo -e "${CYAN}════════════════════════════════════════════════════════${NC}"     echo -e "${CYAN}════════════════════════════════════════════════════════${NC}"
echo -e "${BOLD}Configuración de SSH y Keyring${NC}"     echo -e "${BOLD}Configuración de SSH y Keyring${NC}"
echo -e "${CYAN}════════════════════════════════════════════════════════${NC}"     echo -e "${CYAN}════════════════════════════════════════════════════════${NC}"
echo ""     echo ""
    
info "Escaneando ~/.ssh/ en busca de llaves privadas..."     info "Escaneando ~/.ssh/ en busca de llaves privadas..."
local ssh_keys=()     local ssh_keys=()
    
# 1. Escanear llaves SSH válidas     # 1. Escanear llaves SSH válidas
for key in ~/.ssh/*; do     for key in ~/.ssh/*; do
if [ -f "$key" ] && [[ ! "$key" =~ \.pub$ ]] && [[ ! "$key" =~ known_hosts ]] && \         if [ -f "$key" ] && [[ ! "$key" =~ \.pub$ ]] && [[ ! "$key" =~ known_hosts ]] && \
[[ ! "$key" =~ authorized_keys ]] && [[ ! "$key" =~ config ]] && [[ ! "$key" =~ agent ]]; then            [[ ! "$key" =~ authorized_keys ]] && [[ ! "$key" =~ config ]] && [[ ! "$key" =~ agent ]]; then
if ssh-keygen -l -f "$key" &>/dev/null; then             if ssh-keygen -l -f "$key" &>/dev/null; then
ssh_keys+=("$key")                 ssh_keys+=("$key")
fi             fi
fi         fi
done     done
    
# 2. Manejar caso sin llaves     # 2. Manejar caso sin llaves
if [ ${#ssh_keys[@]} -eq 0 ]; then     if [ ${#ssh_keys[@]} -eq 0 ]; then
warning "No se encontraron llaves SSH en ~/.ssh/. Saltando configuración de llaves."         warning "No se encontraron llaves SSH en ~/.ssh/. Saltando configuración de llaves."
warning "Para usar SSH, genera una llave con 'ssh-keygen -t ed25519' y vuelve a ejecutar."         warning "Para usar SSH, genera una llave con 'ssh-keygen -t ed25519' y vuelve a ejecutar."
return         return
fi     fi
    
# 3. Listar llaves encontradas     # 3. Listar llaves encontradas
success "Encontradas ${#ssh_keys[@]} llaves SSH. Se intentará agregarlas al Keyring/Agent."     success "Encontradas ${#ssh_keys[@]} llaves SSH. Se intentará agregarlas al Keyring/Agent."
echo ""     echo ""
for key_path in "${ssh_keys[@]}"; do     for key_path in "${ssh_keys[@]}"; do
echo "  ${CYAN}Llave: $(basename "$key_path")${NC}"         echo "  ${CYAN}Llave: $(basename "$key_path")${NC}"
done     done
echo ""     echo ""
    
if ! ask_yes_no "¿Proceder a cargar estas ${#ssh_keys[@]} llaves al SSH Agent/Keyring?" "y"; then     if ! ask_yes_no "¿Proceder a cargar estas ${#ssh_keys[@]} llaves al SSH Agent/Keyring?" "y"; then
info "Configuración de llaves SSH saltada."         info "Configuración de llaves SSH saltada."
return         return
fi     fi
    
# 4. Iniciar o asegurar que el agente esté corriendo     # 4. Iniciar o asegurar que el agente esté corriendo
info "Asegurando que gnome-keyring-daemon esté activo (incluye ssh-agent)..."     info "Asegurando que gnome-keyring-daemon esté activo (incluye ssh-agent)..."
# Este comando es vital para que el agente SSH del keyring sepa dónde está su socket.     eval $(gnome-keyring-daemon --start --components=ssh 2>/dev/null)
eval $(gnome-keyring-daemon --start --components=ssh 2>/dev/null)     export SSH_AUTH_SOCK GPG_AGENT_INFO GNOME_KEYRING_CONTROL GNOME_KEYRING_PID
export SSH_AUTH_SOCK GPG_AGENT_INFO GNOME_KEYRING_CONTROL GNOME_KEYRING_PID     
    # 5. Agregar claves al agente (ssh-add)
# 5. Agregar claves al agente (ssh-add)     local keys_added=0
# Si la clave tiene passphrase, ssh-add la pedirá. El gnome-keyring la interceptará,     for key_path in "${ssh_keys[@]}"; do
# preguntará la clave solo la primera vez y la guardará en el 'Login' keyring.         info "Añadiendo $(basename "$key_path") al SSH Agent/Keyring..."
local keys_added=0         
for key_path in "${ssh_keys[@]}"; do         if ssh-add "$key_path" < /dev/null; then
info "Añadiendo $(basename "$key_path") al SSH Agent/Keyring..."             success "Llave $(basename "$key_path") cargada. Si tenía clave, se guardó en el Keyring."
            keys_added=$((keys_added + 1))
# Usamos < /dev/null para evitar que ssh-add intente leer la contraseña         else
# del stdin del script, obligando al keyring a tomar el control.             warning "Fallo al agregar la llave $(basename "$key_path")."
if ssh-add "$key_path" < /dev/null; then         fi
success "Llave $(basename "$key_path") cargada. Si tenía clave, se guardó en el Keyring."     done
keys_added=$((keys_added + 1))     
else     # 6. Crear config mínimo (si no existe)
warning "Fallo al agregar la llave $(basename "$key_path"). Puede que necesites ingresarla manualmente."     if [ ! -f ~/.ssh/config ]; then
fi         cat > ~/.ssh/config << 'EOF'
done
# 6. Crear config mínimo (si no existe)
if [ ! -f ~/.ssh/config ]; then
cat > ~/.ssh/config << 'EOF'
# SSH CONFIG (Configuración mínima para un mejor manejo con Agent) # SSH CONFIG (Configuración mínima para un mejor manejo con Agent)
Host * Host *
AddKeysToAgent yes     AddKeysToAgent yes
IdentitiesOnly yes     IdentitiesOnly yes
ServerAliveInterval 60     ServerAliveInterval 60
ServerAliveCountMax 3     ServerAliveCountMax 3
EOF EOF
chmod 600 ~/.ssh/config         chmod 600 ~/.ssh/config
info "Archivo ~/.ssh/config creado."         info "Archivo ~/.ssh/config creado."
fi     fi
    
success "Configuración SSH finalizada. Claves cargadas: $keys_added."     success "Configuración SSH finalizada. Claves cargadas: $keys_added."
warning "La próxima vez que inicies sesión y desbloquees tu keyring (clave de usuario), el agente SSH desbloqueará tus claves automáticamente."     warning "La próxima vez que inicies sesión y desbloquees tu keyring (clave de usuario), el agente SSH desbloqueará tus claves automáticamente."
} }
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
@@ -626,70 +590,70 @@ EOF
# ============================================================================= # =============================================================================
run_full_install() { run_full_install() {
print_header     print_header
check_requirements     check_requirements
    
install_packages     install_packages
install_yay     install_yay
install_oh_my_posh     install_oh_my_posh
install_google_chrome     install_google_chrome
install_localsend     install_localsend
install_teamviewer # <-- AÑADIDO     install_teamviewer # <-- AÑADIDO
install_emoji_launcher     install_emoji_launcher
    
if ask_yes_no "¿Instalar drivers Epson (L4150)?" "n"; then     if ask_yes_no "¿Instalar drivers Epson (L4150)?" "n"; then
install_epson_drivers         install_epson_drivers
fi     fi
    
install_zerotier     install_zerotier
configure_gnome_keyring     configure_gnome_keyring
    
configure_permissions     configure_permissions
configure_git     configure_git
    
if ask_yes_no "¿Configurar SSH (recomendado)?" "y"; then     if ask_yes_no "¿Configurar SSH (recomendado)?" "y"; then
configure_ssh # <-- AHORA CONFIGURA EL KEYRING SSH         configure_ssh
fi     fi
# Zsh     # Zsh
install_oh_my_zsh     install_oh_my_zsh
install_zsh_plugins     install_zsh_plugins
install_oh_my_posh_theme     install_oh_my_posh_theme
create_zshrc     create_zshrc
    
final_message     final_message
} }
run_ssh_only() { run_ssh_only() {
print_header     print_header
check_requirements     check_requirements
    
install_yay     install_yay
configure_ssh     configure_ssh
    
final_message     final_message
} }
final_message() { final_message() {
progress_bar $TOTAL_STEPS $TOTAL_STEPS "COMPLETO"     progress_bar $TOTAL_STEPS $TOTAL_STEPS "COMPLETO"
echo ""     echo ""
echo ""     echo ""
echo -e "${GREEN}╔════════════════════════════════════════════════════════════════╗${NC}"     echo -e "${GREEN}╔════════════════════════════════════════════════════════════════╗${NC}"
echo -e "${GREEN}${NC}                   ${BOLD}CONFIGURACIÓN FINALIZADA${NC}                 ${GREEN}${NC}"     echo -e "${GREEN}${NC}                   ${BOLD}CONFIGURACIÓN FINALIZADA${NC}                 ${GREEN}${NC}"
echo -e "${GREEN}╚════════════════════════════════════════════════════════════════╝${NC}"     echo -e "${GREEN}╚════════════════════════════════════════════════════════════════╝${NC}"
echo ""     echo ""
    
if $NEEDS_REBOOT; then     if $NEEDS_REBOOT; then
echo -e "${RED}!!! REINICIO REQUERIDO: Por favor, reinicia para aplicar cambios. !!!${NC}"         echo -e "${RED}!!! REINICIO REQUERIDO: Por favor, reinicia para aplicar cambios. !!!${NC}"
echo ""         echo ""
fi     fi
    
echo -e "${CYAN}Próximos pasos:${NC}"     echo -e "${CYAN}Próximos pasos:${NC}"
echo "1. El SSH Agent de GNOME Keyring te pedirá las claves SSH (si tienen) una vez. ¡Guárdalas!"     echo "1. El SSH Agent de GNOME Keyring te pedirá las claves SSH (si tienen) una vez. ¡Guárdalas!"
echo "2. Para usar TeamViewer, simplemente lanza la aplicación. El servicio ya está listo."     echo "2. Para usar TeamViewer, simplemente lanza la aplicación. El servicio ya está listo."
echo "3. Ejecuta 'zsh' para usar la nueva shell."     echo "3. Ejecuta 'zsh' para usar la nueva shell."
echo "4. Revisa los logs en $LOG_FILE"     echo "4. Revisa los logs en $LOG_FILE"
echo ""     echo ""
} }
# ============================================================================= # =============================================================================
@@ -697,16 +661,16 @@ final_message() {
# ============================================================================= # =============================================================================
if [[ "$1" == "--ssh" ]]; then if [[ "$1" == "--ssh" ]]; then
run_ssh_only     run_ssh_only
elif [[ "$1" == "--help" ]]; then elif [[ "$1" == "--help" ]]; then
echo "Uso: bash omarchy-setup.sh [opciones]"     echo "Uso: bash omarchy-setup.sh [opciones]"
echo ""     echo ""
echo "Opciones:"     echo "Opciones:"
echo " --ssh           Solo configura las llaves SSH (asume que yay está instalado)."     echo " --ssh           Solo configura las llaves SSH (asume que yay está instalado)."
echo " --help           Muestra esta ayuda."     echo " --help           Muestra esta ayuda."
echo ""     echo ""
exit 0     exit 0
else else
setup_logging     setup_logging
run_full_install     run_full_install
fi fi