-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.sh
executable file
·155 lines (135 loc) · 3.93 KB
/
bootstrap.sh
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
#!/bin/sh
set -o xtrace
DEVBOX_REPO="[email protected]:devinsba/devbox"
DEVBOX_REPO_HTTP="http://github.com/devinsba/devbox"
onePASSWORD_EMAIL_ADDRESS="[email protected]"
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
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() {
wait
if ! op whoami | grep 'Email:' > /dev/null; then
echo "In another terminal run: op account add --address my.1password.com --email \"${onePASSWORD_EMAIL_ADDRESS}\""
echo "-- Hit enter once this is done"
read
fi
eval $(op signin)
mkdir -p "${HOME}/.ssh"
op read --out-file "$HOME/.ssh/personal_key" "op://private/personal ssh key/private key?ssh-format=openssh" && chmod 600 "${HOME}/.ssh/personal_key"
op read --out-file "$HOME/.ssh/personal_key.pub" "op://private/personal ssh key/public key"
cat << EOF > $HOME/.ssh/config
host github.com
HostName github.com
IdentityFile ~/.ssh/personal_key
EOF
}
public_repo() {
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 [ -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"
ansible-playbook -K -i inventory site.yml
)
# 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