-
Notifications
You must be signed in to change notification settings - Fork 301
/
Copy pathobfuscate-pkg.sh
executable file
·51 lines (38 loc) · 1.59 KB
/
obfuscate-pkg.sh
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
#
# Sample script used to obfuscate a python package.
#
# Before run it, all TODO variables need to set correctly.
#
# TODO: python interpreter
PYTHON=python
# TODO: Absolute path of pyarmor installed, where to find pyarmor.py
PYARMOR_PATH=/usr/local/lib/
# TODO: Absolute path in which all python scripts will be obfuscated
SOURCE=/home/jondy/workspace/project/src
# TODO: Package name, __init__.py shoule be in $SOURCE/$PKGNAME
PKGNAME=foo
# TODO: Output path for obfuscated package and runtime files
OUTPUT=/home/jondy/workspace/project/dist
# TODO: Let obfuscated package expired on some day, uncomment next line
#LICENSE_EXPIRED_DATE=2019-01-01
# TODO: If try to test obfuscated package, uncomment next line
#TEST_OBFUSCATED_PACKAGE=1
# Check package
PKGPATH=$SOURCE/$PKGNAME
[[ -f "$PKGPATH/__init__.py" ]] || ( echo "No __init__.py found in package path $PKGPATH" && exit 1 )
# Obfuscate scripts
cd ${PYARMOR_PATH}
$PYTHON pyarmor.py obfuscate --recursive --src "$PKGPATH" --entry "__init__.py" --output "${OUTPUT}/$PKGNAME" || exit 1
# Generate an expired license if any
if ! [[ "${LICENSE_EXPIRED_DATE}" == "" ]] ; then
RCODE="expired-${LICENSE_EXPIRED_DATE}"
$PYTHON pyarmor.py licenses --expired ${LICENSE_EXPIRED_DATE} $RCODE || exit 1
# Overwrite default license with this expired license
echo "The obfuscated scripts will be expired on ${LICENSE_EXPIRED_DATE}"
cp licenses/$RCODE/license.lic ${OUTPUT}/$PKGNAME
)
# Run obfuscated scripts if
if [[ "${TEST_OBFUSCATED_PACKAGE}" == "1" ]] ; then
cd ${OUTPUT}
$PYTHON -c "import $PKGNAME"
fi