Files
unitforge/demo.sh
William Valentin 860f60591c Fix contrast issues with text-muted and bg-dark classes
- Fixed Bootstrap bg-dark class to use better contrasting color
- Added comprehensive text-muted contrast fixes for various contexts
- Improved dark theme colors for better accessibility
- Fixed CSS inheritance issues for code elements in dark contexts
- All color choices meet WCAG AA contrast requirements
2025-09-14 14:58:35 -07:00

272 lines
8.6 KiB
Bash
Executable File

#!/bin/bash
# UnitForge Demo Script
# This script demonstrates the key features of UnitForge
set -e
# Load centralized color utility
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${SCRIPT_DIR}/scripts/colors.sh"
# Check if virtual environment is activated
if [[ -z "${VIRTUAL_ENV}" ]]; then
echo -e "${YELLOW}Activating virtual environment...${NC}"
if [[ -d ".venv" ]]; then
source .venv/bin/activate
elif [[ -d "venv" ]]; then
source venv/bin/activate
else
echo -e "${RED}No virtual environment found. Run 'make setup-dev' first.${NC}"
exit 1
fi
fi
echo -e "${BLUE}╔══════════════════════════════════════════════╗${NC}"
echo -e "${BLUE}║ UnitForge Demo ║${NC}"
echo -e "${BLUE}║ Systemd Unit File Creator & Manager ║${NC}"
echo -e "${BLUE}╚══════════════════════════════════════════════╝${NC}"
echo ""
# Function to run command with header
run_demo() {
echo -e "${CYAN}=== $1 ===${NC}"
echo -e "${YELLOW}Command: $2${NC}"
echo ""
eval "$2"
echo ""
echo -e "${GREEN}✓ Completed${NC}"
echo ""
read -p "Press Enter to continue..."
echo ""
}
# Check if uv is available
echo -e "${CYAN}Checking development environment...${NC}"
if command -v uv >/dev/null 2>&1; then
echo -e "${GREEN}✓ uv package manager available${NC}"
else
echo -e "${YELLOW}⚠ uv not found, using standard pip${NC}"
fi
echo ""
# 1. Show CLI help
run_demo "CLI Help and Version" "./unitforge-cli --help"
# 2. List available templates
run_demo "List Available Templates" "./unitforge-cli template list"
# 3. Show template details
run_demo "Show Template Details" "./unitforge-cli template show webapp"
# 4. Create a simple service
run_demo "Create Simple Service" "./unitforge-cli create --type service --name myapp --exec-start '/usr/bin/python3 /opt/myapp/main.py' --user myapp --working-directory /opt/myapp --output demo-simple.service"
# 5. Show created file
echo -e "${CYAN}=== Generated Service File ===${NC}"
echo -e "${YELLOW}Content of demo-simple.service:${NC}"
echo ""
cat demo-simple.service
echo ""
echo -e "${GREEN}✓ File created${NC}"
echo ""
read -p "Press Enter to continue..."
echo ""
# 6. Validate the created file
run_demo "Validate Created Service" "./unitforge-cli validate demo-simple.service"
# 7. Generate from webapp template
echo -e "${CYAN}=== Generate from Template (Interactive) ===${NC}"
echo -e "${YELLOW}This will create a web application service using the webapp template${NC}"
echo ""
# Create parameters for the webapp template
./unitforge-cli template generate webapp \
--param name=mywebapp \
--param description="My Demo Web Application" \
--param exec_start="/usr/bin/node /opt/mywebapp/server.js" \
--param user=webapp \
--param group=webapp \
--param working_directory=/opt/mywebapp \
--param port=3000 \
--param restart_policy=on-failure \
--param private_tmp=true \
--param protect_system=strict \
--output demo-webapp.service \
--validate-output
echo ""
echo -e "${GREEN}✓ Generated webapp service${NC}"
echo ""
# 8. Show generated webapp file
echo -e "${CYAN}=== Generated Web App Service File ===${NC}"
echo -e "${YELLOW}Content of demo-webapp.service:${NC}"
echo ""
cat demo-webapp.service
echo ""
echo -e "${GREEN}✓ Generated from template${NC}"
echo ""
read -p "Press Enter to continue..."
echo ""
# 9. Create a timer service
run_demo "Create Timer Service" "./unitforge-cli create --type timer --name backup --description 'Daily backup timer' --output demo-backup.timer"
# 10. Show timer file
echo -e "${CYAN}=== Generated Timer File ===${NC}"
echo -e "${YELLOW}Content of demo-backup.timer:${NC}"
echo ""
cat demo-backup.timer
echo ""
success "Backup timer created!"
echo ""
read -p "Press Enter to continue..."
echo ""
# 11. Generate container service from template
echo -e "${CYAN}=== Generate Container Service ===${NC}"
echo -e "${YELLOW}Creating a Docker container service${NC}"
echo ""
./unitforge-cli template generate container \
--param name=nginx-container \
--param description="Nginx Web Server Container" \
--param container_runtime=docker \
--param image=nginx:alpine \
--param ports="80:80,443:443" \
--param volumes="/data/nginx:/usr/share/nginx/html:ro" \
--param environment="NGINX_HOST=localhost" \
--param restart_policy=unless-stopped \
--output demo-nginx.service \
--validate-output
echo ""
echo -e "${GREEN}✓ Generated container service${NC}"
echo ""
# 12. Show container file
echo -e "${CYAN}=== Generated Container Service File ===${NC}"
echo -e "${YELLOW}Content of demo-nginx.service:${NC}"
echo ""
cat demo-nginx.service
echo ""
read -p "Press Enter to continue..."
echo ""
# 13. Edit a unit file
echo -e "${CYAN}=== Edit Unit File ===${NC}"
echo -e "${YELLOW}Adding environment variables to the simple service${NC}"
echo ""
./unitforge-cli edit demo-simple.service demo-simple-modified.service \
--set "Service.Environment=DEBUG=1" \
--set "Service.EnvironmentFile=/etc/myapp/config" \
--set "Service.RestartSec=10" \
--validate-output
echo ""
echo -e "${GREEN}✓ Modified service file${NC}"
echo ""
# 14. Show differences
echo -e "${CYAN}=== File Modifications ===${NC}"
echo -e "${YELLOW}Differences between original and modified files:${NC}"
echo ""
echo -e "${BLUE}Original file:${NC}"
cat demo-simple.service
echo ""
echo -e "${BLUE}Modified file:${NC}"
cat demo-simple-modified.service
echo ""
read -p "Press Enter to continue..."
echo ""
# 15. Show unit file info
run_demo "Show Unit File Information" "./unitforge-cli info demo-webapp.service"
# 16. Test validation with invalid file
echo -e "${CYAN}=== Test Validation (Invalid File) ===${NC}"
echo -e "${YELLOW}Creating an invalid unit file to test validation${NC}"
echo ""
cat > demo-invalid.service << 'EOF'
[Unit]
Description=Invalid Service
[Service]
Type=invalid-type
ExecStart=
User=
[Install]
WantedBy=invalid.target
EOF
echo "Created invalid service file with errors..."
echo ""
./unitforge-cli validate demo-invalid.service || echo -e "${YELLOW}(Expected validation errors shown above)${NC}"
echo ""
read -p "Press Enter to continue..."
echo ""
# 17. Cleanup and summary
echo -e "${CYAN}=== Demo Summary ===${NC}"
echo ""
echo -e "${GREEN}✓ Created simple service unit file${NC}"
echo -e "${GREEN}✓ Generated web application service from template${NC}"
echo -e "${GREEN}✓ Created timer unit file${NC}"
echo -e "${GREEN}✓ Generated container service from template${NC}"
echo -e "${GREEN}✓ Modified unit file with new settings${NC}"
echo -e "${GREEN}✓ Validated unit files (both valid and invalid)${NC}"
echo -e "${GREEN}✓ Displayed unit file information${NC}"
echo ""
echo -e "${BLUE}Generated files:${NC}"
ls -la demo-*.service demo-*.timer 2>/dev/null || echo "No demo files found"
echo ""
echo -e "${YELLOW}To start the web interface:${NC}"
echo -e " ${CYAN}make server${NC}"
echo -e " ${CYAN}./start-server.sh${NC}"
echo ""
echo -e "${YELLOW}To install the CLI tool:${NC}"
echo -e " ${CYAN}uv pip install -e .${NC}"
echo ""
echo -e "${YELLOW}Development workflow:${NC}"
echo -e " ${CYAN}make setup-dev # Setup environment with uv${NC}"
echo -e " ${CYAN}make test # Run tests${NC}"
echo -e " ${CYAN}make format # Format code${NC}"
echo -e " ${CYAN}make lint # Check code style${NC}"
echo ""
read -p "Clean up demo files? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
rm -f demo-*.service demo-*.timer webapp.service
success "Demo files cleaned up"
else
echo -e "${YELLOW}Demo files preserved for inspection${NC}"
fi
echo ""
echo -e "${BLUE}🎉 UnitForge demo completed! 🎉${NC}"
echo ""
echo -e "${GREEN}Key features demonstrated:${NC}"
echo -e " • CLI for creating, validating, and editing unit files"
echo -e " • Template system for common service types"
echo -e " • Comprehensive validation with helpful error messages"
echo -e " • Support for all major systemd unit types"
echo -e " • Web interface for visual editing"
echo -e " • Lightning-fast development with uv (no pip dependency)"
echo ""
echo -e "${CYAN}Visit the web interface at http://localhost:8000 for more features!${NC}"
echo ""
echo -e "${BLUE}Development commands:${NC}"
echo -e " ${CYAN}make server # Start web interface${NC}"
echo -e " ${CYAN}make test-cov # Run tests with coverage${NC}"
echo -e " ${CYAN}make docker-dev # Docker development${NC}"
echo -e " ${CYAN}make status # Check project status${NC}"