forked from YOU54F/traveling-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.sh
executable file
·207 lines (188 loc) · 8.21 KB
/
cli.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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/usr/bin/env sh
set -e
## Tested with https://www.shellcheck.net/
# Usage: (install latest release & latest ruby version)
# $ curl -fsSL https://raw.githubusercontent.com/you54f/traveling-ruby/main/install.sh | sh
# or
# $ wget -q https://raw.githubusercontent.com/you54f/traveling-ruby/main/install.sh -O- | sh
# Options
# TRAVELING_RUBY_VERSION - set ruby version eg TRAVELING_RUBY_VERSION=2.7.3
# TRAVELING_RUBY_RELEASE_TAG - set release tag eg TRAVELING_RUBY_RELEASE_TAG=rel20240215
# TRAVELING_RUBY_INSTALL_PATH - set install path eg TRAVELING_RUBY_INSTALL_PATH=$HOME/.travelling-ruby
# TRAVELING_RUBY_CLEAN_INSTALL - set to true to remove existing install eg TRAVELING_RUBY_CLEAN_INSTALL=true
# Usage: (install fixed version of a release) -
# $ curl -fsSL https://raw.githubusercontent.com/you54f/traveling-ruby/main/install.sh | TRAVELING_RUBY_RELEASE_TAG=rel-20240215 sh
# or
# $ wget -q https://raw.githubusercontent.com/you54f/traveling-ruby/main/install.sh -O- | TRAVELING_RUBY_RELEASE_TAG=rel-20240215 sh
# Usage: (install fixed version of ruby) -
# $ curl -fsSL https://raw.githubusercontent.com/you54f/traveling-ruby/main/install.sh | TRAVELING_RUBY_VERSION=2.6.10 sh
# or
# $ wget -q https://raw.githubusercontent.com/you54f/traveling-ruby/main/install.sh -O- | TRAVELING_RUBY_VERSION=2.6.10 sh
PROJECT_NAME='traveling-ruby'
TRAVELING_RUBY_GH_SOURCE=YOU54F/${PROJECT_NAME}
TRAVELING_RUBY_VERSION=${TRAVELING_RUBY_VERSION:-3.2.4}
usage() {
echo "Usage: $0 [-v <version>] [-d <release-date>] [--set-path] [--clean-install] [--ci]"
echo ""
echo " -v <version> Ruby version to install (default: 3.2.4)"
echo " -d <release-date> Release date of the traveling ruby package to download (default: latest)"
echo " --set-path Add the traveling ruby bin path to the PATH environment variable (default: false)"
echo " --clean-install Remove any existing traveling ruby installation before installing (default: false)"
echo " --ci Set --set-path to true and --clean-install to true (default: false)"
echo " -g list of gems to install"
exit 0
}
while getopts "hg:v:d:-:" opt; do
case $opt in
v)
TRAVELING_RUBY_VERSION=$OPTARG
;;
d)
TRAVELING_RUBY_PKG_DATE=$OPTARG
;;
g)
TRAVELING_RUBY_GEM_LIST=$OPTARG
;;
-)
case "${OPTARG}" in
set-path)
TRAVELING_RUBY_SET_PATH=true
;;
clean-install)
TRAVELING_RUBY_CLEAN_INSTALL=true
;;
ci)
TRAVELING_RUBY_SET_PATH=true
TRAVELING_RUBY_CLEAN_INSTALL=true
;;
esac
;;
h|*)
usage
;;
esac
done
if [ -z "$TRAVELING_RUBY_VERSION" ]; then
TRAVELING_RUBY_VERSION=3.2.4
fi
if [ -z "$TRAVELING_RUBY_PKG_DATE" ]; then
TRAVELING_RUBY_RELEASE_TAG=$(basename "$(curl -fs -o/dev/null -w "%{redirect_url}" https://github.com/${TRAVELING_RUBY_GH_SOURCE}/releases/latest)")
TRAVELING_RUBY_PKG_DATE=$(echo "$TRAVELING_RUBY_RELEASE_TAG" | cut -d '-' -f 2)
echo "Thanks for downloading the latest release of ${PROJECT_NAME} $TRAVELING_RUBY_RELEASE_TAG."
echo "-------------"
echo "Note:"
echo "-------------"
echo "You can download a fixed version by setting the TRAVELING_RUBY_RELEASE_TAG environment variable eg TRAVELING_RUBY_RELEASE_TAG=$TRAVELING_RUBY_RELEASE_TAG"
echo "example:"
echo " curl -fsSL https://raw.githubusercontent.com/${TRAVELING_RUBY_GH_SOURCE}/main/install.sh | TRAVELING_RUBY_RELEASE_TAG=$TRAVELING_RUBY_RELEASE_TAG sh"
else
echo "Thanks for downloading ${PROJECT_NAME} version $PACT_CLI_VERSION."
fi
echo "-------------"
echo "You can download a fixed ruby version by setting the TRAVELING_RUBY_VERSION environment variable eg TRAVELING_RUBY_VERSION=$TRAVELING_RUBY_VERSION"
echo "example:"
echo " curl -fsSL https://raw.githubusercontent.com/${TRAVELING_RUBY_GH_SOURCE}/main/install.sh | TRAVELING_RUBY_VERSION=$TRAVELING_RUBY_VERSION sh"
echo "-------------"
echo "detecting platform & architecture"
case $(uname -sm) in
'Linux x86_64')
TRAVELING_RUBY_OS=linux
TRAVELING_RUBY_ARCH=x86_64
;;
'Linux aarch64')
TRAVELING_RUBY_OS=linux
TRAVELING_RUBY_ARCH=arm64
;;
'Darwin arm64')
TRAVELING_RUBY_OS=osx
TRAVELING_RUBY_ARCH=arm64
;;
'Darwin x86_64')
TRAVELING_RUBY_OS=osx
TRAVELING_RUBY_ARCH=x86_64
;;
"Windows"* | "MINGW64"*)
TRAVELING_RUBY_OS=windows
TRAVELING_RUBY_ARCH=x86_64
;;
*)
echo "Sorry, you'll need to install the ${PROJECT_NAME} manually."
exit 1
;;
esac
TRAVELING_RUBY_PLATFORM="${TRAVELING_RUBY_OS}-${TRAVELING_RUBY_ARCH}"
TRAVELING_RUBY_INSTALL_PATH="${TRAVELING_RUBY_INSTALL_PATH:-$HOME/.travelling-ruby}"
TRAVELING_RUBY_BASENAME=traveling-ruby-${TRAVELING_RUBY_PKG_DATE}-${TRAVELING_RUBY_VERSION}-${TRAVELING_RUBY_PLATFORM}
TRAVELING_RUBY_FILENAME="${TRAVELING_RUBY_BASENAME}.tar.gz"
TRAVELING_RUBY_BIN_PATH="${TRAVELING_RUBY_INSTALL_PATH}/bin"
echo "-------------"
echo "TRAVELING_RUBY_PKG_DATE: $TRAVELING_RUBY_PKG_DATE"
echo "TRAVELING_RUBY_VERSION: $TRAVELING_RUBY_VERSION"
echo "TRAVELING_RUBY_OS: $TRAVELING_RUBY_OS"
echo "TRAVELING_RUBY_ARCH: $TRAVELING_RUBY_ARCH"
echo "TRAVELING_RUBY_PLATFORM: $TRAVELING_RUBY_PLATFORM"
echo "TRAVELLING_RUBY_BASENAME: $TRAVELING_RUBY_BASENAME"
echo "TRAVELING_RUBY_GH_SOURCE: $TRAVELING_RUBY_GH_SOURCE"
echo "TRAVELING_RUBY_INSTALL_PATH: $TRAVELING_RUBY_INSTALL_PATH"
echo "TRAVELING_RUBY_FILENAME: $TRAVELING_RUBY_FILENAME"
if [ "$TRAVELING_RUBY_CLEAN_INSTALL" = "true" ]; then
echo "-------------"
echo "Cleaning up ${PROJECT_NAME} @ $TRAVELING_RUBY_INSTALL_PATH"
rm -rf "$TRAVELING_RUBY_INSTALL_PATH"
fi
mkdir -p "$TRAVELING_RUBY_INSTALL_PATH"
cd "$TRAVELING_RUBY_INSTALL_PATH"
echo "-------------"
echo "Downloading:"
echo "-------------"
echo curl --fail -LO https://github.com/${TRAVELING_RUBY_GH_SOURCE}/releases/download/"${TRAVELING_RUBY_RELEASE_TAG}"/"${TRAVELING_RUBY_FILENAME}"
(curl --fail -LO https://github.com/${TRAVELING_RUBY_GH_SOURCE}/releases/download/"${TRAVELING_RUBY_RELEASE_TAG}"/"${TRAVELING_RUBY_FILENAME}" && echo downloaded "${TRAVELING_RUBY_FILENAME}") || (echo "Sorry, you'll need to install the ${PROJECT_NAME} manually." && exit 1)
(tar xzf "${TRAVELING_RUBY_FILENAME}" && echo unarchived "${TRAVELING_RUBY_FILENAME}") || (echo "Sorry, you'll need to unarchived ${PROJECT_NAME} manually." && exit 1)
(rm "${TRAVELING_RUBY_FILENAME}" && echo removed "${TRAVELING_RUBY_FILENAME}") || (echo "Sorry, you'll need to remove ${PROJECT_NAME} archive manually." && exit 1)
echo "${PROJECT_NAME} ${TRAVELING_RUBY_RELEASE_TAG} installed to $TRAVELING_RUBY_INSTALL_PATH"
echo "-------------------"
echo "Successfully installed ${PROJECT_NAME} to:"
echo " $TRAVELING_RUBY_INSTALL_PATH:"
echo "-------------------"
echo "ls -1 $TRAVELING_RUBY_INSTALL_PATH"
echo "-------------------"
ls -1 "$TRAVELING_RUBY_INSTALL_PATH"
echo "-------------------"
echo "$TRAVELING_RUBY_BIN_PATH/ruby --version"
echo "-------------------"
"$TRAVELING_RUBY_BIN_PATH"/ruby --version || echo "Sorry, we couldnt find the right path to ruby to check the installed. Please check your installation at $TRAVELING_RUBY_BIN_PATH!"
echo "-------------------"
if [ "$TRAVELING_RUBY_SET_PATH" ]; then
if [ "$GITHUB_ENV" ]; then
echo "Added the following to your path to make ${PROJECT_NAME} available:"
echo ""
echo "PATH=$TRAVELING_RUBY_BIN_PATH:\${PATH}"
echo "PATH=$TRAVELING_RUBY_BIN_PATH:${PATH}" >>"$GITHUB_ENV"
elif [ "$CIRRUS_CI" ]; then
echo "Added the following to your path to make ${PROJECT_NAME} available:"
echo ""
echo "PATH=$TRAVELING_RUBY_BIN_PATH:\${PATH}"
echo "PATH=$TRAVELING_RUBY_BIN_PATH:${PATH}" >>"$CIRRUS_ENV"
else
echo "Add the following to your path to make ${PROJECT_NAME} available:"
echo "--- Linux/MacOS/Windows Bash Users --------"
echo ""
echo " PATH=:$TRAVELING_RUBY_BIN_PATH:\${PATH}"
fi
fi
if [ "$TRAVELING_RUBY_GEM_LIST" ]; then
for GEM in $TRAVELING_RUBY_GEM_LIST; do
GEM_NAME=$(echo "$GEM" | sed -E 's/(.*)-.*/\1/')
GEM_VERSION=$(echo "$GEM" | sed -E 's/(.*)-.*/\2/' || echo "")
echo "-------------------"
echo "gem install $GEM"
echo "version: $GEM_VERSION"
echo "-------------------"
if [ "$GEM_VERSION" ]; then
"$TRAVELING_RUBY_BIN_PATH/gem" install "$GEM_NAME" -v "$GEM_VERSION"
else
"$TRAVELING_RUBY_BIN_PATH/gem" install "$GEM_NAME"
fi
echo "-------------------"
done
fi