Skip to content

Commit

Permalink
Add option to manage venv if it's not detected.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Oct 17, 2023
1 parent 8ebf5b3 commit fc12d7d
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ DATESTAMP=`date "+%Y-%m-%d-%H-%M-%S"`
CONFIG_BACKUP=false
APT_HAS_UPDATED=false
RESOURCES_TOP_DIR=$HOME/Pimoroni
PY_VENV_DIR=$RESOURCES_TOP_DIR/venv
WD=`pwd`
USAGE="./install.sh (--unstable)"
POSITIONAL_ARGS=()
Expand All @@ -13,14 +14,6 @@ UNSTABLE=false
PYTHON="python"


venv_check() {
PYTHON_BIN=`which $PYTHON`
if [[ $VIRTUAL_ENV == "" ]] || [[ $PYTHON_BIN != $VIRTUAL_ENV* ]]; then
printf "This script should be run in a virtual Python environment.\n"
exit 1
fi
}

user_check() {
if [ $(id -u) -eq 0 ]; then
printf "Script should not be run as root. Try './install.sh'\n"
Expand Down Expand Up @@ -62,6 +55,28 @@ warning() {
echo -e "$(tput setaf 1)$1$(tput sgr0)"
}

venv_check() {
PYTHON_BIN=`which $PYTHON`
if [[ $VIRTUAL_ENV == "" ]] || [[ $PYTHON_BIN != $VIRTUAL_ENV* ]]; then
printf "This script should be run in a virtual Python environment.\n"
if confirm "Would you like us to create one for you?"; then
if [ ! -f $PY_VENV_DIR/bin/activate ]; then
inform "Creating virtual Python environment in $PY_VENV_DIR, please wait...\n"
mkdir -p $PY_VENV_DIR
/usr/bin/python3 -m venv $PY_VENV_DIR --system-site-packages
else
inform "Found existing virtual Python environment in $PY_VENV_DIR\n"
fi
inform "Activating virtual Python environment in $PY_VENV_DIR..."
inform "source $PY_VENV_DIR/bin/activate\n"
source $PY_VENV_DIR/bin/activate

else
exit 1
fi
fi
}

function do_config_backup {
if [ ! $CONFIG_BACKUP == true ]; then
CONFIG_BACKUP=true
Expand Down Expand Up @@ -136,7 +151,7 @@ done
user_check
venv_check

if [ ! -f "$PYTHON" ]; then
if [ ! -f `which $PYTHON` ]; then
printf "Python path $PYTHON not found!\n"
exit 1
fi
Expand Down

0 comments on commit fc12d7d

Please sign in to comment.