251 lines
6.4 KiB
Bash
251 lines
6.4 KiB
Bash
|
|
#!/bin/bash
|
||
|
|
# =============================================================================
|
||
|
|
# Initialize bigdisk Development Storage
|
||
|
|
# =============================================================================
|
||
|
|
#
|
||
|
|
# Creates the development data directories on bigdisk for persistent storage.
|
||
|
|
# All Docker volumes mount to these directories instead of Docker-managed volumes.
|
||
|
|
#
|
||
|
|
# Location: /mnt/bigdisk/_/@lilith/dev/lilith-platform/
|
||
|
|
#
|
||
|
|
# Usage:
|
||
|
|
# ./init-bigdisk-dev.sh # Create directories
|
||
|
|
# ./init-bigdisk-dev.sh --check # Check if directories exist
|
||
|
|
# ./init-bigdisk-dev.sh --clean # Remove all data (DESTRUCTIVE)
|
||
|
|
#
|
||
|
|
|
||
|
|
set -euo pipefail
|
||
|
|
|
||
|
|
# Configuration
|
||
|
|
BIGDISK_BASE="/mnt/bigdisk/_/@lilith"
|
||
|
|
DEV_ROOT="${BIGDISK_BASE}/dev/lilith-platform"
|
||
|
|
PROD_ROOT="${BIGDISK_BASE}/prod/lilith-platform"
|
||
|
|
|
||
|
|
# Data directories to create
|
||
|
|
DATA_DIRS=(
|
||
|
|
"postgres" # PostgreSQL data
|
||
|
|
"redis" # Redis persistence (AOF)
|
||
|
|
"meilisearch" # Meilisearch index data
|
||
|
|
"minio" # Object storage (S3-compatible)
|
||
|
|
"seeds" # Seed data snapshots
|
||
|
|
"sdxl-models" # ML model cache (SDXL, etc.)
|
||
|
|
"image-gen-jobs" # Image generation job cache
|
||
|
|
)
|
||
|
|
|
||
|
|
# Colors for output
|
||
|
|
RED='\033[0;31m'
|
||
|
|
GREEN='\033[0;32m'
|
||
|
|
YELLOW='\033[1;33m'
|
||
|
|
BLUE='\033[0;34m'
|
||
|
|
NC='\033[0m' # No Color
|
||
|
|
|
||
|
|
log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
|
||
|
|
log_success() { echo -e "${GREEN}[OK]${NC} $1"; }
|
||
|
|
log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
|
||
|
|
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
|
||
|
|
|
||
|
|
# Check if bigdisk is mounted
|
||
|
|
check_bigdisk() {
|
||
|
|
if [[ ! -d "/mnt/bigdisk" ]]; then
|
||
|
|
log_error "bigdisk not found at /mnt/bigdisk"
|
||
|
|
log_error "Is the drive mounted?"
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
# Check if writable
|
||
|
|
if [[ ! -w "/mnt/bigdisk" ]]; then
|
||
|
|
log_error "bigdisk is not writable"
|
||
|
|
log_error "Check permissions: ls -la /mnt/bigdisk"
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
log_success "bigdisk is mounted and writable"
|
||
|
|
}
|
||
|
|
|
||
|
|
# Create directory structure
|
||
|
|
create_directories() {
|
||
|
|
local root="$1"
|
||
|
|
local env_name="$2"
|
||
|
|
|
||
|
|
log_info "Creating ${env_name} directory structure at ${root}..."
|
||
|
|
|
||
|
|
# Create base directory
|
||
|
|
if [[ ! -d "$root" ]]; then
|
||
|
|
mkdir -p "$root"
|
||
|
|
log_success "Created ${root}"
|
||
|
|
else
|
||
|
|
log_info "${root} already exists"
|
||
|
|
fi
|
||
|
|
|
||
|
|
# Create data directories
|
||
|
|
for dir in "${DATA_DIRS[@]}"; do
|
||
|
|
local full_path="${root}/${dir}"
|
||
|
|
if [[ ! -d "$full_path" ]]; then
|
||
|
|
mkdir -p "$full_path"
|
||
|
|
log_success "Created ${dir}/"
|
||
|
|
else
|
||
|
|
log_info "${dir}/ already exists"
|
||
|
|
fi
|
||
|
|
done
|
||
|
|
|
||
|
|
# Set permissions (allow Docker to write)
|
||
|
|
chmod -R 775 "$root"
|
||
|
|
|
||
|
|
log_success "${env_name} directories initialized at ${root}"
|
||
|
|
}
|
||
|
|
|
||
|
|
# Check if directories exist and show status
|
||
|
|
check_directories() {
|
||
|
|
local root="$1"
|
||
|
|
local env_name="$2"
|
||
|
|
|
||
|
|
echo ""
|
||
|
|
log_info "Checking ${env_name} directories at ${root}..."
|
||
|
|
echo ""
|
||
|
|
|
||
|
|
local all_exist=true
|
||
|
|
|
||
|
|
for dir in "${DATA_DIRS[@]}"; do
|
||
|
|
local full_path="${root}/${dir}"
|
||
|
|
if [[ -d "$full_path" ]]; then
|
||
|
|
local size
|
||
|
|
size=$(du -sh "$full_path" 2>/dev/null | cut -f1)
|
||
|
|
echo -e " ${GREEN}✓${NC} ${dir}/ (${size})"
|
||
|
|
else
|
||
|
|
echo -e " ${RED}✗${NC} ${dir}/ (missing)"
|
||
|
|
all_exist=false
|
||
|
|
fi
|
||
|
|
done
|
||
|
|
|
||
|
|
echo ""
|
||
|
|
|
||
|
|
if $all_exist; then
|
||
|
|
log_success "All ${env_name} directories exist"
|
||
|
|
return 0
|
||
|
|
else
|
||
|
|
log_warn "Some ${env_name} directories are missing"
|
||
|
|
return 1
|
||
|
|
fi
|
||
|
|
}
|
||
|
|
|
||
|
|
# Clean all data (DESTRUCTIVE)
|
||
|
|
clean_directories() {
|
||
|
|
local root="$1"
|
||
|
|
local env_name="$2"
|
||
|
|
|
||
|
|
log_warn "This will DELETE all ${env_name} data at ${root}"
|
||
|
|
log_warn "This action is IRREVERSIBLE!"
|
||
|
|
echo ""
|
||
|
|
read -p "Type 'DELETE' to confirm: " confirm
|
||
|
|
|
||
|
|
if [[ "$confirm" != "DELETE" ]]; then
|
||
|
|
log_info "Aborted"
|
||
|
|
exit 0
|
||
|
|
fi
|
||
|
|
|
||
|
|
log_info "Removing ${root}..."
|
||
|
|
rm -rf "$root"
|
||
|
|
log_success "${env_name} data removed"
|
||
|
|
}
|
||
|
|
|
||
|
|
# Show usage
|
||
|
|
show_usage() {
|
||
|
|
cat << EOF
|
||
|
|
Initialize bigdisk Development Storage
|
||
|
|
|
||
|
|
Usage: $(basename "$0") [OPTIONS]
|
||
|
|
|
||
|
|
Options:
|
||
|
|
--check Check if directories exist
|
||
|
|
--clean Remove all data (DESTRUCTIVE - requires confirmation)
|
||
|
|
--prod Also initialize production directories
|
||
|
|
-h, --help Show this help
|
||
|
|
|
||
|
|
Directories created:
|
||
|
|
/mnt/bigdisk/_/@lilith/dev/lilith-platform/
|
||
|
|
postgres/ - PostgreSQL database files
|
||
|
|
redis/ - Redis AOF persistence
|
||
|
|
meilisearch/ - Search engine index
|
||
|
|
minio/ - Object storage (images, media)
|
||
|
|
seeds/ - Database seed snapshots
|
||
|
|
sdxl-models/ - ML model cache
|
||
|
|
image-gen-jobs/ - Image generation results
|
||
|
|
|
||
|
|
EOF
|
||
|
|
}
|
||
|
|
|
||
|
|
# Main
|
||
|
|
main() {
|
||
|
|
local action="init"
|
||
|
|
local include_prod=false
|
||
|
|
|
||
|
|
while [[ $# -gt 0 ]]; do
|
||
|
|
case "$1" in
|
||
|
|
--check)
|
||
|
|
action="check"
|
||
|
|
shift
|
||
|
|
;;
|
||
|
|
--clean)
|
||
|
|
action="clean"
|
||
|
|
shift
|
||
|
|
;;
|
||
|
|
--prod)
|
||
|
|
include_prod=true
|
||
|
|
shift
|
||
|
|
;;
|
||
|
|
-h|--help)
|
||
|
|
show_usage
|
||
|
|
exit 0
|
||
|
|
;;
|
||
|
|
*)
|
||
|
|
log_error "Unknown option: $1"
|
||
|
|
show_usage
|
||
|
|
exit 1
|
||
|
|
;;
|
||
|
|
esac
|
||
|
|
done
|
||
|
|
|
||
|
|
# Always check bigdisk first
|
||
|
|
check_bigdisk
|
||
|
|
|
||
|
|
case "$action" in
|
||
|
|
init)
|
||
|
|
# Create base @lilith directory
|
||
|
|
mkdir -p "$BIGDISK_BASE"
|
||
|
|
|
||
|
|
create_directories "$DEV_ROOT" "development"
|
||
|
|
|
||
|
|
if $include_prod; then
|
||
|
|
create_directories "$PROD_ROOT" "production"
|
||
|
|
fi
|
||
|
|
|
||
|
|
echo ""
|
||
|
|
log_success "bigdisk storage initialized!"
|
||
|
|
echo ""
|
||
|
|
echo "Use in docker-compose.dev-all.yml:"
|
||
|
|
echo " volumes:"
|
||
|
|
echo " - ${DEV_ROOT}/postgres:/var/lib/postgresql/data"
|
||
|
|
echo " - ${DEV_ROOT}/redis:/data"
|
||
|
|
echo " - ${DEV_ROOT}/meilisearch:/meili_data"
|
||
|
|
echo " - ${DEV_ROOT}/minio:/data"
|
||
|
|
;;
|
||
|
|
check)
|
||
|
|
check_directories "$DEV_ROOT" "development"
|
||
|
|
|
||
|
|
if $include_prod; then
|
||
|
|
check_directories "$PROD_ROOT" "production"
|
||
|
|
fi
|
||
|
|
;;
|
||
|
|
clean)
|
||
|
|
clean_directories "$DEV_ROOT" "development"
|
||
|
|
|
||
|
|
if $include_prod; then
|
||
|
|
echo ""
|
||
|
|
clean_directories "$PROD_ROOT" "production"
|
||
|
|
fi
|
||
|
|
;;
|
||
|
|
esac
|
||
|
|
}
|
||
|
|
|
||
|
|
main "$@"
|