forked from rexray/rexray
-
Notifications
You must be signed in to change notification settings - Fork 1
/
install
executable file
·203 lines (168 loc) · 5.74 KB
/
install
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
200
201
202
203
#!/bin/sh
# the name of the program/product this curl-bash script lists/installs using
# Bintray as the online repository
PROG=rexray
##
# this curl-install script supports the installation of the latest
# version of $PROG for CentOS, Ubuntu, CoreOS, and Darwin using
# RPMs, DEBs, and tarballs.
#
# to install the latest version of $PROG simply execute:
#
# curl -sSL https://dl.bintray.com/emccode/rexray/install | sh
#
# however, this script will also allow users to install specific
# versions of $PROG and even supports the discovery of those versions.
# for example, to list the available $PROG packages use the "list"
# command like so:
#
# curl -sSL https://dl.bintray.com/emccode/rexray/install | sh -s -- list
#
# this will emit the following curl commands to demonstrate how to
# install one or more of the available packages, "unstable", "staged",
# and "stable".
#
# curl -sSL https://dl.bintray.com/emccode/rexray/install | sh -s -- unstable
# curl -sSL https://dl.bintray.com/emccode/rexray/install | sh -s -- staged
# curl -sSL https://dl.bintray.com/emccode/rexray/install | sh -s -- stable
#
# again, the "list" command outputs the curl commands to perform
# installations, not how to traverse deeper into the package structure.
# however, it's not hard to do that traversal. for example, to list the
# contents of the "stable" package we'd execute:
#
# curl -sSL https://dl.bintray.com/emccode/rexray/install | sh -s -- list stable
#
# the above command would emit somthing similar to:
#
# curl -sSL https://dl.bintray.com/emccode/rexray/install | sh -s -- stable 0.2.0
# curl -sSL https://dl.bintray.com/emccode/rexray/install | sh -s -- stable latest
#
# as you can see, to traverse the structure, we simply insert the
# command "list" as the first argument after the "-s" flag.
##
REPO=$PROG
BIN_NAME=$PROG
BINTRAY_URL=https://dl.bintray.com/emccode
URL=$BINTRAY_URL/$REPO
SCRIPT_URL=$URL/install
SCRIPT_CMD="curl -sSL $SCRIPT_URL | sh -s"
sudo() {
if [ "$(id -u)" -eq "0" ]; then $@; else $SUDO $@; fi
}
is_coreos() {
grep DISTRIB_ID=CoreOS /etc/lsb-release 2> /dev/null
}
list() {
if [ -z "$PKG" ]; then
echo "$SCRIPT_CMD -- list unstable"
echo "$SCRIPT_CMD -- list staged"
echo "$SCRIPT_CMD -- list stable"
else
URL="$URL/$PKG"
for v in $(curl -sSL $URL | \
grep 'onclick' | grep -v 'latest' | \
cut -d '>' -f3 | cut -d'/' -f1); do
echo "$SCRIPT_CMD -- $PKG $v"
done
fi
}
install() {
ARCH=$(uname -m)
if [ "$ARCH" != "x86_64" ]; then
echo "$PROG is 64-bit only and not supported on $ARCH platforms"
exit 1
fi
OS=$(uname -s)
URL=$URL/$PKG/$VERSION
LURL=https://api.bintray.com/content/emccode/$REPO/$PKG/\$latest
SUDO=$(which sudo)
BIN_DIR=/usr/bin
BIN_FILE=$BIN_DIR/$BIN_NAME
IS_COREOS=$(is_coreos)
# how to detect the linux distro was taken from http://bit.ly/1JkNwWx
if [ -e "/etc/redhat-release" -o -e "/etc/redhat-version" ]; then
if [ "$VERSION" = "latest" ]; then
FILE_NAME=$BIN_NAME-latest-1.$ARCH.rpm
URL=$LURL/$BIN_NAME-\$latest-1.$ARCH.rpm\?bt_package=$PKG
else
FILE_NAME=$BIN_NAME-$VERSION-1.$ARCH.rpm
URL=$URL/$FILE_NAME
fi
curl -o $FILE_NAME -sSL $URL
if [ "$?" -ne "0" ]; then exit $?; fi
sudo rpm -ih --quiet $FILE_NAME > /dev/null
if [ "$?" -ne "0" ]; then ec=$?; rm -f $FILE_NAME; exit $ec; fi
rm -f $FILE_NAME
elif [ "$ARCH" = "x86_64" -a -z "$IS_COREOS" ] && \
[ -e "/etc/debian-release" -o \
-e "/etc/debian-version" -o \
-e "/etc/lsb-release" ]; then
ARCH=amd64
if [ "$VERSION" = "latest" ]; then
FILE_NAME=${BIN_NAME}_latest-1_$ARCH.deb
URL=$LURL/${BIN_NAME}_\$latest-1_$ARCH.deb\?bt_package=$PKG
else
FILE_NAME=${BIN_NAME}_${VERSION}-1_${ARCH}.deb
URL=$URL/$FILE_NAME
fi
curl -o $FILE_NAME -sSL $URL
if [ "$?" -ne "0" ]; then exit $?; fi
sudo dpkg -i $FILE_NAME
if [ "$?" -ne "0" ]; then ec=$?; rm -f $FILE_NAME; exit $ec; fi
rm -f $FILE_NAME
else
if [ -n "$IS_COREOS" ]; then
BIN_DIR=/opt/bin
BIN_FILE=$BIN_DIR/$BIN_NAME
elif [ "$OS" = "Darwin" ]; then
BIN_DIR=/usr/local/bin
BIN_FILE=$BIN_DIR/$BIN_NAME
fi
if [ -z "$FILE_NAME" ]; then
if [ "$VERSION" = "latest" ]; then
FILE_NAME=$BIN_NAME-$OS-$ARCH-latest.tar.gz
URL=$LURL/$BIN_NAME-$OS-$ARCH-\$latest.tar.gz\?bt_package=$PKG
else
FILE_NAME=$BIN_NAME-$OS-$ARCH-$VERSION.tar.gz
URL=$URL/$FILE_NAME
fi
fi
sudo mkdir -p $BIN_DIR
if [ "$?" -ne "0" ]; then exit $?; fi
curl -o $FILE_NAME -sSL $URL
if [ "$?" -ne "0" ]; then exit $?; fi
sudo tar xzf $FILE_NAME -C $BIN_DIR
if [ "$?" -ne "0" ]; then ec=$?; rm -f $FILE_NAME; exit $ec; fi
rm -f $FILE_NAME
if [ ! -e "$BIN_FILE" ]; then
echo "$BIN_FILE does not exist!"
exit 1
fi
sudo chmod 0755 $BIN_FILE && \
sudo chown 0 $BIN_FILE && \
sudo chgrp 0 $BIN_FILE
if [ "$?" -ne "0" ]; then exit $?; fi
sudo $BIN_FILE install
if [ "$?" -ne "0" ]; then exit $?; fi
fi
echo
echo "$PROG has been installed to $BIN_FILE"
echo
$BIN_FILE version
echo
}
CMD=$1
if [ "$CMD" = "list" ] || [ "$CMD" = "install" ]; then
shift
fi
if [ "$CMD" = "list" ]; then
PKG=$1
VERSION=$2
list
else
PKG=${1:-stable}
VERSION=${2:-latest}
FILE_NAME=$3
install
fi