Skip to content

Instantly share code, notes, and snippets.

@bmoore01
Created May 7, 2016 18:49
Show Gist options
  • Save bmoore01/d68ff7daae6a3a2fd46941290e357fa6 to your computer and use it in GitHub Desktop.
Save bmoore01/d68ff7daae6a3a2fd46941290e357fa6 to your computer and use it in GitHub Desktop.
A script that backs up my dotfiles to github
#!/bin/bash
# variables
gitdir=~/git-dotfiles
dir=~/dotfiles
files="xres cmus config fehbg themes bashrc xinitrc XResources"
NOW=$(date +"%H:%M-%D")
# if directories do not exist create them
mkdir -p $dir
mkdir -p $gitdir
# making sure in home directory
cd ~
for file in $files; do
echo "Moving .$file to $dir"
if [ ! -d $dir/.$file ]; then
mv ~/.$file $dir
fi
echo "Creating a symlink to $file in your home directory"
if [ ! -d ~/.$file ]; then
ln -s $dir/.$file ~/.$file
fi
done
# copy files to your git repo directory
for file in $files; do
echo "Copying .$file to $gitdir"
cp -R $dir/.$file $gitdir
done
cd $gitdir
# if there's a password in one of your dotfiles, uncomment this line and put your password in
# it will be changed to ******** probably a good idea if you're backing up to git
# find ./ -type f -exec sed -i 's/password_here/********/g' {} \;
# backup to git
git add --all
git commit -m "Routine backup at $NOW"
git push -u origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment