refactor(install): changement dans la structure
This commit is contained in:
@@ -113,7 +113,10 @@ git-push-mr() {
|
|||||||
#Export Perso
|
#Export Perso
|
||||||
export SSH_AUTH_SOCK=/home/an.ginder/.keeper/anael.ginder@nameshield.net.ssh_agent
|
export SSH_AUTH_SOCK=/home/an.ginder/.keeper/anael.ginder@nameshield.net.ssh_agent
|
||||||
#source ~/.zsh/zsh-autocomplete/zsh-autocomplete.plugin.zsh
|
#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
|
source /opt/keeper-cli-venv/bin/activate
|
||||||
#export PYTHONPATH=/opt/wapt
|
#export PYTHONPATH=/opt/wapt
|
||||||
eval "$(zoxide init zsh)"
|
eval "$(zoxide init zsh)"
|
||||||
+166
-77
@@ -1,110 +1,199 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
set -euo pipefail
|
set -Eeuo pipefail
|
||||||
|
|
||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
# Le dépôt est cloné dans ~/.dotfiles, avec cette structure :
|
DOTFILES_DIR="$(cd -- "$SCRIPT_DIR/../dotfiles" && pwd)"
|
||||||
# ~/.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)"
|
|
||||||
|
|
||||||
log() { echo "[*] $*"; }
|
BACKUP_ROOT="$HOME/.dotfiles-backup"
|
||||||
err() { echo "Erreur: $*" >&2; }
|
BACKUP_DIR=""
|
||||||
|
|
||||||
# usage: stow_config <nom_package> <répertoire_cible>
|
log() {
|
||||||
# Si le répertoire cible existe déjà, on ne touche à rien (idempotence
|
printf '[*] %s\n' "$*"
|
||||||
# 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")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# --- 1. Dépendances système ---
|
warn() {
|
||||||
log "Mise à jour des paquets apt ..."
|
printf '[!] %s\n' "$*" >&2
|
||||||
sudo apt update
|
}
|
||||||
|
|
||||||
log "Installation des dépendances apt ..."
|
die() {
|
||||||
sudo apt -y install apt-transport-https curl gnupg stow zsh fzf zoxide
|
printf '[✗] %s\n' "$*" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
# --- 2. Rust / cargo ---
|
# ------------------------------------------------------------
|
||||||
if ! command -v cargo >/dev/null 2>&1; then
|
# Vérifications
|
||||||
log "cargo introuvable, installation de rustup ..."
|
# ------------------------------------------------------------
|
||||||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
|
|
||||||
|
if [[ "${EUID}" -eq 0 ]]; then
|
||||||
|
die "Ne lance pas ce script en root."
|
||||||
fi
|
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
|
# shellcheck disable=SC1091
|
||||||
source "$HOME/.cargo/env"
|
source "$HOME/.cargo/env"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! command -v cargo >/dev/null 2>&1; then
|
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# --- 3. Zellij + sa config ---
|
# ------------------------------------------------------------
|
||||||
log "Installation de zellij ..."
|
# Spaceship prompt
|
||||||
#cargo install --locked zellij
|
#
|
||||||
|
# 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 ---
|
if [[ -d "$SPACESHIP_DIR/.git" ]]; then
|
||||||
# Les fichiers restent nommés "zshrc" et "zshrc.perso" (sans point) dans le
|
log "Spaceship déjà installé, mise à jour..."
|
||||||
# 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() {
|
git -C "$SPACESHIP_DIR" pull --ff-only
|
||||||
local src="$1"
|
|
||||||
local dest="$2"
|
|
||||||
|
|
||||||
if [ -e "$dest" ] || [ -L "$dest" ]; then
|
elif [[ -e "$SPACESHIP_DIR" ]]; then
|
||||||
log "$dest existe déjà, on ne touche à rien. Skip."
|
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
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -f "$src" ]; then
|
local timestamp
|
||||||
err "Fichier source introuvable : $src"
|
timestamp="$(date '+%Y%m%d-%H%M%S')"
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
log "Création du symlink $dest -> $src ..."
|
BACKUP_DIR="$BACKUP_ROOT/$timestamp"
|
||||||
ln -s "$src" "$dest"
|
|
||||||
|
mkdir -p "$BACKUP_DIR"
|
||||||
|
|
||||||
|
log "Backup créé dans : $BACKUP_DIR"
|
||||||
}
|
}
|
||||||
|
|
||||||
link_dotfile "$DOTFILES_DIR/zsh/zshrc" "$HOME/.zshrc"
|
backup_if_needed() {
|
||||||
link_dotfile "$DOTFILES_DIR/zsh/zshrc.perso" "$HOME/.zshrc.perso"
|
local target="$1"
|
||||||
|
|
||||||
# --- 5. Spaceship (prompt zsh) ---
|
# Rien n'existe : Stow pourra créer le lien.
|
||||||
SPACESHIP_DIR="$HOME/.zsh/spaceship-prompt"
|
if [[ ! -e "$target" && ! -L "$target" ]]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -d "$SPACESHIP_DIR/.git" ]; then
|
# C'est déjà un symlink.
|
||||||
log "Spaceship (upstream) déjà présent, mise à jour ..."
|
# On ne le déplace pas et on laisse Stow le gérer.
|
||||||
(cd "$HOME/.zsh" && git -C spaceship-prompt pull --ff-only)
|
if [[ -L "$target" ]]; then
|
||||||
elif [ -e "$SPACESHIP_DIR" ]; then
|
log "Symlink déjà présent : $target"
|
||||||
log "$SPACESHIP_DIR existe mais n'est pas un dépôt git, on ne touche à rien. Skip."
|
return
|
||||||
else
|
fi
|
||||||
log "Installation de spaceship (clone upstream) ..."
|
|
||||||
mkdir -p "$HOME/.zsh"
|
create_backup_dir
|
||||||
git clone --depth=1 https://github.com/spaceship-prompt/spaceship-prompt.git "$SPACESHIP_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
|
fi
|
||||||
|
|
||||||
stow_config "spaceship" "$HOME/.config/spaceship"
|
|
||||||
|
|
||||||
# --- 6. Outils Rust additionnels ---
|
|
||||||
log "Installation des outils Rust (bat, bottom, diskus, procs, cargo-update) ..."
|
|
||||||
cargo install --locked bat bottom diskus procs cargo-update
|
|
||||||
|
|
||||||
log "Installation terminée avec succès."
|
log "Installation terminée avec succès."
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user