mirror of
https://github.com/marcogll/omarchy_setup.git
synced 2026-01-13 13:25:16 +00:00
Refactor: Improve and Document All Modules and Readme.md (#3)
* docs: update and improve Readme.md in Spanish Restore the comprehensive Spanish version of the `Readme.md` and add a new section with instructions for installing the Meslo font, which is required for the `oh-my-posh` theme to render correctly. The new section is located in the "Troubleshooting" area and provides the necessary command (`oh-my-posh font install meslo`) to ensure a correct setup. The rest of the document has been reviewed to ensure it is complete and accurately reflects the script's functionality. * refactor: improve and document all modules and Readme.md This is a major refactoring and documentation effort that touches every module in the project. - **Exhaustive In-Code Documentation:** Every module script in the `modules/` directory has been updated with detailed comments. This includes header descriptions, explanations for each function, and justifications for complex logic. This greatly improves the maintainability and readability of the code. - **Code Robustness and Optimization:** Several modules have been refactored to be more robust and efficient. This includes: - Optimizing package installations by grouping them into a single `pacman` command. - Improving dependency checks. - Standardizing the use of helper functions from `common.sh`. - Making network operations more resilient. - **Comprehensive `Readme.md` Update:** The main `Readme.md` has been rewritten to be a complete and professional guide to the project. It now includes: - A clear and detailed description of each module. - Information on what each module installs and how it works. - Instructions for installing the required Nerd Font for `oh-my-posh`. - An updated structure that is easier to navigate. --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: Marco Gallegos <marco.gallegos@outlook.com>
This commit is contained in:
committed by
GitHub
parent
a2fbb1166b
commit
eabfe0cbaf
@@ -2,10 +2,37 @@
|
||||
# ===============================================================
|
||||
# ssh-keyring.sh - Sincronizar claves SSH con GNOME Keyring
|
||||
# ===============================================================
|
||||
#
|
||||
# Este módulo se encarga de encontrar todas las claves SSH privadas
|
||||
# en el directorio ~/.ssh del usuario y añadirlas al agente de
|
||||
# GNOME Keyring. Esto permite que las claves estén disponibles
|
||||
# para autenticación sin necesidad de introducir la passphrase
|
||||
# cada vez, ya que el keyring las gestiona de forma segura.
|
||||
#
|
||||
# Funciones principales:
|
||||
# - Inicia el daemon de GNOME Keyring con los componentes de
|
||||
# SSH y secretos.
|
||||
# - Configura la variable de entorno SSH_AUTH_SOCK para que
|
||||
# apunten al socket del keyring.
|
||||
# - Detecta claves ya cargadas para evitar añadirlas de nuevo.
|
||||
#
|
||||
# Dependencias: gnome-keyring, openssh.
|
||||
#
|
||||
# ===============================================================
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "${SCRIPT_DIR}/common.sh"
|
||||
|
||||
# ---------------------------------------------------------------
|
||||
# _derive_fingerprint(key_path)
|
||||
# ---------------------------------------------------------------
|
||||
# Obtiene el "fingerprint" (huella digital) de una clave SSH.
|
||||
# Esto se usa para identificar de forma única cada clave y así
|
||||
# evitar añadir al agente claves que ya han sido cargadas.
|
||||
#
|
||||
# Parámetros:
|
||||
# $1 - Ruta a la clave SSH privada.
|
||||
# ---------------------------------------------------------------
|
||||
_derive_fingerprint() {
|
||||
local key_path="$1"
|
||||
local pub_path="${key_path}.pub"
|
||||
@@ -19,73 +46,72 @@ _derive_fingerprint() {
|
||||
echo "$fingerprint"
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------
|
||||
# sync_ssh_keyring()
|
||||
# ---------------------------------------------------------------
|
||||
# Función principal que orquesta la sincronización de claves.
|
||||
# ---------------------------------------------------------------
|
||||
sync_ssh_keyring() {
|
||||
log_step "Sincronizar claves SSH con GNOME Keyring"
|
||||
|
||||
# --- 1. Verificación de Dependencias ---
|
||||
if ! command_exists gnome-keyring-daemon; then
|
||||
log_error "gnome-keyring-daemon no está instalado. Ejecuta primero el módulo de aplicaciones."
|
||||
log_error "El comando 'gnome-keyring-daemon' no está instalado. Ejecuta primero el módulo de aplicaciones."
|
||||
return 1
|
||||
fi
|
||||
|
||||
if ! command_exists ssh-add; then
|
||||
log_error "ssh-add no está disponible (openssh). Instala el módulo de aplicaciones antes."
|
||||
log_error "El comando 'ssh-add' (de openssh) no está disponible. Instala primero el módulo de aplicaciones."
|
||||
return 1
|
||||
fi
|
||||
|
||||
# --- 2. Configuración del Entorno de GNOME Keyring ---
|
||||
# Asegura que la variable SSH_AUTH_SOCK apunte al socket correcto.
|
||||
mkdir -p "${HOME}/.config/environment.d"
|
||||
cat <<'EOF' > "${HOME}/.config/environment.d/10-gnome-keyring.conf"
|
||||
SSH_AUTH_SOCK=/run/user/$UID/keyring/ssh
|
||||
EOF
|
||||
|
||||
# Inicia el daemon de GNOME Keyring si no está ya en ejecución.
|
||||
local keyring_eval=""
|
||||
if keyring_eval="$(gnome-keyring-daemon --start --components=ssh,secrets 2>/dev/null)"; then
|
||||
eval "$keyring_eval"
|
||||
log_success "GNOME Keyring iniciado."
|
||||
log_success "El daemon de GNOME Keyring se ha iniciado."
|
||||
else
|
||||
log_info "GNOME Keyring ya estaba en ejecución."
|
||||
log_info "El daemon de GNOME Keyring ya estaba en ejecución."
|
||||
fi
|
||||
|
||||
# Exporta la variable SSH_AUTH_SOCK para la sesión actual.
|
||||
local keyring_socket="${SSH_AUTH_SOCK:-/run/user/$UID/keyring/ssh}"
|
||||
if [[ ! -S "$keyring_socket" ]]; then
|
||||
log_warning "No se encontró el socket de GNOME Keyring en ${keyring_socket}."
|
||||
if [[ -S "/run/user/$UID/keyring/ssh" ]]; then
|
||||
keyring_socket="/run/user/$UID/keyring/ssh"
|
||||
else
|
||||
log_error "GNOME Keyring no expone el componente SSH. Revisa tu sesión."
|
||||
return 1
|
||||
fi
|
||||
log_error "No se encontró el socket de GNOME Keyring. El componente SSH podría no estar activo."
|
||||
return 1
|
||||
fi
|
||||
export SSH_AUTH_SOCK="$keyring_socket"
|
||||
|
||||
# --- 3. Búsqueda y Filtrado de Claves SSH ---
|
||||
local ssh_dir="${HOME}/.ssh"
|
||||
if [[ ! -d "$ssh_dir" ]]; then
|
||||
log_warning "No existe el directorio ${ssh_dir}. No hay claves para agregar."
|
||||
log_warning "El directorio ${ssh_dir} no existe. No hay claves para agregar."
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Encuentra todas las claves privadas en ~/.ssh, excluyendo ficheros públicos y de configuración.
|
||||
mapfile -t ssh_private_keys < <(
|
||||
find "$ssh_dir" -maxdepth 1 -type f -perm -u=r \
|
||||
! -name "*.pub" \
|
||||
! -name "*-cert.pub" \
|
||||
! -name "known_hosts" \
|
||||
! -name "known_hosts.*" \
|
||||
! -name "authorized_keys" \
|
||||
! -name "config" \
|
||||
! -name "*.old" \
|
||||
! -name "agent" \
|
||||
! -name "*.bak" \
|
||||
2>/dev/null | sort
|
||||
! -name "*.pub" ! -name "*-cert.pub" ! -name "known_hosts" \
|
||||
! -name "known_hosts.*" ! -name "authorized_keys" ! -name "config" \
|
||||
! -name "*.old" ! -name "agent" ! -name "*.bak" 2>/dev/null | sort
|
||||
)
|
||||
if [[ ${#ssh_private_keys[@]} -eq 0 ]]; then
|
||||
log_warning "No se encontraron claves privadas SSH en ${ssh_dir}."
|
||||
log_info "No se encontraron claves privadas en ${ssh_dir}."
|
||||
return 0
|
||||
fi
|
||||
|
||||
# --- 4. Sincronización de Claves ---
|
||||
# Obtiene los fingerprints de las claves que ya están cargadas en el agente.
|
||||
local existing_fingerprints=""
|
||||
if output=$(SSH_AUTH_SOCK="$SSH_AUTH_SOCK" ssh-add -l 2>/dev/null); then
|
||||
existing_fingerprints="$(awk '{print $2}' <<<"$output")"
|
||||
else
|
||||
existing_fingerprints=""
|
||||
fi
|
||||
|
||||
local added=0
|
||||
@@ -93,37 +119,40 @@ EOF
|
||||
local fingerprint
|
||||
fingerprint="$(_derive_fingerprint "$key_path")"
|
||||
if [[ -z "$fingerprint" ]] && ! ssh-keygen -y -f "$key_path" >/dev/null 2>&1; then
|
||||
log_warning "El archivo $(basename "$key_path") no parece una clave privada válida. Se omite."
|
||||
log_warning "El archivo $(basename "$key_path") no parece una clave privada válida y será omitido."
|
||||
continue
|
||||
fi
|
||||
|
||||
# Si la clave ya está en el agente, la omite.
|
||||
if [[ -n "$fingerprint" ]] && grep -Fq "$fingerprint" <<<"$existing_fingerprints"; then
|
||||
log_info "Clave $(basename "$key_path") ya está registrada en el keyring."
|
||||
log_info "La clave $(basename "$key_path") ya está registrada en el keyring."
|
||||
continue
|
||||
fi
|
||||
|
||||
log_info "Añadiendo clave $(basename "$key_path") al keyring..."
|
||||
# Intenta añadir la clave. Se pedirá la passphrase si está protegida.
|
||||
log_info "Añadiendo la clave $(basename "$key_path") al keyring..."
|
||||
if SSH_AUTH_SOCK="$SSH_AUTH_SOCK" ssh-add "$key_path"; then
|
||||
log_success "Clave $(basename "$key_path") añadida correctamente."
|
||||
log_success "La clave $(basename "$key_path") se ha añadido correctamente."
|
||||
added=$((added + 1))
|
||||
if [[ -n "$fingerprint" ]]; then
|
||||
existing_fingerprints+=$'\n'"$fingerprint"
|
||||
fi
|
||||
else
|
||||
log_warning "No se pudo añadir la clave $(basename "$key_path")."
|
||||
log_warning "No se pudo añadir la clave $(basename "$key_path"). Es posible que la passphrase sea incorrecta."
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ $added -gt 0 ]]; then
|
||||
log_success "Claves SSH sincronizadas con GNOME Keyring."
|
||||
log_success "Se han sincronizado ${added} claves SSH con GNOME Keyring."
|
||||
else
|
||||
log_info "No se añadieron nuevas claves SSH."
|
||||
log_info "Todas las claves SSH ya estaban sincronizadas. No se añadieron nuevas claves."
|
||||
fi
|
||||
|
||||
log_info "Para verificar, ejecuta: ssh-add -l"
|
||||
log_info "Para verificar las claves cargadas, puedes ejecutar: ssh-add -l"
|
||||
return 0
|
||||
}
|
||||
|
||||
# Ejecutar si se llama directamente al script.
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
sync_ssh_keyring "$@"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user