Skip to content

Commit

Permalink
Drop an auto venv script into ~/Pimoroni, update venv prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Oct 19, 2023
1 parent c8b2011 commit 8052ee4
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ 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
VENV_BASH_SNIPPET=$RESOURCES_TOP_DIR/auto_venv.sh
VENV_DIR=$RESOURCES_TOP_DIR/venv
WD=`pwd`
USAGE="./install.sh (--unstable)"
POSITIONAL_ARGS=()
FORCE=false
UNSTABLE=false
PYTHON="python"


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

venv_bash_snippet() {
if [ ! -f $VENV_BASH_SNIPPET ]; then
cat << EOF > $VENV_BASH_SNIPPET
# Add \`source $RESOURCES_TOP_DIR/auto_venv.sh\` to your ~/.bashrc to activate
# the Pimoroni virtual environment automagically!
PY_ENV_DIR=~/Pimoroni/venv
if [ ! -f \$PY_ENV_DIR/bin/activate ]; then
printf "Creating user Python environment in \$PY_ENV_DIR, please wait...\n"
mkdir -p \$PY_ENV_DIR
python3 -m venv --system-site-packages --prompt Pimoroni \$PY_ENV_DIR
fi
printf " ↓ ↓ ↓ ↓ Hello, we've activated a Python venv for you. To exit, type \"deactivate\".\n"
source \$PY_ENV_DIR/bin/activate
EOF
fi
}

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
if [ ! -f $VENV_DIR/bin/activate ]; then
inform "Creating virtual Python environment in $VENV_DIR, please wait...\n"
mkdir -p $VENV_DIR
/usr/bin/python3 -m venv $VENV_DIR --system-site-packages --prompt Pimoroni
venv_bash_snippet
else
inform "Found existing virtual Python environment in $PY_VENV_DIR\n"
inform "Found existing virtual Python environment in $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
inform "Activating virtual Python environment in $VENV_DIR..."
inform "source $VENV_DIR/bin/activate\n"
source $VENV_DIR/bin/activate

else
exit 1
Expand Down

0 comments on commit 8052ee4

Please sign in to comment.