BASH
Verify and Install Essential Command-Line Tools
Automate the verification and installation of critical command-line tools required for your development environment, ensuring all dependencies are met for your projects and setups.
#!/bin/bash
# List of required tools
REQUIRED_TOOLS=("node" "npm" "git" "docker")
# Function to check if a command exists
command_exists () {
type "$1" &> /dev/null ;
}
echo "Checking for required development tools..."
INSTALL_MISSING=false
for tool in "${REQUIRED_TOOLS[@]}"; do
if command_exists "$tool"; then
echo "✅ $tool is installed."
else
echo "❌ $tool is NOT installed."
INSTALL_MISSING=true
fi
done
if $INSTALL_MISSING; then
read -p "Some tools are missing. Do you want to attempt to install them? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "Attempting to install missing tools (requires sudo privileges)..."
if command_exists apt-get; then
sudo apt-get update
for tool in "${REQUIRED_TOOLS[@]}"; do
if ! command_exists "$tool"; then
echo "Installing $tool..."
sudo apt-get install -y "$tool"
fi
done
elif command_exists yum; then
echo "Using yum for installation (RPM-based systems)..."
for tool in "${REQUIRED_TOOLS[@]}"; do
if ! command_exists "$tool"; then
echo "Installing $tool..."
sudo yum install -y "$tool"
fi
done
elif command_exists brew; then
echo "Using Homebrew for installation (macOS/Linux)..."
for tool in "${REQUIRED_TOOLS[@]}"; do
if ! command_exists "$tool"; then
echo "Installing $tool..."
brew install "$tool"
fi
done
else
echo "No supported package manager (apt-get, yum, brew) found. Please install tools manually."
fi
echo "Re-checking installed tools..."
for tool in "${REQUIRED_TOOLS[@]}"; do
if command_exists "$tool"; then
echo "✅ $tool is now installed."
else
echo "❌ $tool is still NOT installed. Manual intervention may be needed."
fi
done
else
echo "Installation skipped. Please install missing tools manually."
fi
else
echo "All required tools are installed."
fi
How it works: This script verifies the presence of essential command-line tools (e.g., Node.js, npm, Git, Docker) crucial for web development. It defines a list of `REQUIRED_TOOLS` and iterates through them, checking if each command is available in the system's PATH. If any tools are missing, it prompts the user to attempt installation. It then dynamically detects the system's package manager (`apt-get`, `yum`, or `brew`) and uses it to install the identified missing tools, providing a streamlined setup experience.