-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.sh
executable file
·75 lines (62 loc) · 2.22 KB
/
bootstrap.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
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env bash
#------------------------------------------------------------------------------
# Copyright (c) Pourya Shirazian
# All rights reserved.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#------------------------------------------------------------------------------
get_current_dir() {
SOURCE="${BASH_SOURCE[0]}"
# resolve $SOURCE until the file is no longer a symlink
while [ -h "$SOURCE" ]; do
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
# if $SOURCE was a relative symlink, we need to resolve it relative to
# the path where the symlink file was located
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
}
usage() {
echo "usage: bootstrap.sh [-p <custom python binary>] "
echo
echo " -p: custom python3 to use = (default: python3)"
echo
exit 1
}
get_current_dir
# import bash functions
. ${DIR}/scripts/utils.sh
. ${DIR}/scripts/buildsettings.sh
while getopts ":p:v" opt; do
case "${opt}" in
p) PYTHON3="${OPTARG}";;
*) usage;;
esac
done
if [[ "${PYTHON3}" =~ ^python3.* ]]; then
export PYTHON3=${PYTHON3}
info "bootstrap.sh: using python3 with binary name ${PYTHON3}"
else
error "Invalid custom python3 binary. supplied = [${PYTHON3}]"
exit 1
fi
# 1. install the python virtual environment
# exit if the virtual environment already exists
PYTHON3_VENV_FULLPATH="${DIR}/${PYTHON3_VENV_NAME}"
is_dir_valid_and_nonempty ${PYTHON3_VENV_FULLPATH}
if [ $? -eq 0 ] ; then
info "python3 virtual environment already exists at ${PYTHON3_VENV_FULLPATH}"
else
check_min_python_version 3 8
info "creating a virtual environment under ${PYTHON3_VENV_FULLPATH}"
${PYTHON3} -m venv ${PYTHON3_VENV_NAME}
check_result_abort_failed $? "Failed to initial the virtual environment"
source ${PYTHON3_VENV_FULLPATH}/bin/activate
check_result_abort_failed $? "Failed to activate the virtual environment"
info "install required python modules into the virtual environment"
${PYTHON3} -m pip install -r ${DIR}/requirements.txt
check_result_abort_failed $? "Failed to install the required packages"
deactivate
fi