Refactor update_poetry.sh script to install pipx and poetry dependencies
This commit is contained in:
parent
5c2caf23c8
commit
cf403220dc
1 changed files with 3 additions and 85 deletions
|
|
@ -32,90 +32,6 @@ case "$OS" in
|
|||
;;
|
||||
esac
|
||||
|
||||
echo "Detected Operating System: $OS"
|
||||
|
||||
# Installation of pipx based on the detected OS
|
||||
install_pipx() {
|
||||
case $1 in
|
||||
macOS)
|
||||
# macOS installation using Homebrew
|
||||
command -v brew >/dev/null 2>&1 || exit_with_message "Homebrew is not installed. Please install Homebrew first."
|
||||
echo "Installing pipx using Homebrew..."
|
||||
brew install pipx
|
||||
pipx ensurepath
|
||||
;;
|
||||
Linux)
|
||||
# Linux installation. Further checks are needed to distinguish between distributions
|
||||
if grep -qEi "(ubuntu|debian)" /etc/*release; then
|
||||
echo "Installing pipx on Ubuntu/Debian..."
|
||||
sudo apt update
|
||||
sudo apt install pipx -y
|
||||
elif grep -qEi "fedora" /etc/*release; then
|
||||
echo "Installing pipx on Fedora..."
|
||||
sudo dnf install pipx -y
|
||||
else
|
||||
echo "Installing pipx using pip (other Linux distributions)..."
|
||||
python3 -m pip install --user pipx
|
||||
fi
|
||||
pipx ensurepath
|
||||
;;
|
||||
*)
|
||||
exit_with_message "Unsupported operating system for pipx installation."
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Function to fetch the latest version of pipx from GitHub and compare with the installed version
|
||||
check_for_pipx_update() {
|
||||
echo "Checking for updates to pipx..."
|
||||
# Fetch the latest version of pipx, ensuring only to capture the numeric version without 'v' prefix.
|
||||
local latest_version=$(curl -s https://api.github.com/repos/pypa/pipx/releases/latest | grep '"tag_name":' | sed -E 's/.*"tag_name": "v?([^"]+)".*/\1/')
|
||||
# Extract the current installed version of pipx.
|
||||
local current_version=$(pipx --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')
|
||||
|
||||
if [[ "$latest_version" == "$current_version" ]]; then
|
||||
echo "You have the latest version of pipx ($current_version)."
|
||||
else
|
||||
echo "A newer version of pipx ($latest_version) is available. You have $current_version. Do you want to update? (yes/no)"
|
||||
read -r user_input
|
||||
if [[ "$user_input" == "yes" ]]; then
|
||||
echo "Updating pipx..."
|
||||
case "$OS" in
|
||||
macOS)
|
||||
brew upgrade pipx
|
||||
;;
|
||||
Linux)
|
||||
if grep -qEi "(ubuntu|debian)" /etc/*release; then
|
||||
sudo apt update
|
||||
sudo apt install --only-upgrade pipx -y
|
||||
elif grep -qEi "fedora" /etc/*release; then
|
||||
sudo dnf upgrade pipx -y
|
||||
else
|
||||
python3 -m pip install --user --upgrade pipx
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
exit_with_message "Unsupported operating system for pipx update."
|
||||
;;
|
||||
esac
|
||||
pipx ensurepath
|
||||
echo "pipx updated to version $latest_version"
|
||||
else
|
||||
echo "Not updating pipx at this time."
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Now, modify the existing check to call check_for_pipx_update even if pipx is installed
|
||||
if ! command -v pipx &> /dev/null; then
|
||||
echo "Pipx is not installed. Installing..."
|
||||
install_pipx "$OS"
|
||||
echo "Pipx installed successfully."
|
||||
else
|
||||
echo "Pipx is already installed."
|
||||
check_for_pipx_update
|
||||
fi
|
||||
|
||||
|
||||
echo "Checking Poetry installation..."
|
||||
|
||||
|
|
@ -124,7 +40,7 @@ if ! command -v poetry &> /dev/null
|
|||
then
|
||||
echo "Poetry is not installed. Installing..."
|
||||
# Also install python 3.10 and use
|
||||
pipx install poetry --python python3.10 --fetch-missing-python
|
||||
curl -sSL https://install.python-poetry.org | python3 -
|
||||
echo "Poetry installed successfully."
|
||||
else
|
||||
echo "Poetry is already installed."
|
||||
|
|
@ -146,3 +62,5 @@ else
|
|||
echo "Poetry version is $1 or higher. No need to update."
|
||||
fi
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue