| #!/bin/bash |
|
|
| |
| |
|
|
| set -euo pipefail |
|
|
| |
| XET_VERSION="0.9.0" |
| INSTALL_DIR="/usr/local/bin" |
| CONFIG_DIR="/etc/dto/xet" |
| LOG_DIR="/var/log/dto" |
|
|
| |
| RED='\033[0;31m' |
| GREEN='\033[0;32m' |
| YELLOW='\033[1;33m' |
| NC='\033[0m' |
|
|
| |
| 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_root() { |
| if [[ $EUID -ne 0 ]]; then |
| error "This script must be run as root" |
| exit 1 |
| fi |
| } |
|
|
| |
| install_xet() { |
| log "Installing Xet CLI version ${XET_VERSION}" |
| |
| |
| ARCH=$(uname -m) |
| case $ARCH in |
| x86_64) ARCH="amd64" ;; |
| aarch64) ARCH="arm64" ;; |
| *) error "Unsupported architecture: $ARCH"; exit 1 ;; |
| esac |
| |
| |
| 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 |
| } |
| |
| |
| chmod +x "/tmp/xet" |
| mv "/tmp/xet" "${INSTALL_DIR}/xet" |
| |
| |
| 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() { |
| log "Configuring Xet environment" |
| |
| |
| mkdir -p "$CONFIG_DIR" "$LOG_DIR" "/mnt/xet" |
| |
| |
| 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 |
| |
| |
| chmod 755 "/mnt/xet" |
| chmod 644 "${CONFIG_DIR}/environment" |
| |
| log "Xet environment configured" |
| } |
|
|
| |
| 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() { |
| log "Installing dependencies" |
| |
| |
| apt-get update || yum update || { |
| warning "Package manager update failed - continuing anyway" |
| } |
| |
| |
| 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() { |
| 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" |
| } |
|
|
| |
| main "$@" |