-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.sh
62 lines (51 loc) · 1.59 KB
/
build.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
52
53
54
55
56
57
58
59
60
61
62
#! /bin/bash
# Set minimum required versions
PYTHON_MINIMUM_MAJOR=3
PYTHON_MINIMUM_MINOR=3
# Get python references
PYTHON3_REF=$(which python3 | grep "/python3")
PYTHON_REF=$(which python | grep "/python")
error_msg(){
echo "Python executable not found"
}
python_ref(){
local my_ref=$1
echo $($my_ref -c 'import platform; major, minor, patch = platform.python_version_tuple(); print(major); print(minor);')
}
# Print success_msg/error_msg according to the provided minimum required versions
check_version(){
local major=$1
local minor=$2
local python_ref=$3
[[ $major -ge $PYTHON_MINIMUM_MAJOR && $minor -ge $PYTHON_MINIMUM_MINOR ]] && echo $python_ref || error_msg
}
# Logic
if [[ ! -z $PYTHON3_REF ]]; then
version=($(python_ref python3))
check_version ${version[0]} ${version[1]} $PYTHON3_REF
PYTHON_EXEC=python3
elif [[ ! -z $PYTHON_REF ]]; then
# Didn't find python3, let's try python
version=($(python_ref python))
check_version ${version[0]} ${version[1]} $PYTHON_REF
PYTHON_EXEC=python
else
# Python is not installed at all
error_msg
fi
VIRTUAL_ENV_ACTIVE=$($PYTHON_EXEC -c "import sys; print(hasattr(sys, 'real_prefix') or (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix))")
if [ $VIRTUAL_ENV_ACTIVE = "False" ]; then
if [ ! -d "./venv/bin" ]; then
python -m "venv" ./venv
fi
source "./venv/bin/activate"
pip install -r requirements.txt
STARTED_VENV=0
fi
pyinstaller \
--add-data "Plugins:Plugins" \
--additional-hooks-dir "hooks" \
"$@" smarthash.py
if [ $STARTED_VENV ]; then
deactivate
fi