#!/bin/bash # This file is intended to be run as: # # bash <(curl https://cryptonomic.net/dotfiles.sh) # # It clones and then installs my dotfiles via # git clone d@cryptonomic.net:public_git/dotfiles.git ( set -e as_root() { if [ "$(id -u)" = 0 ] then "$@" else sudo "$@" fi } check_dep() { if ! [ "$(command -v "$1")" ] then DEPS="$DEPS $2" fi } DEPS= # make git retry on ssh errors (presumed to be network errors). git_retry() { OUR_TEMPDIR=$(mktemp -d) || exit GIT_SSH_COMMAND=$OUR_TEMPDIR/git_ssh_command GIT_SSH_COMMAND_RESULT=$OUR_TEMPDIR/result printf '%s\n' \ '#!/bin/sh' \ 'ssh "$@"; r=$?; echo $r > $GIT_SSH_COMMAND_RESULT; exit $r' \ > "$GIT_SSH_COMMAND" chmod +x $GIT_SSH_COMMAND export GIT_SSH_COMMAND GIT_SSH_COMMAND_RESULT SLEEP=1 while ! git "$@" do read result < "$GIT_SSH_COMMAND_RESULT" [ "$result" = 255 ] || break sleep $SLEEP SLEEP=$((SLEEP + 1)) done } check_dep ssh-keygen ssh-client check_dep git git if [ "$DEPS" ] then as_root apt install $DEPS fi [ -d ~/.ssh ] || mkdir ~/.ssh [ -e ~/.ssh/id_ed25519.pub ] || ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -N '' if ! [ -d dotfiles ] then git_retry clone --recurse-submodules d@cryptonomic.net:public_git/dotfiles.git cd dotfiles else cd dotfiles git pull --ff-only fi make diff read -p 'Install dotfiles (will overwrite your existing dotfiles)? [y/N]> ' case "$REPLY" in [yY]) make install ;; esac )