summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDebian Live user <user@debian-BULLSEYE-live-builder-AMD64>2023-04-28 09:01:54 -0400
committerDebian Live user <user@debian-BULLSEYE-live-builder-AMD64>2023-04-28 09:01:54 -0400
commit49b42e352dae1eac7499090db68e5f18ebe75c8b (patch)
tree159b4708dcbf05eb6d645bdf26a95f96105de98f
parent6500a9f6f387fb8f0046ffe1566c75796f61d6d5 (diff)
create dotfiles.sh script to handle install
-rw-r--r--dotfiles.sh79
1 files changed, 79 insertions, 0 deletions
diff --git a/dotfiles.sh b/dotfiles.sh
new file mode 100644
index 0000000..98dbb04
--- /dev/null
+++ b/dotfiles.sh
@@ -0,0 +1,79 @@
1#!/bin/bash
2
3# This file is intended to be run as:
4#
5# bash <(curl https://cryptonomic.net/dotfiles.sh)
6#
7# It clones and then installs my dotfiles via
8# git clone d@cryptonomic.net:public_git/dotfiles.git
9
10(
11set -e
12as_root()
13{
14 if [ "$(id -u)" = 0 ]
15 then
16 "$@"
17 else
18 sudo "$@"
19 fi
20}
21
22check_dep()
23{
24 if ! [ "$(command -v "$1")" ]
25 then
26 DEPS="$DEPS $2"
27 fi
28}
29DEPS=
30
31# make git retry on ssh errors (presumed to be network errors).
32git_retry()
33{
34 OUR_TEMPDIR=$(mktemp -d) || exit
35 GIT_SSH_COMMAND=$OUR_TEMPDIR/git_ssh_command
36 GIT_SSH_COMMAND_RESULT=$OUR_TEMPDIR/result
37 printf '%s\n' \
38 '#!/bin/sh' \
39 'ssh "$@"; r=$?; echo $r > $GIT_SSH_COMMAND_RESULT; exit $r' \
40 > "$GIT_SSH_COMMAND"
41 chmod +x $GIT_SSH_COMMAND
42 export GIT_SSH_COMMAND GIT_SSH_COMMAND_RESULT
43 SLEEP=1
44 while ! git "$@"
45 do
46 read result < "$GIT_SSH_COMMAND_RESULT"
47 [ "$result" = 255 ] || break
48 sleep $SLEEP
49 SLEEP=$((SLEEP + 1))
50 done
51}
52
53check_dep ssh-keygen ssh-client
54check_dep git git
55
56if [ "$DEPS" ]
57then
58 as_root apt install $DEPS
59fi
60
61[ -d ~/.ssh ] || mkdir ~/.ssh
62[ -e ~/.ssh/id_ed25519.pub ] || ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -N ''
63
64if ! [ -d dotfiles ]
65then
66 git_retry clone --recurse-submodules d@cryptonomic.net:public_git/dotfiles.git
67 cd dotfiles
68else
69 cd dotfiles
70 git pull --ff-only
71fi
72
73make diff
74read -p 'Install dotfiles (will overwrite your existing dotfiles)? [y/N]> '
75case "$REPLY" in
76 [yY]) make install ;;
77esac
78
79)