forked from dashingsoft/pyarmor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-header.sh
More file actions
executable file
·432 lines (397 loc) · 13.6 KB
/
test-header.sh
File metadata and controls
executable file
·432 lines (397 loc) · 13.6 KB
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
#! /bin/bash
SED=sed
AWK=gawk
SHA256SUM=sha256sum
UNAME=$(uname)
if [[ ${UNAME:0:5} == Linux ]] ; then
if [[ $(arch) == x86_64 ]] ; then
PLATFORM=linux_x86_64
else
PLATFORM=linux_i386
fi
PKGEXT=tar.bz2
DLLEXT=.so
ARMOR=./pyarmor
else
if [[ $(uname) == Darwin ]] ; then
PLATFORM=macosx_x86_64
PKGEXT=tar.bz2
DLLEXT=.dylib
ARMOR=./pyarmor
SED=gsed
AWK=awk
SHA256SUM="shasum -a 256"
else
if [[ $(arch) == x86_64 ]] ; then
PLATFORM=win_amd64
else
PLATFORM=win32
fi
PKGEXT=zip
DLLEXT=.dll
ARMOR=./pyarmor.bat
fi
fi
# From pyarmor 3.5.1, dist is moved to top level
DIST="../dist"
[[ -d "../dist" ]] || DIST="../src/dist"
filename=$(cd ${DIST}; ls -t pyarmor-*.${PKGEXT}) || exit 1
version=${filename:8:6}
if [[ "${version:5:1}" == "." ]] ; then
version=${filename:8:5}
fi
workpath=__runtest2__
pkgfile=$(pwd)/${DIST}/pyarmor-${version}.${PKGEXT}
declare -i _bug_counter=0
PYARMOR_CORE_PLATFORM=~/workspace/pyarmor-core/platforms
case ${PLATFORM} in
win32)
PYTHON=${PYTHON:-C:/Python26/python}
PYARMOR_CORE_PLATFORM=D:/projects/pyarmor-core/platforms
declare -r harddisk_sn=013040BP2N80S13FJNT5
declare -r ifmac_address=70:f1:a1:23:f0:94
declare -r ifip_address=192.168.121.101
declare -r domain_name=
;;
win_amd64)
PYTHON=${PYTHON:-C:/Python26/python}
PYARMOR_CORE_PLATFORM=C:/workspace/pyarmor-core/platforms
declare -r harddisk_sn=BV2adfe08e4-84c2a1d
declare -r ifmac_address=08:00:27:51:d9:fe
declare -r ifip_address=192.168.121.112
declare -r domain_name=
;;
linux_i386)
PYTHON=${PYTHON:-python}
declare -r harddisk_sn=VB07ab3ff6-81eb5787
declare -r ifname=enp0s3
declare -r ifmac_address=08:00:27:88:4b:88
declare -r ifip_address=192.168.121.106
declare -r domain_name=
;;
linux_x86_64)
PYTHON=${PYTHON:-python}
declare -r harddisk_sn=9WK3FEMQ
declare -r ifname=eth0
declare -r ifmac_address=00:23:8b:e0:4f:a7
declare -r ifip_address=192.168.121.103
declare -r domain_name=
;;
macosx_x86_64)
PYTHON=${PYTHON:-python}
# declare -r harddisk_sn=VB85de09d4-23402b07
# declare -r ifmac_address=08:00:27:b0:b3:94
declare -r harddisk_sn=FV994730S6LLF07AY
declare -r ifmac_address=f8:ff:c2:27:00:7f
declare -r ifip_address=$(ipconfig getifaddr en0)
declare -r domain_name=
;;
*)
echo Unknown platform "${PLATFORM}"
exit 1
esac
# ======================================================================
# csih routines
# ======================================================================
_csih_trace=
_csih_ERROR_STR_COLOR="\e[1;31m*** ERROR:\e[0;0m"
_csih_WARN_STR_COLOR="\e[1;33m*** Warning:\e[0;0m"
_csih_INFO_STR_COLOR="\e[1;32m*** Info:\e[0;0m"
_csih_QUERY_STR_COLOR="\e[1;35m*** Query:\e[0;0m"
_csih_STACKTRACE_STR_COLOR="\e[1;36m*** STACKTRACE:\e[0;0m"
readonly _csih_ERROR_STR_COLOR _csih_WARN_STR_COLOR
readonly _csih_INFO_STR_COLOR _csih_QUERY_STR_COLOR _csih_STACKTRACE_STR_COLOR
_csih_ERROR_STR_PLAIN="*** ERROR:"
_csih_WARN_STR_PLAIN="*** Warning:"
_csih_INFO_STR_PLAIN="*** Info:"
_csih_QUERY_STR_PLAIN="*** Query:"
_csih_STACKTRACE_STR_PLAIN="*** STACKTRACE:"
readonly _csih_ERROR_STR_PLAIN _csih_WARN_STR_PLAIN
readonly _csih_INFO_STR_PLAIN _csih_QUERY_STR_PLAIN _csih_STACKTRACE_STR_PLAIN
_csih_ERROR_STR="${_csih_ERROR_STR_COLOR}"
_csih_WARN_STR="${_csih_WARN_STR_COLOR}"
_csih_INFO_STR="${_csih_INFO_STR_COLOR}"
_csih_QUERY_STR="${_csih_QUERY_STR_COLOR}"
_csih_STACKTRACE_STR="${_csih_STACKTRACE_STR_COLOR}"
# ======================================================================
# Routine: csih_disable_color
# Provided so that scripts which are invoked via postinstall
# can prevent escape codes from showing up in /var/log/setup.log
# ======================================================================
csih_disable_color()
{
_csih_ERROR_STR="${_csih_ERROR_STR_PLAIN}"
_csih_WARN_STR="${_csih_WARN_STR_PLAIN}"
_csih_INFO_STR="${_csih_INFO_STR_PLAIN}"
_csih_QUERY_STR="${_csih_QUERY_STR_PLAIN}"
_csih_STACKTRACE_STR="${_csih_STACKTRACE_STR_PLAIN}"
} # === End of csih_disable_color() === #
readonly -f csih_disable_color
# ======================================================================
# Routine: csih_stacktrace
# ======================================================================
csih_stacktrace()
{
set +x # don''t trace this!
local -i n=$(( ${#FUNCNAME} - 1 ))
local val=""
if [ -n "$_csih_trace" ]
then
while [ $n -gt 0 ]
do
if [ -n "${FUNCNAME[$n]}" ]
then
if [ -z "$val" ]
then
val="${FUNCNAME[$n]}[${BASH_LINENO[$(($n-1))]}]"
else
val="${val}->${FUNCNAME[$n]}[${BASH_LINENO[$(($n-1))]}]"
fi
fi
n=$(($n-1))
done
echo -e "${_csih_STACKTRACE_STR} ${val} ${@}"
fi
} # === End of csih_stacktrace() === #
readonly -f csih_stacktrace
# ======================================================================
# Routine: csih_trace_on
# turns on shell tracing of csih functions
# ======================================================================
csih_trace_on()
{
_csih_trace='set -x'
trap 'csih_stacktrace "returning with" $?; set -x' RETURN
set -T
csih_stacktrace "${@}"
} # === End of csih_trace_on() === #
readonly -f csih_trace_on
# ======================================================================
# Routine: csih_trace_off
# turns off shell tracing of csih functions
# ======================================================================
csih_trace_off()
{
trap '' RETURN
csih_stacktrace "${@}"
_csih_trace=
set +x
set +T
} # === End of csih_trace_off() === #
readonly -f csih_trace_off
# ======================================================================
# Routine: csih_error
# Prints the (optional) error message $1, then
# Exits with the error code contained in $? if $? is non-zero, otherwise
# exits with status 1
# All other arguments are ignored
# Example: csih_error "missing file"
# NEVER RETURNS
# ======================================================================
csih_error()
{
local errorcode=$?
set +x # don't trace this, but we are interested in who called
csih_stacktrace # we'll see the arguments in the next statement
if ((errorcode == 0))
then
errorcode=1
fi
echo -e "${_csih_ERROR_STR} ${1:-no error message provided}"
exit ${errorcode};
} # === End of csih_error() === #
readonly -f csih_error
# ======================================================================
# Routine: csih_error_multi
# Prints the (optional) error messages in the positional arguments, one
# per line, and then
# Exits with the error code contained in $? if $? is non-zero, otherwise
# exits with status 1
# All other arguments are ignored
# Example: csih_error_multi "missing file" "see documentation"
# NEVER RETURNS
# ======================================================================
csih_error_multi()
{
local errorcode=$?
set +x # don't trace this, but we are interested in who called
csih_stacktrace # we'll see the arguments in the next statement
if ((errorcode == 0))
then
errorcode=1
fi
while test $# -gt 1
do
echo -e "${_csih_ERROR_STR} ${1}"
shift
done
echo -e "${_csih_ERROR_STR} ${1:-no error message provided}"
exit ${errorcode};
} # === End of csih_error_multi() === #
readonly -f csih_error_multi
# ======================================================================
# Routine: csih_error_recoverable
# Prints the supplied errormessage, and propagates the $? value
# Example: csih_error_recoverable "an error message"
# ======================================================================
csih_error_recoverable()
{
local errorcode=$?
set +x # don't trace this, but we are interested in who called
csih_stacktrace # we'll see the arguments in the next statement
echo -e "${_csih_ERROR_STR} ${1}"
$_csih_trace
return $errorcode
} # === End of csih_error_recoverable() === #
readonly -f csih_error_recoverable
# ======================================================================
# Routine: csih_warning
# Prints the supplied warning message
# Example: csih_warning "replacing default file foo"
# ======================================================================
csih_warning()
{
set +x # don't trace this, but we are interested in who called
csih_stacktrace # we'll see the arguments in the next statement
echo -e "${_csih_WARN_STR} ${1}"
$_csih_trace
} # === End of csih_warning() === #
readonly -f csih_warning
# ======================================================================
# Routine: csih_inform
# Prints the supplied informational message
# Example: csih_inform "beginning dependency analysis..."
# ======================================================================
csih_inform()
{
set +x # don't trace this, but we are interested in who called
csih_stacktrace # we'll see the arguments in the next statement
echo -e "${_csih_INFO_STR} ${1}"
$_csih_trace
} # === End of csih_inform() === #
readonly -f csih_inform
# ======================================================================
# Routine: csih_bug
# Prints the supplied warning message and increase bug counter
# ======================================================================
csih_bug()
{
let _bug_counter++
set +x # don't trace this, but we are interested in who called
csih_stacktrace # we'll see the arguments in the next statement
echo -e "${_csih_WARN_STR} ${1}"
$_csih_trace
} # === End of csih_bug() === #
readonly -f csih_bug
# ======================================================================
# Routine: next_month
# Print next month
# ======================================================================
next_month()
{
let -i _year=10#$(date +%Y)
let -i _month=10#$(date +%m)
if (( _month == 12 )) ; then
let _year++
let _month=1
else
let _month++
fi
if (( _month > 9 )) ; then
month="${_month}"
else
month="0${_month}"
fi
echo -e "${_year}-${month}-01"
} # === End of next_month() === #
readonly -f next_month
# ======================================================================
# Routine: check_file_exists
# Write a bug if file doesn't exists
# Example: check_file_exists dist/foo.py
# ======================================================================
check_file_exists()
{
[[ -f "$1" ]] || csih_bug "no $1 found"
}
# ======================================================================
# Routine: check_file_not_exists
# Write a bug if file exists
# Example: check_file_not_exists dist/foo.py
# ======================================================================
check_file_not_exists()
{
[[ -f "$1" ]] && csih_bug "unexpected $1 found"
}
# ======================================================================
# Routine: check_file_content
# Write a bug if file doesn't include some content
# Example: check_file_content result.log "__pyarmor__"
# ======================================================================
check_file_content()
{
if [[ "$3" == "not" ]] ; then
grep -q "$2" "$1" && csih_bug "'$2' found in '$1'"
else
grep -q "$2" "$1" || csih_bug "'$2' not found in '$1'"
fi
}
# ======================================================================
# Routine: check_return_value
# Write a bug if return value is not 0
# Example: check_return_value
# ======================================================================
check_return_value()
{
(( $? )) && csih_bug "command return non-zero value"
}
# ======================================================================
# Routine: check_python_version_for_auto_wrap_mode
# Return 0 if auto wrap mode doesn't work in this version
# Example:
# check_python_version_for_auto_wrap_mode && echo "No auto wrap"
# if ! check_python_version_for_auto_wrap_mode ; then
# echo "Auto wrap mode works"
# fi
# ======================================================================
check_python_version_for_auto_wrap_mode()
{
# unused, now all python versions work in auto-wrap mode
$PYTHON --version 2>&1 \
| grep -q "\(Python 3.0\|Python 3.1\|Python 3.2\)" \
&& csih_inform "The auto wrap mode doesn't work for $PYTHON"
}
# ======================================================================
# Routine: patch_cross_protection_code_for_python3.0
#
# Remove "assert_buildin(open)" from cross protection code if python
# version is 3.0, because it return OpenWrapper in Python3.0
# ======================================================================
patch_cross_protection_code_for_python3.0()
{
$PYTHON --version 2>&1 | grep -q "Python 3.0" \
&& $SED -i -e "/assert_builtin.open./d" protect_code.pt
}
# ======================================================================
# Routine: clear_pyarmor_installed_data
#
# ======================================================================
clear_pyarmor_installed_data()
{
rm -rf ~/.pyarmor ~/.pyarmor_capsule.*
[[ -n "$USERPROFILE" ]] && rm -rf "$USERPROFILE\\.pyarmor" "$USERPROFILE\\.pyarmor_capsule.*"
}
# ======================================================================
# Routine: update_pytransform_hash256
#
# ======================================================================
update_pytransform_hash256()
{
datafile=$1
libfile=$2
path=$3
if [ -f "$libfile" ] ; then
data=$(${SHA256SUM} ${libfile} | $AWK '{ print $1 }')
$SED -i -e "/\"path\": \"$path\"/,+6 s/\"sha256\":.*$/\"sha256\": \"$data\",/" $datafile
fi
}