#!/bin/bash # Xet Setup Script for DTO Framework # Prometheus - Head of Data Migration & Transfer Operations set -euo pipefail # Configuration XET_VERSION="0.9.0" INSTALL_DIR="/usr/local/bin" CONFIG_DIR="/etc/dto/xet" LOG_DIR="/var/log/dto" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Logging function log() { echo -e "${GREEN}[$(date '+%Y-%m-%d %H:%M:%S')]${NC} $1" } error() { echo -e "${RED}[ERROR]${NC} $1" >&2 } warning() { echo -e "${YELLOW}[WARNING]${NC} $1" } # Check if running as root check_root() { if [[ $EUID -ne 0 ]]; then error "This script must be run as root" exit 1 fi } # Install Xet CLI install_xet() { log "Installing Xet CLI version ${XET_VERSION}" # Detect architecture ARCH=$(uname -m) case $ARCH in x86_64) ARCH="amd64" ;; aarch64) ARCH="arm64" ;; *) error "Unsupported architecture: $ARCH"; exit 1 ;; esac # Download Xet DOWNLOAD_URL="https://github.com/xetdata/xet-core/releases/download/v${XET_VERSION}/xet-linux-${ARCH}" log "Downloading Xet from: $DOWNLOAD_URL" curl -L -o "/tmp/xet" "$DOWNLOAD_URL" || { error "Failed to download Xet" exit 1 } # Install to system chmod +x "/tmp/xet" mv "/tmp/xet" "${INSTALL_DIR}/xet" # Verify installation if command -v xet >/dev/null 2>&1; then log "Xet installed successfully: $(xet --version)" else error "Xet installation failed" exit 1 fi } # Configure Xet environment configure_xet() { log "Configuring Xet environment" # Create directories mkdir -p "$CONFIG_DIR" "$LOG_DIR" "/mnt/xet" # Create configuration cat > "${CONFIG_DIR}/environment" << EOF # Xet Environment Configuration export XET_CACHE_DIR="/var/cache/xet" export XET_CONFIG_DIR="${CONFIG_DIR}" export XET_LOG_DIR="${LOG_DIR}" export XET_MOUNT_DIR="/mnt/xet" EOF # Set permissions chmod 755 "/mnt/xet" chmod 644 "${CONFIG_DIR}/environment" log "Xet environment configured" } # Setup systemd service (optional) setup_service() { log "Setting up Xet systemd service" cat > "/etc/systemd/system/dto-xet.service" << EOF [Unit] Description=DTO Xet Integration Service After=network.target [Service] Type=simple User=root Group=root EnvironmentFile=${CONFIG_DIR}/environment ExecStart=/usr/bin/bash -c "source ${CONFIG_DIR}/environment && ${INSTALL_DIR}/xet mount /mnt/xet" Restart=always RestartSec=5 [Install] WantedBy=multi-user.target EOF systemctl daemon-reload log "Xet systemd service configured" } # Install dependencies install_dependencies() { log "Installing dependencies" # Update package list apt-get update || yum update || { warning "Package manager update failed - continuing anyway" } # Install required packages if command -v apt-get >/dev/null 2>&1; then apt-get install -y curl fuse libfuse2 elif command -v yum >/dev/null 2>&1; then yum install -y curl fuse elif command -v dnf >/dev/null 2>&1; then dnf install -y curl fuse else warning "Unknown package manager - please install curl and fuse manually" fi } # Main installation function main() { log "Starting Xet installation for DTO Framework" check_root install_dependencies install_xet configure_xet setup_service log "Xet installation completed successfully!" log "Next steps:" log " 1. Configure Xet repositories in ${CONFIG_DIR}/" log " 2. Set XET_AUTH_TOKEN environment variable" log " 3. Start service: systemctl start dto-xet" log " 4. Enable service: systemctl enable dto-xet" } # Run main function main "$@"