-
Notifications
You must be signed in to change notification settings - Fork 195
/
install.sh
193 lines (167 loc) · 5.62 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
184
185
186
187
188
189
190
191
192
193
#!/bin/bash -e
{ # this ensures the entire script is downloaded
JABBA_HOME=${JABBA_HOME:-$JABBA_DIR} # JABBA_DIR is here for backward-compatibility
JABBA_VERSION=${JABBA_VERSION:-latest}
if [ "$JABBA_HOME" == "" ] || [ "$JABBA_HOME" == "$HOME/.jabba" ]; then
JABBA_HOME=$HOME/.jabba
JABBA_HOME_TO_EXPORT=\$HOME/.jabba
else
JABBA_HOME_TO_EXPORT=$JABBA_HOME
fi
has_command() {
if ! command -v "$1" > /dev/null 2>&1
then echo 1;
else echo 0;
fi
}
# curl looks for HTTPS_PROXY while wget for https_proxy
https_proxy=${https_proxy:-$HTTPS_PROXY}
HTTPS_PROXY=${HTTPS_PROXY:-$https_proxy}
if [ "$JABBA_GET" == "" ]; then
if [ 0 -eq $(has_command curl) ]; then
JABBA_GET="curl -sL"
elif [ 0 -eq $(has_command wget) ]; then
JABBA_GET="wget -qO-"
else
echo "[ERROR] This script needs wget or curl to be installed."
exit 1
fi
fi
if [ "$JABBA_VERSION" == "latest" ]; then
# resolving "latest" to an actual tag
JABBA_VERSION=$($JABBA_GET https://shyiko.github.com/jabba/latest)
fi
# http://semver.org/spec/v2.0.0.html
if [[ ! "$JABBA_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.+-]+)?$ ]]; then
echo "'$JABBA_VERSION' is not a valid version."
exit 1
fi
case "$OSTYPE" in
darwin*)
BINARY_URL=https://github.com/shyiko/jabba/releases/download/${JABBA_VERSION}/jabba-${JABBA_VERSION}-darwin-amd64
;;
linux*)
case "$(uname -m)" in
arm*|aarch*)
if [ `getconf LONG_BIT` = "64" ]; then OSARCH=arm64; else OSARCH=arm; fi
;;
*)
if [ `getconf LONG_BIT` = "64" ]; then OSARCH=amd64; else OSARCH=386; fi
;;
esac
BINARY_URL=https://github.com/shyiko/jabba/releases/download/${JABBA_VERSION}/jabba-${JABBA_VERSION}-linux-${OSARCH}
;;
*)
echo "Unsupported OS $OSTYPE. If you believe this is an error -
please create a ticket at https://github.com/shyiko/jabba/issues."
exit 1
;;
esac
echo "Installing v$JABBA_VERSION..."
echo
if [ ! -f "${JABBA_HOME}/bin/jabba" ]; then
JABBA_SELF_DESTRUCT_AFTER_COMMAND="true"
fi
mkdir -p ${JABBA_HOME}/bin
if [ "$JABBA_MAKE_INSTALL" == "true" ]; then
cp jabba ${JABBA_HOME}/bin
else
$JABBA_GET ${BINARY_URL} > ${JABBA_HOME}/bin/jabba && chmod a+x ${JABBA_HOME}/bin/jabba
fi
if ! ${JABBA_HOME}/bin/jabba --version &>/dev/null; then
echo "${JABBA_HOME}/bin/jabba does not appear to be a valid binary.
Check your Internet connection / proxy settings and try again.
If the problem persists - please create a ticket at https://github.com/shyiko/jabba/issues."
exit 1
fi
if [ "$JABBA_COMMAND" != "" ]; then
${JABBA_HOME}/bin/jabba $JABBA_COMMAND
if [ "$JABBA_SELF_DESTRUCT_AFTER_COMMAND" == "true" ]; then
rm -f ${JABBA_HOME}/bin/jabba
rmdir ${JABBA_HOME}/bin
exit 0
fi
fi
{
echo "# https://github.com/shyiko/jabba"
echo "# This file is indented to be \"sourced\" (i.e. \". ~/.jabba/jabba.sh\")"
echo ""
echo "export JABBA_HOME=\"$JABBA_HOME_TO_EXPORT\""
echo ""
echo "jabba() {"
echo " local fd3=\$(mktemp /tmp/jabba-fd3.XXXXXX)"
echo " (JABBA_SHELL_INTEGRATION=ON $JABBA_HOME_TO_EXPORT/bin/jabba \"\$@\" 3>| \${fd3})"
echo " local exit_code=\$?"
echo " eval \$(cat \${fd3})"
echo " rm -f \${fd3}"
echo " return \${exit_code}"
echo "}"
echo ""
echo "if [ ! -z \"\$(jabba alias default)\" ]; then"
echo " jabba use default"
echo "fi"
} > ${JABBA_HOME}/jabba.sh
SOURCE_JABBA="\n[ -s \"$JABBA_HOME/jabba.sh\" ] && source \"$JABBA_HOME/jabba.sh\""
files=("$HOME/.bashrc")
if [ -f "$HOME/.bash_profile" ]; then
files+=("$HOME/.bash_profile")
elif [ -f "$HOME/.bash_login" ]; then
files+=("$HOME/.bash_login")
elif [ -f "$HOME/.profile" ]; then
files+=("$HOME/.profile")
else
files+=("$HOME/.bash_profile")
fi
for file in "${files[@]}"
do
touch ${file}
if ! grep -qc '/jabba.sh' "${file}"; then
echo "Adding source string to ${file}"
printf "$SOURCE_JABBA\n" >> "${file}"
else
echo "Skipped update of ${file} (source string already present)"
fi
done
if [ -f "$(which zsh 2>/dev/null)" ]; then
file="$HOME/.zshrc"
touch ${file}
if ! grep -qc '/jabba.sh' "${file}"; then
echo "Adding source string to ${file}"
printf "$SOURCE_JABBA\n" >> "${file}"
else
echo "Skipped update of ${file} (source string already present)"
fi
fi
{
echo "# https://github.com/shyiko/jabba"
echo "# This file is indented to be \"sourced\" (i.e. \". ~/.jabba/jabba.fish\")"
echo ""
echo "set -xg JABBA_HOME \"$JABBA_HOME_TO_EXPORT\""
echo ""
echo "function jabba"
echo " set fd3 (mktemp /tmp/jabba-fd3.XXXXXX)"
echo " env JABBA_SHELL_INTEGRATION=ON $JABBA_HOME_TO_EXPORT/bin/jabba \$argv 3> \$fd3"
echo " set exit_code \$status"
echo " eval (cat \$fd3 | sed \"s/^export/set -xg/g\" | sed \"s/^unset/set -e/g\" | tr '=' ' ' | sed \"s/:/\\\" \\\"/g\" | tr '\\\\n' ';')"
echo " rm -f \$fd3"
echo " return \$exit_code"
echo "end"
echo ""
echo "[ ! -z (echo (jabba alias default)) ]; and jabba use default"
} > ${JABBA_HOME}/jabba.fish
FISH_SOURCE_JABBA="\n[ -s \"$JABBA_HOME/jabba.fish\" ]; and source \"$JABBA_HOME/jabba.fish\""
if [ -f "$(which fish 2>/dev/null)" ]; then
file="$HOME/.config/fish/config.fish"
mkdir -p $(dirname ${file})
touch ${file}
if ! grep -qc '/jabba.fish' "${file}"; then
echo "Adding source string to ${file}"
printf "$FISH_SOURCE_JABBA\n" >> "${file}"
else
echo "Skipped update of ${file} (source string already present)"
fi
fi
echo ""
echo "Installation completed
(if you have any problems please report them at https://github.com/shyiko/jabba/issues)"
} # this ensures the entire script is downloaded