k2hdkc 1.0.13 → 2.0.0

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