-
Notifications
You must be signed in to change notification settings - Fork 47
/
update.sh
executable file
·150 lines (124 loc) · 4.24 KB
/
update.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
#!/bin/bash
# Author: Hologram <[email protected]>
#
# Copyright 2016 - Hologram (Konekt, Inc.)
#
# LICENSE: Distributed under the terms of the MIT License
#
# update.sh - This file helps update this Python SDK and all required dependencies
# on a machine.
set -euo pipefail
required_programs=('python3' 'pip3' 'ps' 'kill' 'libpython3.9-dev')
OS=''
# Check OS.
if [ "$(uname)" == "Darwin" ]; then
echo 'Darwin system detected'
OS='DARWIN'
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
echo 'Linux system detected'
OS='LINUX'
required_programs+=('ip' 'pppd')
elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]; then
echo 'Windows 32-bit system detected'
OS='WINDOWS'
elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW64_NT" ]; then
echo 'Windows 64-bit system detected'
OS='WINDOWS'
fi
# Error out on unsupported OS.
if [ "$OS" == 'DARWIN' ] || [ "$OS" == 'WINDOWS' ]; then
echo "$OS is not supported right now"
exit 1
fi
function pause() {
read -p "$*"
}
function install_software() {
if [ "$OS" == 'LINUX' ]; then
sudo apt -y install "$*"
elif [ "$OS" == 'DARWIN' ]; then
brew install "$*"
echo 'TODO: macOS should go here'
elif [ "$OS" == 'WINDOWS' ]; then
echo 'TODO: windows should go here'
fi
}
function check_python_version() {
if ! python3 -V | grep -E '3.(9|1[012]).[0-9]' > /dev/null 2>&1; then
echo "An unsupported version of python 3 is installed. Must have python 3.9+ installed to use the Hologram SDK"
exit 1
fi
}
# EFFECTS: Returns true if the specified program is installed, false otherwise.
function check_if_installed() {
if command -v "$*" >/dev/null 2>&1; then
return 0
else
return 1
fi
}
function update_repository() {
if [ "$OS" == 'LINUX' ]; then
sudo apt update
elif [ "$OS" == 'DARWIN' ]; then
brew update
echo 'TODO: macOS should go here'
elif [ "$OS" == 'WINDOWS' ]; then
echo 'TODO: windows should go here'
fi
}
# EFFECTS: Verifies that all required software is installed.
function verify_installation() {
echo 'Verifying that all dependencies are installed correctly...'
# Verify pip packages
INSTALLED_PIP_PACKAGES="$(pip3 list)"
if ! [[ "$INSTALLED_PIP_PACKAGES" == *"python-sdk-auth"* ]]; then
echo 'Cannot find python-sdk-auth. Please rerun the install script.'
exit 1
fi
if ! [[ "$INSTALLED_PIP_PACKAGES" == *"hologram-python"* ]]; then
echo 'Cannot find hologram-python. Please rerun the install script.'
exit 1
fi
echo 'You are now ready to use the Hologram Python SDK!'
}
check_python_version
update_repository
# Check if an older version exists and uninstall it
if command hologram version | grep '0.[0-8]'; then
echo "Found a previous version of the SDK on Python 2. The new update uses"
echo "Python 3 and is not compatible with Python 2. This script will uninstall"
echo "the previous SDK version, install Python 3 and then install the new"
echo "Python 3 version of the SDK. It will not make Python 3 your default"
echo "Python version."
pause "Press [Enter] key to continue...";
sudo pip uninstall -y hologram-python
fi
# Iterate over all programs to see if they are installed
# Installs them if necessary
for program in ${required_programs[*]}
do
if [ "$program" == 'pppd' ]; then
if ! check_if_installed "$program"; then
pause "Installing $program. Press [Enter] key to continue...";
install_software 'ppp'
fi
elif [ "$program" == 'pip3' ]; then
if ! check_if_installed "$program"; then
pause "Installing $program. Press [Enter] key to continue...";
install_software 'python3-pip'
fi
if ! pip3 -V | grep -E '3.(9|1[012])' >/dev/null 2>&1; then
echo "pip3 is installed for an unsupported version of python."
exit 1
fi
elif check_if_installed "$program"; then
echo "$program is already installed."
else
pause "Installing $program. Press [Enter] key to continue...";
install_software "$program"
fi
done
# Install SDK itself.
sudo pip3 install hologram-python --upgrade
verify_installation