blob: 98dbb04d37854c70f1d126d59f029bcb535bcb9c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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
)
|