Created
February 13, 2025 15:30
-
-
Save shubham0204/6eb56265aa95bd6e0b63dbc48f7d5ae7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Function to check if Python is installed | |
check_python_installed() { | |
if command -v python3 &>/dev/null; then | |
echo "Python is installed" | |
else | |
echo "Python is not installed. Please install Python 3 and try again." | |
exit 1 | |
fi | |
} | |
# Function to create a virtual environment | |
create_virtualenv() { | |
python3 -m venv venv | |
if [ $? -ne 0 ]; then | |
echo "Failed to create virtual environment" | |
exit 1 | |
fi | |
echo "Virtual environment created" | |
} | |
# Function to install packages in the virtual environment | |
install_packages() { | |
source venv/bin/activate | |
pip install prometheus_client psutil | |
if [ $? -ne 0 ]; then | |
echo "Failed to install packages" | |
deactivate | |
exit 1 | |
fi | |
echo "Packages installed" | |
} | |
# Function to download the Python script from GitHub Snippets | |
download_python_script() { | |
SCRIPT_URL="https://gist.githubusercontent.com/shubham0204/2369b0b09d3e6b1cad1fe561587bb205/raw/e5426ae98fe1e0952c958afcdcef077b0bba41b7/measure.py" # Replace with actual URL | |
curl -o script.py $SCRIPT_URL | |
if [ $? -ne 0 ]; then | |
echo "Failed to download Python script" | |
deactivate | |
exit 1 | |
fi | |
echo "Python script downloaded" | |
} | |
# Function to execute the Python script from the virtual environment | |
execute_python_script() { | |
python script.py | |
if [ $? -ne 0 ]; then | |
echo "Failed to execute Python script" | |
deactivate | |
exit 1 | |
fi | |
echo "Python script executed successfully" | |
deactivate | |
} | |
# Main script execution | |
check_python_installed | |
create_virtualenv | |
install_packages | |
download_python_script | |
execute_python_script | |
``` ▋ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment