-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(setup): update setup script to create backups
- Loading branch information
Showing
2 changed files
with
40 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
*.local | ||
~backup/ | ||
*~ |
This file contains 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
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 |