diff options
author | Debian Live user <user@debian-BULLSEYE-live-builder-AMD64> | 2023-04-28 09:01:54 -0400 |
---|---|---|
committer | Debian Live user <user@debian-BULLSEYE-live-builder-AMD64> | 2023-04-28 09:01:54 -0400 |
commit | 49b42e352dae1eac7499090db68e5f18ebe75c8b (patch) | |
tree | 159b4708dcbf05eb6d645bdf26a95f96105de98f | |
parent | 6500a9f6f387fb8f0046ffe1566c75796f61d6d5 (diff) |
create dotfiles.sh script to handle install
-rw-r--r-- | dotfiles.sh | 79 |
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 | ( | ||
11 | set -e | ||
12 | as_root() | ||
13 | { | ||
14 | if [ "$(id -u)" = 0 ] | ||
15 | then | ||
16 | "$@" | ||
17 | else | ||
18 | sudo "$@" | ||
19 | fi | ||
20 | } | ||
21 | |||
22 | check_dep() | ||
23 | { | ||
24 | if ! [ "$(command -v "$1")" ] | ||
25 | then | ||
26 | DEPS="$DEPS $2" | ||
27 | fi | ||
28 | } | ||
29 | DEPS= | ||
30 | |||
31 | # make git retry on ssh errors (presumed to be network errors). | ||
32 | git_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 | |||
53 | check_dep ssh-keygen ssh-client | ||
54 | check_dep git git | ||
55 | |||
56 | if [ "$DEPS" ] | ||
57 | then | ||
58 | as_root apt install $DEPS | ||
59 | fi | ||
60 | |||
61 | [ -d ~/.ssh ] || mkdir ~/.ssh | ||
62 | [ -e ~/.ssh/id_ed25519.pub ] || ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -N '' | ||
63 | |||
64 | if ! [ -d dotfiles ] | ||
65 | then | ||
66 | git_retry clone --recurse-submodules d@cryptonomic.net:public_git/dotfiles.git | ||
67 | cd dotfiles | ||
68 | else | ||
69 | cd dotfiles | ||
70 | git pull --ff-only | ||
71 | fi | ||
72 | |||
73 | make diff | ||
74 | read -p 'Install dotfiles (will overwrite your existing dotfiles)? [y/N]> ' | ||
75 | case "$REPLY" in | ||
76 | [yY]) make install ;; | ||
77 | esac | ||
78 | |||
79 | ) | ||