Skip to content

Commit

Permalink
feat(setup): update setup script to create backups
Browse files Browse the repository at this point in the history
backups are now created before a file is symlinked

Closes closes #2 closes #3
  • Loading branch information
terriann committed Aug 3, 2017
1 parent 38e99ad commit f5b3991
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
*.local
~backup/
*~
47 changes: 38 additions & 9 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,55 @@
#!/bin/bash

# 1. Backup current dot files
# Going to have to save path to a variable
# mkdir .dotfile/backup/YYYY/mm-dd h:i:s/
# @Todo add /backup dir to git ignore
# cp .* to the above dir



# 2. Make symlinks
# set date so we have a consistent path to move copies of backup files to
DATE=$(date +%Y-%m-%d"_"%H:%M:%S)

link() {
if [ ! -h $HOME/.$1 ]; then
ln -s "$HOME/.dotfiles/$1" "$HOME/.$1"
fi
}

backup() {
if [ ! $2 ]; then
printf " !! No date passed - Backup could not be created\n"
return
else
if [ ! -h $HOME/.$1 ]; then
mkdir -p "$HOME/.dotfiles/~backup/$2/"
mv "$HOME/.$1" "$HOME/.dotfiles/~backup/$2/.$1"
fi
fi
}

restore() {
if [ ! $2 ]; then
printf " !! No date passed - Restore could not occur\n"
return
else
if [ ! -h $HOME/.dotfiles/~backup/$2/.$1 ]; then
mv "$HOME/.dotfiles/~backup/$2/.$1" "$HOME/.$1"
fi
fi
}

# make sure local config files exist
touch ~/.dotfiles/gitconfig.local
touch ~/.dotfiles/profile.local

# backup and link the git config
backup "gitconfig" $DATE
link "gitconfig"

# backup and link profile information
backup "profile" $DATE
backup "bash_profile" $DATE
link "profile"

# reset the terminal with the latest profile settings
source ~/.profile
printf '=> Bash profile reset.\n'

# backup and restore debugging
#backup "hgignore_global" $DATE
#REVERT="2017-07-31_16:27:45"
#restore "hgignore_global" $REVERT

0 comments on commit f5b3991

Please sign in to comment.