-
Notifications
You must be signed in to change notification settings - Fork 8
/
install.sh
183 lines (150 loc) · 4.48 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
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
#!/bin/sh
# Inspired by:
# - https://github.com/creationix/nvm
# - https://github.com/moovweb/gvm
# - https://blog.markvincze.com/download-artifacts-from-a-latest-github-release-in-sh-and-powershell/
{ # this ensures the entire script is downloaded #
is_installed() {
type "$1" > /dev/null 2>&1
}
error_exit() {
if is_installed tput; then
tput sgr0
tput setaf 1
echo "ERROR: $1"
tput sgr0
else
echo "ERROR: $1"
fi
exit 1
}
success_msg() {
if is_installed tput; then
command printf "["
tput sgr0
tput setaf 2
command printf "OK"
tput sgr0
command printf "] ${1}\\n"
else
echo "[OK]: $1"
fi
}
warning_msg() {
if is_installed tput; then
command printf "["
tput sgr0
tput setaf 3
command printf "!!"
tput sgr0
command printf "] ${1}\\n"
else
echo "[!!]: $1"
fi
}
try_profile() {
if [ -z "${1-}" ] || [ ! -f "${1}" ]; then
return 1
fi
echo "${1}"
}
#
# Detect profile file if not specified as environment variable
# (eg: PROFILE=~/.myprofile)
# The echo'ed path is guaranteed to be an existing file
# Otherwise, an empty string is returned
#
detect_profile() {
if [ -n "${PROFILE}" ] && [ -f "${PROFILE}" ]; then
echo "${PROFILE}"
return
fi
local DETECTED_PROFILE
DETECTED_PROFILE=''
local SHELLTYPE
SHELLTYPE="$(basename "/$SHELL")"
if [ "$SHELLTYPE" = "bash" ]; then
if [ -f "$HOME/.bash_profile" ]; then
DETECTED_PROFILE="$HOME/.bash_profile"
elif [ -f "$HOME/.bashrc" ]; then
DETECTED_PROFILE="$HOME/.bashrc"
fi
elif [ "$SHELLTYPE" = "zsh" ]; then
DETECTED_PROFILE="$HOME/.zshrc"
fi
if [ -z "$DETECTED_PROFILE" ]; then
for EACH_PROFILE in ".profile" ".bashrc" ".bash_profile" ".zshrc"
do
if DETECTED_PROFILE="$(try_profile "${HOME}/${EACH_PROFILE}")"; then
break
fi
done
fi
if [ ! -z "$DETECTED_PROFILE" ]; then
echo "$DETECTED_PROFILE"
else
command touch $HOME/.bash_profile
echo "$HOME/.bash_profile"
fi
}
MACHINE_TYPE=`uname -m`
if [ ${MACHINE_TYPE} != 'x86_64' ]; then
error_exit "32 bits architecture is not supported"
fi
OS=`uname | tr '[:upper:]' '[:lower:]'`
if [ "$OS" != "linux" ] && [ "$OS" != "darwin" ]; then
error_exit "Operational System $OS not supported."
fi
if ! is_installed tar; then
error_exit "You must have 'tar' installed before proceeding."
fi
if is_installed manifold; then
warning_msg "Previous installation detected: v`manifold -v`"
fi
REPO="https://github.com/manifoldco/manifold-cli"
if [ -z "$MANIFOLD_VERSION" ]; then
MANIFOLD_VERSION="0.15.1"
fi
if [ -z "$MANIFOLD_DIR" ]; then
MANIFOLD_DIR="${HOME}/.manifold/bin"
fi
mkdir -p $MANIFOLD_DIR
CURRENT_DIR=`pwd`
cd $MANIFOLD_DIR
# Create filename accordingly to manifoldco/promulgate structure
FILENAME="manifold-cli_${MANIFOLD_VERSION}_${OS}_amd64.tar.gz"
ARTIFACT_URL="${REPO}/releases/download/v${MANIFOLD_VERSION}/${FILENAME}"
curl -sS --compressed -L -q $ARTIFACT_URL --output $FILENAME
success_msg "Version ($MANIFOLD_VERSION) downloaded"
tar xvf $FILENAME 1> /dev/null
rm $FILENAME
if is_installed manifold; then
PREVIOUS_INSTALLATION=`which manifold`
if [ "$PREVIOUS_INSTALLATION" = "$MANIFOLD_DIR/manifold" ]; then
success_msg "Binary updated at $MANIFOLD_DIR"
else
success_msg "Binary installed at $MANIFOLD_DIR"
warning_msg "Another executable detected: `type manifold`"
warning_msg "To manually run this current installation: .$MANIFOLD_DIR/manifold"
fi
else
success_msg "Binary installed at $MANIFOLD_DIR"
fi
PROFILE=`detect_profile`
PATH_CHANGE="export PATH=\"\$PATH:$MANIFOLD_DIR\""
if echo ":$PATH:" | grep -q ":$MANIFOLD_DIR:" > /dev/null; then
success_msg "\$PATH already contained $MANIFOLD_DIR. Skipping..."
elif [ "$PROFILE" = "" ]; then
warning_msg "Unable to locate profile settings file (something like $HOME/.bashrc or $HOME/.bash_profile)"
warning_msg "You will have to manually add the following line:"
echo
command printf "\\t$PATH_CHANGE\\n"
else
echo $PATH_CHANGE >> $PROFILE
success_msg "Your $PROFILE has changed to include $MANIFOLD_DIR into your PATH"
warning_msg "Please restart or re-source your terminal session."
fi
cd $CURRENT_DIR
echo
success_msg "All done. Happy manifold use! :)"
}