1#!/bin/bash
2
3# install.sh - Install ask CLI tool system-wide
4
5set -euo pipefail
6
7# Colors
8GREEN='\033[0;32m'
9YELLOW='\033[1;33m'
10NC='\033[0m'
11
12echo "Installing 'ask' CLI tool..."
13
14# Check if script exists
15if [ ! -f "ask" ]; then
16 echo "Error: 'ask' script not found in current directory" >&2
17 exit 1
18fi
19
20# Make executable
21chmod +x ask
22
23# Install to /usr/local/bin
24echo "Installing to /usr/local/bin/ask (requires sudo)..."
25sudo cp ask /usr/local/bin/
26
27echo -e "${GREEN}✓ Installation complete!${NC}"
28echo
29
30# Get OpenRouter IPs
31echo "Resolving OpenRouter DNS..."
32IPS=$(dig +short openrouter.ai 2>/dev/null | grep -E '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$' || nslookup openrouter.ai 2>/dev/null | grep -A1 "Name:" | grep "Address:" | awk '{print $2}' | grep -E '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$')
33
34if [ -n "$IPS" ]; then
35 echo -e "${YELLOW}OpenRouter IP addresses:${NC}"
36 echo "$IPS"
37 echo
38 echo "To improve performance, you can add these to /etc/hosts:"
39 echo "----------------------------------------"
40 for IP in $IPS; do
41 echo "$IP openrouter.ai"
42 done | head -1 # Only show first IP as hosts file needs single entry
43 echo "----------------------------------------"
44 echo
45 echo "Add with: sudo nano /etc/hosts"
46 echo "(Only add ONE IP address to avoid conflicts)"
47else
48 echo "Could not resolve OpenRouter IPs. Network may be unavailable."
49fi
50
51echo
52echo -e "${GREEN}Usage:${NC}"
53echo " ask 'What is 2+2?'"
54echo " ask -g 'Explain quantum computing'"
55echo " ask --help"
56echo
57echo "Don't forget to set your API key:"
58echo " export OPENROUTER_API_KEY='your-key-here'"