Skip to content

Commit 5631d45

Browse files
fix(install): Use proper bash testing (#673)
Fixes #672 I split this PR up into 4 commits. The first one is the bare minimum for the issue. The rest are just consistency corrections that we neckbeards at irc://chat.freenode.net/%23bash would always make.
1 parent 9a18a4a commit 5631d45

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

install.sh

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,22 @@ trap_with_arg() {
6060
DID_CLEAN_UP=0
6161
# the cleanup function will be the exit point
6262
cleanup () {
63-
if [ "$DID_CLEAN_UP" -eq 1 ]; then
63+
if [[ "$DID_CLEAN_UP" -eq 1 ]]; then
6464
return 0;
6565
fi
6666
DID_CLEAN_UP=1
6767

68-
if [ "$1" != "EXIT" ]; then
68+
if [[ "$1" != "EXIT" ]]; then
6969
echo "An error occurred, caught SIG$1 on line $2";
7070

71-
if [[ "$MINIMIZE_DOWNTIME" ]]; then
71+
if [[ -n "$MINIMIZE_DOWNTIME" ]]; then
7272
echo "*NOT* cleaning up, to clean your environment run \"docker-compose stop\"."
7373
else
7474
echo "Cleaning up..."
7575
fi
7676
fi
7777

78-
if [[ ! "$MINIMIZE_DOWNTIME" ]]; then
78+
if [[ -z "$MINIMIZE_DOWNTIME" ]]; then
7979
$dc stop &> /dev/null
8080
fi
8181
}
@@ -93,35 +93,35 @@ function ver () { echo "$@" | awk -F. '{ printf("%d%03d%03d", $1,$2,$3); }'; }
9393

9494
# Thanks to https://stackoverflow.com/a/25123013/90297 for the quick `sed` pattern
9595
function ensure_file_from_example {
96-
if [ -f "$1" ]; then
96+
if [[ -f "$1" ]]; then
9797
echo "$1 already exists, skipped creation."
9898
else
9999
echo "Creating $1..."
100100
cp -n $(echo "$1" | sed 's/\.[^.]*$/.example&/') "$1"
101101
fi
102102
}
103103

104-
if [ $(ver $DOCKER_VERSION) -lt $(ver $MIN_DOCKER_VERSION) ]; then
104+
if [[ "$(ver $DOCKER_VERSION)" -lt "$(ver $MIN_DOCKER_VERSION)" ]]; then
105105
echo "FAIL: Expected minimum Docker version to be $MIN_DOCKER_VERSION but found $DOCKER_VERSION"
106106
exit 1
107107
fi
108108

109-
if [ $(ver $COMPOSE_VERSION) -lt $(ver $MIN_COMPOSE_VERSION) ]; then
109+
if [[ "$(ver $COMPOSE_VERSION)" -lt "$(ver $MIN_COMPOSE_VERSION)" ]]; then
110110
echo "FAIL: Expected minimum docker-compose version to be $MIN_COMPOSE_VERSION but found $COMPOSE_VERSION"
111111
exit 1
112112
fi
113113

114-
if [ "$RAM_AVAILABLE_IN_DOCKER" -lt "$MIN_RAM" ]; then
114+
if [[ "$RAM_AVAILABLE_IN_DOCKER" -lt "$MIN_RAM" ]]; then
115115
echo "FAIL: Expected minimum RAM available to Docker to be $MIN_RAM MB but found $RAM_AVAILABLE_IN_DOCKER MB"
116116
exit 1
117117
fi
118118

119119
#SSE4.2 required by Clickhouse (https://clickhouse.yandex/docs/en/operations/requirements/)
120120
# On KVM, cpuinfo could falsely not report SSE 4.2 support, so skip the check. https://github.com/ClickHouse/ClickHouse/issues/20#issuecomment-226849297
121121
IS_KVM=$(docker run --rm busybox grep -c 'Common KVM processor' /proc/cpuinfo || :)
122-
if (($IS_KVM == 0)); then
122+
if [[ "$IS_KVM" -eq 0 ]]; then
123123
SUPPORTS_SSE42=$(docker run --rm busybox grep -c sse4_2 /proc/cpuinfo || :)
124-
if (($SUPPORTS_SSE42 == 0)); then
124+
if [[ "$SUPPORTS_SSE42" -eq 0 ]]; then
125125
echo "FAIL: The CPU your machine is running on does not support the SSE 4.2 instruction set, which is required for one of the services Sentry uses (Clickhouse). See https://git.io/JvLDt for more info."
126126
exit 1
127127
fi
@@ -157,7 +157,7 @@ fi
157157

158158
replace_tsdb() {
159159
if (
160-
[ -f "$SENTRY_CONFIG_PY" ] &&
160+
[[ -f "$SENTRY_CONFIG_PY" ]] &&
161161
! grep -xq 'SENTRY_TSDB = "sentry.tsdb.redissnuba.RedisSnubaTSDB"' "$SENTRY_CONFIG_PY"
162162
); then
163163
# Do NOT indent the following string as it would be reflected in the end result,
@@ -218,7 +218,7 @@ $dc build --force-rm --parallel
218218
echo ""
219219
echo "Docker images built."
220220

221-
if [[ "$MINIMIZE_DOWNTIME" ]]; then
221+
if [[ -n "$MINIMIZE_DOWNTIME" ]]; then
222222
# Stop everything but relay and nginx
223223
$dc rm -fsv $($dc config --services | grep -v -E '^(nginx|relay)$')
224224
else
@@ -230,11 +230,11 @@ else
230230
fi
231231

232232
ZOOKEEPER_SNAPSHOT_FOLDER_EXISTS=$($dcr zookeeper bash -c 'ls 2>/dev/null -Ubad1 -- /var/lib/zookeeper/data/version-2 | wc -l | tr -d '[:space:]'')
233-
if [ "$ZOOKEEPER_SNAPSHOT_FOLDER_EXISTS" -eq "1" ]; then
233+
if [[ "$ZOOKEEPER_SNAPSHOT_FOLDER_EXISTS" -eq 1 ]]; then
234234
ZOOKEEPER_LOG_FILE_COUNT=$($dcr zookeeper bash -c 'ls 2>/dev/null -Ubad1 -- /var/lib/zookeeper/log/version-2/* | wc -l | tr -d '[:space:]'')
235235
ZOOKEEPER_SNAPSHOT_FILE_COUNT=$($dcr zookeeper bash -c 'ls 2>/dev/null -Ubad1 -- /var/lib/zookeeper/data/version-2/* | wc -l | tr -d '[:space:]'')
236236
# This is a workaround for a ZK upgrade bug: https://issues.apache.org/jira/browse/ZOOKEEPER-3056
237-
if [ "$ZOOKEEPER_LOG_FILE_COUNT" -gt "0" ] && [ "$ZOOKEEPER_SNAPSHOT_FILE_COUNT" -eq "0" ]; then
237+
if [[ "$ZOOKEEPER_LOG_FILE_COUNT" -gt 0 ]] && [[ "$ZOOKEEPER_SNAPSHOT_FILE_COUNT" -eq 0 ]]; then
238238
$dcr -v $(pwd)/zookeeper:/temp zookeeper bash -c 'cp /temp/snapshot.0 /var/lib/zookeeper/data/version-2/snapshot.0'
239239
$dc run -d -e ZOOKEEPER_SNAPSHOT_TRUST_EMPTY=true zookeeper
240240
fi
@@ -246,7 +246,7 @@ $dcr snuba-api migrations migrate --force
246246
echo ""
247247

248248
# Very naively check whether there's an existing sentry-postgres volume and the PG version in it
249-
if [[ $(docker volume ls -q --filter name=sentry-postgres) && $(docker run --rm -v sentry-postgres:/db busybox cat /db/PG_VERSION 2>/dev/null) == "9.5" ]]; then
249+
if [[ -n "$(docker volume ls -q --filter name=sentry-postgres)" && "$(docker run --rm -v sentry-postgres:/db busybox cat /db/PG_VERSION 2>/dev/null)" == "9.5" ]]; then
250250
docker volume rm sentry-postgres-new || true
251251
# If this is Postgres 9.5 data, start upgrading it to 9.6 in a new volume
252252
docker run --rm \
@@ -268,7 +268,7 @@ fi
268268

269269
echo ""
270270
echo "Setting up database..."
271-
if [ $CI ] || [ $SKIP_USER_PROMPT == 1 ]; then
271+
if [[ -n "$CI" || "$SKIP_USER_PROMPT" == 1 ]]; then
272272
$dcr web upgrade --noinput
273273
echo ""
274274
echo "Did not prompt for user creation due to non-interactive shell."
@@ -282,7 +282,7 @@ fi
282282

283283

284284
SENTRY_DATA_NEEDS_MIGRATION=$(docker run --rm -v sentry-data:/data alpine ash -c "[ ! -d '/data/files' ] && ls -A1x /data | wc -l || true")
285-
if [ "$SENTRY_DATA_NEEDS_MIGRATION" ]; then
285+
if [[ -n "$SENTRY_DATA_NEEDS_MIGRATION" ]]; then
286286
echo "Migrating file storage..."
287287
# Use the web (Sentry) image so the file owners are kept as sentry:sentry
288288
# The `\"` escape pattern is to make this compatible w/ Git Bash on Windows. See #329.
@@ -291,7 +291,7 @@ if [ "$SENTRY_DATA_NEEDS_MIGRATION" ]; then
291291
fi
292292

293293

294-
if [ ! -f "$RELAY_CREDENTIALS_JSON" ]; then
294+
if [[ ! -f "$RELAY_CREDENTIALS_JSON" ]]; then
295295
echo ""
296296
echo "Generating Relay credentials..."
297297

0 commit comments

Comments
 (0)