-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·343 lines (286 loc) · 9.44 KB
/
setup.sh
File metadata and controls
executable file
·343 lines (286 loc) · 9.44 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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
#!/bin/bash
# screenshot-memory setup script
# This script sets up everything needed to run screenshot-memory
set -e
# ============================================
# Uninstall mode
# ============================================
if [[ "$1" == "--remove" ]] || [[ "$1" == "--uninstall" ]] || [[ "$1" == "-r" ]]; then
echo ""
echo "Uninstalling screenshot-memory..."
echo ""
# Remove symlinks
rm -f ~/.bun/bin/ssm 2>/dev/null && echo "✓ Removed ~/.bun/bin/ssm"
rm -f ~/.bun/bin/screenshot-memory 2>/dev/null && echo "✓ Removed ~/.bun/bin/screenshot-memory"
rm -f /usr/local/bin/ssm 2>/dev/null && echo "✓ Removed /usr/local/bin/ssm"
rm -f ~/.local/bin/ssm 2>/dev/null && echo "✓ Removed ~/.local/bin/ssm"
# Remove index data
rm -rf ~/.config/screenshot-memory 2>/dev/null && echo "✓ Removed config"
rm -rf ~/Library/Application\ Support/screenshot-memory 2>/dev/null && echo "✓ Removed index data"
echo ""
echo "Done! screenshot-memory has been uninstalled."
echo "Note: Ollama and its models were not removed."
echo ""
exit 0
fi
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
WHITE='\033[1;37m'
NC='\033[0m' # No Color
# Print with color
print_header() {
echo ""
echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${WHITE} $1${NC}"
echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
}
print_step() {
echo -e "${BLUE}▶${NC} $1"
}
print_success() {
echo -e "${GREEN}✓${NC} $1"
}
print_warning() {
echo -e "${YELLOW}⚠${NC} $1"
}
print_error() {
echo -e "${RED}✗${NC} $1"
}
print_info() {
echo -e "${CYAN}ℹ${NC} $1"
}
# Check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Detect OS
detect_os() {
case "$(uname -s)" in
Darwin*) echo "macos" ;;
Linux*) echo "linux" ;;
MINGW*|MSYS*|CYGWIN*) echo "windows" ;;
*) echo "unknown" ;;
esac
}
OS=$(detect_os)
print_header "📸 screenshot-memory Setup"
echo -e "${WHITE}This script will set up screenshot-memory on your system.${NC}"
echo ""
echo "It will:"
echo " • Check/install Bun (fast JavaScript runtime)"
echo " • Check/install Ollama (local AI for image captioning)"
echo " • Download the llava-phi3 vision model (~2.9GB)"
echo " • Install dependencies and build the project"
echo " • Create the 'ssm' command globally"
echo ""
# Confirm
read -p "Continue? (Y/n) " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Nn]$ ]]; then
echo "Setup cancelled."
exit 0
fi
# ============================================
# Step 1: Check/Install Bun
# ============================================
print_header "Step 1: JavaScript Runtime"
if command_exists bun; then
BUN_VERSION=$(bun --version 2>/dev/null)
print_success "Bun is installed (v$BUN_VERSION)"
else
print_step "Installing Bun..."
if [[ "$OS" == "macos" ]] || [[ "$OS" == "linux" ]]; then
curl -fsSL https://bun.sh/install | bash
# Source the updated profile
export BUN_INSTALL="$HOME/.bun"
export PATH="$BUN_INSTALL/bin:$PATH"
if command_exists bun; then
print_success "Bun installed successfully"
else
print_warning "Bun installed but not in PATH. Please restart your terminal."
fi
else
print_error "Please install Bun manually: https://bun.sh"
exit 1
fi
fi
# ============================================
# Step 2: Check/Install Ollama
# ============================================
print_header "Step 2: Ollama (AI Vision)"
if command_exists ollama; then
print_success "Ollama is installed"
else
print_step "Installing Ollama..."
if [[ "$OS" == "macos" ]]; then
if command_exists brew; then
brew install ollama
else
print_info "Downloading Ollama installer..."
curl -fsSL https://ollama.com/install.sh | sh
fi
elif [[ "$OS" == "linux" ]]; then
curl -fsSL https://ollama.com/install.sh | sh
else
print_error "Please install Ollama manually: https://ollama.com"
exit 1
fi
if command_exists ollama; then
print_success "Ollama installed successfully"
else
print_error "Failed to install Ollama"
exit 1
fi
fi
# ============================================
# Step 3: Start Ollama & Download Model
# ============================================
print_header "Step 3: Vision Model"
# Check if Ollama is running
OLLAMA_RUNNING=false
if curl -s http://localhost:11434/api/tags >/dev/null 2>&1; then
OLLAMA_RUNNING=true
print_success "Ollama is running"
else
print_step "Starting Ollama..."
if [[ "$OS" == "macos" ]]; then
# On macOS, Ollama runs as an app
open -a Ollama 2>/dev/null || ollama serve &
else
ollama serve &
fi
# Wait for Ollama to start
print_info "Waiting for Ollama to start..."
for i in {1..30}; do
if curl -s http://localhost:11434/api/tags >/dev/null 2>&1; then
OLLAMA_RUNNING=true
break
fi
sleep 1
done
if $OLLAMA_RUNNING; then
print_success "Ollama started"
else
print_warning "Could not start Ollama automatically."
print_info "Please start Ollama manually and re-run this script."
fi
fi
# Check for vision model
if $OLLAMA_RUNNING; then
print_step "Checking for vision model..."
# Check if llava-phi3 is installed
MODELS=$(curl -s http://localhost:11434/api/tags 2>/dev/null | grep -o '"name":"[^"]*"' | cut -d'"' -f4)
HAS_VISION_MODEL=false
for model in llava-phi3 llava-phi3:latest llava:7b smolvlm2; do
if echo "$MODELS" | grep -q "^$model"; then
HAS_VISION_MODEL=true
print_success "Vision model found: $model"
break
fi
done
if ! $HAS_VISION_MODEL; then
print_step "Downloading llava-phi3 vision model (~2.9GB)..."
print_info "This may take a few minutes depending on your internet speed."
echo ""
ollama pull llava-phi3
if [ $? -eq 0 ]; then
print_success "Vision model downloaded"
else
print_warning "Failed to download vision model."
print_info "You can download it later with: ollama pull llava-phi3"
fi
fi
else
print_warning "Skipping model download (Ollama not running)"
print_info "After starting Ollama, run: ollama pull llava-phi3"
fi
# ============================================
# Step 4: Install Dependencies
# ============================================
print_header "Step 4: Project Dependencies"
print_step "Installing dependencies..."
bun install
if [ $? -eq 0 ]; then
print_success "Dependencies installed"
else
print_error "Failed to install dependencies"
exit 1
fi
# ============================================
# Step 5: Build Project
# ============================================
print_header "Step 5: Building"
print_step "Building project..."
bun run build
if [ $? -eq 0 ]; then
print_success "Build complete"
else
print_error "Build failed"
exit 1
fi
# ============================================
# Step 6: Create Global Command
# ============================================
print_header "Step 6: Global Command"
print_step "Creating 'ssm' command..."
# Create symlink in ~/.bun/bin (or /usr/local/bin as fallback)
SSM_SOURCE="$(pwd)/bin/ssm"
SSM_TARGET=""
if [[ -d "$HOME/.bun/bin" ]]; then
SSM_TARGET="$HOME/.bun/bin/ssm"
elif [[ -d "/usr/local/bin" ]]; then
SSM_TARGET="/usr/local/bin/ssm"
else
mkdir -p "$HOME/.local/bin"
SSM_TARGET="$HOME/.local/bin/ssm"
fi
# Remove old symlink if exists
rm -f "$SSM_TARGET" 2>/dev/null
# Create new symlink
ln -s "$SSM_SOURCE" "$SSM_TARGET"
print_success "Created 'ssm' command at $SSM_TARGET"
# Make sure the bin directory is in PATH
if ! echo "$PATH" | grep -q "$(dirname "$SSM_TARGET")"; then
SHELL_RC=""
if [[ "$SHELL" == *"zsh"* ]]; then
SHELL_RC="$HOME/.zshrc"
elif [[ "$SHELL" == *"bash"* ]]; then
SHELL_RC="$HOME/.bashrc"
fi
if [[ -n "$SHELL_RC" ]]; then
echo "" >> "$SHELL_RC"
echo "# screenshot-memory" >> "$SHELL_RC"
echo "export PATH=\"$(dirname "$SSM_TARGET"):\$PATH\"" >> "$SHELL_RC"
print_info "Added $(dirname "$SSM_TARGET") to PATH in $SHELL_RC"
fi
fi
# ============================================
# Done!
# ============================================
print_header "Setup Complete!"
echo -e "${GREEN}screenshot-memory is ready to use!${NC}"
echo ""
echo -e "${WHITE}Quick Start:${NC}"
echo ""
echo -e " ${CYAN}1.${NC} Index your screenshots:"
echo -e " ${WHITE}ssm index ~/Screenshots${NC}"
echo ""
echo -e " ${CYAN}2.${NC} Search for anything:"
echo -e " ${WHITE}ssm find \"error message\"${NC}"
echo -e " ${WHITE}ssm find \"red car\"${NC}"
echo ""
echo -e " ${CYAN}3.${NC} Auto-index new screenshots:"
echo -e " ${WHITE}ssm watch${NC}"
echo ""
if [[ -n "$SHELL_RC" ]]; then
echo -e "${YELLOW}Note:${NC} Run ${WHITE}source $SHELL_RC${NC} or restart your terminal"
echo " to use the 'ssm' command."
echo ""
fi
echo -e "${CYAN}Documentation:${NC} https://github.com/memvid/screenshot-memory"
echo ""