This repository has been archived by the owner on Nov 10, 2024. It is now read-only.
forked from cedarbdd/cedar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·102 lines (88 loc) · 2.86 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
#!/bin/bash
INSTALL_UUID=$(uuidgen)
log() {
printf "%b\n" "$*"
}
fail() {
log "\nERROR: $*\n"
log_event "Install Error" error "${*}"
exit 1
}
usage() {
log "$0 [--head] [--version]"
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."
log " --version version_tag Gets the specified version from the version tag."
}
switch_to_tag() {
# Defaults to latest version if not given
VERSION_TAG="$1"
[ "$VERSION_TAG" ] || VERSION_TAG=$(git for-each-ref refs/tags --sort=-refname --format="%(refname:short)" | grep v\\?\\d\\+\\.\\d\\+\\.\\d\\+ | ruby -e 'puts STDIN.read.split("\n").sort { |a,b| a.gsub("v", "").split(".").map(&:to_i) <=> b.gsub("v", "").split(".").map(&:to_i) }.last')
git checkout "$VERSION_TAG" &>/dev/null || fail "Unable to find tag for version $VERSION_TAG"
}
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"
case "$TOKEN" in
--head|--HEAD|head|HEAD)
GET_HEAD=1
shift
;;
-version|--version)
VERSION_TAG="v${2#v}"
shift 2
;;
*)
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"
elif [ "$VERSION_TAG" ] ; then
echo "Installing Cedar version ${VERSION_TAG}"
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
VERSION_TAG=$(git rev-parse HEAD)
log_event "Install Script Run" version HEAD
else
switch_to_tag "$VERSION_TAG"
log_event "Install Script Run" version "$VERSION_TAG"
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 $VERSION_TAG installed to ~/Library"
log_event "Successful Install"