From 3f934600c965d031c00504ecd6d76325596c6f7f Mon Sep 17 00:00:00 2001 From: Pyotr Void Date: Fri, 8 Mar 2024 15:22:17 +0800 Subject: [PATCH] add backup logic to main script --- install.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/install.sh b/install.sh index 1eae8138..3cb90b05 100755 --- a/install.sh +++ b/install.sh @@ -10,6 +10,13 @@ # dotfiles directory dotfiledir="${HOME}/dotfiles" +# Create the backup directory if it doesn't exist +currentdate=$(date +%Y-%m-%d) +backupdir="${HOME}/dotfiles/backups/${currentdate}" + +mkdir -p "${backupdir}" +echo "Backup dir created" + # list of files/folders to symlink in ${homedir} files=(zshrc zprofile zprompt bashrc bash_profile bash_prompt aliases private) @@ -19,6 +26,12 @@ cd "${dotfiledir}" || exit # create symlinks (will overwrite old dotfiles) for file in "${files[@]}"; do + if [ -e "${HOME}/.${file}" ]; then + # Backup existing files to the backup directory + echo "Backing up $file to ${backupdir}" + cp "${HOME}/.${file}" "${backupdir}/" + fi + echo "Creating symlink to $file in home directory." ln -sf "${dotfiledir}/.${file}" "${HOME}/.${file}" done