Upgrade omarchy-setup.sh to version 2.5

Updated the Omarchy setup script to version 2.5, enhancing logging, package installation, and function organization. Improved error handling and added new features for Zsh and Docker setup.
This commit is contained in:
Marco Gallegos
2025-11-02 09:20:45 -06:00
committed by GitHub
parent 540d2b00f9
commit 9b5f4fcd4f

View File

@@ -1,221 +1,188 @@
#!/bin/bash #!/usr/bin/env bash
# =============================================================================
# Omarchy Setup Script v2.5 (Omarchy-MG Edition)
# Autor: Marco G. / 2025
# Descripción:
# Script de automatización para configurar un entorno Zsh completo
# con Oh My Zsh, Oh My Posh, Docker, TeamViewer, Inkscape, Audacity,
# y utilidades esenciales. Compatible con Arch Linux.
# =============================================================================
# ================================================================ set -euo pipefail
# Omarchy Zsh Setup Script v2.4
# Author: Marco G
# Description: Automated Zsh environment setup for Arch/Omarchy Linux
# ================================================================
set -Eeo pipefail # =============================================================================
# COLORES Y UTILIDADES DE LOGGING
LOG_FILE="omarchy-setup.log" # =============================================================================
ERROR_LOG="omarchy-errors.log"
START_TIME=$(date +%s)
NEEDS_REBOOT=false
# Colors
GREEN="\e[32m" GREEN="\e[32m"
YELLOW="\e[33m" YELLOW="\e[33m"
RED="\e[31m" RED="\e[31m"
BLUE="\e[34m" RESET="\e[0m"
NC="\e[0m"
# Logging step() { echo -e "\n${YELLOW}$1${RESET}"; sleep 0.3; }
log() { echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a "$LOG_FILE"; } success() { echo -e "${GREEN} $1${RESET}"; }
error() { echo -e "${RED}${NC} $1" | tee -a "$ERROR_LOG" >&2; } error() { echo -e "${RED} $1${RESET}" >&2; }
success() { echo -e "${GREEN}${NC} $1"; log "SUCCESS: $1"; printf '\a'; } log() { echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1"; }
step() { echo -e "\n${BLUE}${NC} $1"; log "STEP: $1"; }
# Progress bar # =============================================================================
progress_bar() { # FUNCIÓN: Verificar conexión a Internet
local duration=$1 # =============================================================================
local interval=0.2
local elapsed=0
echo -n "["
while (( $(echo "$elapsed < $duration" | bc -l) )); do
echo -n "#"
sleep $interval
elapsed=$(echo "$elapsed + $interval" | bc)
done
echo "]"
}
# Internet check
check_internet() { check_internet() {
step "Verificando conexión a Internet..."
if ! ping -c 1 archlinux.org &>/dev/null; then if ! ping -c 1 archlinux.org &>/dev/null; then
error "Sin conexión a Internet. Abortando instalación." error "Sin conexión a Internet. Abortando instalación."
exit 1 exit 1
fi fi
success "Conexión a Internet verificada."
} }
# Package installation # =============================================================================
yay_install() { # FUNCIÓN: Actualizar sistema y dependencias base
local packages=($@) # =============================================================================
for pkg in "${packages[@]}"; do
if ! pacman -Qi $pkg &>/dev/null; then
yay -S --noconfirm --needed $pkg || error "Error instalando $pkg"
else
log "$pkg ya está instalado."
fi
done
}
# Install yay if missing
install_yay() {
if ! command -v yay &>/dev/null; then
step "Instalando yay desde AUR..."
mkdir -p /tmp/yay
cd /tmp/yay
git clone https://aur.archlinux.org/yay.git .
makepkg -si --noconfirm
cd - >/dev/null
rm -rf /tmp/yay
success "yay instalado correctamente."
else
log "yay ya está instalado."
fi
}
# Base system packages
install_base_packages() { install_base_packages() {
step "Instalando paquetes base..." step "Actualizando sistema e instalando paquetes base"
yay_install git curl wget zsh neovim unzip p7zip tree fzf ripgrep bat exa htop btop nano sudo pacman -Syu --noconfirm
success "Paquetes base instalados."
}
# GNOME Keyring configuration (skipped if no graphical session) # Paquetes esenciales del sistema
configure_gnome_keyring() { local pkgs=(
if [ -n "$DISPLAY" ]; then git curl wget unzip tar base-devel
step "Configurando GNOME Keyring..." zsh zsh-completions
yay_install gnome-keyring libsecret seahorse eza bat zoxide
mkdir -p ~/.config/systemd/user docker docker-compose
systemctl --user enable gcr-ssh-agent.socket || true teamviewer
systemctl --user start gcr-ssh-agent.socket || true audacity inkscape
success "GNOME Keyring configurado." oh-my-posh
else
log "Entorno sin interfaz gráfica, se omite GNOME Keyring."
fi
}
# Install Oh My Zsh
install_oh_my_zsh() {
step "Instalando Oh My Zsh..."
if [ ! -d "$HOME/.oh-my-zsh" ]; then
RUNZSH=no CHSH=no sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
success "Oh My Zsh instalado."
else
log "Oh My Zsh ya está instalado."
fi
}
# Install Zsh plugins
install_zsh_plugins() {
step "Instalando plugins de Zsh..."
mkdir -p ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins
local plugins=(
"zsh-users/zsh-autosuggestions"
"zsh-users/zsh-syntax-highlighting"
"zsh-users/zsh-completions"
) )
for repo in "${plugins[@]}"; do # Instalar con yay o pacman dependiendo de la disponibilidad
local name=$(basename "$repo") if command -v yay &>/dev/null; then
local path="${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/$name" yay -S --noconfirm "${pkgs[@]}"
if [ ! -d "$path" ]; then
git clone https://github.com/$repo "$path"
log "Plugin $name instalado."
else else
log "Plugin $name ya existe." sudo pacman -S --needed --noconfirm "${pkgs[@]}"
fi
done
success "Plugins de Zsh instalados."
}
# Install Oh My Posh
install_oh_my_posh() {
step "Instalando Oh My Posh..."
yay_install oh-my-posh
mkdir -p ~/.poshthemes
curl -fsSL https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/jandedobbeleer.omp.json -o ~/.poshthemes/omarchy.omp.json
success "Oh My Posh instalado."
}
# Create .zshrc
create_zshrc() {
step "Creando configuración de Zsh..."
cat > ~/.zshrc <<'EOF'
# ================================================================
# Omarchy Zsh Configuration
# ================================================================
export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME="agnoster"
plugins=(git zsh-autosuggestions zsh-syntax-highlighting zsh-completions)
source $ZSH/oh-my-zsh.sh
# Aliases y extras
alias ll='exa -lh --icons'
alias la='exa -lha --icons'
alias gs='git status'
alias v='nvim'
# Oh My Posh
if command -v oh-my-posh &>/dev/null; then
eval "$(oh-my-posh init zsh --config ~/.poshthemes/omarchy.omp.json)"
fi fi
# PATH success "Paquetes base instalados correctamente."
export PATH="$HOME/.local/bin:$PATH"
EOF
success ".zshrc creado."
} }
# Configure SSH # =============================================================================
configure_ssh() { # FUNCIÓN: Configurar Docker
step "Configurando SSH..." # =============================================================================
mkdir -p ~/.ssh setup_docker() {
chmod 700 ~/.ssh step "Configurando Docker y permisos de usuario"
if [ ! -f ~/.ssh/id_ed25519 ]; then sudo systemctl enable docker.service
ssh-keygen -t ed25519 -C "$(whoami)@$(hostname)" -f ~/.ssh/id_ed25519 -N "" sudo systemctl start docker.service
success "Clave SSH generada."
# Agregar usuario al grupo docker para evitar usar sudo
sudo usermod -aG docker "$USER"
success "Docker configurado. Recuerda cerrar y volver a iniciar sesión."
}
# =============================================================================
# FUNCIÓN: Instalar Oh My Zsh y plugins
# =============================================================================
install_ohmyzsh() {
step "Instalando Oh My Zsh y sus plugins"
if [ ! -d "$HOME/.oh-my-zsh" ]; then
# Instalar Oh My Zsh sin preguntar
RUNZSH=no CHSH=no KEEP_ZSHRC=yes \
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
else else
log "Clave SSH existente detectada." log "Oh My Zsh ya está instalado, se omite."
fi fi
eval "$(ssh-agent -s)" >/dev/null
ssh-add ~/.ssh/id_ed25519 || true # Crear carpeta custom de plugins si no existe
for key in ~/.ssh/*.pub; do mkdir -p "${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins"
log "Clave pública: $(cat $key)"
done # Instalar plugins adicionales
success "SSH configurado." git clone https://github.com/zsh-users/zsh-autosuggestions.git \
"${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-autosuggestions" || true
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git \
"${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting" || true
success "Oh My Zsh y plugins instalados correctamente."
} }
# Final summary # =============================================================================
finish_installation() { # FUNCIÓN: Descargar y aplicar el .zshrc personalizado
END_TIME=$(date +%s) # =============================================================================
DURATION=$((END_TIME - START_TIME)) install_zshrc() {
echo -e "\n${GREEN}Instalación completada.${NC}" step "Aplicando configuración personalizada de Zsh (.zshrc)"
echo -e "Duración: ${DURATION}s" local ZSHRC_URL="https://raw.githubusercontent.com/marcogll/scripts_mg/main/omarchy_zsh_setup/.zshrc"
echo -e "Logs: ${LOG_FILE}" local DEST="$HOME/.zshrc"
echo -e "Errores: ${ERROR_LOG}"
$NEEDS_REBOOT && echo -e "${YELLOW}Se recomienda reiniciar el sistema.${NC}" # Backup del anterior
echo -e "${BLUE}Para activar zsh como shell predeterminada, ejecuta:${NC} chsh -s $(which zsh)" if [ -f "$DEST" ]; then
cp "$DEST" "${DEST}.backup.$(date +%Y%m%d_%H%M%S)"
log "Backup del .zshrc existente creado."
fi
# Descargar el nuevo
if curl -fsSL "$ZSHRC_URL" -o "$DEST"; then
success "Nuevo .zshrc instalado desde GitHub."
else
error "Fallo al descargar .zshrc desde $ZSHRC_URL"
fi
# Cambiar shell por defecto a zsh
chsh -s "$(which zsh)" "$USER" || true
} }
# ================================================================ # =============================================================================
# MAIN EXECUTION FLOW # FUNCIÓN: Configurar TeamViewer (servicio)
# ================================================================ # =============================================================================
setup_teamviewer() {
step "Configurando TeamViewer"
sudo systemctl enable teamviewerd.service
sudo systemctl start teamviewerd.service
success "TeamViewer habilitado y activo."
}
step "Verificando entorno y conexión..." # =============================================================================
# FUNCIÓN: Instalación de fuentes y temas (opcional)
# =============================================================================
install_fonts() {
step "Instalando fuentes para Oh My Posh y terminal"
local FONTS_DIR="$HOME/.local/share/fonts"
mkdir -p "$FONTS_DIR"
# Ejemplo: instalar JetBrainsMono Nerd Font
if [ ! -f "$FONTS_DIR/JetBrainsMonoNerdFont-Regular.ttf" ]; then
curl -fsSL -o "$FONTS_DIR/JetBrainsMonoNerdFont-Regular.ttf" \
"https://github.com/ryanoasis/nerd-fonts/raw/master/patched-fonts/JetBrainsMono/Regular/complete/JetBrains%20Mono%20Nerd%20Font%20Complete.ttf"
fc-cache -f
fi
success "Fuentes Nerd instaladas."
}
# =============================================================================
# FUNCIÓN: Limpieza y resumen final
# =============================================================================
finish_setup() {
step "Finalizando configuración"
echo -e "\n${GREEN}🎉 Instalación completada correctamente.${RESET}"
echo -e "Reinicia tu sesión o ejecuta ${YELLOW}zsh${RESET} para activar la configuración."
echo -e "\nVerifica:"
echo " - Docker: 'docker ps'"
echo " - Zsh funcionando con Oh My Posh"
echo " - TeamViewer corriendo (teamviewer info)"
echo -e "\n🚀 ¡Listo para usar Omarchy en todo su esplendor!"
}
# =============================================================================
# MAIN
# =============================================================================
main() {
check_internet check_internet
install_yay
install_base_packages install_base_packages
configure_gnome_keyring setup_docker
install_oh_my_zsh install_ohmyzsh
install_zsh_plugins install_zshrc
install_oh_my_posh setup_teamviewer
create_zshrc install_fonts
configure_ssh finish_setup
finish_installation }
success "Setup completo. Reinicia o ejecuta 'zsh' para aplicar cambios." main "$@"