mirror of
https://github.com/marcogll/omarchy_setup.git
synced 2026-01-13 13:25:16 +00:00
feat: Refactor AUR package installation and improve logging in setup scripts
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
# Asegurarse de que las funciones comunes están cargadas
|
||||
SCRIPT_DIR_MODULE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
SCRIPT_DIR_ROOT="$(cd "${SCRIPT_DIR_MODULE}/.." && pwd)"
|
||||
if [[ -f "${SCRIPT_DIR_MODULE}/common.sh" ]]; then
|
||||
source "${SCRIPT_DIR_MODULE}/common.sh"
|
||||
else
|
||||
@@ -15,6 +16,16 @@ fi
|
||||
install_zsh() {
|
||||
log_step "Configuración Completa de Zsh"
|
||||
|
||||
local target_user="${SUDO_USER:-$USER}"
|
||||
local target_home="$HOME"
|
||||
if [[ -n "${SUDO_USER:-}" ]]; then
|
||||
target_home="$(getent passwd "$target_user" 2>/dev/null | cut -d: -f6)"
|
||||
if [[ -z "$target_home" ]]; then
|
||||
target_home="$(eval echo "~${target_user}")"
|
||||
fi
|
||||
fi
|
||||
target_home="${target_home:-$HOME}"
|
||||
|
||||
# --- 1. Instalar paquetes necesarios desde Pacman ---
|
||||
log_info "Instalando Zsh y herramientas esenciales..."
|
||||
local pkgs=(
|
||||
@@ -22,7 +33,6 @@ install_zsh() {
|
||||
zsh-completions
|
||||
zsh-syntax-highlighting
|
||||
zsh-autosuggestions
|
||||
oh-my-posh # Para el prompt
|
||||
zoxide # Navegación inteligente
|
||||
fastfetch # Información del sistema
|
||||
yt-dlp # Descarga de videos/audio
|
||||
@@ -31,13 +41,38 @@ install_zsh() {
|
||||
for pkg in "${pkgs[@]}"; do
|
||||
check_and_install_pkg "$pkg"
|
||||
done
|
||||
|
||||
# Instalar Oh My Posh con fallback a AUR si es necesario
|
||||
if ! command_exists oh-my-posh; then
|
||||
log_info "Instalando Oh My Posh..."
|
||||
if command_exists pacman && sudo pacman -S --noconfirm --needed oh-my-posh 2>/dev/null; then
|
||||
log_success "Oh My Posh instalado desde pacman."
|
||||
else
|
||||
log_warning "Pacman no pudo instalar oh-my-posh. Intentando con un helper AUR..."
|
||||
if aur_install_packages "oh-my-posh-bin"; then
|
||||
log_success "Oh My Posh instalado usando helper AUR (${AUR_HELPER_CMD})."
|
||||
else
|
||||
log_warning "No se pudo instalar Oh My Posh mediante pacman ni AUR."
|
||||
log_info "Descargando instalador oficial de Oh My Posh..."
|
||||
if curl -fsSL https://ohmyposh.dev/install.sh | sudo bash -s -- -d /usr/local/bin; then
|
||||
log_success "Oh My Posh instalado usando el script oficial."
|
||||
else
|
||||
log_error "Fallo la instalación de Oh My Posh usando el script oficial."
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
else
|
||||
log_info "Oh My Posh ya está instalado."
|
||||
fi
|
||||
|
||||
# --- 2. Instalar Oh My Zsh (si no existe) ---
|
||||
if [[ ! -d "$HOME/.oh-my-zsh" ]]; then
|
||||
local target_ohmyzsh_dir="${target_home}/.oh-my-zsh"
|
||||
if [[ ! -d "$target_ohmyzsh_dir" ]]; then
|
||||
log_info "Instalando Oh My Zsh..."
|
||||
# Usar RUNZSH=no para evitar que inicie un nuevo shell y CHSH=no para no cambiar el shell aún
|
||||
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended --keep-zshrc
|
||||
if [[ $? -ne 0 ]]; then
|
||||
if ! env HOME="$target_home" RUNZSH=no CHSH=no \
|
||||
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended --keep-zshrc; then
|
||||
log_error "Falló la instalación de Oh My Zsh."
|
||||
return 1
|
||||
fi
|
||||
@@ -46,39 +81,84 @@ install_zsh() {
|
||||
fi
|
||||
|
||||
# --- 3. Descargar y configurar el .zshrc personalizado ---
|
||||
log_info "Descargando configuración .zshrc desde el repositorio..."
|
||||
# Crear copia de seguridad antes de sobrescribir
|
||||
backup_file "$HOME/.zshrc" || return 1
|
||||
log_info "Actualizando configuración .zshrc..."
|
||||
local repo_zshrc_path="${SCRIPT_DIR_ROOT}/.zshrc"
|
||||
local tmp_download="${target_home}/.zshrc.omarchy-tmp"
|
||||
local source_file=""
|
||||
|
||||
if curl -fsSL "${REPO_BASE}/.zshrc" -o "$HOME/.zshrc.omarchy-tmp" && [[ -s "$HOME/.zshrc.omarchy-tmp" ]]; then
|
||||
mv "$HOME/.zshrc.omarchy-tmp" "$HOME/.zshrc"
|
||||
log_success "Archivo .zshrc actualizado."
|
||||
if curl -fsSL "${REPO_BASE}/.zshrc" -o "$tmp_download" && [[ -s "$tmp_download" ]]; then
|
||||
source_file="$tmp_download"
|
||||
log_success "Configuración .zshrc descargada desde el repositorio remoto."
|
||||
else
|
||||
log_error "No se pudo descargar el archivo .zshrc."
|
||||
return 1
|
||||
rm -f "$tmp_download"
|
||||
if [[ -f "$repo_zshrc_path" ]]; then
|
||||
log_warning "No se pudo descargar .zshrc. Usando la copia local del repositorio."
|
||||
source_file="$repo_zshrc_path"
|
||||
else
|
||||
log_error "No se pudo obtener la configuración .zshrc (sin red y sin copia local)."
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Crear copia de seguridad antes de sobrescribir
|
||||
backup_file "${target_home}/.zshrc" || { rm -f "$tmp_download"; return 1; }
|
||||
|
||||
if [[ "$source_file" == "$tmp_download" ]]; then
|
||||
if mv "$tmp_download" "${target_home}/.zshrc"; then
|
||||
log_success "Archivo .zshrc actualizado."
|
||||
else
|
||||
rm -f "$tmp_download"
|
||||
log_error "No se pudo mover el archivo .zshrc descargado."
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
if cp "$source_file" "${target_home}/.zshrc"; then
|
||||
log_success "Archivo .zshrc actualizado desde la copia local."
|
||||
else
|
||||
log_error "No se pudo copiar la configuración .zshrc local."
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# --- 4. Descargar el tema de Oh My Posh ---
|
||||
log_info "Configurando tema de Oh My Posh (Catppuccin Frappe)..."
|
||||
local posh_themes_dir="$HOME/.poshthemes"
|
||||
local posh_themes_dir="${target_home}/.poshthemes"
|
||||
local theme_file="$posh_themes_dir/catppuccin_frappe.omp.json"
|
||||
local posh_theme_local="${SCRIPT_DIR_ROOT}/themes/catppuccin_frappe.omp.json"
|
||||
mkdir -p "$posh_themes_dir"
|
||||
|
||||
if curl -fsSL "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/catppuccin_frappe.omp.json" -o "$theme_file"; then
|
||||
chmod 644 "$theme_file" 2>/dev/null || true
|
||||
log_success "Tema Catppuccin Frappe descargado en $theme_file"
|
||||
else
|
||||
log_error "No se pudo descargar el tema de Oh My Posh."
|
||||
# No retornamos error, el .zshrc tiene un fallback
|
||||
rm -f "$theme_file"
|
||||
if [[ -f "$posh_theme_local" ]]; then
|
||||
if cp "$posh_theme_local" "$theme_file"; then
|
||||
chmod 644 "$theme_file" 2>/dev/null || true
|
||||
log_warning "No se pudo descargar el tema remoto. Se utilizó la copia incluida en el repositorio."
|
||||
else
|
||||
log_error "No se pudo copiar la versión local del tema Catppuccin."
|
||||
fi
|
||||
else
|
||||
log_error "No se pudo descargar el tema de Oh My Posh y no hay copia local disponible."
|
||||
# No retornamos error, el .zshrc tiene un fallback
|
||||
fi
|
||||
fi
|
||||
|
||||
# --- 5. Cambiar el shell por defecto a Zsh para el usuario actual ---
|
||||
if [[ "$(basename "$SHELL")" != "zsh" ]]; then
|
||||
local current_shell
|
||||
current_shell="$(getent passwd "$target_user" 2>/dev/null | cut -d: -f7)"
|
||||
current_shell="${current_shell:-$SHELL}"
|
||||
if [[ "$(basename "$current_shell")" != "zsh" ]]; then
|
||||
log_info "Cambiando el shell por defecto a Zsh..."
|
||||
# chsh requiere la contraseña del usuario
|
||||
if chsh -s "$(which zsh)"; then
|
||||
local zsh_path
|
||||
zsh_path="$(command -v zsh)"
|
||||
if [[ -z "$zsh_path" ]]; then
|
||||
log_error "No se encontró la ruta de Zsh. Aborta el cambio de shell."
|
||||
elif sudo -n chsh -s "$zsh_path" "$target_user"; then
|
||||
log_success "Shell cambiado a Zsh. El cambio será efectivo en el próximo inicio de sesión."
|
||||
else
|
||||
log_error "No se pudo cambiar el shell. Por favor, ejecute 'chsh -s $(which zsh)' manualmente."
|
||||
log_error "No se pudo cambiar el shell automáticamente. Ejecuta 'sudo chsh -s \"$zsh_path\" $target_user' manualmente."
|
||||
fi
|
||||
else
|
||||
log_info "Zsh ya es el shell por defecto."
|
||||
@@ -90,9 +170,9 @@ install_zsh() {
|
||||
if [ -t 1 ]; then
|
||||
exec zsh
|
||||
fi'
|
||||
if [[ -f "$HOME/.bashrc" ]] && ! grep -q "exec zsh" "$HOME/.bashrc"; then
|
||||
if [[ -f "${target_home}/.bashrc" ]] && ! grep -q "exec zsh" "${target_home}/.bashrc"; then
|
||||
log_info "Configurando .bashrc para iniciar Zsh automáticamente..."
|
||||
echo "$bashrc_zsh_loader" >> "$HOME/.bashrc"
|
||||
echo "$bashrc_zsh_loader" >> "${target_home}/.bashrc"
|
||||
else
|
||||
log_info ".bashrc ya está configurado para lanzar Zsh."
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user