mirror of
https://github.com/marcogll/omarchy_setup.git
synced 2026-01-13 13:25:16 +00:00
Feat: Improve Keyring UX and Icon Manager Flow (#7)
* feat: add dev tools, AI aliases, and improve zshrc documentation
This commit introduces several new features and improvements:
- **Adds Development Tools to `apps.sh`:** The `apps.sh` module now installs essential development tools, including `python`, `pip`, `nodejs`, `npm`, `uv`, and `nvm`.
- **Implements `.zshrc.local` for Private Variables:**
- A `.zshrc.local.example` file has been added to serve as a template for users to securely store their private environment variables, such as API keys.
- The main `.zshrc` file now sources `.zshrc.local` if it exists.
- **Adds AI Aliases to `.zshrc`:** A new section has been added to `.zshrc` with example aliases for interacting with command-line AI tools.
- **Improves `.zshrc` Documentation:** The `.zshrc` file has been thoroughly documented with comments in Spanish, explaining the purpose of each section. The title has also been updated and professionalized.
- **Fixes a Regression:** This commit restores the `ytm`, `ytv`, `ytls`, and SSH agent functions in `.zshrc` that were accidentally removed in a previous step.
* feat: improve keyring UX and icon manager flow
This commit introduces two main improvements to the user experience:
1. **Refactors the Icon Manager for Non-Interactive Installation:**
- The `icon_manager.sh` module can now be run in a non-interactive mode.
- The "Install All" process has been updated to use this non-interactive mode, which installs the default icon theme without pausing the script or requiring user input.
2. **Improves the GNOME Keyring Workflow:**
- The script no longer errors out if the GNOME Keyring agent is not immediately available after installation.
- Instead, a clear summary message is now displayed at the end of the "Install All" process, instructing the user to log out and back in, and then run the SSH key synchronization module separately. This provides a much smoother and more intuitive user experience.
---------
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
e33719682e
commit
ae8e3c3c40
@@ -2,37 +2,10 @@
|
||||
# ===============================================================
|
||||
# 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"
|
||||
@@ -46,72 +19,73 @@ _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 "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 "El comando 'ssh-add' (de openssh) no está disponible. Instala primero el módulo de aplicaciones."
|
||||
log_error "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."
|
||||
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 "El daemon de GNOME Keyring se ha iniciado."
|
||||
log_success "GNOME Keyring iniciado."
|
||||
else
|
||||
log_info "El daemon de GNOME Keyring ya estaba en ejecución."
|
||||
log_info "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_error "No se encontró el socket de GNOME Keyring. El componente SSH podría no estar activo."
|
||||
return 1
|
||||
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
|
||||
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 "El directorio ${ssh_dir} no existe. No hay claves para agregar."
|
||||
log_warning "No existe el directorio ${ssh_dir}. 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_info "No se encontraron claves privadas en ${ssh_dir}."
|
||||
log_warning "No se encontraron claves privadas SSH 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
|
||||
@@ -119,40 +93,37 @@ 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 y será omitido."
|
||||
log_warning "El archivo $(basename "$key_path") no parece una clave privada válida. Se omite."
|
||||
continue
|
||||
fi
|
||||
|
||||
# Si la clave ya está en el agente, la omite.
|
||||
if [[ -n "$fingerprint" ]] && grep -Fq "$fingerprint" <<<"$existing_fingerprints"; then
|
||||
log_info "La clave $(basename "$key_path") ya está registrada en el keyring."
|
||||
log_info "Clave $(basename "$key_path") ya está registrada en el keyring."
|
||||
continue
|
||||
fi
|
||||
|
||||
# Intenta añadir la clave. Se pedirá la passphrase si está protegida.
|
||||
log_info "Añadiendo la clave $(basename "$key_path") al keyring..."
|
||||
log_info "Añadiendo clave $(basename "$key_path") al keyring..."
|
||||
if SSH_AUTH_SOCK="$SSH_AUTH_SOCK" ssh-add "$key_path"; then
|
||||
log_success "La clave $(basename "$key_path") se ha añadido correctamente."
|
||||
log_success "Clave $(basename "$key_path") añadida 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"). Es posible que la passphrase sea incorrecta."
|
||||
log_warning "No se pudo añadir la clave $(basename "$key_path")."
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ $added -gt 0 ]]; then
|
||||
log_success "Se han sincronizado ${added} claves SSH con GNOME Keyring."
|
||||
log_success "Claves SSH sincronizadas con GNOME Keyring."
|
||||
else
|
||||
log_info "Todas las claves SSH ya estaban sincronizadas. No se añadieron nuevas claves."
|
||||
log_info "No se añadieron nuevas claves SSH."
|
||||
fi
|
||||
|
||||
log_info "Para verificar las claves cargadas, puedes ejecutar: ssh-add -l"
|
||||
log_info "Para verificar, ejecuta: 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