Skip to content

Instantly share code, notes, and snippets.

@zevisert
Last active May 23, 2019 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zevisert/f3e3b698ad09637b071e394671e7896a to your computer and use it in GitHub Desktop.
Save zevisert/f3e3b698ad09637b071e394671e7896a to your computer and use it in GitHub Desktop.
Initialize from my private dotfiles repository
# Call this using curl:
# curl -Lks https://bit.do/zevisert-dots | /bin/bash
# Fallback to MD5(zevisert-ssh) if no hash is specified
MD5_KEY=${1:-d2:68:da:ce:5c:d8:d1:30:19:6c:63:b8:e9:fa:38:d1}
# Check for an ssh-agent
if [ -n "$SSH_AGENT_PID" -a -e /proc/$SSH_AGENT_PID ];
then
matching_hashes=$(ssh-add -E MD5 -l | grep -c $MD5_KEY);
if [[ $matching_hashes -le 0 ]];
then
echo "[zevisert-dots]: SSH-Agent does not have key MD5: $MD5_KEY, cloning aborted.";
exit 1;
fi
else
echo "[zevisert-dots]: No SSH-Agent found, needed to secure clone dot files.";
exit 1;
fi
# Clone the repo
git clone --bare git@github.com:zevisert/dots.git $HOME/.cfg
if [ $? -ne 0 ];
then
echo "[zevisert-dots]: Aborting";
exit 1;
fi
# Temporary config 'alias'
function config {
/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME $@
}
config checkout
if [ $? = 0 ];
then
echo "[zevisert-dots]: Checked out config.";
else
mkdir -p $HOME/.dots-conflicts
echo "[zevisert-dots]: Backing up pre-existing dot files.";
config checkout 2>&1 | egrep "\s+\." | awk {'print $1'} | xargs -I{} sh -c "mkdir --parents $HOME/.dots-conflicts/{}; mv {} $HOME/.dots-conflicts/{}"
fi;
config checkout
config config status.showUntrackedFiles no
echo "[zevisert-dots]: Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment