From 49b42e352dae1eac7499090db68e5f18ebe75c8b Mon Sep 17 00:00:00 2001 From: Debian Live user Date: Fri, 28 Apr 2023 09:01:54 -0400 Subject: create dotfiles.sh script to handle install --- dotfiles.sh | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 dotfiles.sh diff --git a/dotfiles.sh b/dotfiles.sh new file mode 100644 index 0000000..98dbb04 --- /dev/null +++ b/dotfiles.sh @@ -0,0 +1,79 @@ +#!/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 + +) -- cgit v1.2.3