#!/bin/bash -eu
#curl https://raw.githubusercontent.com/thomasdstewart/dotfiles/master/iau | bash
if [ ! -d .dotfiles ]; then
        git clone https://github.com/thomasdstewart/dotfiles.git ~/.dotfiles
fi
cd ~/.dotfiles && git pull
#version 1.7.1 does not have -C
#git -C ~/.dotfiles pull

find ~/.dotfiles/ ! -path '*/.dotfiles/.git' -name '.*' -type f \
                | while read f; do
        hf="$HOME/$(basename $f)"
        if [ -f "$hf" -a ! -L "$hf" ]; then
                mv -v "$hf" "$hf.old"
        fi
        if [ ! -f "$hf" -o ! -L "$hf" ]; then
                ln -svft ~ $f
        fi
done