forked from RediSearch/RediSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-redisjson
executable file
·195 lines (171 loc) · 5.09 KB
/
get-redisjson
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
#!/bin/bash
PROGNAME="${BASH_SOURCE[0]}"
HERE="$(cd "$(dirname "$PROGNAME")" &>/dev/null && pwd)"
ROOT=$(cd $HERE/.. && pwd)
READIES=$ROOT/deps/readies
. $READIES/shibumi/defs
if [[ $1 == --help || $1 == help || $HELP == 1 ]]; then
cat <<-'END'
Get RedisJSON module binaries
get-redisjson [--help|help]
Argument variables:
OSNICK=nick Get binaries for given `nick`
BRANCH=name Use given branch
OSS=1 Download JSON/OSS
REPO_PATH=dir Get binary artifacts from given repo `dir`
BUILD=0 Do not build if unable to download
FORCE=1 Download module even if already present
MODULE_FILE=file Write module path into `file`
NOP=1 No operation
HELP=1 Show help
END
exit 0
fi
MOD_NAME=RedisJSON
BRANCH=${BRANCH:-master}
OP=""
[[ $NOP == 1 ]] && OP=echo
os="$($READIES/bin/platform --os)"
arch="$($READIES/bin/platform --arch)"
if [[ -n $REPO_PATH ]]; then
platform="$($READIES/bin/platform -t)"
else
if [[ $os != linux && $os != macos ]]; then
if [[ BUILD == 0 ]]; then
eprint "Cannot match binary artifacts - build ${MOD_NAME} and set REPO_PATH"
exit 1
fi
echo "Cannot match binary artifacts - build ${MOD_NAME} and set REPO_PATH"
$ROOT/sbin/build-redisjson
exit $?
fi
dist="$($READIES/bin/platform --dist)"
nick="$($READIES/bin/platform --osnick)"
[[ $os == linux ]] && os=Linux
[[ $arch == x64 ]] && arch=x86_64
[[ $arch == arm64v8 ]] && arch=aarch64
if [[ $dist == ubuntu ]]; then
if [[ $nick == noble ]]; then
nick="ubuntu24.04"
elif [[ $nick == jammy ]]; then
nick="ubuntu22.04"
elif [[ $nick == focal ]]; then
nick="ubuntu20.04"
elif [[ $nick == bionic ]]; then
nick="ubuntu18.04"
elif [[ $nick == xenial ]]; then
nick="ubuntu16.04"
elif [[ $nick == trusty ]]; then
nick="ubuntu14.04"
else
nick="ubuntu18.04"
fi
elif [[ $dist == debian ]]; then
if [[ $nick == bookworm ]]; then
nick="ubuntu22.04"
elif [[ $nick == bullseye ]]; then
if [[ $arch == aarch64 ]]; then
nick="ubuntu20.04"
fi
fi
elif [[ $dist == centos || $dist == redhat || $dist == fedora || $dist == rocky ]]; then
if [[ $nick == centos9 || $nick == ol9 || $nick == rocky9 || $nick == rhel9 ]]; then
nick="rhel9"
elif [[ $nick == centos8 || $nick == rocky8 ]]; then
nick="rhel8"
else
nick="rhel7"
fi
elif [[ $dist == mariner ]]; then
OSS=1
if [[ $BRANCH == master ]]; then
# Mariner2 is created using github actions,
# for master branch the artifacts are uploaded to staging
STAGING=1
fi
elif [[ $os == macos ]]; then
# as we don't build on macOS for every platform, we converge to a least common denominator
if [[ $arch == x86_64 ]]; then
nick=catalina # to be aligned with the rest of the modules in redis stack
else
[[ $nick == ventura ]] && nick=monterey
[[ $nick == sonoma ]] && nick=monterey
fi
OSS=1
elif [[ -n $OSNICK ]]; then
nick=$OSNICK
OSS=1
else
OSS=1
fi
platform="${os}-${nick}-${arch}"
fi
if [[ $OSS == 1 ]]; then
STEM=rejson-oss
else
STEM=rejson
fi
if [[ $STAGING == 1 ]]; then
MOD_S3_URL="https://redismodules.s3.amazonaws.com/lab/staging/${STEM}/snapshots"
else
MOD_S3_URL="https://redismodules.s3.amazonaws.com/${STEM}/snapshots"
fi
MOD_RAMP="${STEM}.${platform}.${BRANCH}.zip"
if [[ $OSS == 1 && -z $REPO_PATH ]]; then
# fallback to old storage model
if ! wget -q --spider $WORK_DIR $MOD_S3_URL/$MOD_RAMP; then
STEM=rejson
MOD_S3_URL="http://redismodules.s3.amazonaws.com/${STEM}/snapshots"
MOD_RAMP="${STEM}.${platform}.$BRANCH.zip"
fi
fi
DEST_DIR="$ROOT/bin/$($READIES/bin/platform -t)/RedisJSON/${BRANCH}"
if [[ -n $MODULE_FILE ]]; then
echo "${DEST_DIR}/rejson.so" > $MODULE_FILE
fi
if [[ $FORCE != 1 && -d $DEST_DIR && -f $DEST_DIR/rejson.so ]]; then
echo "${MOD_NAME} is in ${DEST_DIR}:"
$OP du -ah --apparent-size $DEST_DIR
exit 0
fi
$OP mkdir -p $(dirname $DEST_DIR)
WORK_DIR=$(mktemp -d /tmp/${MOD_NAME}.XXXXXX)
if [[ -z $REPO_PATH ]]; then
F_MOD_RAMP="${WORK_DIR}/${MOD_RAMP}"
if [[ $FORCE == 1 || ! -f $F_MOD_RAMP ]]; then
# check if redisjson module exists in the s3 bucket
if wget -q --spider ${MOD_S3_URL}/${MOD_RAMP}; then
echo "Download ${MOD_NAME} [${MOD_S3_URL}/${MOD_RAMP}] ..."
runn wget -P ${WORK_DIR} ${MOD_S3_URL}/${MOD_RAMP}
else
if [[ $NOP != 1 ]]; then
if [[ BUILD == 0 ]]; then
eprint "Cannot download binary artifacts - build ${MOD_NAME} and set REPO_PATH"
exit 1
fi
echo "Cannot download binary artifacts - building ${MOD_NAME} from source."
$ROOT/sbin/build-redisjson
exit $?
fi
fi
fi
else
F_MOD_RAMP="${REPO_PATH}/bin/artifacts/snapshots/${MOD_RAMP}"
if [[ ! -f $F_MOD_RAMP ]]; then
eprint "$F_MOD_RAMP is missing - build ${MOD_NAME} and set REPO_PATH"
exit 1
fi
fi
runn unzip $F_MOD_RAMP -d $WORK_DIR
if [[ -e ${DEST_DIR} ]]; then
echo "Removing existing ${DEST_DIR}"
$OP rm -rf ${DEST_DIR}
fi
# $OP mv $WORK_DIR $DEST_DIR
runn rsync -a --no-owner --no-group --remove-source-files $WORK_DIR/* $DEST_DIR
echo "${MOD_NAME} installed into ${DEST_DIR}:"
if [[ $os == linux ]]; then
$OP du -ah --apparent-size $DEST_DIR
else
$OP du -ah $DEST_DIR
fi