forked from zynga/jasy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-jasy.sh
executable file
·199 lines (172 loc) · 5.94 KB
/
install-jasy.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
#!/bin/bash
##########################################################################
# Copyright Zynga Corp - 2012
#
# install-jasy.sh : Bash Script to install Jasy
#
##########################################################################
# Mixpanel helper routines
# Usage : track_event EVENT_NAME
MIXPANEL_TOKEN="cdd7359ea0c86f5b58f074f369829e41"
function track_event {
# $1 : EVENT_NAME
if [ -z $1 ]
then
EVENT_NAME= "unknown"
else
EVENT_NAME=$1
fi
# $2 : extra properties to be passed to Mixpanel
# Format is : \"PROPERTY1_NAME\" : \"PROPERTY1_VALUE\",\"PROPERTY2_NAME\" : \"PROPERTY2_VALUE\"
if [ -n $2 ]
then
TRACK_DATA_EXTRA_PROPERTIES=",$2"
else
TRACK_DATA_EXTRA_PROPERTIES=""
fi
TRACK_DATA_PROPERTIES="\"properties\":{\"token\":\"$MIXPANEL_TOKEN\",\"distinct_id\":\"$DISTINCT_ID\" $TRACK_DATA_EXTRA_PROPERTIES}"
TRACK_DATA="{$TRACK_DATA_PROPERTIES,\"event\":\"$EVENT_NAME\"}"
ENCODED_TRACK_DATA=`echo $TRACK_DATA | base64`
MIXPANEL_API_ENDPOINT="https://api.mixpanel.com/track/?data=$ENCODED_TRACK_DATA"
if [ -n $ENABLE_TRACKING ]
then
curl -s -X POST $MIXPANEL_API_ENDPOINT > /dev/null
fi
}
# Track the install of required command
# Usage : track_command_install COMMAND METHOD STEP
function track_command_install {
track_event INSTALL "\"command\":\"$1\", \"method\":\"$2\",\"step\":\"$3\""
}
# Function to grab the Mac Address of the local machine using a local Python install (This will work on MacOS/Linux but not Windows)
function get_mac_address {
echo `python -c "from uuid import getnode as get_mac; print get_mac()"`
}
# Routine to check whether an executable is already installed, if not provide a helpful error message and
function check_exec {
EXIT="echo 1"
if [ -z "$2" ]
then
OUTPUT="$1"
else
OUTPUT="$2"
fi
if [ -z "$3" ]
then
HELP="Aborting"
else
HELP="$3"
fi
if [ -n "$4" ]
then
EXIT="$4"
fi
command -v $1 >/dev/null 2>&1 || { echo "[Info] I require $OUTPUT but it's not installed. $HELP." >&2; track_event CHECK_EXEC "\"command\":\"$1\",\"installed\":\"false\""; $EXIT; }
track_event CHECK_EXEC "\"command\":\"$1\",\"installed\":\"true\""
}
# Python3 Install Action with homebrew for MacOS
function do_install_python3_with_brew {
track_command_install "python3" "brew" "start"
brew update && brew install python3
track_command_install "python3" "brew" "complete"
track_event CHECK_EXEC "\"command\":\"python3\",\"installed\":\"true\""
}
# Python3 Install Action with yum for Redhat/Centos derivatives
function do_install_python3_with_yum {
track_command_install "python3" "yum" "start"
sudo yum install python3
track_command_install "python3" "yum" "complete"
track_event CHECK_EXEC "\"command\":\"python3\",\"installed\":\"true\""
}
# Python3 Install Action with apt-get for Debian/Ubuntu derivatives
function do_install_python3_with_deb {
track_command_install "python3" "apt-get" "start"
sudo apt-get install python3
track_command_install "python3" "apt-get" "complete"
track_event CHECK_EXEC "\"command\":\"python3\",\"installed\":\"true\""
}
# PIP Install Action
function do_install_pip {
track_command_install "pip" "curl" "start"
curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python3
track_command_install "pip" "curl" "complete"
track_event CHECK_EXEC "\"command\":\"pip\",\"installed\":\"true\""
}
# Jasy Install Action
function do_install_or_update_jasy {
track_command_install "jasy" "pip" "start"
pip-3.2 install -U jasy
track_command_install "jasy" "pip" "complete"
track_event CHECK_EXEC "\"command\":\"jasy\",\"installed\":\"true\""
}
# Python3 Install with Brew
function check_python3_and_install {
executable="python3"
executable_pretty_print="python3"
executable_action="Installing ..."
result=`check_exec $executable $executable_pretty_print $executable_action`
if [[ $result == "0" ]]; then
track_event CHECK_EXEC "\"command\":\"$executable\",\"installed\":\"false\""
do_install_python3_with_brew
else
track_event CHECK_EXEC "\"command\":\"$executable\",\"installed\":\"true\""
echo "[Info] Found $executable_pretty_print"
fi
}
# PIP Install
function check_pip_and_install {
executable="pip-3.2"
executable_pretty_print="pip"
executable_action="Installing ..."
result=`check_exec $executable $executable_pretty_print $executable_action`
if [[ $result == "0" ]]; then
track_event CHECK_EXEC "\"command\":\"$executable\",\"installed\":\"false\""
do_install_pip
else
track_event CHECK_EXEC "\"command\":\"$executable\",\"installed\":\"true\""
echo "[Info] Found $executable_pretty_print"
fi
}
# Jasy Install
function check_jasy_and_install {
executable="jasy"
executable_pretty_print="jasy"
executable_action="Installing ..."
result=`check_exec $executable $executable_pretty_print $executable_action`
if [[ $result == "0" ]]; then
track_event CHECK_EXEC "\"command\":\"$executable\",\"installed\":\"false\""
do_install_or_update_jasy
else
track_event CHECK_EXEC "\"command\":\"$executable\",\"installed\":\"true\""
echo "[Info] Found $executable_pretty_print"
fi
}
# Main function
function main {
DISTINCT_ID=`get_mac_address`
ENABLE_TRACKING="True"
echo "[Info] Starting Jasy install!"
case $OSTYPE in
darwin*) platform="MacOS"; echo Detected MacOS ;;
linux*) platform="Linux"; echo Detected Linux ;;
*) platform="$OSTYPE"; echo Detected $OSTYPE ;;
esac
track_event START "\"platform\":\"$platform\""
if [[ $platform == "MacOS" ]]; then
check_exec "brew" "Homebrew" "Please see install instructions here : http://bit.ly/Sv5lhA" "exit 1"
check_python3_and_install
else
echo "This is an unsupported platform : $platform"
exit 1;
fi
check_exec "curl"
check_exec "base64"
check_pip_and_install
check_jasy_and_install
echo "[Info] Finished - Jasy is ready to use!"
echo "[Info] Optional Dependencies check :"
jasy doctor
track_event COMPLETE "\"status\":\"$?\""
}
# Run!
main