-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.sh
131 lines (109 loc) · 4.29 KB
/
setup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/bash
security_note="\n\e[33mNOTE: \e[0mYour API key is stored securely in your system's keyring and is not shared outside of this machine."
# ASCII art as a multi-line string
cat << "EOF"
██████╗██╗ ██╗ █████╗ ██╗
██╔════╝██║ ██║ ██╔══██╗██║
██║ ██║ ██║ ███████║██║
██║ ██║ ██║ ██╔══██║██║
╚██████╗███████╗██║ ██║ ██║██║
╚═════╝╚══════╝╚═╝ ╚═╝ ╚═╝╚═╝
EOF
echo -e "\nWelcome to CLI AI Assistant!\n"
# Prompt for API key instead of passing as an argument
read -sp "Enter your API key: " api_key
echo
# Check if the API key is provided
if [ -z "$api_key" ]; then
echo -e "\e[31mWARNING: API key not provided!\e[0m"
echo -e "\e[33mUsage: curl -sSL https://raw.githubusercontent.com/fmdz387/cli-ai/refs/heads/master/setup.sh | bash -s <your_anthropic_api_key>\e[0m"
echo -e "$security_note"
exit 1
fi
# Define colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# Define a function to execute Python commands
run_python() {
if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then
python - "$@"
else
python3 - "$@"
fi
}
# Step 1: Set up environment
echo -e "${YELLOW}Step 1: Setting up environment${NC}"
mkdir -p ~/.cli_ai_assistant
curl -sSL https://raw.githubusercontent.com/fmdz387/cli-ai/refs/heads/master/ai_assistant.py -o ~/.cli_ai_assistant/ai_assistant.py
curl -sSL https://raw.githubusercontent.com/fmdz387/cli-ai/refs/heads/master/utils.py -o ~/.cli_ai_assistant/utils.py
# Make the script executable
chmod +x ~/.cli_ai_assistant/ai_assistant.py
# Step 2: Install dependencies
echo -e "${YELLOW}Step 2: Installing dependencies${NC}"
# Check if Python is installed
if ! command -v python3 &> /dev/null; then
echo -e "${YELLOW}Python not found. Installing Python...${NC}"
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS
brew install python
elif [[ -f /etc/debian_version || -f /etc/lsb-release ]]; then
# Debian or Ubuntu
sudo apt-get update
sudo apt-get install -y python3
else
echo -e "${RED}Unsupported OS. Please install Python manually.${NC}"
exit 1
fi
fi
# Check if pip is installed
if ! command -v pip3 &> /dev/null; then
echo -e "${YELLOW}pip not found. Installing pip...${NC}"
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py
rm get-pip.py
elif [[ -f /etc/debian_version || -f /etc/lsb-release ]]; then
# Debian or Ubuntu
sudo apt-get install -y python3-pip
else
echo -e "${RED}Unsupported OS. Please install pip manually.${NC}"
exit 1
fi
fi
pip install anthropic pyreadline3 keyring keyrings.alt
# Step 3: Secure API key
echo -e "${YELLOW}Step 3: Securing API key${NC}"
run_python <<EOF
import keyring
keyring.set_password("cli_ai_assistant", "anthropic_api_key", "$api_key")
EOF
# Step 4: Configure CLI
echo -e "${YELLOW}Step 4: Configuring CLI${NC}"
echo "AI_ASSISTANT_SKIP_CONFIRM=true" >~/.cli_ai_assistant/config
echo "AI_DIRECTORY_TREE_CONTEXT=true" >>~/.cli_ai_assistant/config
if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" ]]; then
# Windows (Git Bash or Cygwin)
if ! grep -q "alias s='python ~/.cli_ai_assistant/ai_assistant.py'" ~/.bashrc; then
echo "alias s='python ~/.cli_ai_assistant/ai_assistant.py'" >>~/.bashrc
fi
else
# Unix-based systems
if ! grep -q "alias s='python3 ~/.cli_ai_assistant/ai_assistant.py'" ~/.bashrc; then
echo "alias s='python3 ~/.cli_ai_assistant/ai_assistant.py'" >>~/.bashrc
fi
fi
# Apply the changes made in .bashrc
source ~/.bashrc
# Print setup completion message
echo -e "${GREEN}✔ Setup complete!${NC}"
# Print usage information
echo -e "\n${YELLOW}Usage:${NC}"
echo -e " ${CYAN}s${NC} <natural language command>"
# Print example
echo -e "\n${YELLOW}Example:${NC}"
echo -e " ${CYAN}s${NC} show all docker images - ${GREEN}↳${NC} docker ps -a\n"
# Add colored note about API key security
echo -e "$security_note"