This repository has been archived by the owner on Feb 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathqs-init.sh
executable file
·207 lines (179 loc) · 4.83 KB
/
qs-init.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
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
#!/bin/sh
##
## USAGE: ./qs-init.sh --client UNIQUE_SLUG --git-repo GIT_REMOTE [--wxr WXR_TO_IMPORT] [--theme DIRECTORY_NAME] [--up]
## Include `--up` when setting up a fresh instance of this VM.
##
usage() {
echo "
Usage: $(basename "$0") --client UNIQUE_SLUG --git-repo GIT_REMOTE [--wxr WXR_TO_IMPORT] [--theme DIRECTORY_NAME] [--up]
--client The client slug of the site we're going to work on next
--git-repo The location of the git repo we're going to work on next
--wxr The location of a WXR if we have one to import
--up Start the VM
--help Output usage information
"
}
# Kicking things off!
printf '\nPreparing to initialize the VIP Go Quickstart environment...\n\n'
# Get the local and Git versions to compare
QS_VERSION=`cat .version.txt`
if [ -f .version-current.txt ]; then
QS_VERSION_CURRENT=`cat .version-current.txt`
else
QS_VERSION_CURRENT=0
fi
if [ "$QS_VERSION" -gt "$QS_VERSION_CURRENT" ]; then
vagrant provision
fi
# Note the latest version we've updated to
echo $QS_VERSION > .version-current.txt
# Parse args and set necessary envars
printf '1) Parsing arguments...\n\n'
client=''
client_git_repo=''
client_git_branch='master'
theme=0
wxr=0
needs_to_up=0
# This while loop will go forever until we break out of it or exit,
# as the : operator aliases to `true`.
while :; do
case $1 in
--client)
if [ -n "$2" ]; then
client=$2
shift 2
continue
else
printf 'ERROR: "--client" is a required argument.\n' >&2
usage
exit 1
fi
;;
--git-repo)
if [ -n "$2" ]; then
client_git_repo=$2
shift 2
continue
else
printf 'ERROR: "--git-repo" is a required argument.\n' >&2
usage
exit 1
fi
;;
--git-branch)
if [ -n "$2" ]; then
client_git_branch=$2
shift 2
continue
else
client_git_branch="master"
shift 2
continue
fi
;;
--wxr)
if [ -n "$2" ]; then
rm data/import.xml
cp "$2" data/import.xml
printf 'CONTENT: Using specified WXR to initialize environment.\n\n'
wxr=1
shift 2
continue
fi
;;
--theme)
if [ -n "$2" ]; then
theme=$2
shift 2
continue
fi
;;
--up)
needs_to_up=1
;;
--help)
usage
exit
;;
*)
if [ "$1" ]; then
echo "\n\nERROR: Unknown parameter or bad parameter value detected: $1 $2\n"
usage
exit 1
fi
break
esac
shift
done
if [ -z "$client" ]; then
printf 'ERROR: "--client" is a required argument.\n' >&2
usage
exit 1
fi
if [ -z "$client_git_repo" ]; then
printf 'ERROR: "--git-repo" is a required argument.\n' >&2
usage
exit 1
fi
if [ "$wxr" = 0 ]; then
git checkout -- data/import.xml
printf 'CONTENT: Using default WXR to initialize environment.\n\n'
fi
export VIP_GO_CLIENT=$client
export VIP_GO_CLIENT_GIT=$client_git_repo
export VIP_GO_CLIENT_GIT_BRANCH=$client_git_branch
export VIP_GO_THEME=$theme
printf "CLIENT: %s\nGIT REMOTE: %s\nGIT BRANCH: %s\nTHEME: %s\nVAGRANT UP REQUESTED: %d\n\n" "$client" "$client_git_repo" "$client_git_branch" "$theme" "$needs_to_up"
# Require confirmation before destructive actions that follow
read -p "Continue (y/n)? " CONT
if [ "$CONT" != "y" ]; then
printf 'Aborting at your request.\n';
exit 0;
fi
# Load client's custom code into VM's NFS shares
# Can't simply delete `go-client-repo` and replace it, as removing the synced folders sends Vagrant into a tizzy
printf '2) Loading new client code...\n\n'
rm -rf go-client-repo-new/
rm -rf go-client-repo/.git/
rm -rf go-client-repo/languages/*
rm -rf go-client-repo/plugins/*
rm -rf go-client-repo/themes/*
git clone "$client_git_repo" go-client-repo-new
EXIT_CODE=$?
if [ 0 != $EXIT_CODE ]; then
echo "\n\nERROR: Cloning git repository at $client_git_repo failed with the error code $EXIT_CODE."
exit 210
fi
cd go-client-repo-new
git checkout $client_git_branch
cd ..
EXIT_CODE=$?
if [ 0 != $EXIT_CODE ]; then
echo "\n\nERROR: Checkout out branch $client_git_branch failed with the error code $EXIT_CODE."
exit 220
fi
cp -r go-client-repo-new/. go-client-repo
rm -rf go-client-repo-new/
# Ensure theme directory exists, otherwise exit with an error
if [ "$theme" != 0 ] && [ ! -d "./go-client-repo/themes/$theme" ]; then
printf '\n\nERROR: Theme directory "%s" not found. Please check your entry, or omit the "--theme" argument, and try again.\n' "$theme" >&2
usage
exit 1
fi
# Ensure optional languages directory exists
# Vagrant doesn't respond well if the directory exists sometimes but not always
if [ ! -d "./go-client-repo/languages/" ]; then
mkdir ./go-client-repo/languages/
fi
# Provision the VM
if [ $needs_to_up = 1 ]; then
printf '\n3) Starting to provision VM. vagrant up can take some time...\n\n'
vagrant up
else
printf '\n3) Starting to re-provision VM...\n\n'
vagrant provision
fi
# Done!
printf '\n4) DONE!\nYour VIP Go Quickstart is ready at http://go-vip.local/\n'
printf 'Synchronized git checkout is at ./go-client-repo/\n'