Skip to content

Commit

Permalink
Create certimailer_mac.sh
Browse files Browse the repository at this point in the history
Signed-off-by: Manas <[email protected]>
  • Loading branch information
scienmanas authored Feb 4, 2024
1 parent 46fc809 commit d347193
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions certimailer_mac.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/bin/bash

# Function to check if a command is available
command_exists() {
command -v "$1" >/dev/null 2>&1
}

loading_animation() {
local load_interval="${1}"
local loading_message="${2}"
local elapsed=0
local loading_animation=( '' "\\" '|' '/' )

while [ "${load_interval}" -ne "${elapsed}" ]; do
for frame in "${loading_animation[@]}" ; do
printf "%s\b" "${frame}"
sleep 0.25
done
elapsed=$(( elapsed + 1 ))
done
printf " \b\n"
}

# Function to install dependencies asynchronously
install_dependencies() {
pip3 install -r requirements.txt >/dev/null 2>&1
}

# Detect the operating system
os=$(uname -s)

# Check if Python is installed
if command_exists python3; then
echo "Python 3 is already installed."
else
echo "Python 3 not found. Installing..."
case "$os" in
Linux*) sudo apt-get update >/dev/null 2>&1
sudo apt-get install -y python3 >/dev/null 2>&1 ;;
Darwin*) brew update >/dev/null 2>&1
brew install python3 >/dev/null 2>&1 ;;
*) echo "Unsupported operating system: $os"; exit 1 ;;
esac
loading_animation 10 "Installing Python 3..."
echo "Python 3 installed successfully."
fi

# Check if pip is installed
if command_exists pip3; then
echo "pip is already installed."
else
echo "pip not found. Installing..."
case "$os" in
Linux*) sudo apt-get install -y python3-pip >/dev/null 2>&1 ;;
Darwin*) brew install python3-pip >/dev/null 2>&1 ;;
*) echo "Unsupported operating system: $os"; exit 1 ;;
esac
loading_animation 10 "Installing pip..."
echo "pip installed successfully."
fi

# Generate and activate virtual environment
if [[ "$os" == "Linux" ]]; then
sudo apt install python3.11-venv
fi

python3 -m venv venv >/dev/null 2>&1
source venv/bin/activate
echo "Virtual environment activated successfully.."

# Install dependencies from requirements.txt asynchronously
echo "Installing dependencies..."
install_dependencies &
loading_animation 10 "Installing dependencies..."
wait $!
echo "Dependencies installed successfully."

# Run the Python script
echo "Executing main.py..."
# Add any loading animations or delays here if desired
clear
python3 main.py

0 comments on commit d347193

Please sign in to comment.