k2hash 1.1.34 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,371 @@
1
+ #!/bin/sh
2
+ #
3
+ # K2HASH
4
+ #
5
+ # Copyright 2015 Yahoo Japan Corporation.
6
+ #
7
+ # K2HASH is key-valuew store base libraries.
8
+ # K2HASH is made for the purpose of the construction of
9
+ # original KVS system and the offer of the library.
10
+ # The characteristic is this KVS library which Key can
11
+ # layer. And can support multi-processing and multi-thread,
12
+ # and is provided safely as available KVS.
13
+ #
14
+ # For the full copyright and license information, please view
15
+ # the license file that was distributed with this source code.
16
+ #
17
+ # AUTHOR: Takeshi Nakatani
18
+ # CREATE: Wed 19 Nov 2025
19
+ # REVISION:
20
+ #
21
+
22
+ #==============================================================
23
+ # Node Prebuild Warpper
24
+ #==============================================================
25
+ #
26
+ # Instead of pipefail(for shells not support "set -o pipefail")
27
+ #
28
+ PIPEFAILURE_FILE="/tmp/.pipefailure.$(od -An -tu4 -N4 /dev/random | tr -d ' \n')"
29
+
30
+ #
31
+ # For shellcheck
32
+ #
33
+ if command -v locale >/dev/null 2>&1; then
34
+ if locale -a | grep -q -i '^[[:space:]]*C.utf8[[:space:]]*$'; then
35
+ LANG=$(locale -a | grep -i '^[[:space:]]*C.utf8[[:space:]]*$' | sed -e 's/^[[:space:]]*//g' -e 's/[[:space:]]*$//g' | tr -d '\n')
36
+ LC_ALL="${LANG}"
37
+ export LANG
38
+ export LC_ALL
39
+ elif locale -a | grep -q -i '^[[:space:]]*en_US.utf8[[:space:]]*$'; then
40
+ LANG=$(locale -a | grep -i '^[[:space:]]*en_US.utf8[[:space:]]*$' | sed -e 's/^[[:space:]]*//g' -e 's/[[:space:]]*$//g' | tr -d '\n')
41
+ LC_ALL="${LANG}"
42
+ export LANG
43
+ export LC_ALL
44
+ fi
45
+ fi
46
+
47
+ #==============================================================
48
+ # Variables
49
+ #==============================================================
50
+ #PRGNAME=$(basename "$0")
51
+ SCRIPTDIR=$(dirname "$0")
52
+ SCRIPTDIR=$(cd "${SCRIPTDIR}" || exit 1; pwd)
53
+ SRCTOP=$(cd "${SCRIPTDIR}"/.. || exit 1; pwd)
54
+
55
+ #
56
+ # Common variables
57
+ #
58
+ MAKE_VARS_FILE="make_node_prebuild_variables.sh"
59
+ MAKE_VARS_BIN="${SCRIPTDIR}/${MAKE_VARS_FILE}"
60
+ META_JSON_FILE="metadata.json"
61
+
62
+ #
63
+ # Variables for prebuild
64
+ #
65
+ PREBUILD_NAME="prebuild"
66
+ PREBUILD_PARAMTERS=$("${MAKE_VARS_BIN}" --prebuild-parameters)
67
+ PREBUILD_OUTPUT_DIR=$("${MAKE_VARS_BIN}" --output-dirname)
68
+ PREBUILD_OUTPUT_FILENAME=$("${MAKE_VARS_BIN}" --prebuild-filename)
69
+ RENAMED_FILENAME=$("${MAKE_VARS_BIN}" --tgz-filename)
70
+ SHA256_FILENAME=$("${MAKE_VARS_BIN}" --sha256-filename)
71
+ RENAMED_TAR_FILENAME=$(echo "${RENAMED_FILENAME}" | sed 's#\.tar\.gz$#\.tar#g')
72
+
73
+ #
74
+ # Variables for metadata.json
75
+ #
76
+ META_PKG_NAME=$("${MAKE_VARS_BIN}" --package-name)
77
+ META_PKG_VERSION=$("${MAKE_VARS_BIN}" --package-version)
78
+ META_FILENAME="${RENAMED_FILENAME}"
79
+ META_PLATFORM=$("${MAKE_VARS_BIN}" --platform-name)
80
+ META_DISTRO=$("${MAKE_VARS_BIN}" --distro-name)
81
+ META_DISTRO_VER=$("${MAKE_VARS_BIN}" --distro-version)
82
+ META_ARCH=$("${MAKE_VARS_BIN}" --architecture-name)
83
+ META_NODE_VER_MAJOR=$("${MAKE_VARS_BIN}" --node-major-version)
84
+ META_NODE_VER_FULL=$("${MAKE_VARS_BIN}" --node-version)
85
+ META_ABI_VER=$("${MAKE_VARS_BIN}" --node-abi-version)
86
+ META_NAPI_VER=$("${MAKE_VARS_BIN}" --napi-version)
87
+ META_LIBC_TYPE=$("${MAKE_VARS_BIN}" --libc-type)
88
+ META_BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
89
+
90
+ if command -v git >/dev/null 2>&1; then
91
+ META_GIT_HASH=$(git rev-parse --short HEAD 2>/dev/null)
92
+ else
93
+ META_GIT_HASH=""
94
+ fi
95
+
96
+ #==============================================================
97
+ # Utility functions and variables for messaging
98
+ #==============================================================
99
+ #
100
+ # Utilities for message
101
+ #
102
+ if [ -t 1 ] || { [ -n "${CI}" ] && [ "${CI}" = "true" ]; }; then
103
+ # CBLD=$(printf '\033[1m')
104
+ CREV=$(printf '\033[7m')
105
+ CRED=$(printf '\033[31m')
106
+ CYEL=$(printf '\033[33m')
107
+ CGRN=$(printf '\033[32m')
108
+ CDEF=$(printf '\033[0m')
109
+ else
110
+ # CBLD=""
111
+ CREV=""
112
+ CRED=""
113
+ CYEL=""
114
+ CGRN=""
115
+ CDEF=""
116
+ fi
117
+
118
+ PRNTITLE()
119
+ {
120
+ echo ""
121
+ echo "${CGRN}${CREV}[TITLE]${CDEF} ${CGRN}$*${CDEF}"
122
+ }
123
+
124
+ PRNMSG()
125
+ {
126
+ echo ""
127
+ echo "${CYEL}${CREV}[MSG]${CDEF} ${CYEL}$*${CDEF}"
128
+ }
129
+
130
+ PRNINFO()
131
+ {
132
+ echo "${CREV}[INFO]${CDEF} $*"
133
+ }
134
+
135
+ PRNWARN()
136
+ {
137
+ echo "${CYEL}${CREV}[WARNING]${CDEF} ${CYEL}$*${CDEF}"
138
+ }
139
+
140
+ PRNERR()
141
+ {
142
+ echo "${CRED}${CREV}[ERROR]${CDEF} ${CRED}$*${CDEF}"
143
+ }
144
+
145
+ PRNSUCCESS()
146
+ {
147
+ echo ""
148
+ echo "${CGRN}${CREV}[SUCCEED]${CDEF} ${CGRN}$*${CDEF}"
149
+ echo ""
150
+ }
151
+
152
+ #PRNFAILURE()
153
+ #{
154
+ # echo "${CBLD}${CRED}${CREV}[FAILURE]${CDEF} ${CRED}$*${CDEF}"
155
+ #}
156
+
157
+ #==============================================================
158
+ # Create binary package with metadata.json and sigunature file
159
+ #==============================================================
160
+ PRNTITLE "Create binary package with metadata.json and sigunature files"
161
+
162
+ #
163
+ # Check prebuild tool
164
+ #
165
+ if [ -x "${SRCTOP}/node_modules/.bin/${PREBUILD_NAME}" ]; then
166
+ PREBUILD_BIN="${SRCTOP}/node_modules/.bin/${PREBUILD_NAME}"
167
+ elif command -v "${PREBUILD_NAME}" >/dev/null 2>&1; then
168
+ PREBUILD_BIN="$(command -v ${PREBUILD_NAME})"
169
+ else
170
+ PRNERR "Not found ${PREBUILD_NAME} tool, please install it before run this script."
171
+ exit 1
172
+ fi
173
+
174
+ #
175
+ # Check output directory
176
+ #
177
+ if [ ! -d "${SRCTOP}/${PREBUILD_OUTPUT_DIR}" ]; then
178
+ if ! mkdir -p "${SRCTOP}/${PREBUILD_OUTPUT_DIR}" >/dev/null 2>&1; then
179
+ PRNERR "Could not create ${PREBUILD_OUTPUT_DIR} directory."
180
+ exit 1
181
+ fi
182
+ fi
183
+
184
+ #--------------------------------------------------------------
185
+ # Create binary package
186
+ #--------------------------------------------------------------
187
+ PRNMSG "Run prebuild: \"GYP_DEFINES=openssl_fips= ${PREBUILD_BIN} ${PREBUILD_PARAMTERS}\""
188
+
189
+ if ({ /bin/sh -c "GYP_DEFINES=openssl_fips= ${PREBUILD_BIN} ${PREBUILD_PARAMTERS}" 2>&1 || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's|^| |g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then
190
+ PRNERR "Failed to run ${PREBUILD_NAME}."
191
+ exit 1
192
+ fi
193
+
194
+ #
195
+ # Check output file
196
+ #
197
+ if [ ! -f "${SRCTOP}/${PREBUILD_OUTPUT_DIR}/${PREBUILD_OUTPUT_FILENAME}" ]; then
198
+ PRNERR "Not found ${PREBUILD_OUTPUT_FILENAME} file in ${PREBUILD_OUTPUT_DIR} directory."
199
+ exit 1
200
+ fi
201
+
202
+ PRNINFO "Succeed to run prebuild"
203
+
204
+ #--------------------------------------------------------------
205
+ # Make temporary directory and Extract tgz and Make metadata.json
206
+ #--------------------------------------------------------------
207
+ PRNMSG "Re-pack binary file with metadata.json"
208
+
209
+ #
210
+ # Create work directory
211
+ #
212
+ _TMP_DIR=$(mktemp -d)
213
+ _CUR_DIR=$(pwd)
214
+ cd "${_TMP_DIR}" || exit 1
215
+
216
+ #
217
+ # Extract tgz file
218
+ #
219
+ if ! tar xvfz "${SRCTOP}/${PREBUILD_OUTPUT_DIR}/${PREBUILD_OUTPUT_FILENAME}" >/dev/null 2>&1; then
220
+ PRNERR "Failed to extract ${PREBUILD_OUTPUT_FILENAME} to ${_TMP_DIR}."
221
+ exit 1
222
+ fi
223
+
224
+ #
225
+ # Create metadata.json
226
+ #
227
+ {
228
+ echo '{'
229
+ echo " \"module\": \"${META_PKG_NAME}\","
230
+ echo " \"version\": \"${META_PKG_VERSION}\","
231
+ echo " \"filename\": \"${META_FILENAME}\","
232
+ echo " \"platform\": \"${META_PLATFORM}\","
233
+
234
+ if [ -n "${META_DISTRO}" ]; then
235
+ echo " \"distro\": \"${META_DISTRO}\","
236
+
237
+ if [ -n "${META_DISTRO_VER}" ]; then
238
+ echo " \"distro_version\": \"${META_DISTRO_VER}\","
239
+ fi
240
+ fi
241
+
242
+ echo " \"arch\": \"${META_ARCH}\","
243
+ echo " \"node_major\": \"${META_NODE_VER_MAJOR}\","
244
+ echo " \"node_full\": \"${META_NODE_VER_FULL}\","
245
+ echo " \"abi\": \"${META_ABI_VER}\","
246
+ echo " \"napi\": \"${META_NAPI_VER}\","
247
+ echo " \"libc\": \"${META_LIBC_TYPE}\","
248
+ echo " \"build_date\": \"${META_BUILD_DATE}\","
249
+
250
+ if [ -n "${META_GIT_HASH}" ]; then
251
+ echo " \"git_commit\": \"${META_GIT_HASH}\","
252
+ fi
253
+
254
+ echo ' "builder": "AntPickax Node addon prebuild helper"'
255
+ echo '}'
256
+ } > "${META_JSON_FILE}"
257
+
258
+ PRNINFO "Created ${META_JSON_FILE}:"
259
+ sed -e 's#^# #g' "${META_JSON_FILE}"
260
+ echo ""
261
+
262
+ #
263
+ # Set file permission
264
+ #
265
+ _TMP_ALL_FILES=$(find . -type f 2>/dev/null)
266
+ _TMP_ALL_TARGETS=""
267
+ for _ONE_FILE in ${_TMP_ALL_FILES}; do
268
+ if echo "${_ONE_FILE}" | grep -q '\.node$'; then
269
+ # *.node file
270
+ if ! chmod 0755 "${_ONE_FILE}" >/dev/null 2>&1; then
271
+ PRNERR "Could not change permission 0755 to ${_ONE_FILE}."
272
+ exit 1
273
+ fi
274
+ else
275
+ # other file
276
+ if ! chmod 0644 "${_ONE_FILE}" >/dev/null 2>&1; then
277
+ PRNERR "Could not change permission 0644 to ${_ONE_FILE}."
278
+ exit 1
279
+ fi
280
+ fi
281
+ _TMP_ALL_TARGETS="${_TMP_ALL_TARGETS} ${_ONE_FILE}"
282
+ done
283
+
284
+ #
285
+ # Recompress with metadata.json
286
+ #
287
+ if [ -f "${SRCTOP}/${PREBUILD_OUTPUT_DIR}/${RENAMED_FILENAME}" ]; then
288
+ PRNWARN "Found ${RENAMED_FILENAME} file in ${PREBUILD_OUTPUT_DIR} directory, so try to remove it."
289
+ rm -f "${SRCTOP}/${PREBUILD_OUTPUT_DIR}/${RENAMED_FILENAME}" >/dev/null 2>&1
290
+ fi
291
+
292
+ if ! /bin/sh -c "tar --owner=0 --group=0 -C ${_TMP_DIR} -cvf - ${_TMP_ALL_TARGETS} | gzip - > ${SRCTOP}/${PREBUILD_OUTPUT_DIR}/${RENAMED_FILENAME}" >/dev/null 2>&1; then
293
+ PRNERR "Failed to compress(gip) ${RENAMED_TAR_FILENAME} file."
294
+ exit 1
295
+ fi
296
+
297
+ #
298
+ # Remove original tgz file(created by prebuild)
299
+ #
300
+ rm -f "${SRCTOP}/${PREBUILD_OUTPUT_DIR}/${PREBUILD_OUTPUT_FILENAME}" >/dev/null 2>&1
301
+
302
+ #
303
+ # Cleanup
304
+ #
305
+ cd "${_CUR_DIR}" || exit 1
306
+ rm -rf "${_TMP_DIR}" >/dev/null 2>&1
307
+
308
+ PRNINFO "Succeed to re-pack binary file with metadata.json"
309
+
310
+ #--------------------------------------------------------------
311
+ # Create signature(SHA256) for binary package
312
+ #--------------------------------------------------------------
313
+ PRNMSG "Create signature(SHA256) for binary package"
314
+
315
+ _CUR_DIR=$(pwd)
316
+ cd "${SRCTOP}/${PREBUILD_OUTPUT_DIR}" || exit 1
317
+
318
+ if ! sha256sum "${RENAMED_FILENAME}" > "${SHA256_FILENAME}" 2>/dev/null; then
319
+ PRNERR "Failed to create signature(SHA256) for binary package"
320
+ exit 1
321
+ fi
322
+ cd "${_CUR_DIR}" || exit 1
323
+
324
+ PRNINFO "Succeed to create signature(SHA256) for binary package"
325
+
326
+ #--------------------------------------------------------------
327
+ # Run build:ts
328
+ #--------------------------------------------------------------
329
+ PRNMSG "Run build:ts"
330
+
331
+ # [NOTE]
332
+ # When run prebuild, the build directory is recreated, so the
333
+ # type information file(index.js) will no longer exist.
334
+ # Therefore, we need to run npm run build:ts to recreate the
335
+ # necessary files.
336
+ #
337
+ if ({ npm run build:ts 2>&1 || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's|^| |g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then
338
+ PRNERR "Failed to run build:ts."
339
+ exit 1
340
+ fi
341
+
342
+ PRNINFO "Succeed to run build:ts"
343
+
344
+ #==============================================================
345
+ # Finished and Print messages
346
+ #==============================================================
347
+ PRNSUCCESS "Created binary package with metadata.json and sigunature files"
348
+
349
+ echo " ${CGRN}Directory${CDEF}: ${PREBUILD_OUTPUT_DIR}"
350
+ echo " ${CGRN}Binary file${CDEF}: ${RENAMED_FILENAME}"
351
+ if ({ tar tvfz "${SRCTOP}/${PREBUILD_OUTPUT_DIR}/${RENAMED_FILENAME}" 2>&1 || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's|^| |g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then
352
+ PRNERR "Failed to unzip ${RENAMED_FILENAME}"
353
+ exit 1
354
+ fi
355
+ echo " ${CGRN}Signature file${CDEF}: ${SHA256_FILENAME}"
356
+ if ({ cat "${SRCTOP}/${PREBUILD_OUTPUT_DIR}/${SHA256_FILENAME}" 2>&1 || echo > "${PIPEFAILURE_FILE}"; } | sed -e 's|^| |g') && rm "${PIPEFAILURE_FILE}" >/dev/null 2>&1; then
357
+ PRNERR "Failed to dump ${SHA256_FILENAME}"
358
+ exit 1
359
+ fi
360
+ echo ""
361
+
362
+ exit 0
363
+
364
+ #
365
+ # Local variables:
366
+ # tab-width: 4
367
+ # c-basic-offset: 4
368
+ # End:
369
+ # vim600: noexpandtab sw=4 ts=4 fdm=marker
370
+ # vim<600: noexpandtab sw=4 ts=4
371
+ #
@@ -0,0 +1,307 @@
1
+ #!/bin/sh
2
+ #
3
+ # K2HASH
4
+ #
5
+ # Copyright 2015 Yahoo Japan Corporation.
6
+ #
7
+ # K2HASH is key-valuew store base libraries.
8
+ # K2HASH is made for the purpose of the construction of
9
+ # original KVS system and the offer of the library.
10
+ # The characteristic is this KVS library which Key can
11
+ # layer. And can support multi-processing and multi-thread,
12
+ # and is provided safely as available KVS.
13
+ #
14
+ # For the full copyright and license information, please view
15
+ # the license file that was distributed with this source code.
16
+ #
17
+ # AUTHOR: Takeshi Nakatani
18
+ # CREATE: Wed 19 Nov 2025
19
+ # REVISION:
20
+ #
21
+
22
+ #==============================================================
23
+ # Node Prebuild Warpper
24
+ #==============================================================
25
+ #
26
+ # Instead of pipefail(for shells not support "set -o pipefail")
27
+ #
28
+ #PIPEFAILURE_FILE="/tmp/.pipefailure.$(od -An -tu4 -N4 /dev/random | tr -d ' \n')"
29
+
30
+ #
31
+ # For shellcheck
32
+ #
33
+ if command -v locale >/dev/null 2>&1; then
34
+ if locale -a | grep -q -i '^[[:space:]]*C.utf8[[:space:]]*$'; then
35
+ LANG=$(locale -a | grep -i '^[[:space:]]*C.utf8[[:space:]]*$' | sed -e 's/^[[:space:]]*//g' -e 's/[[:space:]]*$//g' | tr -d '\n')
36
+ LC_ALL="${LANG}"
37
+ export LANG
38
+ export LC_ALL
39
+ elif locale -a | grep -q -i '^[[:space:]]*en_US.utf8[[:space:]]*$'; then
40
+ LANG=$(locale -a | grep -i '^[[:space:]]*en_US.utf8[[:space:]]*$' | sed -e 's/^[[:space:]]*//g' -e 's/[[:space:]]*$//g' | tr -d '\n')
41
+ LC_ALL="${LANG}"
42
+ export LANG
43
+ export LC_ALL
44
+ fi
45
+ fi
46
+
47
+ #==============================================================
48
+ # Variables
49
+ #==============================================================
50
+ #PRGNAME=$(basename "$0")
51
+ SCRIPTDIR=$(dirname "$0")
52
+ SCRIPTDIR=$(cd "${SCRIPTDIR}" || exit 1; pwd)
53
+ SRCTOP=$(cd "${SCRIPTDIR}"/.. || exit 1; pwd)
54
+
55
+ #
56
+ # Common variables
57
+ #
58
+ MAKE_VARS_FILE="make_node_prebuild_variables.sh"
59
+ MAKE_VARS_BIN="${SCRIPTDIR}/${MAKE_VARS_FILE}"
60
+ META_JSON_FILE="metadata.json"
61
+
62
+ #
63
+ # Variables
64
+ #
65
+ ASSET_TGZ_FILENAME=$("${MAKE_VARS_BIN}" --tgz-filename)
66
+ ASSET_SHA256_FILENAME=$("${MAKE_VARS_BIN}" --sha256-filename)
67
+ ASSET_TGZ_DOWNLOAD_URL=$("${MAKE_VARS_BIN}" --tgz-download-url)
68
+ ASSET_SHA256_DOWNLOAD_URL=$("${MAKE_VARS_BIN}" --sha256-download-url)
69
+
70
+ #==============================================================
71
+ # Utility functions and variables for messaging
72
+ #==============================================================
73
+ #
74
+ # Utilities for message
75
+ #
76
+ if [ -t 1 ] || { [ -n "${CI}" ] && [ "${CI}" = "true" ]; }; then
77
+ # CBLD=$(printf '\033[1m')
78
+ # CREV=$(printf '\033[7m')
79
+ # CRED=$(printf '\033[31m')
80
+ # CYEL=$(printf '\033[33m')
81
+ CGRN=$(printf '\033[32m')
82
+ CDEF=$(printf '\033[0m')
83
+ else
84
+ # CBLD=""
85
+ # CREV=""
86
+ # CRED=""
87
+ # CYEL=""
88
+ CGRN=""
89
+ CDEF=""
90
+ fi
91
+
92
+ PRNTITLE()
93
+ {
94
+ echo ""
95
+ echo "${CGRN}[TITLE]${CDEF} ${CGRN}$*${CDEF}"
96
+ }
97
+
98
+ PRNINFO()
99
+ {
100
+ echo "[INFO] $*"
101
+ }
102
+
103
+ PRNSUCCESS()
104
+ {
105
+ echo ""
106
+ echo "${CGRN}[SUCCEED]${CDEF} ${CGRN}$*${CDEF}"
107
+ echo ""
108
+ }
109
+
110
+ #==============================================================
111
+ # Utility functons
112
+ #==============================================================
113
+ #
114
+ # Check binary tgz file in local and Setup it
115
+ #
116
+ check_and_setup_local_asset_file()
117
+ {
118
+ if [ ! -f "${SRCTOP}/build/Assets/${ASSET_TGZ_FILENAME}" ]; then
119
+ PRNINFO "Not found ${ASSET_TGZ_FILENAME} in build/Assets directory."
120
+ return 1
121
+ fi
122
+
123
+ #
124
+ # Exract file from tgz file
125
+ #
126
+ _CUR_DIR=$(pwd)
127
+ cd "${SRCTOP}" || exit 1
128
+ if ! tar xvfz "${SRCTOP}/build/Assets/${ASSET_TGZ_FILENAME}" >/dev/null 2>&1; then
129
+ PRNINFO "Could not extract files from ${ASSET_TGZ_FILENAME} file."
130
+ cd "${_CUR_DIR}" || exit 1
131
+ return 1
132
+ fi
133
+ cd "${_CUR_DIR}" || exit 1
134
+
135
+ #
136
+ # metadata.json file
137
+ #
138
+ if [ ! -f "${SRCTOP}/${META_JSON_FILE}" ]; then
139
+ PRNINFO "Not found ${META_JSON_FILE} file."
140
+ return 1
141
+ fi
142
+
143
+ #
144
+ # Print binary file information
145
+ #
146
+ PRNINFO "Seup local asset file:"
147
+ sed -e 's#^# #g' "${SRCTOP}/${META_JSON_FILE}" 2>/dev/null
148
+ echo ""
149
+
150
+ return 0
151
+ }
152
+
153
+ #
154
+ # Download asset files and Install it
155
+ #
156
+ check_and_download_asset_file()
157
+ {
158
+ #
159
+ # Check curl
160
+ #
161
+ if ! CURLCMD=$(command -v curl); then
162
+ PRNINFO "Not found curl command"
163
+ return 1
164
+ fi
165
+
166
+ #
167
+ # Download TGZ and sha256 file
168
+ #
169
+ if ! _RESULT_CODE=$("${CURLCMD}" -s -S -L -w '%{http_code}' -o "${SRCTOP}/${ASSET_TGZ_FILENAME}" -X GET "${ASSET_TGZ_DOWNLOAD_URL}" --insecure); then
170
+ PRNINFO "Failed to get download tgz file(${ASSET_TGZ_FILENAME})."
171
+ rm -f "${SRCTOP}/${ASSET_TGZ_FILENAME}" 2>/dev/null
172
+ return 1
173
+ fi
174
+ if [ -z "${_RESULT_CODE}" ] || [ "${_RESULT_CODE}" -ne 200 ]; then
175
+ PRNINFO "Not found ${ASSET_TGZ_FILENAME}(http status code: (${_RESULT_CODE})."
176
+ rm -f "${SRCTOP}/${ASSET_TGZ_FILENAME}" 2>/dev/null
177
+ return 1
178
+ fi
179
+ if [ ! -f "${SRCTOP}/${ASSET_TGZ_FILENAME}" ]; then
180
+ PRNINFO "Not found ${ASSET_TGZ_FILENAME} file."
181
+ return 1
182
+ fi
183
+ if ! _RESULT_CODE=$("${CURLCMD}" -s -S -L -w '%{http_code}' -o "${SRCTOP}/${ASSET_SHA256_FILENAME}" -X GET "${ASSET_SHA256_DOWNLOAD_URL}" --insecure); then
184
+ PRNINFO "Failed to get sha256 file(${ASSET_SHA256_FILENAME})."
185
+ rm -f "${SRCTOP}/${ASSET_SHA256_FILENAME}" 2>/dev/null
186
+ return 1
187
+ fi
188
+ if [ -z "${_RESULT_CODE}" ] || [ "${_RESULT_CODE}" -ne 200 ]; then
189
+ PRNINFO "Not found ${ASSET_SHA256_FILENAME}(http status code: ${_RESULT_CODE})."
190
+ rm -f "${SRCTOP}/${ASSET_SHA256_FILENAME}" 2>/dev/null
191
+ return 1
192
+ fi
193
+ if [ ! -f "${SRCTOP}/${ASSET_SHA256_FILENAME}" ]; then
194
+ PRNINFO "Not found ${ASSET_SHA256_FILENAME} file."
195
+ return 1
196
+ fi
197
+
198
+ #
199
+ # Check sha256
200
+ #
201
+ SHA256_VALUE=$(awk '{print $1}' "${SRCTOP}/${ASSET_SHA256_FILENAME}" 2>/dev/null | tr -d '\n')
202
+ if ! DL_TGZ_SHA256_VALUE=$(sha256sum "${SRCTOP}/${ASSET_TGZ_FILENAME}" 2>/dev/null | awk '{print $1}' 2>/dev/null | tr -d '\n'); then
203
+ PRNINFO "Failed to make sha256 value from download tgz file."
204
+ return 1
205
+ fi
206
+ if [ -z "${SHA256_VALUE}" ] || [ -z "${DL_TGZ_SHA256_VALUE}" ] || [ "${SHA256_VALUE}" != "${DL_TGZ_SHA256_VALUE}" ]; then
207
+ PRNINFO "The sha256 value of the downloaded tgz file is incorrect."
208
+ return 1
209
+ fi
210
+
211
+ #
212
+ # Exract file from tgz file
213
+ #
214
+ _CUR_DIR=$(pwd)
215
+ cd "${SRCTOP}" || exit 1
216
+ if ! tar xvfz "${SRCTOP}/${ASSET_TGZ_FILENAME}" >/dev/null 2>&1; then
217
+ PRNINFO "Could not extract files from ${ASSET_TGZ_FILENAME} file."
218
+ cd "${_CUR_DIR}" || exit 1
219
+ return 1
220
+ fi
221
+ cd "${_CUR_DIR}" || exit 1
222
+
223
+ #
224
+ # metadata.json file
225
+ #
226
+ if [ ! -f "${SRCTOP}/${META_JSON_FILE}" ]; then
227
+ PRNINFO "Not found ${META_JSON_FILE} file."
228
+ return 1
229
+ fi
230
+
231
+ #
232
+ # Print binary file information
233
+ #
234
+ PRNINFO "Download asset file:"
235
+ sed -e 's#^# #g' "${SRCTOP}/${META_JSON_FILE}" 2>/dev/null
236
+ echo ""
237
+
238
+ return 0
239
+ }
240
+
241
+ #==============================================================
242
+ # Check environments
243
+ #==============================================================
244
+ # [NOTE]
245
+ # If ANTPICKAX_SKIP_PREBUILD_INSTALL is set (true/1), it will
246
+ # return the same result as if the binary was found.
247
+ #
248
+ if [ -n "${ANTPICKAX_SKIP_PREBUILD_INSTALL}" ] && echo "${ANTPICKAX_SKIP_PREBUILD_INSTALL}" | grep -q -i -e 'true' -e '1'; then
249
+ #
250
+ # Skip all check
251
+ #
252
+ PRNSUCCESS "\"ANTPICKAX_SKIP_PREBUILD_INSTALL\" environment is set, so no binaries check and skip prebuild-install."
253
+ exit 0
254
+ fi
255
+
256
+ #==============================================================
257
+ # Check local binary files
258
+ #==============================================================
259
+ PRNTITLE "Check local binary files"
260
+
261
+ # [NOTE]
262
+ # Check *.node in build/Release directory
263
+ #
264
+ if [ -d "${SRCTOP}/build/Release" ] && find "${SRCTOP}/build/Release" -maxdepth 1 -name \*.node -print -quit | grep -q .; then
265
+ PRNSUCCESS "Found local binary files."
266
+ exit 0
267
+ fi
268
+ PRNINFO "Not found local binary files."
269
+
270
+ #==============================================================
271
+ # Check binary tgz file in NPM package
272
+ #==============================================================
273
+ PRNTITLE "Check local asset file and Setup it"
274
+
275
+ if check_and_setup_local_asset_file; then
276
+ PRNSUCCESS "Downloaded and Installed binaries from github asset."
277
+ exit 0
278
+ fi
279
+ PRNINFO "Could not find local asset file or setup it."
280
+
281
+ #==============================================================
282
+ # Check asset file and Download it
283
+ #==============================================================
284
+ PRNTITLE "Check asset file and Download it"
285
+
286
+ if check_and_download_asset_file; then
287
+ PRNSUCCESS "Downloaded and Installed binaries from github asset."
288
+ exit 0
289
+ fi
290
+ PRNINFO "Could not download or install binaries from github asset."
291
+
292
+ #==============================================================
293
+ # Finished all check
294
+ #==============================================================
295
+ PRNINFO "Need to build all binaries locally, because neither local nor asset file installations worked."
296
+ echo ""
297
+
298
+ exit 1
299
+
300
+ #
301
+ # Local variables:
302
+ # tab-width: 4
303
+ # c-basic-offset: 4
304
+ # End:
305
+ # vim600: noexpandtab sw=4 ts=4 fdm=marker
306
+ # vim<600: noexpandtab sw=4 ts=4
307
+ #
package/index.js CHANGED
@@ -20,7 +20,10 @@
20
20
 
21
21
  'use strict';
22
22
 
23
- module.exports = require('bindings')('k2hash');
23
+ //
24
+ // Thin CommonJS re-export to built CJS artifact (safe for existing users)
25
+ //
26
+ module.exports = require('./build/cjs/index.js');
24
27
 
25
28
  /*
26
29
  * Local variables: