Created
July 19, 2025 14:20
-
-
Save dzogrim/7b7aa378a6ad2fd19b83466f99e9d0a2 to your computer and use it in GitHub Desktop.
Compare les fichiers de configuration bash locaux avec des références sauvegardées sur Dropbox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# ------------------------------------------------------------------------------ | |
# Compare les fichiers de configuration bash (~/.bashrc.d) locaux avec des | |
# références sauvegardées sur Dropbox, selon l'environnement détecté (pro ou perso). | |
# | |
# Ce script est utile pour détecter les différences ou les oublis dans les fichiers | |
# de configuration shell synchronisés entre plusieurs machines. | |
# | |
# Dépendances : jq, diff, Dropbox installé et configuré avec fichier info.json | |
# ------------------------------------------------------------------------------ | |
dropboxDir="$(jq -r '.personal.path' <"${HOME}/.dropbox/info.json")" | |
current="${HOME}/.bashrc.d" | |
ref_pro="${dropboxDir}/Private/_SyncThat/.dotfiles_work/.bashrc.d" | |
ref_perso="${dropboxDir}/Private/_SyncThat/.dotfiles/.bashrc.d" | |
case "$LOGNAME" in | |
my_pro_usernam) | |
current_env="pro" | |
primary="${ref_pro}" | |
secondary="${ref_perso}" | |
;; | |
my_pero_usernam) | |
current_env="perso" | |
primary="${ref_perso}" | |
secondary="${ref_pro}" | |
;; | |
*) | |
echo "❌ Environnement non reconnu pour l'utilisateur ${LOGNAME}" | |
exit 1 | |
;; | |
esac | |
audit_against() { | |
local reference="$1" | |
local label="$2" | |
find "${current}" -maxdepth 1 -type f ! -name '.DS_Store' | while read -r f ; do | |
base="$(basename "$f")" | |
ref_file="${reference}/${base}" | |
if [[ -f "$ref_file" ]]; then | |
if ! diff -q "$f" "$ref_file" >/dev/null ; then | |
echo -e "\n⚠️ ${base} differs from ${label} backup:" | |
diff -u -1 "$ref_file" "$f" | sed 's/^/ /' | |
fi | |
else | |
echo -e "\n❌ ${base} missing from ${label} backup" | |
fi | |
done | |
} | |
audit_against "$primary" "$current_env" | |
audit_against "$secondary" "$( [[ "$current_env" == "pro" ]] && echo "perso" || echo "pro" )" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment