Technical Implementation Guide
Complete technical reference for implementing and using the customer deployment system.
System Architecture
Core Components
graph TB
A[Customer Project] --> B[Universal Script]
A --> C[Customer Template]
B --> D[DirectAdmin API]
B --> E[Manual Fallback]
D --> F[SatoshiHost]
D --> G[External Host]
E --> H[File Manager]
style A fill:#e3f2fd
style B fill:#f3e5f5
style C fill:#fff3e0
style D fill:#e8f5e8
File Structure
customer-project/
├── deploy-customer.sh # Universal deployment script
├── customer-template.sh # Per-customer configuration
├── index.html # Website files
├── style.css
├── assets/
└── README.md
Installation & Setup
1. Copy Deployment Tools
# Create tools directory
mkdir -p ~/customer-tools
# Copy from DirectSponsor project
cp /path/to/directsponsor/org-site/deploy-customer.sh ~/customer-tools/
cp /path/to/directsponsor/org-site/customer-template.sh ~/customer-tools/
cp /path/to/directsponsor/org-site/CUSTOMER-DEPLOYMENT.md ~/customer-tools/
# Make executable
chmod +x ~/customer-tools/*.sh
2. Create Customer Project
# New customer project
mkdir ~/customer-projects/client-name
cd ~/customer-projects/client-name
# Copy tools
cp ~/customer-tools/deploy-customer.sh .
cp ~/customer-tools/customer-template.sh deploy.sh
chmod +x *.sh
3. Configure Customer Details
Edit deploy.sh
:
# Customer Details
CUSTOMER_NAME="Client Company Name"
CUSTOMER_DOMAIN="client-domain.com"
CUSTOMER_EMAIL="contact@client-domain.com"
# SatoshiHost Configuration
DA_USERNAME="client_hosting_username" # Account you created
DA_PASSWORD="client_hosting_password" # Password you set
# External Host Configuration (if needed)
# DA_SERVER="external-host.com"
# DA_PORT="2222"
# DA_PATH="public_html"
Universal Deployment Script
Core Features
1. Environment Detection
# Parse arguments or use environment defaults
DA_DOMAIN="${1:-$DA_DOMAIN}"
DA_PATH="${2:-$DA_PATH}"
DA_SERVER="${3:-$DA_SERVER}"
DA_PORT="${4:-${DA_PORT:-2222}}"
# Set intelligent defaults
DA_PATH="${DA_PATH:-domains/$DA_DOMAIN/public_html}"
DA_SERVER="${DA_SERVER:-directadmin-de.kxe.io}" # SatoshiHost default
2. Credential Management
# Security: Use environment variables
DA_USER="$DA_USERNAME" # Never expose in command line
DA_PASS="$DA_PASSWORD" # Secure credential handling
# Validation
if [[ -z "$DA_USERNAME" || -z "$DA_PASSWORD" ]]; then
echo "❌ DirectAdmin credentials required"
exit 1
fi
3. API Functions
function da_api_call() {
local endpoint="$1"
local data="$2"
local method="${3:-POST}"
curl -s -X "$method" \
"https://${DA_SERVER}:${DA_PORT}/CMD_API_${endpoint}" \
-d "$data" \
-u "${DA_USER}:${DA_PASS}" \
--connect-timeout 10 \
--max-time 30 \
--insecure # DirectAdmin often uses self-signed certs
}
4. Deployment Process
# 1. Validate HTML files
for html_file in *.html; do
if [ -f "$html_file" ]; then
tidy -q -e "$html_file" || echo "⚠️ Warnings in $html_file"
fi
done
# 2. Create deployment package
TIMESTAMP=$(date '+%Y%m%d_%H%M%S')
PACKAGE_NAME="${DA_DOMAIN}_${TIMESTAMP}.zip"
zip -r "$PACKAGE_NAME" *.html *.css *.js *.png *.jpg *.gif *.svg
# 3. Test API connection
API_TEST=$(da_api_call "SHOW_USER_CONFIG" "" "GET" 2>/dev/null || echo "FAILED")
# 4. Upload files
if [[ "$API_TEST" != "FAILED" ]]; then
# API upload
da_api_call "FILE_MANAGER" "action=upload&path=/$DA_PATH" "POST" -F "file=@$PACKAGE_NAME"
else
# Fallback to manual instructions
show_manual_deployment_steps
fi
# 5. Set permissions
for file in *.html *.css *.js; do
da_api_call "FILE_MANAGER" "action=chmod&path=/$DA_PATH/$file&chmod=644"
done
# 6. Test deployment
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "http://$DA_DOMAIN")
HTTPS_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "https://$DA_DOMAIN")
Error Handling
API Connection Failures
if [[ "$API_TEST" == "FAILED" ]]; then
echo "❌ DirectAdmin API connection failed!"
echo "📝 Manual deployment instructions:"
echo " 1. Login: https://$DA_SERVER:$DA_PORT"
echo " 2. File Manager → $DA_PATH"
echo " 3. Upload files, set permissions 644"
echo " 4. Test: https://$DA_DOMAIN"
fi
Upload Failures
# Automatic fallback to individual file upload
if [[ "$UPLOAD_RESULT" == *"error"* ]]; then
echo "❌ Package upload failed, trying individual files..."
for file in *.html *.css *.js; do
da_api_call "FILE_MANAGER" "action=upload&path=/$DA_PATH" "POST" -F "file=@$file"
done
fi
Customer Template System
Template Structure
#!/bin/bash
# Customer Project Deployment Template
# Customer Configuration
CUSTOMER_NAME="Customer Name"
CUSTOMER_DOMAIN="example.com"
CUSTOMER_EMAIL="customer@example.com"
# Hosting Configuration
DA_USERNAME="" # Set customer's hosting username
DA_PASSWORD="" # Set customer's hosting password
# Functions
function deploy_customer() {
export DA_USERNAME DA_PASSWORD
./deploy-customer.sh "$CUSTOMER_DOMAIN"
}
function deploy_auto() {
export DA_USERNAME DA_PASSWORD
./deploy-customer.sh --auto "$CUSTOMER_DOMAIN"
}
# Usage
case "${1:-help}" in
"deploy") deploy_customer ;;
"auto") deploy_auto ;;
"info") show_customer_info ;;
*) show_help ;;
esac
Usage Commands
# Interactive deployment
./deploy.sh deploy
# Automated deployment (no prompts)
./deploy.sh auto
# Show customer information
./deploy.sh info
# Show help
./deploy.sh help
Advanced Configuration
Environment Variables
Variable | Required | Default | Description |
---|---|---|---|
DA_USERNAME |
✅ | - | DirectAdmin username |
DA_PASSWORD |
✅ | - | DirectAdmin password |
DA_SERVER |
⭕ | directadmin-de.kxe.io |
DirectAdmin server |
DA_PORT |
⭕ | 2222 |
DirectAdmin port |
DA_PATH |
⭕ | domains/DOMAIN/public_html |
Upload path |
Git Integration
# Automatic git workflow during deployment
if git rev-parse --git-dir > /dev/null 2>&1; then
if [[ -n $(git status --porcelain) ]]; then
COMMIT_MSG="Deploy $DA_DOMAIN: $(date '+%Y-%m-%d %H:%M')"
git add .
git commit -m "$COMMIT_MSG"
fi
fi
Batch Deployment
# Deploy multiple customer sites
for customer in coffee-shop law-firm restaurant; do
cd ~/customer-projects/$customer
./deploy.sh auto # No prompts
echo "✅ Deployed $customer"
cd ..
done
Security Considerations
Credential Security
# ✅ Good: Environment variables
export DA_USERNAME='username'
export DA_PASSWORD='password'
./deploy-customer.sh domain.com
# ❌ Bad: Command line arguments (visible in process list)
./deploy-customer.sh domain.com username password
File Permissions
# Set secure permissions
chmod 644 *.html *.css *.js # Files: read/write owner, read others
chmod 755 directories/ # Directories: execute permissions
chmod 700 deploy.sh # Scripts: owner only
API Security
# Use HTTPS with timeout
curl -s -X POST \
"https://${DA_SERVER}:${DA_PORT}/CMD_API_${endpoint}" \
--connect-timeout 10 \
--max-time 30 \
--insecure # Only for DirectAdmin self-signed certs
Troubleshooting
Common Issues
API Connection Failed
Symptoms: - "DirectAdmin API connection failed!" - Curl timeout or connection refused
Solutions:
# Check credentials
echo "Username: $DA_USERNAME"
echo "Server: $DA_SERVER:$DA_PORT"
# Test manual connection
curl -u "$DA_USERNAME:$DA_PASSWORD" "https://$DA_SERVER:$DA_PORT/CMD_API_SHOW_USER_CONFIG"
# Use manual deployment
# Script automatically provides File Manager instructions
Upload Failed
Symptoms: - "Package upload failed" - Individual file upload errors
Solutions:
# Check file sizes and disk space
ls -lah *.html *.css *.js
# Check hosting account quotas in DirectAdmin
# Reduce file sizes if needed
# Use manual File Manager upload as fallback
Site Not Accessible
Symptoms: - HTTP 404 or 500 errors - Site not loading
Solutions:
# Check DNS settings
nslookup $DA_DOMAIN
# Verify domain added in DirectAdmin
# Check file permissions (should be 644)
# Allow DNS propagation time (24-48 hours)
Debug Mode
# Enable debug output
set -x # Show all commands
set -e # Exit on first error
# Test individual components
./deploy-customer.sh domain.com 2>&1 | tee deployment.log
Performance Optimization
File Packaging
# Optimize package creation
zip -r "$PACKAGE_NAME" \
*.html *.css *.js \
*.png *.jpg *.jpeg *.gif *.svg \
-x "*.tmp" "*.log" "*.bak"
Parallel Deployment
# Deploy multiple customers in parallel
for customer in customer1 customer2 customer3; do
(
cd ~/customer-projects/$customer
./deploy.sh auto
) &
done
wait # Wait for all deployments to complete
API Optimization
# Batch API operations where possible
# Use connection reuse
# Cache API responses when appropriate
Integration Examples
WordPress Deployment
# Download WordPress
wget https://wordpress.org/latest.zip
unzip latest.zip
mv wordpress/* .
# Deploy with custom path
./deploy-customer.sh domain.com wp-content/themes/custom
Static Site Generators
# Jekyll
jekyll build
cp -r _site/* .
./deploy.sh deploy
# Hugo
hugo
cp -r public/* .
./deploy.sh deploy
CI/CD Integration
# GitHub Actions example
name: Deploy Customer Site
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Deploy
env:
DA_USERNAME: ${{ secrets.DA_USERNAME }}
DA_PASSWORD: ${{ secrets.DA_PASSWORD }}
run: ./deploy.sh auto
This technical guide provides complete implementation details for the customer deployment system, enabling developers to deploy professional websites efficiently while maintaining security and reliability.