forked from wballard/starphleet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
virtualbox
executable file
·184 lines (136 loc) · 5.08 KB
/
virtualbox
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
#!/usr/bin/env bash
#######################################################################
## Author: Benjamin Hudgens
## Date: March 28, 2015
##
## Description: Setup the necessary environment to install
## starphleet via vagrant
#######################################################################
# *********************
# Config
# *********************
ENVIRONMENT_FILE="${HOME}/.starphleet"
STARPHLEET_DEV_DIR="${HOME}/starphleet_dev"
STARPHLEET_PRIVATE_KEY_FILE="${HOME}/.ssh/starphleet"
# *********************
# Fix Promiscuious mode crash
#
# Bug Fix
# See: https://github.com/coreos/coreos-vagrant/issues/123
# *********************
sudo touch '/Library/Preferences/VMware Fusion/promiscAuthorized'
# *********************
# Helpers
# *********************
function test_git() {
SUCCESS=$(ssh -i ${1} [email protected] 2>&1 | grep "successfully authenticated")
}
function get_starphleet_branch() {
read -p "Which branch for your Headquarters: " STARPHLEET_HEADQUARTERS_BRANCH
}
function headquarters_branch_help() {
cat <<EOF
In development mode it is strongly recommended that you create a branch for
yourself in the development headquarters git repo.
The concensus is that it is rude to make changes to the main branch unless
they are global and are intended for everyone to consume.
Current Headquarters: ${STARPHLEET_HEADQUARTERS}
EOF
}
function starphleet_dev_help() {
cat <<EOF
The starphleet dev directory already exists on your machine. This implies
you may have previous work still in this directory:
${STARPHLEET_DEV_DIR}
If you are doing a clean install of a new headquarters you may want to remove
this directory and start fresh.
EOF
}
function stale_vagrant_help() {
cat <<EOF
---------------------
!!WARNING!!
It is possible you did not cleanly destroy a previous vagrant installation.
This may have left stale data in your local machines "/etc/hosts" file.
You may be unable to reach your ship after a successful deployment.
You most likely want to remove this stale data before installing. You can
cleanup this data by editing the following file:
/etc/hosts
You should remove any lines that are similar to this:
## vagrant-hostmanager-start id: f2ae1ca9-1ddf-419e-a3e8-37fd4f23143a
172.16.114.129 ship ship ship.local ship.glgresearch.com
## vagrant-hostmanager-end
EOF
}
function key_help() {
cat <<EOF
You must put a non-password protected key file here:
${STARPHLEET_PRIVATE_KEY_FILE}
To generate a new key you can try (do not enter a password - hit <enter>):
ssh-keygen -b 1024 -t rsa -f ${HOME}/.ssh/starphleet
Make sure your key is setup with GitHub. Read here:
https://help.github.com/articles/generating-ssh-keys/
EOF
}
# *********************
# Environment Setup
# *********************
# Check if the user has an environment file
[ -f "${ENVIRONMENT_FILE}" ] && source "${ENVIRONMENT_FILE}"
# If the user doesn't cleanly shutdown vagrant it can leave
# stale host records in /etc/hosts
# Let's warn them and possibly punt
if [ "$(cat /etc/hosts | grep 'vagrant-hostmanager')" != "" ]; then
stale_vagrant_help
unset ANSWER
read -p "Do you want to exit and fix this? [y/N]: " ANSWER
if [ "${ANSWER}" == "y" ] || [ "${ANSWER}" == "Y" ]; then
exit 1
fi
fi
# Make sure a headquarters is set
if [ -z "${STARPHLEET_HEADQUARTERS}" ]; then
read -p "Please paste a starphleet headquarters: " STARPHLEET_HEADQUARTERS
export STARPHLEET_HEADQUARTERS="${STARPHLEET_HEADQUARTERS}"
fi
# Require users to specify a branch explicitly so they remember not to trample
# on everyone else. If their headquarters doesn't contain a branch .. prompt
if [ -z "$(echo ${STARPHLEET_HEADQUARTERS} | grep '#')" ]; then
headquarters_branch_help
get_starphleet_branch
# They should now have a branch set - so if the variable isn't empty
# that's good and we set the branch on their headquarters. Otherwise,
# at this point we should not proceed
if [ -n "${STARPHLEET_HEADQUARTERS_BRANCH}" ]; then
export STARPHLEET_HEADQUARTERS="${STARPHLEET_HEADQUARTERS}#${STARPHLEET_HEADQUARTERS_BRANCH}"
else
exit 1
fi
fi
# Graceful fallback if the user didn't setup the keys in their environment
if [ -z "${STARPHLEET_PRIVATE_KEY}" ]; then
# Test to make sure their key connects to github without issue
[ -f "${STARPHLEET_PRIVATE_KEY_FILE}" ] && \
test_git "${STARPHLEET_PRIVATE_KEY_FILE}"
# If success - export the starphleet key
if [ ! -z "${SUCCESS}" ]; then
export STARPHLEET_PRIVATE_KEY="${STARPHLEET_PRIVATE_KEY_FILE}"
else
# Starphleet key didn't work out - be a pal and try their default key
test_git "${HOME}/.ssh/id_rsa"
if [ ! -z "${SUCCESS}" ]; then
export STARPHLEET_PRIVATE_KEY="${HOME}/.ssh/id_rsa"
else
# Sheesh - nothing is working
key_help
exit 1
fi
fi
fi
# *********************
# Main
# *********************
echo Starphleet HQ: ${STARPHLEET_HEADQUARTERS}
echo SSH Private Key: ${STARPHLEET_PRIVATE_KEY}
echo "Go get some coffee. This will take a while..."
vagrant up --provider virtualbox