forked from rexray/dvdcli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·152 lines (131 loc) · 4.26 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
#!/bin/sh
##
# this curl-install script supports the installation of the latest
# version of dvdcli for CentOS, Ubuntu, CoreOS, and Darwin using
# RPMs, DEBs, and tarballs.
#
# to install the latest version of dvdcli simply execute:
#
# curl -sSL https://dl.bintray.com/emccode/dvdcli/install | sh -
#
# however, this script will also allow users to install specific
# versions of REX-Ray and even supports the discovery of those versions.
# for example, to list the available REX-Ray packages use the "list"
# command like so:
#
# curl -sSL https://dl.bintray.com/emccode/dvdcli/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/dvdcli/install | sh -s unstable -
# curl -sSL https://dl.bintray.com/emccode/dvdcli/install | sh -s staged -
# curl -sSL https://dl.bintray.com/emccode/dvdcli/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/dvdcli/install | sh -s list stable -
#
# the above command would emit somthing similar to:
#
# curl -sSL https://dl.bintray.com/emccode/dvdcli/install | sh -s stable 0.2.0 -
# curl -sSL https://dl.bintray.com/emccode/dvdcli/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.
##
PROD=dvdcli
REPO=dvdcli
BIN_NAME=dvdcli
BINTRAY_URL=https://dl.bintray.com/emccode
URL=$BINTRAY_URL/$REPO
SCRIPT_URL=$URL/install
SCRIPT_CMD="curl -sSL $SCRIPT_URL | sh -s"
CMD=$1
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 '<a' | grep -v 'latest' | \
perl -pe 's/^.*?<a.+?>([^<]+?)\/?<\/a>.*$/$1/gm'); do
echo "$SCRIPT_CMD $PKG $v -"
done
fi
}
install() {
URL=$URL/$PKG/$VERSION
OS=$(uname -s)
ARCH=$(uname -m)
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
#echo "installing rpm"
sudo rpm -ih --quiet $URL/$BIN_NAME-latest-$ARCH.rpm > /dev/null
elif [ "$ARCH" = "x86_64" -a -z "$IS_COREOS" ] && \
[ -e "/etc/debian-release" -o \
-e "/etc/debian-version" -o \
-e "/etc/lsb-release" ]; then
#echo "installing deb"
curl -sSLO $URL/$BIN_NAME-latest-$ARCH.deb && \
sudo dpkg -i $BIN_NAME-latest-$ARCH.deb && \
rm -f $BIN_NAME-latest-$ARCH.deb
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.tar.gz
else
FILE_NAME=$BIN_NAME-$OS-$ARCH-$VERSION.tar.gz
fi
fi
FILE_URL=$URL/$FILE_NAME
sudo mkdir -p $BIN_DIR && \
curl -sSLO $FILE_URL && \
sudo tar xzf $FILE_NAME -C $BIN_DIR && \
rm -f $FILE_NAME && \
sudo chmod 0755 $BIN_FILE && \
sudo chown 0 $BIN_FILE && \
sudo chgrp 0 $BIN_FILE
fi
echo
echo "$PROD has been installed to $BIN_FILE"
echo
$BIN_FILE version
echo
}
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