#!/bin/sh # Ziew installer for macOS and Linux # Usage: curl -fsSL ziew.sh/install | sh set -e # Colors RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' CYAN='\033[0;36m' BOLD='\033[1m' NC='\033[0m' # No Color # Versions ZIG_VERSION="0.13.0" ZIEW_VERSION="0.3.0-alpha" # Install locations INSTALL_DIR="$HOME/.ziew" BIN_DIR="$INSTALL_DIR/bin" print_banner() { echo "" echo "${CYAN}${BOLD}" echo " ███████╗██╗███████╗██╗ ██╗" echo " ╚══███╔╝██║██╔════╝██║ ██║" echo " ███╔╝ ██║█████╗ ██║ █╗ ██║" echo " ███╔╝ ██║██╔══╝ ██║███╗██║" echo " ███████╗██║███████╗╚███╔███╔╝" echo " ╚══════╝╚═╝╚══════╝ ╚══╝╚══╝ " echo "${NC}" echo " ${BOLD}Native performance. Native size.${NC}" echo " ${BOLD}Desktop apps, minus the bloat.${NC}" echo "" } info() { echo "${BLUE}info${NC} $1" } success() { echo "${GREEN}✓${NC} $1" } warn() { echo "${YELLOW}warn${NC} $1" } error() { echo "${RED}error${NC} $1" exit 1 } detect_platform() { OS="$(uname -s)" ARCH="$(uname -m)" case "$OS" in Linux*) PLATFORM="linux" ;; Darwin*) PLATFORM="macos" ;; MINGW*|MSYS*|CYGWIN*) error "Please use PowerShell installer on Windows: irm ziew.sh/install.ps1 | iex" ;; *) error "Unsupported operating system: $OS" ;; esac case "$ARCH" in x86_64|amd64) ARCH="x86_64" ;; aarch64|arm64) ARCH="aarch64" ;; *) error "Unsupported architecture: $ARCH" ;; esac info "Detected platform: ${BOLD}$PLATFORM-$ARCH${NC}" } check_dependencies() { # Check for required tools for cmd in curl tar; do if ! command -v "$cmd" >/dev/null 2>&1; then error "Required command not found: $cmd" fi done # Check Linux dependencies if [ "$PLATFORM" = "linux" ]; then if ! pkg-config --exists gtk+-3.0 2>/dev/null; then warn "GTK3 not found. You'll need to install it:" echo " ${CYAN}sudo apt install libgtk-3-dev libwebkit2gtk-4.1-dev${NC}" echo "" fi fi } create_directories() { mkdir -p "$BIN_DIR" mkdir -p "$INSTALL_DIR/models" } get_zig_url() { case "$PLATFORM-$ARCH" in linux-x86_64) echo "https://ziglang.org/download/$ZIG_VERSION/zig-linux-x86_64-$ZIG_VERSION.tar.xz" ;; linux-aarch64) echo "https://ziglang.org/download/$ZIG_VERSION/zig-linux-aarch64-$ZIG_VERSION.tar.xz" ;; macos-x86_64) echo "https://ziglang.org/download/$ZIG_VERSION/zig-macos-x86_64-$ZIG_VERSION.tar.xz" ;; macos-aarch64) echo "https://ziglang.org/download/$ZIG_VERSION/zig-macos-aarch64-$ZIG_VERSION.tar.xz" ;; *) error "No Zig build available for $PLATFORM-$ARCH" ;; esac } install_zig() { if command -v zig >/dev/null 2>&1; then CURRENT_ZIG=$(zig version 2>/dev/null || echo "unknown") success "Zig already installed: $CURRENT_ZIG" return fi info "Installing Zig $ZIG_VERSION..." ZIG_URL=$(get_zig_url) ZIG_DIR="$INSTALL_DIR/zig" ZIG_ARCHIVE="/tmp/zig-$ZIG_VERSION.tar.xz" # Download info "Downloading Zig (~40MB)..." curl -fsSL "$ZIG_URL" -o "$ZIG_ARCHIVE" # Extract info "Extracting..." rm -rf "$ZIG_DIR" mkdir -p "$ZIG_DIR" tar -xf "$ZIG_ARCHIVE" -C "$ZIG_DIR" --strip-components=1 rm "$ZIG_ARCHIVE" # Symlink ln -sf "$ZIG_DIR/zig" "$BIN_DIR/zig" success "Zig $ZIG_VERSION installed" } install_ziew() { info "Installing ziew CLI..." # Determine download URL (matches GitHub release artifact names) case "$PLATFORM-$ARCH" in linux-x86_64) ZIEW_ARTIFACT="ziew-linux-x64" ;; linux-aarch64) ZIEW_ARTIFACT="ziew-linux-arm64" ;; macos-x86_64) ZIEW_ARTIFACT="ziew-macos-x64" ;; macos-aarch64) ZIEW_ARTIFACT="ziew-macos-arm64" ;; esac ZIEW_URL="https://github.com/ziews/ziew/releases/download/v$ZIEW_VERSION/$ZIEW_ARTIFACT" # Try to download release binary if curl -fsSL "$ZIEW_URL" -o "$BIN_DIR/ziew" 2>/dev/null; then chmod +x "$BIN_DIR/ziew" success "ziew CLI installed" else # No release available yet - build from source warn "No pre-built binary available. Building from source..." ZIEW_SRC="/tmp/ziew-src" rm -rf "$ZIEW_SRC" info "Cloning ziew repository..." git clone --depth 1 https://github.com/ziews/ziew.git "$ZIEW_SRC" info "Building ziew CLI..." cd "$ZIEW_SRC" "$BIN_DIR/zig" build -Doptimize=ReleaseSmall cp zig-out/bin/ziew "$BIN_DIR/ziew" 2>/dev/null || \ cp zig-out/bin/hello "$BIN_DIR/ziew" 2>/dev/null || \ warn "Build completed but CLI binary not found yet (this is expected for v0.1)" rm -rf "$ZIEW_SRC" success "ziew built from source" fi } setup_path() { SHELL_NAME=$(basename "$SHELL") PROFILE="" case "$SHELL_NAME" in bash) if [ -f "$HOME/.bashrc" ]; then PROFILE="$HOME/.bashrc" elif [ -f "$HOME/.bash_profile" ]; then PROFILE="$HOME/.bash_profile" fi ;; zsh) PROFILE="$HOME/.zshrc" ;; fish) PROFILE="$HOME/.config/fish/config.fish" ;; esac PATH_LINE="export PATH=\"$BIN_DIR:\$PATH\"" if [ -n "$PROFILE" ]; then if ! grep -q "$BIN_DIR" "$PROFILE" 2>/dev/null; then echo "" >> "$PROFILE" echo "# Ziew" >> "$PROFILE" echo "$PATH_LINE" >> "$PROFILE" success "Added to PATH in $PROFILE" else success "PATH already configured" fi else warn "Could not detect shell profile. Add this to your shell config:" echo " ${CYAN}$PATH_LINE${NC}" fi } print_next_steps() { echo "" echo "${GREEN}${BOLD}Installation complete!${NC}" echo "" echo "To get started, restart your terminal or run:" echo " ${CYAN}export PATH=\"$BIN_DIR:\$PATH\"${NC}" echo "" echo "Then create your first app:" echo " ${CYAN}ziew init myapp${NC}" echo " ${CYAN}cd myapp${NC}" echo " ${CYAN}ziew dev${NC}" echo "" if [ "$PLATFORM" = "linux" ]; then echo "${YELLOW}Note:${NC} Linux requires GTK3 and WebKit2GTK:" echo " ${CYAN}sudo apt install libgtk-3-dev libwebkit2gtk-4.1-dev${NC}" echo "" fi echo "Documentation: ${CYAN}https://ziew.sh${NC}" echo "GitHub: ${CYAN}https://github.com/ziews/ziew${NC}" echo "" } main() { print_banner detect_platform check_dependencies create_directories install_zig install_ziew setup_path print_next_steps } main "$@"