#!/bin/bash # Jamdesk CLI installer # Usage: curl -fsSL https://get.jamdesk.com | bash # With version: curl -fsSL https://get.jamdesk.com | bash -s -- --version 1.2.3 set -e RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' VERSION="latest" # Parse arguments while [[ $# -gt 0 ]]; do case $1 in --version|-v) VERSION="$2"; shift 2 ;; *) shift ;; esac done print_banner() { echo -e "${BLUE}" echo " _ _ _ " echo " | | __ _ _ __ ___ __| | ___ ___| | __" echo " _ | |/ _\` | '_ \` _ \\ / _\` |/ _ \\/ __| |/ /" echo "| |_| | (_| | | | | | | (_| | __/\\__ \\ < " echo " \\___/ \\__,_|_| |_| |_|\\__,_|\\___||___/_|\\_\\" echo -e "${NC}" echo "Documentation Platform CLI Installer" echo "" } # Check Node.js version check_node() { if ! command -v node &> /dev/null; then echo -e "${RED}Error: Node.js is required${NC}" echo "" echo "Install Node.js 20+ from: https://nodejs.org" echo "Or use a version manager:" echo " - nvm: https://github.com/nvm-sh/nvm" echo " - fnm: https://github.com/Schniz/fnm" exit 1 fi NODE_VERSION=$(node -v | grep -oE '^v?[0-9]+' | grep -oE '[0-9]+') if ! [[ "$NODE_VERSION" =~ ^[0-9]+$ ]] || [ "$NODE_VERSION" -lt 20 ]; then echo -e "${RED}Error: Node.js 20+ required (found v$(node -v | cut -d'v' -f2))${NC}" echo "" echo "Upgrade Node.js: https://nodejs.org" exit 1 fi echo -e "${GREEN}✓${NC} Node.js $(node -v) detected" } # Check npm permissions check_npm_permissions() { NPM_PREFIX=$(npm prefix -g 2>/dev/null || echo "") if [ -z "$NPM_PREFIX" ]; then return 0 fi if [ ! -w "$NPM_PREFIX" ]; then echo -e "${YELLOW}Warning: npm global directory not writable${NC}" echo "" echo "Options:" echo " 1. Run with sudo: curl -fsSL https://get.jamdesk.com | sudo bash" echo " 2. Fix npm permissions: https://docs.npmjs.com/resolving-eacces-permissions-errors" echo " 3. Use npx instead: npx jamdesk " if [ -t 0 ]; then echo "" read -p "Try installing anyway? [y/N] " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi else echo "" echo -e "${RED}Cannot prompt for confirmation (non-interactive).${NC}" echo "Fix npm permissions or use sudo, then retry." exit 1 fi fi } # Install via npm install_cli() { echo -e "${BLUE}Installing Jamdesk CLI${NC} (version: $VERSION)..." # This installer prints its own banner; suppress the npm postinstall one # so the user doesn't see the Jamdesk banner twice. if JAMDESK_INSTALLER=1 npm install -g "jamdesk@$VERSION"; then echo -e "${GREEN}✓${NC} Installation successful" else echo -e "${RED}Installation failed${NC}" echo "" echo "Troubleshooting:" echo " - Check npm permissions: npm config get prefix" echo " - Try with npx: npx jamdesk " echo " - See docs: https://www.jamdesk.com/docs/cli/installation" exit 1 fi } # Verify installation verify() { if command -v jamdesk &> /dev/null; then echo -e "${GREEN}✓${NC} Jamdesk CLI installed: $(jamdesk --version)" echo "" echo "Get started:" echo " jamdesk init # Create new docs project" echo " jamdesk dev # Start dev server" echo " jamdesk --help # See all commands" else echo -e "${YELLOW}Installation completed but 'jamdesk' not in PATH${NC}" echo "" echo "Add to your shell profile:" echo " export PATH=\"\$(npm prefix -g)/bin:\$PATH\"" fi } main() { print_banner check_node check_npm_permissions install_cli verify } main