-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbootstrap
executable file
·113 lines (100 loc) · 2.5 KB
/
bootstrap
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env zsh
GITHUB_USERNAME=${GITHUB_USERNAME:-rjernst}
DOTFILES=$HOME/.dotfiles
bootstrap_macos() {
command -v brew &> /dev/null || {
echo "---> installing homebrew"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
}
if [[ "$ARCH" == "arm64" ]]; then
# homebrew on arm it installed to /opt/homebrew
export PATH=/opt/homebrew/bin:$PATH
fi
platform_install() {
brew install $1
}
}
bootstrap_arch() {
platform_install() {
pacman -S --noconfirm --needed $1
}
}
bootstrap_unknown() {
echo "unsupported platform, cannot install dependencies"
platform_install() {
echo "Missing $1, please install it"
exit 1
}
}
identify_platform() {
if [[ "$(uname)" == "Darwin" ]]; then
echo "macos"
else
if [ -f /etc/arch-release ]; then
echo "arch"
else
echo "unknown"
fi
fi
}
install_package() {
command -v $1 &> /dev/null || {
echo "---> installing $1"
platform_install $1
}
}
install_dependencies() {
install_package git
}
ensure_ssh_key_exists() {
keyfile=$ssh_dir/$1
if [ ! -f $keyfile ]; then
echo "---> creating $keyfile"
ssh-keygen -f $keyfile -t ed25519
fi
}
check_ssh_keys() {
ssh_dir=~/.ssh
# ensure directory exists
if [ ! -d $ssh_dir ]; then
echo "---> creating $ssh_dir"
mkdir $ssh_dir
fi
# with the correct permissions
if [ "$(ls -ld $ssh_dir | cut -f 1 -d ' ')" != "drwx------" ]; then
echo "---> setting permissions on $ssh_dir"
chmod 700 $ssh_dir
fi
ensure_ssh_key_exists id_ed25519
ensure_ssh_key_exists github_ed25519
}
clone_dotfiles() {
if [ -d $DOTFILES ]; then
echo "---> $DOTFILES exists, skipping clone"
return
fi
dotfiles_url=https://github.com/rjernst/dotfiles.git
if [ "$USER"=="rjernst" ]; then
dotfiles_url=git@github.com:rjernst/dotfiles.git
echo "---> Checking authentication with github"
ssh -T git@github.com &> /dev/null
if [ $? -ne 1 ]; then
echo "---> SSH authentication failed with github. Add the following ssh key to github:\n"
cat ~/.ssh/id_ed25519.pub
echo ""
read -s -k "?Press any key when ready to continue"
fi
fi
echo "---> cloning $dotfiles_url"
git clone $dotfiles_url $DOTFILES
}
PLATFORM=$(identify_platform)
echo "---> detected platform: $PLATFORM"
ARCH=$(uname -m)
echo "---> detected architecture: $ARCH"
EXTRA_VARS="$EXTRA_VARS -e os=$PLATFORM"
eval bootstrap_$PLATFORM
install_dependencies
check_ssh_keys
clone_dotfiles
$DOTFILES/setup