#!/bin/bash
#
# zfsdu - Quick Binary Installation
# Downloads and installs pre-built binary from GitLab
#
# No additional packages required - uses only standard glibc
#

set -e

GITLAB_URL="https://gitlab.datazone.de/kidev/zfsdu/-/raw/main/releases/zfsdu-linux-amd64"
INSTALL_PATH="/usr/local/bin/zfsdu"

RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'

echo -e "${GREEN}================================${NC}"
echo -e "${GREEN}  zfsdu - Binary Installation   ${NC}"
echo -e "${GREEN}================================${NC}"
echo

# Check root
if [ "$EUID" -ne 0 ]; then
    echo -e "${RED}Error: Please run as root${NC}"
    echo "Usage: curl -sSL ... | sudo bash"
    exit 1
fi

# Download and install
echo -e "${YELLOW}Downloading zfsdu...${NC}"
curl -sSL -o "$INSTALL_PATH" "$GITLAB_URL"
chmod +x "$INSTALL_PATH"

# Verify
if [ -x "$INSTALL_PATH" ]; then
    echo -e "${GREEN}Successfully installed to $INSTALL_PATH${NC}"
else
    echo -e "${RED}Installation failed${NC}"
    exit 1
fi

# Check ZFS
if ! command -v zfs &> /dev/null; then
    echo
    echo -e "${YELLOW}Note: ZFS not found. Install with:${NC}"
    echo "  apt install zfsutils-linux"
fi

echo
echo -e "${GREEN}Done! Run 'zfsdu' to start.${NC}"
