-
Notifications
You must be signed in to change notification settings - Fork 9
/
install.sh
executable file
·109 lines (90 loc) · 2.83 KB
/
install.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
// NOTES. This is the cedar unit testing CURL install script. pretty cool... just call
curl -L https://raw.github.com/pivotal/cedar/master/install.sh | bash
and it does the rests!
#!/bin/sh
INSTALL_UUID=$(uuidgen)
log() {
printf "%b\n" "$*"
}
fail() {
log "\nERROR: $*\n"
log_event "Install Error" error "${*}"
exit 1
}
usage() {
log "$0 [--head]"
log ""
log "Unless otherwise specified, the latest release of Cedar will be installed"
log ""
log "Options:"
log " --head Gets the latest master revision of Cedar from github.com/pivotal/cedar"
}
switch_to_latest_tag() {
LATEST_VERSION_TAG=$(git for-each-ref refs/tags --sort=-refname --format="%(refname:short)" | grep v\\?\\d\\+\\.\\d\\+\\.\\d\\+ | head -n1)
git checkout ${LATEST_VERSION_TAG} > /dev/null 2>&1
if [[ $? != 0 ]]; then
fail "Unable to find tag for version ${LATEST_VERSION_TAG}"
fi
}
log_event() {
TOKEN=6bcfa72d98e6f7af1d647acfcd663051
EVENT=$1
PROPERTY_NAME=$2
PROPERTY_VALUE=$3
if [[ -n ${PROPERTY_NAME} ]] ; then
PAYLOAD=$(echo '{"event": "'${EVENT}'", "properties": { "distinct_id":"'${INSTALL_UUID}'", "'${PROPERTY_NAME}'":"'${PROPERTY_VALUE}'", "token": "'${TOKEN}'" } }' | base64)
else
PAYLOAD=$(echo '{"event": "'${EVENT}'", "properties": { "distinct_id":"'${INSTALL_UUID}'", "token": "'${TOKEN}'" } }' | base64)
fi
curl 'https://api.mixpanel.com/track/?data='${PAYLOAD} > /dev/null 2>&1
}
while (($# > 0))
do
TOKEN="$1"
shift
case "$TOKEN" in
--head|--HEAD|head|HEAD)
GET_HEAD=1
;;
*)
usage
exit 1
;;
esac
done
if [[ -z "$(which git)" ]] ; then
echo "Unable to find git. Have you installed Xcode as well as command line tools?"
echo "You can install them from Xcode's Preferences, in the Downloads pane."
fail "Could not find git; installation aborted."
fi
if [[ $GET_HEAD == 1 ]] ; then
echo "Installing Cedar HEAD from master"
else
echo "Installing latest Cedar release"
fi
rm -rf ~/.cedar > /dev/null
echo "Cloning Cedar repo to ~/.cedar"
git clone https://github.com/pivotal/cedar.git ~/.cedar > /dev/null 2>&1
if [[ $? != 0 ]] ; then
fail "Unable to clone Cedar GitHub repo"
fi
cd ~/.cedar > /dev/null
if [[ $GET_HEAD == 1 ]] ; then
LATEST_VERSION_TAG=$(git rev-parse HEAD)
log_event "Install Script Run" version HEAD
else
switch_to_latest_tag
log_event "Install Script Run" version "${LATEST_VERSION_TAG}"
fi
echo "Initializing Cedar submodules"
git submodule update --init --recursive > /dev/null 2>&1
if [[ $? != 0 ]] ; then
fail "Unable to initialize Cedar Git submodules"
fi
echo "Installing Cedar snippets and templates"
./installCodeSnippetsAndTemplates > /dev/null 2>&1
if [[ $? != 0 ]] ; then
fail "Unable to install Cedar snippets and templates"
fi
echo "Cedar version ${LATEST_VERSION_TAG} installed to ~/Library"
log_event "Successful Install"