diff --git a/dotfiles/zellij/config.kdl b/dotfiles/zellij/dot-config/zellij/config.kdl similarity index 100% rename from dotfiles/zellij/config.kdl rename to dotfiles/zellij/dot-config/zellij/config.kdl diff --git a/dotfiles/zellij/layouts/default.kdl b/dotfiles/zellij/dot-config/zellij/layouts/default.kdl similarity index 100% rename from dotfiles/zellij/layouts/default.kdl rename to dotfiles/zellij/dot-config/zellij/layouts/default.kdl diff --git a/dotfiles/zellij/plugins/monocle.wasm b/dotfiles/zellij/dot-config/zellij/plugins/monocle.wasm similarity index 100% rename from dotfiles/zellij/plugins/monocle.wasm rename to dotfiles/zellij/dot-config/zellij/plugins/monocle.wasm diff --git a/dotfiles/spaceship/spaceship.zsh b/dotfiles/zsh/dot-zsh/spaceship.zsh similarity index 100% rename from dotfiles/spaceship/spaceship.zsh rename to dotfiles/zsh/dot-zsh/spaceship.zsh diff --git a/dotfiles/zsh/zshrc b/dotfiles/zsh/dot-zshrc similarity index 100% rename from dotfiles/zsh/zshrc rename to dotfiles/zsh/dot-zshrc diff --git a/dotfiles/zsh/zshrc.perso b/dotfiles/zsh/dot-zshrc.perso similarity index 96% rename from dotfiles/zsh/zshrc.perso rename to dotfiles/zsh/dot-zshrc.perso index dde7583..4f7332b 100644 --- a/dotfiles/zsh/zshrc.perso +++ b/dotfiles/zsh/dot-zshrc.perso @@ -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)" diff --git a/install/install.sh b/install/install.sh index 73823b1..dd2dc06 100755 --- a/install/install.sh +++ b/install/install.sh @@ -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 -# 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 - -# --- 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 -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." - exit 1 -fi - -# --- 3. Zellij + sa config --- -log "Installation de zellij ..." -#cargo install --locked zellij - -stow_config "zellij" "$HOME/.config/zellij" - -# --- 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. - -link_dotfile() { - local src="$1" - local dest="$2" - - if [ -e "$dest" ] || [ -L "$dest" ]; then - log "$dest existe déjà, on ne touche à rien. Skip." - return - fi - - if [ ! -f "$src" ]; then - err "Fichier source introuvable : $src" +die() { + printf '[✗] %s\n' "$*" >&2 exit 1 - fi - - log "Création du symlink $dest -> $src ..." - ln -s "$src" "$dest" } -link_dotfile "$DOTFILES_DIR/zsh/zshrc" "$HOME/.zshrc" -link_dotfile "$DOTFILES_DIR/zsh/zshrc.perso" "$HOME/.zshrc.perso" +# ------------------------------------------------------------ +# Vérifications +# ------------------------------------------------------------ + +if [[ "${EUID}" -eq 0 ]]; then + die "Ne lance pas ce script en root." +fi + +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 + echo "Cargo est toujours introuvable après l'installation de Rust." + exit 1 +fi + +# ------------------------------------------------------------ +# 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 +# ------------------------------------------------------------ -# --- 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." +if [[ -d "$SPACESHIP_DIR/.git" ]]; then + log "Spaceship déjà installé, mise à jour..." + + git -C "$SPACESHIP_DIR" pull --ff-only + +elif [[ -e "$SPACESHIP_DIR" ]]; then + die "$SPACESHIP_DIR existe mais n'est pas un dépôt Git." + 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" + log "Installation de Spaceship..." + + mkdir -p "$HOME/.zsh" + + git clone \ + --depth=1 \ + https://github.com/spaceship-prompt/spaceship-prompt.git \ + "$SPACESHIP_DIR" fi -stow_config "spaceship" "$HOME/.config/spaceship" +# ------------------------------------------------------------ +# Migration des configurations existantes +# ------------------------------------------------------------ -# --- 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() { + if [[ -n "$BACKUP_DIR" ]]; then + return + fi + + local timestamp + timestamp="$(date '+%Y%m%d-%H%M%S')" + + BACKUP_DIR="$BACKUP_ROOT/$timestamp" + + mkdir -p "$BACKUP_DIR" + + log "Backup créé dans : $BACKUP_DIR" +} + +backup_if_needed() { + local target="$1" + + # Rien n'existe : Stow pourra créer le lien. + if [[ ! -e "$target" && ! -L "$target" ]]; then + return + fi + + # 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 + + 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." -