-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·248 lines (207 loc) · 8.99 KB
/
setup.sh
File metadata and controls
executable file
·248 lines (207 loc) · 8.99 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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#!/bin/bash
set -e
RED="\033[1;31m"
GREEN="\033[1;32m"
YELLOW="\033[1;33m"
NOCOLOR="\033[0m"
# avoids an edgecase where employees do not have 1password accounts set up
BC_RAW_1PASS_ID="CMUGFRT7Y5BRJMYKQIXJDO2654"
function abort {
echo -e "\n${RED}Exiting early, please re-run after correcting errors!${NOCOLOR}"
exit 1
}
function activate_brew {
if ! command -v brew &> /dev/null; then
echo -e "${GREEN}Activating Homebrew...${NOCOLOR}"
eval "$(/opt/homebrew/bin/brew shellenv)"
if [ ! -e ~/.profile ]; then
touch ~/.zprofile
fi
if ! grep -q "eval \"\$(/opt/homebrew/bin/brew shellenv)\"" ~/.zprofile; then
echo "eval \"\$(/opt/homebrew/bin/brew shellenv)\"" >> ~/.zprofile
fi
fi
}
if [ ! -e "/opt/homebrew/bin/brew" ]; then
echo -e "${RED}Homebrew not found. Installing...${NOCOLOR}"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
else
echo -e "${GREEN}Homebrew found. Updating/Upgrading...${NOCOLOR}"
activate_brew
brew update && brew upgrade && brew upgrade --cask && brew cleanup
fi
echo -e "\n${GREEN}### Installing packages ###${NOCOLOR}\n"
activate_brew
function brew_install {
if [ ! -e "$2" ]; then
echo -e "\nInstalling ${GREEN}$1${NOCOLOR}..."
brew install $1
else
echo -e "Skipping ${YELLOW}$1${NOCOLOR} - already installed"
fi
}
if brew list libyaml &>/dev/null; then
echo -e "Skipping ${YELLOW}libyaml${NOCOLOR} - already installed"
else
echo -e "\nInstalling ${GREEN}libyaml${NOCOLOR}..."
brew install --quiet libyaml
fi
brew_install "1password-cli" "/opt/homebrew/bin/op"
brew_install "gh" "/opt/homebrew/bin/gh"
brew_install "mas" "/opt/homebrew/bin/mas"
brew_install "mise" "/opt/homebrew/bin/mise"
brew_install "orbstack" "/Applications/OrbStack.app"
brew_install "stripe/stripe-cli/stripe" "/opt/homebrew/bin/stripe"
if [ ! -e "/Applications/Tailscale.app" ]; then
echo -e "Installing ${GREEN}Tailscale${NOCOLOR}..."
mas get 1475387142 || echo -e "${RED}Tailscale not installed - you'll need to do this from the Mac App Store manually${NOCOLOR}"
fi
echo -e "\n${GREEN}### Setting up SSH ###${NOCOLOR}\n"
if [ ! -d "~/.ssh" ]; then
mkdir -p ~/.ssh
fi
if [ ! -e "/Users/$USER/Library/Group Containers/2BUA8C4S2C.com.1password/t/agent.sock" ]; then
echo -e "${RED}1Password SSH Agent not found. Make sure you have 1Password installed, configured, and have turned on SSH Agent in it's developer settings area${NOCOLOR}"
echo "See https://www.notion.so/bigcartel/Development-Machine-Setup-40e4c8bdfdac449b817e9b025f7bef09?pvs=4#197152faaa024522ba22221d49bed6a4"
abort
else
if ! awk -v RS='' '/Host \*\n IdentityAgent/ { found=1; exit } END { if(found) exit 0; else exit 1 }' ~/.ssh/config; then
cat <<EOF >> ~/.ssh/config
Host *
IdentityAgent "/Users/$USER/Library/Group Containers/2BUA8C4S2C.com.1password/t/agent.sock"
EOF
fi
fi
# pre-populate known_hosts file with correct GitHub keys
if [ -e ~/.ssh/known_hosts ]; then
sed -i '' '/^github.com/d' ~/.ssh/known_hosts
fi
mkdir -p ~/.ssh
cat <<EOF >> ~/.ssh/known_hosts
github.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl
github.com ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEmKSENjQEezOmxkZMy7opKgwFB9nkt5YRrYMjNuG5N87uRgg6CLrbo5wAdT/y6v0mKV0U2w0WZ2YB/++Tpockg=
github.com ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCj7ndNxQowgcQnjshcLrqPEiiphnt+VTTvDP6mHBL9j1aNUkY4Ue1gvwnGLVlOhGeYrnZaMgRK6+PKCUXaDbC7qtbW8gIkhL7aGCsOr/C56SJMy/BCZfxd1nWzAOxSDPgVsmerOBYfNqltV9/hWCqBywINIR+5dIg6JTJ72pcEpEjcYgXkE2YEFXV1JHnsKgbLWNlhScqb2UmyRkQyytRLtL+38TGxkxCflmO+5Z8CSSNY7GidjMIZ7Q4zMjA2n1nGrlTDkzwDCsw+wqFPGQA179cnfGWOWRVruj16z6XyvxvjJwbz0wQZ75XK5tKSb7FNyeIEs4TT4jk+S4dhPeAUC5y+bDYirYgM4GC7uEnztnZyaVWQ7B381AK4Qdrwt51ZqExKbQpTUNn+EjqoTwvqNj4kqx5QUCI0ThS/YkOxJCXmPUWZbhjpCg56i+2aB6CmK2JGhn57K5mj0MNdBXA4/WnwH6XoPWJzK5Nyu2zB3nAZp+S5hpQs+p1vN1/wsjk=
EOF
echo -ne "${YELLOW}Testing GitHub ssh access...${NOCOLOR} "
ssh -q git@github.com > /dev/null 2>&1 || last_exit=$?
if [ $last_exit -eq 1 ]; then
echo -e "${GREEN}Success${NOCOLOR}"
else
echo -e "${RED}Failed${NOCOLOR}"
echo "Make sure have configured your ssh key in 1password, added it to your GitHub Account, and enabled the 1password SSH Agent"
echo "See https://www.notion.so/bigcartel/Development-Machine-Setup-40e4c8bdfdac449b817e9b025f7bef09?pvs=4#197152faaa024522ba22221d49bed6a4"
abort
fi
echo -ne "${YELLOW}Testing 1Password CLI...${NOCOLOR} "
if op account get --account $BC_RAW_1PASS_ID > /dev/null 2>&1; then
echo -e "${GREEN}Success${NOCOLOR}"
else
echo -e "${RED}Failed${NOCOLOR}"
echo "Make sure you have 1Password installed, configured, and have turned on CLI access in developer settings"
abort
fi
# avoids an edgecase where employees do not have 1password accounts set up
echo -ne "${YELLOW}Testing Access to developer vaults...${NOCOLOR} "
if op --account $BC_RAW_1PASS_ID item get "Rails Secrets [admin]" > /dev/null 2>&1; then
echo -e "${GREEN}Success${NOCOLOR}"
else
echo -e "${RED}Failed${NOCOLOR}"
echo "Make sure you have been granted access to the Development vault by a 1Password Admin"
abort
fi
echo -e "\n${GREEN}### Establishing preferences ###${NOCOLOR}\n"
function ask_w_default {
eval def=\$\{$2:="$3"\}
echo -ne "${GREEN}$1${NOCOLOR} "
if [ ! -z $def ]; then
echo -ne "[$def] "
fi
read response
if [ -z "$response" ]; then
response=$def
fi
eval $2="$response"
echo "export $2=\"$response\"" >> ~/.bc_profile
}
function get_prefs {
ask_w_default "Where would you like BC code to live?" BC_HOME "~/code/bc"
}
if [ -e ~/.bc_profile ]; then
eval $(cat ~/.bc_profile)
fi
get_prefs
if [ ! -e "$HOME/.gitconfig.local" ]; then
echo -n "\n${GREEN}Setting up your git config...${NOCOLOR}"
read -p "Enter your full name: " name
git config -f ~/.gitconfig.local --add user.name "$name"
read -p "Enter your email: " email
git config -f ~/.gitconfig.local --add user.email "$email"
fi
echo -e "\n${GREEN}### Installing dev environment ###${NOCOLOR}\n"
if [ ! -e "$BC_HOME" ]; then
mkdir -p "$BC_HOME"
fi
pushd "$BC_HOME" > /dev/null
echo -e "${GREEN}Installing cartel...${NOCOLOR}"
if [ ! -e "$BC_HOME/cartel" ]; then
git clone git@github.com:bigcartel/cartel.git
else
echo -e "${YELLOW}cartel already exists, updating...${NOCOLOR}"
pushd cartel > /dev/null
git pull
popd > /dev/null
fi
add_to_dotfiles() {
local config_file="$1"
config_file=$(echo "$config_file" | sed "s|^~|$HOME|")
if ! grep -q "# Added by bigcartel dev script" "$config_file" 2>/dev/null; then
mkdir -p "$(dirname "$config_file")"
touch "$config_file"
echo "" >> "$config_file"
echo "# Added by bigcartel dev script" >> "$config_file"
echo "export PATH=\"$BC_HOME/cartel:\$PATH\"" >> "$config_file"
echo "export BIG_CARTEL_DOCKER_COMPOSE_DIR=\"$BC_HOME/compose-dev\"" >> "$config_file"
echo -e "${GREEN}Added cartel alias to $config_file${NOCOLOR}"
return 0
else
echo -e "${YELLOW}cartel alias already exists in $config_file${NOCOLOR}"
return 1
fi
}
echo -e "\n${GREEN}Adding cartel to PATH...${NOCOLOR}"
echo -e "Which shell configuration file would you like to add to?"
DEFAULT_CONFIG="~/.zshrc"
if [[ "$SHELL" == *"bash"* ]]; then
if [ -f ~/.bash_profile ]; then
DEFAULT_CONFIG="~/.bash_profile"
else
DEFAULT_CONFIG="~/.bashrc"
fi
fi
echo -ne "${GREEN}Shell config file${NOCOLOR} [$DEFAULT_CONFIG]: "
read SHELL_CONFIG_FILE
if [ -z "$SHELL_CONFIG_FILE" ]; then
SHELL_CONFIG_FILE="$DEFAULT_CONFIG"
fi
if add_to_dotfiles "$SHELL_CONFIG_FILE"; then
echo -e "${GREEN}The cartel command will be available in new shell sessions${NOCOLOR}"
echo -e "${YELLOW}Note: You may need to restart your shell or run 'source $SHELL_CONFIG_FILE' to use the cartel command${NOCOLOR}"
fi
echo -e "${GREEN}cartel installed and available via 'cartel' command${NOCOLOR}"
echo -e "\n${GREEN}We'll now launch Orbstack. When prompted select docker and complete any signin/configuration steps"
echo -e "Return here when Orbstack is running to continue setup${NOCOLOR}\n"
echo -ne "${YELLOW}Press enter to launch Orbstack...${NOCOLOR}"
read
open -a OrbStack
echo -ne "${YELLOW}Press enter when you've completed the Orbstack setup...${NOCOLOR}"
read
echo -e "${GREEN}All base software installed and configured${NOCOLOR}"
if [ -e "$BC_HOME/compose-dev" ]; then
echo -e "${YELLOW}compose-dev repo present. Not attempting redundant setup${NOCOLOR}"
else
echo -e "${GREEN}Setting up compose dev...${NOCOLOR}"
git clone git@github.com:bigcartel/compose-dev.git
echo -e "${YELLOW}The final step is to cd to $BC_HOME/compose-dev and run ./setup.sh${NOCOLOR}"
echo -e "${YELLOW}compose-dev is the base checkout of our docker-compose based dev environment${NOCOLOR}"
echo -e "${YELLOW}The setup script will build container images and bootstap the actual dev environment${NOCOLOR}"
fi