File size: 3,821 Bytes
fd357f4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
#!/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 "$@" |