Skip to content

Commit

Permalink
Update to handle debian 12
Browse files Browse the repository at this point in the history
  • Loading branch information
pipiche38 committed Dec 19, 2024
1 parent 4394ed7 commit 1aa957a
Showing 1 changed file with 48 additions and 17 deletions.
65 changes: 48 additions & 17 deletions Tools/plugin-auto-upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,35 +37,64 @@ set_pip_options() {
echo "PIP Options: $PIP_OPTIONS"
}

# Function to check if pip is installed in the virtual environment
check_pip_in_venv() {
if [ ! -f "$VENV_PATH/bin/$PYTHON_VERSION" ]; then
echo "pip is not installed in the virtual environment. Installing pip..."
install_pip
$PYTHON_VERSION -m venv $VENV_PATH
fi
}

# Function to install pip
install_pip() {
if command -v lsb_release &> /dev/null && [ "$(lsb_release -is)" = "Debian" ] || [ "$(lsb_release -is)" = "Ubuntu" ]; then
echo "We are expecting the user to properly install python3-pip package. if not yet done !!"
else
$PYTHON_VERSION -m ensurepip
$PYTHON_VERSION -m pip install --upgrade pip virtualenv -t $VENV_PATH
fi
}

# Function to activate virtual environment
activate_venv() {
echo "Using virtual environment at: $VENV_PATH"
source $VENV_PATH/bin/activate
}

# Function to check and activate virtual environment
check_and_activate_venv() {
if [ -n "$PYTHONPATH" ]; then
echo "PYTHONPATH is set to: $PYTHONPATH"
VENV_PATH=$(echo $PYTHONPATH | cut -d':' -f1)
if [ -d "$VENV_PATH/bin" ]; then
VENV_ACTIVATED=true
if [ ! -f "$VENV_PATH/bin/$PYTHON_VERSION" ]; then
echo "pip is not installed in the virtual environment. Installing pip..."
$PYTHON_VERSION -m ensurepip
$PYTHON_VERSION -m pip install --upgrade pip virtualenv -t $VENV_PATH
$PYTHON_VERSION -m venv $VENV_PATH
fi
check_pip_in_venv
else
echo "Virtual environment path $VENV_PATH does not exist"
echo "pip is not installed in the virtual environment. Installing pip..."
$PYTHON_VERSION -m ensurepip
$PYTHON_VERSION -m pip install --upgrade pip virtualenv -t $VENV_PATH
install_pip
$PYTHON_VERSION -m venv $VENV_PATH
VENV_ACTIVATED=true
fi
VENV_ACTIVATED=true
activate_venv
else
echo "PYTHONPATH is not set"
VENV_ACTIVATED=false
fi
}

if [ "$VENV_ACTIVATED" = true ]; then
echo "Using virtual environment at: $VENV_PATH"
source $VENV_PATH/bin/activate
# Function to install python3-pip on Debian if necessary
install_pip_on_debian() {
if command -v lsb_release &> /dev/null; then
DISTRIB_ID=$(lsb_release -is)
DISTRIB_RELEASE=$(lsb_release -rs)
if [ "$DISTRIB_ID" = "Debian" ] && [ "$DISTRIB_RELEASE" = "12" ]; then
if ! command -v pip3 &> /dev/null; then
echo "pip3 is not installed. Installing python3-pip..."
sudo apt-get update
sudo apt-get install -y python3-pip
fi
fi
fi
}

Expand Down Expand Up @@ -111,6 +140,7 @@ PIP_VERSION="python${1:-3}"
set_home
print_env_details
set_pip_options
#install_pip_on_debian
check_and_activate_venv
print_version_info
update_git_config
Expand All @@ -127,7 +157,8 @@ exit 0
# 2. Prints environment details for debugging purposes.
# 3. Sets PIP options based on the distribution.
# 4. Checks if PYTHONPATH is set and activates the virtual environment if available.
# 5. Updates the git configuration to add the current directory as a safe directory.
# 6. Updates Python modules using pip.
# 7. Prints the current version and latest git commit of the plugin.
# 8. Completes the upgrade process and exits.
# 5. Installs python3-pip on Debian if necessary.
# 6. Updates the git configuration to add the current directory as a safe directory.
# 7. Updates Python modules using pip.
# 8. Prints the current version and latest git commit of the plugin.
# 9. Completes the upgrade process and exits.

0 comments on commit 1aa957a

Please sign in to comment.