-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathinstall.sh
executable file
·143 lines (100 loc) · 3.42 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
#!/bin/sh
# NOTE: this script is largely inspired by Meteor install script,
# which can be found here: https://install.meteor.com
## NOTE sh NOT bash. This script should be POSIX sh only, since we don't
## know what shell the user has. Debian uses 'dash' for 'sh', for
## example.
# Is RESTX already installed (in /usr/local/bin (engine) or /usr/bin
# (pre-engine)? If so, just ask the user to run the upgrade command
PREFIX="${RESTX_BIN:-/usr/local}"
if [ -x /usr/local/bin/restx ] || [ -x /usr/bin/restx ] || [ -x $PREFIX/bin/restx ]; then
cat <<"EOF"
RESTX is already installed, to update it:
(1) run the 'restx' command
(2) run 'shell upgrade' command inside restx shell
If you want to reinstall it from scratch:
(1) run 'rm `which restx`'
(2) relaunch this script
You can also check the docs at
http://restx.io/docs/
EOF
exit 0
fi
set -e
set -u
# Let's display everything on stderr.
exec 1>&2
UNAME=`uname`
if [ "$UNAME" != "Linux" -a "$UNAME" != "Darwin" ] ; then
echo "Sorry, this OS is not supported yet."
exit 1
fi
trap "echo Installation failed." EXIT
# If you already have an existing installation (but don't have restx in PATH), we do a clean
# install here:
[ -e "$HOME/.restx" ] && rm -rf "$HOME/.restx"
if [ "${1:-unset}" = "unset" ] ; then
# get current version from web site
VERSION=`curl -Ls http://restx.io/version | head -n 1`
# get current tarball URL from web site
TARBALL_URL=`curl -Ls http://restx.io/version | tail -n 1`
# the url has no extension on web site, because it's used for updates where choosing between zip and tar.gz
# depends on platform
TARBALL_URL="$TARBALL_URL.tar.gz"
else
VERSION=$1
if [ "${2:-unset}" = "unset" ] ; then
TARBALL_URL="https://repo1.maven.org/maven2/io/restx/restx-package/${VERSION}/restx-package-${VERSION}.tar.gz"
else
TARBALL_URL=$2
fi
fi
INSTALL_TMPDIR="$HOME/.restx-install-tmp"
rm -rf "$INSTALL_TMPDIR"
mkdir "$INSTALL_TMPDIR"
echo "Downloading RESTX $VERSION distribution"
curl --progress-bar --fail "$TARBALL_URL" | tar -xzf - -C "$INSTALL_TMPDIR"
# bomb out if it didn't work, eg no net
test -x "${INSTALL_TMPDIR}/restx"
mv "${INSTALL_TMPDIR}" "$HOME/.restx"
# just double-checking :)
test -x "$HOME/.restx/restx"
echo
echo "RESTX $VERSION has been installed in your home directory (~/.restx)."
LAUNCHER="$HOME/.restx/restx"
if ln -s "$LAUNCHER" "$PREFIX/bin/restx" >/dev/null 2>&1; then
echo "Writing a launcher script to $PREFIX/bin/restx for your convenience."
cat <<"EOF"
RESTX is now properly installed, you can launch it using the restx command.
To get started, see the docs at:
http://restx.io/docs/
EOF
elif type sudo >/dev/null 2>&1; then
echo "Writing a launcher script to $PREFIX/bin/restx for your convenience."
echo "This may prompt for your password."
if sudo ln -s "$LAUNCHER" "$PREFIX/bin/restx"; then
cat <<"EOF"
RESTX is now properly installed, you can launch it using the restx command.
To get started, see the docs at:
http://restx.io/docs/
EOF
else
cat <<"EOF"
Couldn't write the launcher script. Please either:
(1) Add ~/.restx to your path, or
(2) Rerun this command to try again.
Then to get started, see the docs at
http://restx.io/docs/
EOF
fi
else
cat <<"EOF"
Now you need to do one of the following:
(1) Add ~/.restx to your path, or
(2) Run this command as root:
ln -s ~/.restx/restx /usr/bin/restx
Then to get started, see the docs at
http://restx.io/docs/
EOF
fi
trap - EXIT