@@ -5,6 +5,7 @@ DATESTAMP=`date "+%Y-%m-%d-%H-%M-%S"`
55CONFIG_BACKUP=false
66APT_HAS_UPDATED=false
77RESOURCES_TOP_DIR=$HOME /Pimoroni
8+ PY_VENV_DIR=$RESOURCES_TOP_DIR /venv
89WD=` pwd`
910USAGE=" ./install.sh (--unstable)"
1011POSITIONAL_ARGS=()
@@ -13,14 +14,6 @@ UNSTABLE=false
1314PYTHON=" python"
1415
1516
16- venv_check () {
17- PYTHON_BIN=` which $PYTHON `
18- if [[ $VIRTUAL_ENV == " " ]] || [[ $PYTHON_BIN != $VIRTUAL_ENV * ]]; then
19- printf " This script should be run in a virtual Python environment.\n"
20- exit 1
21- fi
22- }
23-
2417user_check () {
2518 if [ $( id -u) -eq 0 ]; then
2619 printf " Script should not be run as root. Try './install.sh'\n"
@@ -62,6 +55,28 @@ warning() {
6255 echo -e " $( tput setaf 1) $1 $( tput sgr0) "
6356}
6457
58+ venv_check () {
59+ PYTHON_BIN=` which $PYTHON `
60+ if [[ $VIRTUAL_ENV == " " ]] || [[ $PYTHON_BIN != $VIRTUAL_ENV * ]]; then
61+ printf " This script should be run in a virtual Python environment.\n"
62+ if confirm " Would you like us to create one for you?" ; then
63+ if [ ! -f $PY_VENV_DIR /bin/activate ]; then
64+ inform " Creating virtual Python environment in $PY_VENV_DIR , please wait...\n"
65+ mkdir -p $PY_VENV_DIR
66+ /usr/bin/python3 -m venv $PY_VENV_DIR --system-site-packages
67+ else
68+ inform " Found existing virtual Python environment in $PY_VENV_DIR \n"
69+ fi
70+ inform " Activating virtual Python environment in $PY_VENV_DIR ..."
71+ inform " source $PY_VENV_DIR /bin/activate\n"
72+ source $PY_VENV_DIR /bin/activate
73+
74+ else
75+ exit 1
76+ fi
77+ fi
78+ }
79+
6580function do_config_backup {
6681 if [ ! $CONFIG_BACKUP == true ]; then
6782 CONFIG_BACKUP=true
136151user_check
137152venv_check
138153
139- if [ ! -f " $PYTHON " ]; then
154+ if [ ! -f ` which $PYTHON ` ]; then
140155 printf " Python path $PYTHON not found!\n"
141156 exit 1
142157fi
0 commit comments