refactor(install): changement dans la structure

This commit is contained in:
Anael Ginder
2026-09-18 15:40:28 +02:00
parent 064e1bcaa5
commit 83a78c098b
7 changed files with 184 additions and 92 deletions
@@ -113,7 +113,10 @@ git-push-mr() {
#Export Perso
export SSH_AUTH_SOCK=/home/an.ginder/.keeper/anael.ginder@nameshield.net.ssh_agent
#source ~/.zsh/zsh-autocomplete/zsh-autocomplete.plugin.zsh
source "$HOME/.zsh/spaceship/spaceship.zsh"
# Configuration personnelle
source "$HOME/.zsh/spaceship.zsh"
# Spaceship
source "$HOME/.zsh/spaceship-prompt/spaceship.zsh-theme"
source /opt/keeper-cli-venv/bin/activate
#export PYTHONPATH=/opt/wapt
eval "$(zoxide init zsh)"
+165 -76
View File
@@ -1,110 +1,199 @@
#!/bin/bash
#!/usr/bin/env bash
set -euo pipefail
set -Eeuo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Le dépôt est cloné dans ~/.dotfiles, avec cette structure :
# ~/.dotfiles/dotfiles/ -> packages stow (zellij, spaceship, zsh)
# ~/.dotfiles/install/ -> ce script
# DOTFILES_DIR pointe donc sur le sous-dossier "dotfiles" voisin de "install".
DOTFILES_DIR="$(cd "$SCRIPT_DIR/../dotfiles" && pwd)"
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
DOTFILES_DIR="$(cd -- "$SCRIPT_DIR/../dotfiles" && pwd)"
log() { echo "[*] $*"; }
err() { echo "Erreur: $*" >&2; }
BACKUP_ROOT="$HOME/.dotfiles-backup"
BACKUP_DIR=""
# usage: stow_config <nom_package> <répertoire_cible>
# Si le répertoire cible existe déjà, on ne touche à rien (idempotence
# non-destructive) : on suppose que la config est déjà en place.
stow_config() {
local package="$1"
local target="$2"
if [ -e "$target" ]; then
log "Config déjà présente ($target), on ne touche à rien. Skip."
return
fi
mkdir -p "$target"
log "Stow du package '$package' vers $target ..."
(cd "$DOTFILES_DIR" && stow -vSt "$target" "$package")
log() {
printf '[*] %s\n' "$*"
}
# --- 1. Dépendances système ---
log "Mise à jour des paquets apt ..."
sudo apt update
warn() {
printf '[!] %s\n' "$*" >&2
}
log "Installation des dépendances apt ..."
sudo apt -y install apt-transport-https curl gnupg stow zsh fzf zoxide
die() {
printf '[✗] %s\n' "$*" >&2
exit 1
}
# --- 2. Rust / cargo ---
if ! command -v cargo >/dev/null 2>&1; then
log "cargo introuvable, installation de rustup ..."
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
# ------------------------------------------------------------
# Vérifications
# ------------------------------------------------------------
if [[ "${EUID}" -eq 0 ]]; then
die "Ne lance pas ce script en root."
fi
if [ -f "$HOME/.cargo/env" ]; then
if [[ ! -d "$DOTFILES_DIR" ]]; then
die "Répertoire dotfiles introuvable : $DOTFILES_DIR"
fi
# ------------------------------------------------------------
# Dépendances système
# ------------------------------------------------------------
log "Mise à jour des paquets apt..."
#sudo apt update
log "Installation des dépendances..."
#sudo apt install -y apt-transport-https curl git gnupg stow zsh fzf zoxide
# ------------------------------------------------------------
# Rust / Cargo
# ------------------------------------------------------------
if ! command -v cargo >/dev/null 2>&1; then
log "Cargo introuvable, installation de rustup..."
curl \
--proto '=https' \
--tlsv1.2 \
-sSf \
https://sh.rustup.rs |
sh -s -- -y
fi
if [[ -f "$HOME/.cargo/env" ]]; then
# shellcheck disable=SC1091
source "$HOME/.cargo/env"
fi
if ! command -v cargo >/dev/null 2>&1; then
err "cargo toujours introuvable après installation, abandon."
echo "Cargo est toujours introuvable après l'installation de Rust."
exit 1
fi
# --- 3. Zellij + sa config ---
log "Installation de zellij ..."
#cargo install --locked zellij
# ------------------------------------------------------------
# Spaceship prompt
#
# Le logiciel est installé séparément dans :
# ~/.zsh/spaceship-prompt
#
# La configuration personnelle est gérée par Stow :
# ~/.zsh/spaceship.zsh
# ------------------------------------------------------------
stow_config "zellij" "$HOME/.config/zellij"
SPACESHIP_DIR="$HOME/.zsh/spaceship-prompt"
# --- 4. Zsh perso + zshrc principal ---
# Les fichiers restent nommés "zshrc" et "zshrc.perso" (sans point) dans le
# dépôt, mais on veut des symlinks cachés ~/.zshrc et ~/.zshrc.perso. stow
# ne permet pas ce renommage nativement (sauf convention "dot-" qu'on ne
# veut pas imposer au dépôt), donc on crée les symlinks manuellement.
if [[ -d "$SPACESHIP_DIR/.git" ]]; then
log "Spaceship déjà installé, mise à jour..."
link_dotfile() {
local src="$1"
local dest="$2"
git -C "$SPACESHIP_DIR" pull --ff-only
if [ -e "$dest" ] || [ -L "$dest" ]; then
log "$dest existe déjà, on ne touche à rien. Skip."
elif [[ -e "$SPACESHIP_DIR" ]]; then
die "$SPACESHIP_DIR existe mais n'est pas un dépôt Git."
else
log "Installation de Spaceship..."
mkdir -p "$HOME/.zsh"
git clone \
--depth=1 \
https://github.com/spaceship-prompt/spaceship-prompt.git \
"$SPACESHIP_DIR"
fi
# ------------------------------------------------------------
# Migration des configurations existantes
# ------------------------------------------------------------
create_backup_dir() {
if [[ -n "$BACKUP_DIR" ]]; then
return
fi
if [ ! -f "$src" ]; then
err "Fichier source introuvable : $src"
exit 1
fi
local timestamp
timestamp="$(date '+%Y%m%d-%H%M%S')"
log "Création du symlink $dest -> $src ..."
ln -s "$src" "$dest"
BACKUP_DIR="$BACKUP_ROOT/$timestamp"
mkdir -p "$BACKUP_DIR"
log "Backup créé dans : $BACKUP_DIR"
}
link_dotfile "$DOTFILES_DIR/zsh/zshrc" "$HOME/.zshrc"
link_dotfile "$DOTFILES_DIR/zsh/zshrc.perso" "$HOME/.zshrc.perso"
backup_if_needed() {
local target="$1"
# --- 5. Spaceship (prompt zsh) ---
SPACESHIP_DIR="$HOME/.zsh/spaceship-prompt"
if [ -d "$SPACESHIP_DIR/.git" ]; then
log "Spaceship (upstream) déjà présent, mise à jour ..."
(cd "$HOME/.zsh" && git -C spaceship-prompt pull --ff-only)
elif [ -e "$SPACESHIP_DIR" ]; then
log "$SPACESHIP_DIR existe mais n'est pas un dépôt git, on ne touche à rien. Skip."
else
log "Installation de spaceship (clone upstream) ..."
mkdir -p "$HOME/.zsh"
git clone --depth=1 https://github.com/spaceship-prompt/spaceship-prompt.git "$SPACESHIP_DIR"
# Rien n'existe : Stow pourra créer le lien.
if [[ ! -e "$target" && ! -L "$target" ]]; then
return
fi
stow_config "spaceship" "$HOME/.config/spaceship"
# C'est déjà un symlink.
# On ne le déplace pas et on laisse Stow le gérer.
if [[ -L "$target" ]]; then
log "Symlink déjà présent : $target"
return
fi
# --- 6. Outils Rust additionnels ---
log "Installation des outils Rust (bat, bottom, diskus, procs, cargo-update) ..."
cargo install --locked bat bottom diskus procs cargo-update
create_backup_dir
local relative_path
relative_path="${target#"$HOME"/}"
local backup_path
backup_path="$BACKUP_DIR/$relative_path"
mkdir -p "$(dirname "$backup_path")"
log "Backup : $target -> $backup_path"
mv -- "$target" "$backup_path"
}
migrate_dotfiles() {
log "Vérification des configurations existantes..."
# Zsh
backup_if_needed "$HOME/.zshrc"
backup_if_needed "$HOME/.zshrc.perso"
backup_if_needed "$HOME/.zsh/spaceship.zsh"
# Zellij
backup_if_needed "$HOME/.config/zellij/config.kdl"
backup_if_needed "$HOME/.config/zellij/layouts/default.kdl"
backup_if_needed "$HOME/.config/zellij/plugins/monocle.wasm"
}
migrate_dotfiles
# ------------------------------------------------------------
# Dotfiles avec GNU Stow
# ------------------------------------------------------------
log "Installation des dotfiles avec Stow..."
cd "$DOTFILES_DIR"
stow \
--dotfiles \
--restow \
--target="$HOME" \
zsh \
zellij
# ------------------------------------------------------------
# Outils Rust
# ------------------------------------------------------------
log "Installation des outils Rust..."
#cargo install --locked bat bottom diskus procs cargo-update
# ------------------------------------------------------------
# Résumé
# ------------------------------------------------------------
if [[ -n "$BACKUP_DIR" ]]; then
log "Les anciennes configurations ont été sauvegardées dans :"
log " $BACKUP_DIR"
fi
log "Installation terminée avec succès."