Repository navigation
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·361 lines (326 loc) · 12.8 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·361 lines (326 loc) · 12.8 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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
#!/usr/bin/env bash
# SPDX-License-Identifier: MIT
# Copyright (c) 2025 dr.max
set -e
echo "🚀 Setting up development environment for Weave CLI..."
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
print_status() {
echo -e "${GREEN}[INFO]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
print_header() {
echo -e "${BLUE}[SETUP]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
# Function to check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Function to detect OS
detect_os() {
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "macos"
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
echo "linux"
else
echo "unknown"
fi
}
# Function to detect CI environment
is_ci() {
[[ -n "${CI:-}" ]] || [[ -n "${GITHUB_ACTIONS:-}" ]] || [[ -n "${GITLAB_CI:-}" ]] || [[ -n "${JENKINS_URL:-}" ]]
}
OS=$(detect_os)
CI_ENV=$(is_ci && echo "true" || echo "false")
print_header "Setting up linting tools for Weave CLI development..."
if [ "$CI_ENV" = "true" ]; then
print_status "Running in CI environment - using automated setup"
fi
# Check if Go is installed
if ! command_exists go; then
print_error "Go is not installed. Please install Go first:"
print_status "Visit: https://golang.org/doc/install"
exit 1
fi
print_status "Go version: $(go version)"
# Install golangci-lint
print_header "Installing golangci-lint..."
if ! command_exists golangci-lint; then
print_status "Installing golangci-lint..."
if command_exists curl; then
# Use go install to build with current Go version for compatibility
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
print_success "golangci-lint installed successfully!"
else
print_error "curl not found, please install golangci-lint manually"
print_status "Visit: https://golangci-lint.run/usage/install/"
exit 1
fi
else
print_success "golangci-lint is already installed"
fi
# Install goimports
print_header "Installing goimports..."
if ! command_exists goimports; then
print_status "Installing goimports..."
go install golang.org/x/tools/cmd/goimports@latest
print_success "goimports installed successfully!"
else
print_success "goimports is already installed"
fi
# Install govulncheck (official Go vulnerability scanner)
print_header "Installing govulncheck..."
if ! command_exists govulncheck; then
print_status "Installing govulncheck..."
go install golang.org/x/vuln/cmd/govulncheck@latest
print_success "govulncheck installed successfully!"
else
print_success "govulncheck is already installed"
fi
# Install gosec (optional, for additional security checks)
print_header "Installing gosec..."
if ! command_exists gosec; then
print_status "Installing gosec..."
print_status "CI_ENV: $CI_ENV"
print_status "GITHUB_ACTIONS: ${GITHUB_ACTIONS:-not set}"
# Try the install script method (most reliable)
print_status "Using install script method..."
if curl -sfL https://raw.githubusercontent.com/securecodewarrior/gosec/master/install.sh | sh -s -- -b "$(go env GOPATH)/bin"; then
print_success "gosec installed via install script!"
else
print_warning "gosec installation failed - skipping (govulncheck provides security coverage)"
print_status "Note: govulncheck is already installed and provides comprehensive security scanning"
fi
else
print_success "gosec is already installed"
fi
# Install poppler-utils (for pdftotext)
print_header "Installing poppler-utils (for PDF text extraction)..."
if ! command_exists pdftotext; then
print_status "Installing poppler-utils..."
case $OS in
"macos")
if command_exists brew; then
brew install poppler
print_success "poppler-utils installed successfully via Homebrew!"
else
print_warning "Homebrew not found. Please install poppler manually:"
print_status "Visit: https://poppler.freedesktop.org/"
fi
;;
"linux")
if command_exists apt-get; then
sudo apt-get update && sudo apt-get install -y poppler-utils
print_success "poppler-utils installed successfully via apt-get!"
elif command_exists yum; then
sudo yum install -y poppler-utils
print_success "poppler-utils installed successfully via yum!"
else
print_warning "Package manager not found. Please install poppler-utils manually:"
print_status "Visit: https://poppler.freedesktop.org/"
fi
;;
*)
print_warning "Unknown OS. Please install poppler-utils manually:"
print_status "Visit: https://poppler.freedesktop.org/"
;;
esac
else
print_success "poppler-utils is already installed"
fi
# Install tesseract and leptonica (for OCR)
print_header "Installing tesseract and leptonica (for OCR support)..."
if ! command_exists tesseract || ! pkg-config --exists tesseract lept 2>/dev/null; then
print_status "Installing tesseract..."
case $OS in
"macos")
if command_exists brew; then
brew install tesseract leptonica
print_success "tesseract and leptonica installed successfully via Homebrew!"
else
print_warning "Homebrew not found. Please install tesseract manually:"
print_status "Visit: https://github.com/tesseract-ocr/tesseract"
fi
;;
"linux")
if command_exists apt-get; then
sudo apt-get update && sudo apt-get install -y tesseract-ocr libtesseract-dev libleptonica-dev
print_success "tesseract and leptonica installed successfully via apt-get!"
elif command_exists yum; then
sudo yum install -y tesseract leptonica-devel
print_success "tesseract and leptonica installed successfully via yum!"
else
print_warning "Package manager not found. Please install tesseract manually:"
print_status "Visit: https://github.com/tesseract-ocr/tesseract"
fi
;;
*)
print_warning "Unknown OS. Please install tesseract manually:"
print_status "Visit: https://github.com/tesseract-ocr/tesseract"
;;
esac
else
print_success "tesseract is already installed"
fi
# Install shellcheck
print_header "Installing shellcheck..."
if ! command_exists shellcheck; then
print_status "Installing shellcheck..."
case $OS in
"macos")
if command_exists brew; then
brew install shellcheck
print_success "shellcheck installed successfully via Homebrew!"
else
print_warning "Homebrew not found. Please install shellcheck manually:"
print_status "Visit: https://github.com/koalaman/shellcheck#installing"
fi
;;
"linux")
if command_exists apt-get; then
sudo apt-get update && sudo apt-get install -y shellcheck
print_success "shellcheck installed successfully via apt-get!"
elif command_exists yum; then
sudo yum install -y shellcheck
print_success "shellcheck installed successfully via yum!"
else
print_warning "Package manager not found. Please install shellcheck manually:"
print_status "Visit: https://github.com/koalaman/shellcheck#installing"
fi
;;
*)
print_warning "Unknown OS. Please install shellcheck manually:"
print_status "Visit: https://github.com/koalaman/shellcheck#installing"
;;
esac
else
print_success "shellcheck is already installed"
fi
# Install yamllint
print_header "Installing yamllint..."
if ! command_exists yamllint; then
print_status "Installing yamllint..."
# Try different installation methods
if command_exists brew; then
print_status "Trying Homebrew installation..."
if brew install yamllint; then
print_success "yamllint installed successfully via Homebrew!"
else
print_warning "Homebrew installation failed, trying pipx..."
if command_exists pipx; then
pipx install yamllint
print_success "yamllint installed successfully via pipx!"
else
print_warning "pipx not found, trying pip with --user flag..."
if command_exists pip3; then
pip3 install --user yamllint
print_success "yamllint installed successfully via pip3 --user!"
elif command_exists pip; then
pip install --user yamllint
print_success "yamllint installed successfully via pip --user!"
else
print_warning "pip not found. Please install yamllint manually:"
print_status "Visit: https://yamllint.readthedocs.io/en/stable/quickstart.html"
print_status "Or install via Homebrew: brew install yamllint"
fi
fi
fi
elif command_exists pipx; then
print_status "Using pipx installation..."
pipx install yamllint
print_success "yamllint installed successfully via pipx!"
elif command_exists pip3; then
print_status "Using pip3 with --user flag..."
pip3 install --user yamllint
print_success "yamllint installed successfully via pip3 --user!"
elif command_exists pip; then
print_status "Using pip with --user flag..."
pip install --user yamllint
print_success "yamllint installed successfully via pip --user!"
else
print_warning "No suitable package manager found. Please install yamllint manually:"
print_status "Visit: https://yamllint.readthedocs.io/en/stable/quickstart.html"
print_status "Or install via Homebrew: brew install yamllint"
fi
else
print_success "yamllint is already installed"
fi
# Install markdownlint
print_header "Installing markdownlint..."
if ! command_exists markdownlint; then
print_status "Installing markdownlint..."
if command_exists npm; then
# Try installing without sudo first, then with sudo if needed
if npm install -g markdownlint-cli; then
print_success "markdownlint installed successfully!"
else
print_warning "Global install failed, trying with sudo..."
if sudo npm install -g markdownlint-cli; then
print_success "markdownlint installed successfully with sudo!"
else
print_warning "markdownlint installation failed - skipping"
print_status "You can install it manually: npm install -g markdownlint-cli"
fi
fi
else
print_warning "npm not found. Please install markdownlint manually:"
print_status "Visit: https://github.com/igorshubovych/markdownlint-cli"
fi
else
print_success "markdownlint is already installed"
fi
# Install go-mod-outdated (optional)
print_header "Installing go-mod-outdated..."
if ! command_exists go-mod-outdated; then
print_status "Installing go-mod-outdated..."
go install github.com/psampaz/go-mod-outdated@latest
print_success "go-mod-outdated installed successfully!"
else
print_success "go-mod-outdated is already installed"
fi
# Verify installations
print_header "Verifying installations..."
echo ""
tools=("go" "golangci-lint" "goimports" "govulncheck" "gosec" "pdftotext" "tesseract" "shellcheck" "yamllint" "markdownlint" "go-mod-outdated")
all_installed=true
for tool in "${tools[@]}"; do
if command_exists "$tool"; then
print_success "✓ $tool is installed"
else
print_warning "✗ $tool is not installed"
all_installed=false
fi
done
echo ""
if [ "$all_installed" = true ]; then
print_success "🎉 All linting tools are installed and ready!"
print_status "You can now run ./lint.sh without warnings"
else
print_warning "⚠️ Some tools are missing. Please install them manually."
print_status "Run this script again after installing missing tools."
fi
# Update PATH if needed
print_header "Checking PATH configuration..."
GOPATH=$(go env GOPATH)
if [[ ":$PATH:" != *":$GOPATH/bin:"* ]]; then
print_warning "GOPATH/bin is not in your PATH"
print_status "Adding GOPATH/bin to PATH for this session..."
export PATH="$PATH:$GOPATH/bin"
print_status "Add this to your shell profile (.bashrc, .zshrc, etc.):"
echo "export PATH=\$PATH:$GOPATH/bin"
echo ""
fi
print_success "🚀 Setup completed!"
print_status "Run './lint.sh' to test the linting setup"