-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·284 lines (239 loc) · 8.53 KB
/
install.sh
File metadata and controls
executable file
·284 lines (239 loc) · 8.53 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
#!/bin/bash
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
# Function to print colored messages
print_message() {
echo -e "${2}${1}${NC}"
}
# Function to check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Function to check Docker/Podman
check_container_runtime() {
if command_exists docker; then
CONTAINER_CMD="docker"
print_message "Docker detected" "$GREEN"
# Check if Docker daemon is running
if ! docker info >/dev/null 2>&1; then
print_message "Error: Docker daemon is not running" "$RED"
print_message "Please start Docker and try again" "$YELLOW"
exit 1
fi
elif command_exists podman; then
CONTAINER_CMD="podman"
print_message "Podman detected" "$GREEN"
# Check if Podman daemon is running
if ! podman info >/dev/null 2>&1; then
print_message "Error: Podman daemon is not running" "$RED"
print_message "Please start Podman and try again" "$YELLOW"
exit 1
fi
else
print_message "Error: Neither Docker nor Podman is installed" "$RED"
print_message "Please install Docker or Podman first" "$YELLOW"
exit 1
fi
}
# Function to check Git
check_git() {
if ! command_exists git; then
print_message "Error: Git is not installed" "$RED"
print_message "Please install Git first" "$YELLOW"
exit 1
fi
}
# Function to check Ollama
check_ollama() {
if ! command_exists ollama; then
print_message "Warning: Ollama is not installed" "$YELLOW"
print_message "Please install Ollama from https://ollama.ai" "$YELLOW"
print_message "After installation, run: ollama pull qwen3:8b" "$YELLOW"
fi
}
# Function to create necessary directories
create_directories() {
print_message "Creating necessary directories..." "$YELLOW"
# Create ~/.local/bin if it doesn't exist
if [ ! -d ~/.local/bin ]; then
print_message "Creating ~/.local/bin directory..." "$YELLOW"
mkdir -p ~/.local/bin
chmod 755 ~/.local/bin
fi
# Create ~/.local/lib/convcommitgpt if it doesn't exist
if [ ! -d ~/.local/lib/convcommitgpt ]; then
print_message "Creating ~/.local/lib/convcommitgpt directory..." "$YELLOW"
mkdir -p ~/.local/lib/convcommitgpt
chmod 755 ~/.local/lib/convcommitgpt
fi
# Add ~/.local/bin to PATH if it's not already there
if [[ ":$PATH:" != *":$HOME/.local/bin:"* ]]; then
print_message "Adding ~/.local/bin to PATH..." "$YELLOW"
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
export PATH="$HOME/.local/bin:$PATH"
fi
}
# Function to backup existing installation
backup_existing() {
if [ -f ~/.local/bin/convcommit ]; then
print_message "Backing up existing installation..." "$YELLOW"
mv ~/.local/bin/convcommit ~/.local/bin/convcommit.bak
fi
if [ -f ~/.local/lib/convcommitgpt/.env ]; then
cp ~/.local/lib/convcommitgpt/.env ~/.local/lib/convcommitgpt/.env.bak
fi
}
# Function to setup configuration
setup_configuration() {
if [ ! -f ~/.local/lib/convcommitgpt/.env ]; then
print_message "Setting up configuration..." "$YELLOW"
read -p "Enter the Ollama base URL (default: http://localhost:11434/v1): " base_url
read -p "Enter the model name (default: qwen3:8b): " model
base_url=${base_url:-"http://localhost:11434/v1"}
model=${model:-"qwen3:8b"}
cat > ~/.local/lib/convcommitgpt/.env << EOF
BASE_URL=${base_url}
MODEL=${model}
EOF
fi
}
# Function to download files
download_files() {
print_message "Downloading files..." "$YELLOW"
cd /tmp
local files=(
"convcommit.py"
"assistant.py"
"diff_generator.py"
"runner.py"
"spinner.py"
"requirements.txt"
"instructions_prompt.md"
"convcommit.sh"
)
for file in "${files[@]}"; do
if ! curl -sSL "https://raw.githubusercontent.com/mnofresno/convcommitgpt/main/${file}" -o "${file}"; then
print_message "Error: Failed to download ${file}" "$RED"
exit 1
fi
done
print_message "Copying files to installation directory..." "$YELLOW"
cp -r /tmp/*.py /tmp/*.txt /tmp/*.md /tmp/convcommit.sh ~/.local/lib/convcommitgpt/
cd -
}
# Function to detect system architecture
detect_architecture() {
local arch=$(uname -m)
case $arch in
x86_64)
echo "amd64"
;;
aarch64|arm64)
echo "arm64"
;;
*)
print_message "Error: Unsupported architecture: $arch" "$RED"
exit 1
;;
esac
}
# Function to setup container runtime
setup_container_runtime() {
print_message "Setting up container runtime..." "$YELLOW"
# Detect architecture
local arch=$(detect_architecture)
print_message "Detected architecture: $arch" "$GREEN"
# Pull Docker image with architecture-specific tag
print_message "Pulling container image for $arch..." "$YELLOW"
if ! $CONTAINER_CMD pull "ghcr.io/mnofresno/convcommitgpt:latest-$arch"; then
print_message "Error: Failed to pull container image for $arch" "$RED"
exit 1
fi
# Tag image for local use
if [[ "$CONTAINER_CMD" == "podman" ]]; then
print_message "Tagging image for Podman..." "$YELLOW"
$CONTAINER_CMD tag "ghcr.io/mnofresno/convcommitgpt:latest-$arch" localhost/convcommitgpt:latest
fi
}
# Function to setup symlinks
setup_symlinks() {
print_message "Setting up symlinks..." "$YELLOW"
# Ensure directories exist
create_directories
# Verify source file exists
if [ ! -f ~/.local/lib/convcommitgpt/convcommit.sh ]; then
print_message "Error: Source file ~/.local/lib/convcommitgpt/convcommit.sh does not exist" "$RED"
exit 1
fi
# Set permissions on source file
print_message "Setting permissions on convcommit.sh..." "$YELLOW"
chmod +x ~/.local/lib/convcommitgpt/convcommit.sh
# Remove existing symlink if it exists
if [ -L ~/.local/bin/convcommit ]; then
print_message "Removing existing symlink..." "$YELLOW"
rm ~/.local/bin/convcommit
fi
# Create new symlink
print_message "Creating new symlink..." "$YELLOW"
ln -sf ~/.local/lib/convcommitgpt/convcommit.sh ~/.local/bin/convcommit
# Verify the symlink was created
if [ ! -L ~/.local/bin/convcommit ]; then
print_message "Error: Failed to create symlink" "$RED"
exit 1
fi
# Verify the script is executable
if [ ! -x ~/.local/lib/convcommitgpt/convcommit.sh ]; then
print_message "Error: Failed to set executable permissions" "$RED"
exit 1
fi
print_message "Symlink created successfully" "$GREEN"
}
# Main installation process
main() {
print_message "Starting convcommitgpt installation..." "$GREEN"
# Check dependencies
check_container_runtime
check_git
check_ollama
# Create directories
create_directories
# Backup existing installation
backup_existing
# Download and copy files
download_files
# Setup container runtime
setup_container_runtime
# Setup configuration
setup_configuration
# Setup symlinks and permissions
setup_symlinks
print_message "Installation completed successfully!" "$GREEN"
print_message "You can now use 'convcommit' command" "$GREEN"
print_message "Make sure Ollama is running with: ollama serve" "$YELLOW"
print_message "And the model is pulled with: ollama pull qwen3:8b" "$YELLOW"
# Print PATH information
print_message "Note: You may need to restart your terminal or run 'source ~/.bashrc' (or 'source ~/.zshrc') to update your PATH" "$YELLOW"
# Print verification information
print_message "Verifying installation..." "$YELLOW"
if [ -L ~/.local/bin/convcommit ]; then
print_message "✓ Symlink exists" "$GREEN"
else
print_message "✗ Symlink does not exist" "$RED"
fi
if [ -x ~/.local/lib/convcommitgpt/convcommit.sh ]; then
print_message "✓ Script is executable" "$GREEN"
else
print_message "✗ Script is not executable" "$RED"
fi
if [[ ":$PATH:" == *":$HOME/.local/bin:"* ]]; then
print_message "✓ ~/.local/bin is in PATH" "$GREEN"
else
print_message "✗ ~/.local/bin is not in PATH" "$RED"
fi
}
# Run main function
main