Add automatic dependency installer and package checks

DEPENDENCY MANAGEMENT:
- Created scripts/install-dependencies.sh - automatic installer for all required packages
- Detects OS (Ubuntu, Debian, CentOS, RHEL, Fedora, Arch, macOS)
- Installs PostgreSQL client (psql) automatically
- Installs Docker & Docker Compose if missing
- Installs utility packages (curl, wget, git)

SCRIPT ENHANCEMENTS:
- Updated setup-database.sh with dependency checking
- Updated generate_data.sh with dependency checking
- Updated verify-setup.sh with dependency checking
- All scripts now prompt to run installer if dependencies are missing
- Interactive prompts guide users through installation

DOCUMENTATION:
- Updated README.md with dependency installation instructions
- Updated QUICKSTART.md with Step 0: Install Dependencies
- Added supported OS list
- Added automatic dependency check notes

USER EXPERIENCE:
- No more manual package installation required
- Scripts fail gracefully with helpful error messages
- One-command installation: ./scripts/install-dependencies.sh
- Automatic detection and installation on Linux/macOS
- Clear instructions for Windows users

This ensures users can get started immediately without hunting for package installation commands.
This commit is contained in:
Alphaeus Mote
2025-10-23 14:34:11 -04:00
parent aa803bd3bd
commit 3dde2997f6
6 changed files with 484 additions and 5 deletions
+30 -5
View File
@@ -83,16 +83,39 @@ kpi_definitions → daily_metrics → trend_analysis
### Prerequisites ### Prerequisites
- Docker and Docker Compose - Docker and Docker Compose
- PostgreSQL client (psql)
- 8GB RAM minimum - 8GB RAM minimum
- 20GB disk space - 20GB disk space
**🔧 Don't have the prerequisites?** Run the automatic installer:
```bash
chmod +x scripts/install-dependencies.sh
./scripts/install-dependencies.sh
```
This will automatically install:
- ✅ PostgreSQL client (psql)
- ✅ Docker & Docker Compose
- ✅ Required utilities (curl, wget, git)
**Supported OS:** Ubuntu, Debian, CentOS, RHEL, Fedora, Arch Linux, macOS
---
### 1. Clone the Repository ### 1. Clone the Repository
```bash ```bash
git clone https://github.com/yourusername/SQL.git git clone https://github.com/freedbygrace/SQL.git
cd SQL cd SQL
``` ```
### 2. Start the Database ### 2. Install Dependencies (Optional)
```bash
# Only if you don't have Docker, psql, etc.
chmod +x scripts/install-dependencies.sh
./scripts/install-dependencies.sh
```
### 3. Start the Database
```bash ```bash
docker-compose up -d docker-compose up -d
``` ```
@@ -101,13 +124,15 @@ This starts:
- **PostgreSQL 16** on port `5432` - **PostgreSQL 16** on port `5432`
- **DB-UI** web interface on port `3000` - **DB-UI** web interface on port `3000`
### 3. Initialize the Schema ### 4. Initialize the Schema
```bash ```bash
chmod +x scripts/setup-database.sh chmod +x scripts/setup-database.sh
./scripts/setup-database.sh ./scripts/setup-database.sh
``` ```
### 4. Generate Test Data **Note:** The script will automatically check for required dependencies and prompt you to install them if missing.
### 5. Generate Test Data
```bash ```bash
chmod +x data/generate_data.sh chmod +x data/generate_data.sh
./data/generate_data.sh ./data/generate_data.sh
@@ -115,7 +140,7 @@ chmod +x data/generate_data.sh
⏱️ **Note:** Data generation takes 15-30 minutes depending on your system. ⏱️ **Note:** Data generation takes 15-30 minutes depending on your system.
### 5. Access the Database ### 6. Access the Database
**Option A: DB-UI Web Interface** **Option A: DB-UI Web Interface**
``` ```
+47
View File
@@ -32,6 +32,10 @@ NUM_CARDS=200000
NUM_TRANSACTIONS=5000000 NUM_TRANSACTIONS=5000000
FRAUD_PERCENTAGE=7 # 7% of transactions will be fraudulent FRAUD_PERCENTAGE=7 # 7% of transactions will be fraudulent
# Script directory
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
echo -e "${BLUE}============================================================================${NC}" echo -e "${BLUE}============================================================================${NC}"
echo -e "${BLUE}Business Analytics Database - Data Generation${NC}" echo -e "${BLUE}Business Analytics Database - Data Generation${NC}"
echo -e "${BLUE}============================================================================${NC}" echo -e "${BLUE}============================================================================${NC}"
@@ -43,6 +47,49 @@ echo -e "Cards: ${GREEN}$NUM_CARDS${NC}"
echo -e "Transactions: ${GREEN}$NUM_TRANSACTIONS${NC} (${YELLOW}${FRAUD_PERCENTAGE}% fraudulent${NC})" echo -e "Transactions: ${GREEN}$NUM_TRANSACTIONS${NC} (${YELLOW}${FRAUD_PERCENTAGE}% fraudulent${NC})"
echo -e "${BLUE}============================================================================${NC}" echo -e "${BLUE}============================================================================${NC}"
echo "" echo ""
# Check for required dependencies
check_dependencies() {
local missing_deps=()
# Check for psql
if ! command -v psql >/dev/null 2>&1; then
missing_deps+=("psql (PostgreSQL client)")
fi
if [ ${#missing_deps[@]} -gt 0 ]; then
echo -e "${RED}✗ Missing required dependencies:${NC}"
for dep in "${missing_deps[@]}"; do
echo -e " - ${YELLOW}$dep${NC}"
done
echo ""
echo -e "${YELLOW}Would you like to run the dependency installer? (y/n)${NC}"
read -r response
if [[ "$response" =~ ^[Yy]$ ]]; then
if [ -f "$PROJECT_ROOT/scripts/install-dependencies.sh" ]; then
chmod +x "$PROJECT_ROOT/scripts/install-dependencies.sh"
"$PROJECT_ROOT/scripts/install-dependencies.sh"
echo ""
echo -e "${GREEN}Dependencies installed. Please re-run this script.${NC}"
exit 0
else
echo -e "${RED}✗ install-dependencies.sh not found${NC}"
echo -e "${YELLOW}Please install PostgreSQL client manually${NC}"
exit 1
fi
else
echo -e "${RED}✗ Cannot proceed without required dependencies${NC}"
exit 1
fi
fi
echo -e "${GREEN}✓ All required dependencies are installed${NC}"
echo ""
}
# Run dependency check
check_dependencies
echo -e "${RED}WARNING: This will DELETE all existing data and regenerate it!${NC}" echo -e "${RED}WARNING: This will DELETE all existing data and regenerate it!${NC}"
echo -e "${YELLOW}Press Ctrl+C within 5 seconds to cancel...${NC}" echo -e "${YELLOW}Press Ctrl+C within 5 seconds to cancel...${NC}"
sleep 5 sleep 5
+23
View File
@@ -2,6 +2,29 @@
## 🚀 Get Up and Running in 5 Minutes ## 🚀 Get Up and Running in 5 Minutes
### Step 0: Install Dependencies (Optional - 5 minutes)
**If you don't have Docker, PostgreSQL client (psql), or other required tools:**
```bash
# Make script executable
chmod +x scripts/install-dependencies.sh
# Run the installer
./scripts/install-dependencies.sh
```
**What this installs:**
- PostgreSQL client (psql)
- Docker & Docker Compose
- Utility packages (curl, wget, git)
**Supported OS:** Ubuntu, Debian, CentOS, RHEL, Fedora, Arch Linux, macOS
**Note:** All other scripts will automatically check for dependencies and prompt you to install them if missing.
---
### Step 1: Start Docker Containers (1 minute) ### Step 1: Start Docker Containers (1 minute)
```bash ```bash
+297
View File
@@ -0,0 +1,297 @@
#!/bin/bash
# ============================================================================
# Dependency Installation Script
# ============================================================================
# Automatically detects OS and installs required packages:
# - PostgreSQL client (psql)
# - Docker & Docker Compose
# - curl, wget, git (if missing)
# ============================================================================
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo -e "${BLUE}============================================================================${NC}"
echo -e "${BLUE}Business Analytics Database - Dependency Installer${NC}"
echo -e "${BLUE}============================================================================${NC}"
echo ""
# Detect OS
detect_os() {
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
if [ -f /etc/os-release ]; then
. /etc/os-release
OS=$ID
VER=$VERSION_ID
else
OS="unknown"
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
OS="macos"
elif [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "cygwin" ]]; then
OS="windows"
else
OS="unknown"
fi
echo -e "${BLUE}Detected OS: ${GREEN}$OS${NC}"
}
# Check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Install PostgreSQL client
install_psql() {
echo -e "\n${YELLOW}[1/4] Checking PostgreSQL client (psql)...${NC}"
if command_exists psql; then
PSQL_VERSION=$(psql --version | awk '{print $3}')
echo -e "${GREEN}✓ psql is already installed (version $PSQL_VERSION)${NC}"
return 0
fi
echo -e "${YELLOW}Installing PostgreSQL client...${NC}"
case $OS in
ubuntu|debian)
sudo apt-get update
sudo apt-get install -y postgresql-client
;;
centos|rhel|fedora)
sudo yum install -y postgresql
;;
arch)
sudo pacman -S --noconfirm postgresql-libs
;;
macos)
if command_exists brew; then
brew install postgresql
else
echo -e "${RED}✗ Homebrew not found. Please install Homebrew first: https://brew.sh${NC}"
exit 1
fi
;;
windows)
echo -e "${YELLOW}On Windows, please install PostgreSQL client manually:${NC}"
echo -e " 1. Download from: https://www.postgresql.org/download/windows/"
echo -e " 2. Or use WSL2 with Ubuntu"
echo -e " 3. Or use Docker Desktop (includes psql in containers)"
exit 1
;;
*)
echo -e "${RED}✗ Unsupported OS. Please install PostgreSQL client manually.${NC}"
exit 1
;;
esac
if command_exists psql; then
echo -e "${GREEN}✓ PostgreSQL client installed successfully${NC}"
else
echo -e "${RED}✗ Failed to install PostgreSQL client${NC}"
exit 1
fi
}
# Install Docker
install_docker() {
echo -e "\n${YELLOW}[2/4] Checking Docker...${NC}"
if command_exists docker; then
DOCKER_VERSION=$(docker --version | awk '{print $3}' | sed 's/,//')
echo -e "${GREEN}✓ Docker is already installed (version $DOCKER_VERSION)${NC}"
# Check if Docker daemon is running
if docker ps >/dev/null 2>&1; then
echo -e "${GREEN}✓ Docker daemon is running${NC}"
else
echo -e "${YELLOW}⚠ Docker is installed but daemon is not running${NC}"
echo -e "${YELLOW} Please start Docker and try again${NC}"
fi
return 0
fi
echo -e "${YELLOW}Installing Docker...${NC}"
case $OS in
ubuntu|debian)
# Install Docker using official script
curl -fsSL https://get.docker.com -o /tmp/get-docker.sh
sudo sh /tmp/get-docker.sh
sudo usermod -aG docker $USER
echo -e "${YELLOW}⚠ You may need to log out and back in for Docker group membership to take effect${NC}"
;;
centos|rhel|fedora)
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install -y docker-ce docker-ce-cli containerd.io
sudo systemctl start docker
sudo systemctl enable docker
sudo usermod -aG docker $USER
;;
macos)
echo -e "${YELLOW}On macOS, please install Docker Desktop manually:${NC}"
echo -e " Download from: https://www.docker.com/products/docker-desktop"
exit 1
;;
windows)
echo -e "${YELLOW}On Windows, please install Docker Desktop manually:${NC}"
echo -e " Download from: https://www.docker.com/products/docker-desktop"
exit 1
;;
*)
echo -e "${RED}✗ Unsupported OS for automatic Docker installation${NC}"
exit 1
;;
esac
if command_exists docker; then
echo -e "${GREEN}✓ Docker installed successfully${NC}"
else
echo -e "${RED}✗ Failed to install Docker${NC}"
exit 1
fi
}
# Install Docker Compose
install_docker_compose() {
echo -e "\n${YELLOW}[3/4] Checking Docker Compose...${NC}"
# Check for docker-compose (standalone) or docker compose (plugin)
if command_exists docker-compose || docker compose version >/dev/null 2>&1; then
if command_exists docker-compose; then
COMPOSE_VERSION=$(docker-compose --version | awk '{print $3}' | sed 's/,//')
else
COMPOSE_VERSION=$(docker compose version --short)
fi
echo -e "${GREEN}✓ Docker Compose is already installed (version $COMPOSE_VERSION)${NC}"
return 0
fi
echo -e "${YELLOW}Installing Docker Compose...${NC}"
case $OS in
ubuntu|debian|centos|rhel|fedora)
# Install Docker Compose plugin
COMPOSE_VERSION=$(curl -s https://api.github.com/repos/docker/compose/releases/latest | grep 'tag_name' | cut -d\" -f4)
sudo curl -L "https://github.com/docker/compose/releases/download/${COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
;;
macos)
echo -e "${GREEN}✓ Docker Compose is included with Docker Desktop${NC}"
return 0
;;
windows)
echo -e "${GREEN}✓ Docker Compose is included with Docker Desktop${NC}"
return 0
;;
*)
echo -e "${RED}✗ Unsupported OS for automatic Docker Compose installation${NC}"
exit 1
;;
esac
if command_exists docker-compose; then
echo -e "${GREEN}✓ Docker Compose installed successfully${NC}"
else
echo -e "${RED}✗ Failed to install Docker Compose${NC}"
exit 1
fi
}
# Install utility packages
install_utilities() {
echo -e "\n${YELLOW}[4/4] Checking utility packages...${NC}"
local missing_packages=()
# Check for required utilities
if ! command_exists curl; then
missing_packages+=("curl")
fi
if ! command_exists wget; then
missing_packages+=("wget")
fi
if ! command_exists git; then
missing_packages+=("git")
fi
if [ ${#missing_packages[@]} -eq 0 ]; then
echo -e "${GREEN}✓ All utility packages are installed${NC}"
return 0
fi
echo -e "${YELLOW}Installing missing utilities: ${missing_packages[*]}${NC}"
case $OS in
ubuntu|debian)
sudo apt-get update
sudo apt-get install -y "${missing_packages[@]}"
;;
centos|rhel|fedora)
sudo yum install -y "${missing_packages[@]}"
;;
arch)
sudo pacman -S --noconfirm "${missing_packages[@]}"
;;
macos)
if command_exists brew; then
brew install "${missing_packages[@]}"
else
echo -e "${YELLOW}⚠ Some utilities are missing but Homebrew is not installed${NC}"
fi
;;
*)
echo -e "${YELLOW}⚠ Cannot automatically install utilities on this OS${NC}"
;;
esac
echo -e "${GREEN}✓ Utility packages installed${NC}"
}
# Main installation flow
main() {
detect_os
echo -e "\n${BLUE}Starting dependency installation...${NC}"
echo -e "${YELLOW}This script will install:${NC}"
echo -e " - PostgreSQL client (psql)"
echo -e " - Docker"
echo -e " - Docker Compose"
echo -e " - Utility packages (curl, wget, git)"
echo ""
echo -e "${YELLOW}Some installations may require sudo privileges.${NC}"
echo -e "${YELLOW}Press Ctrl+C to cancel, or wait 5 seconds to continue...${NC}"
sleep 5
echo ""
install_psql
install_docker
install_docker_compose
install_utilities
echo -e "\n${BLUE}============================================================================${NC}"
echo -e "${GREEN}✓ All dependencies installed successfully!${NC}"
echo -e "${BLUE}============================================================================${NC}"
echo ""
echo -e "${YELLOW}Next steps:${NC}"
echo -e " 1. If Docker was just installed, you may need to log out and back in"
echo -e " 2. Start Docker if it's not running"
echo -e " 3. Run: ${GREEN}docker-compose up -d${NC}"
echo -e " 4. Run: ${GREEN}./scripts/setup-database.sh${NC}"
echo -e " 5. Run: ${GREEN}./data/generate_data.sh${NC}"
echo ""
}
main
+55
View File
@@ -36,6 +36,61 @@ echo -e "User: ${GREEN}$DB_USER${NC}"
echo -e "${BLUE}============================================================================${NC}" echo -e "${BLUE}============================================================================${NC}"
echo "" echo ""
# Check for required dependencies
check_dependencies() {
local missing_deps=()
# Check for psql
if ! command -v psql >/dev/null 2>&1; then
missing_deps+=("psql (PostgreSQL client)")
fi
# Check for docker
if ! command -v docker >/dev/null 2>&1; then
missing_deps+=("docker")
fi
# Check for docker-compose or docker compose
if ! command -v docker-compose >/dev/null 2>&1 && ! docker compose version >/dev/null 2>&1; then
missing_deps+=("docker-compose")
fi
if [ ${#missing_deps[@]} -gt 0 ]; then
echo -e "${RED}✗ Missing required dependencies:${NC}"
for dep in "${missing_deps[@]}"; do
echo -e " - ${YELLOW}$dep${NC}"
done
echo ""
echo -e "${YELLOW}Would you like to run the dependency installer? (y/n)${NC}"
read -r response
if [[ "$response" =~ ^[Yy]$ ]]; then
if [ -f "$SCRIPT_DIR/install-dependencies.sh" ]; then
chmod +x "$SCRIPT_DIR/install-dependencies.sh"
"$SCRIPT_DIR/install-dependencies.sh"
echo ""
echo -e "${GREEN}Dependencies installed. Please re-run this script.${NC}"
exit 0
else
echo -e "${RED}✗ install-dependencies.sh not found${NC}"
echo -e "${YELLOW}Please install the following manually:${NC}"
for dep in "${missing_deps[@]}"; do
echo -e " - $dep"
done
exit 1
fi
else
echo -e "${RED}✗ Cannot proceed without required dependencies${NC}"
exit 1
fi
fi
echo -e "${GREEN}✓ All required dependencies are installed${NC}"
echo ""
}
# Run dependency check
check_dependencies
# Function to execute SQL command # Function to execute SQL command
execute_sql() { execute_sql() {
PGPASSWORD=$DB_PASSWORD psql -h $DB_HOST -p $DB_PORT -U $DB_USER -d $DB_NAME -c "$1" 2>&1 PGPASSWORD=$DB_PASSWORD psql -h $DB_HOST -p $DB_PORT -U $DB_USER -d $DB_NAME -c "$1" 2>&1
+32
View File
@@ -22,11 +22,43 @@ DB_NAME="${POSTGRES_DB:-business_analytics}"
DB_USER="${POSTGRES_USER:-data_analyst}" DB_USER="${POSTGRES_USER:-data_analyst}"
DB_PASSWORD="${POSTGRES_PASSWORD:-SecurePass123!}" DB_PASSWORD="${POSTGRES_PASSWORD:-SecurePass123!}"
# Script directory
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo -e "${BLUE}============================================================================${NC}" echo -e "${BLUE}============================================================================${NC}"
echo -e "${BLUE}Business Analytics Database - Verification${NC}" echo -e "${BLUE}Business Analytics Database - Verification${NC}"
echo -e "${BLUE}============================================================================${NC}" echo -e "${BLUE}============================================================================${NC}"
echo "" echo ""
# Check for required dependencies
check_dependencies() {
local missing_deps=()
# Check for psql
if ! command -v psql >/dev/null 2>&1; then
missing_deps+=("psql (PostgreSQL client)")
fi
# Check for docker
if ! command -v docker >/dev/null 2>&1; then
missing_deps+=("docker")
fi
if [ ${#missing_deps[@]} -gt 0 ]; then
echo -e "${RED}✗ Missing required dependencies:${NC}"
for dep in "${missing_deps[@]}"; do
echo -e " - ${YELLOW}$dep${NC}"
done
echo ""
echo -e "${YELLOW}Run the dependency installer:${NC}"
echo -e " ${GREEN}./scripts/install-dependencies.sh${NC}"
exit 1
fi
}
# Run dependency check
check_dependencies
# Function to execute SQL and get result # Function to execute SQL and get result
execute_sql() { execute_sql() {
PGPASSWORD=$DB_PASSWORD psql -h $DB_HOST -p $DB_PORT -U $DB_USER -d $DB_NAME -t -c "$1" 2>/dev/null | xargs PGPASSWORD=$DB_PASSWORD psql -h $DB_HOST -p $DB_PORT -U $DB_USER -d $DB_NAME -t -c "$1" 2>/dev/null | xargs