-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.sh
More file actions
executable file
·196 lines (169 loc) · 5.18 KB
/
Copy pathbootstrap.sh
File metadata and controls
executable file
·196 lines (169 loc) · 5.18 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/bin/sh
set -o xtrace
DEVBOX_REPO="${DEVBOX_REPO:-git@github.com:devinsba/devbox}"
DEVBOX_REPO_HTTP="${DEVBOX_REPO_HTTP:-http://github.com/devinsba/devbox}"
# When set, skips the steps that need real secrets/network access a
# container can't have (1Password ssh-key pull, cloning from GitHub) and
# assumes ${HOME}/.local/opt/devbox[-private] are already populated, and
# that sudo doesn't need a password. See test-bootstrap.sh.
DEVBOX_LOCAL_TEST="${DEVBOX_LOCAL_TEST:-}"
get_linux_distro() {
if [ -f /etc/os-release ]; then
# freedesktop.org and systemd
. /etc/os-release
echo $NAME
elif type lsb_release >/dev/null 2>&1; then
# linuxbase.org
lsb_release -si
elif [ -f /etc/lsb-release ]; then
# For some versions of Debian/Ubuntu without lsb_release command
. /etc/lsb-release
echo $DISTRIB_ID
elif [ -f /etc/debian_version ]; then
# Older Debian/Ubuntu/etc.
echo "Debian"
else
# Fall back to uname, e.g. "Linux", also works for BSD, etc.
uname -s
fi
}
macos() {
if ! xcode-select -p > /dev/null 2>&1; then
xcode-select --install
fi
while ! xcode-select -p > /dev/null 2>&1
do
sleep 10
done
if ! xcode-select -p > /dev/null 2>&1; then
echo "xcode command line tools not installed"
exit 1
fi
sudo -v
if ! brew commands > /dev/null 2>&1; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
if [ "$(uname -m)" != "x86_64" ] ; then
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
brew install git ansible lastpass-cli
}
debian() {
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install -y git ansible gnupg
curl -sS https://downloads.1password.com/linux/keys/1password.asc | \
sudo gpg --dearmor --output /usr/share/keyrings/1password-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/1password-archive-keyring.gpg] https://downloads.1password.com/linux/debian/$(dpkg --print-architecture) stable main" | \
sudo tee /etc/apt/sources.list.d/1password.list
sudo mkdir -p /etc/debsig/policies/AC2D62742012EA22/
curl -sS https://downloads.1password.com/linux/debian/debsig/1password.pol | \
sudo tee /etc/debsig/policies/AC2D62742012EA22/1password.pol
sudo mkdir -p /usr/share/debsig/keyrings/AC2D62742012EA22
curl -sS https://downloads.1password.com/linux/keys/1password.asc | \
sudo gpg --dearmor --output /usr/share/debsig/keyrings/AC2D62742012EA22/debsig.gpg
sudo apt update && sudo apt install 1password-cli
}
freebsd() {
sudo pkg install git
}
ssh_key() {
if [ -n "${DEVBOX_LOCAL_TEST}" ]; then
echo "DEVBOX_LOCAL_TEST set, skipping ssh_key"
return
fi
case $(uname) in
Darwin)
AGENT_SOCK="${HOME}/Library/Group Containers/2BUA8C4S2C.com.1password/t/agent.sock"
;;
*)
AGENT_SOCK="${HOME}/.1password/agent.sock"
;;
esac
if [ -S "${AGENT_SOCK}" ]; then
echo "1Password SSH agent socket already found at ${AGENT_SOCK}, skipping setup."
else
echo "In 1Password, enable Settings > Developer > 'Use the SSH Agent', then toggle 'Use for SSH' on your personal ssh key item."
echo "-- Hit enter once this is done"
read _ < /dev/tty
if [ ! -S "${AGENT_SOCK}" ] && [ "$(uname)" = "Darwin" ]; then
FOUND_CONTAINER=$(find "${HOME}/Library/Group Containers" -maxdepth 1 -iname '*1password*' 2>/dev/null | head -n1)
if [ -n "${FOUND_CONTAINER}" ] && [ -S "${FOUND_CONTAINER}/t/agent.sock" ]; then
AGENT_SOCK="${FOUND_CONTAINER}/t/agent.sock"
fi
fi
if [ ! -S "${AGENT_SOCK}" ]; then
echo "Warning: no socket found at ${AGENT_SOCK} -- ssh will not authenticate until the 1Password SSH Agent is actually running there."
fi
fi
mkdir -p "${HOME}/.ssh"
cat << EOF > "$HOME/.ssh/config"
host *
IdentityAgent "${AGENT_SOCK}"
EOF
}
public_repo() {
if [ -n "${DEVBOX_LOCAL_TEST}" ]; then
echo "DEVBOX_LOCAL_TEST set, skipping public_repo sync"
return
fi
mkdir -p "${HOME}/.local/opt"
if [ -d "${HOME}/.local/opt/devbox" ]; then
(
cd "${HOME}/.local/opt/devbox"
git pull
)
else
git clone "${DEVBOX_REPO}" "${HOME}/.local/opt/devbox"
fi
}
private_repo() {
if [ -n "${DEVBOX_LOCAL_TEST}" ]; then
echo "DEVBOX_LOCAL_TEST set, skipping private_repo sync"
return
fi
if [ -d "${HOME}/.local/opt/devbox-private" ]; then
(
cd "${HOME}/.local/opt/devbox-private"
git pull
)
else
git clone "${DEVBOX_REPO}-private" "${HOME}/.local/opt/devbox-private"
fi
}
case $(uname) in
Darwin)
macos
ssh_key
public_repo
private_repo
;;
Linux)
case $(get_linux_distro) in
Debian | "Debian GNU/Linux" | Ubuntu | "Pop!_OS" | "KDE neon")
debian
;;
esac
ssh_key
public_repo
private_repo
;;
FreeBSD)
freebsd
DEVBOX_REPO=$DEVBOX_REPO_HTTP
public_repo
;;
esac
(
cd "${HOME}/.local/opt/devbox/ansible"
if [ -n "${DEVBOX_LOCAL_TEST}" ]; then
ansible-playbook -i inventory site.yml
else
ansible-playbook -K -i inventory site.yml
fi
)
# rcm
echo "DOTFILES_DIRS=\"${HOME}/.local/opt/devbox/dotfiles ${HOME}/.local/opt/devbox-private/dotfiles\"" > "${HOME}/.rcrc"
echo "TAGS=\"$(uname)\"" >> "${HOME}/.rcrc"
rcup -vf
set +o xtrace