forked from binary-knight/logwhisperer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·933 lines (783 loc) · 24.3 KB
/
build.sh
File metadata and controls
executable file
·933 lines (783 loc) · 24.3 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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
#!/bin/bash
set -euo pipefail
# Script metadata
readonly SCRIPT_NAME="LogWhisperer Build Script"
readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Color codes
readonly GREEN='\033[0;32m'
readonly RED='\033[0;31m'
readonly YELLOW='\033[1;33m'
readonly BLUE='\033[0;34m'
readonly NC='\033[0m'
# Build configuration
readonly BUILD_DIR="${SCRIPT_DIR}/build"
readonly RELEASE_DIR="${SCRIPT_DIR}/release"
readonly DIST_DIR="${SCRIPT_DIR}/dist"
readonly ARTIFACTS_DIR="${SCRIPT_DIR}/artifacts"
# Build options (can be overridden by environment)
PYTHON_CMD="${PYTHON_CMD:-python3}"
BUILD_TYPE="${BUILD_TYPE:-release}" # release or debug
SKIP_TESTS="${SKIP_TESTS:-false}"
SKIP_CLEANUP="${SKIP_CLEANUP:-false}"
COMPRESS_BINARY="${COMPRESS_BINARY:-true}"
CREATE_CHECKSUM="${CREATE_CHECKSUM:-true}"
SIGN_RELEASE="${SIGN_RELEASE:-false}"
GPG_KEY="${GPG_KEY:-}"
# Platform detection
PLATFORM="unknown"
ARCH="unknown"
case "$(uname -s)" in
Linux*)
PLATFORM="linux"
ARCH=$(uname -m)
;;
Darwin*)
PLATFORM="macos"
ARCH=$(uname -m)
;;
*)
die "Unsupported platform: $(uname -s)"
;;
esac
# Utility functions
log() {
echo -e "${GREEN}[$(date +'%Y-%m-%d %H:%M:%S')]${NC} $*"
}
error() {
echo -e "${RED}[ERROR]${NC} $*" >&2
}
warning() {
echo -e "${YELLOW}[WARNING]${NC} $*"
}
info() {
echo -e "${BLUE}[INFO]${NC} $*"
}
die() {
error "$@"
exit 1
}
# Version detection with multiple fallbacks
detect_version() {
local version=""
# Try git describe first
if command -v git >/dev/null 2>&1 && git rev-parse --git-dir >/dev/null 2>&1; then
version=$(git describe --tags --abbrev=0 2>/dev/null || true)
# If no tags, try to create version from commit
if [[ -z "$version" ]]; then
local commit_count=$(git rev-list --count HEAD 2>/dev/null || echo "0")
local commit_hash=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown")
version="0.0.0-dev.${commit_count}+${commit_hash}"
fi
fi
# Try reading from version file
if [[ -z "$version" ]] && [[ -f "${SCRIPT_DIR}/VERSION" ]]; then
version=$(cat "${SCRIPT_DIR}/VERSION" | tr -d '[:space:]')
fi
# Try extracting from Python code
if [[ -z "$version" ]] && [[ -f "${SCRIPT_DIR}/logwhisperer.py" ]]; then
version=$(grep -E '__version__\s*=\s*"[^"]*"' "${SCRIPT_DIR}/logwhisperer.py" | sed 's/.*"\([^"]*\)".*/\1/' | head -1 || true)
fi
# Default version
if [[ -z "$version" ]]; then
version="1.0.0"
warning "Could not detect version, using default: $version"
fi
echo "$version"
}
# Check prerequisites
check_requirements() {
log "Checking build requirements..."
local missing_deps=()
# Check Python
if ! command -v "$PYTHON_CMD" >/dev/null 2>&1; then
missing_deps+=("Python 3")
else
local python_version=$("$PYTHON_CMD" -c 'import sys; print(".".join(map(str, sys.version_info[:2])))')
info "Python version: $python_version"
# Check minimum Python version
if [[ $(echo "$python_version" | cut -d. -f1) -lt 3 ]] || \
[[ $(echo "$python_version" | cut -d. -f1) -eq 3 && $(echo "$python_version" | cut -d. -f2) -lt 7 ]]; then
missing_deps+=("Python 3.7+")
fi
fi
# Check Nuitka
if ! "$PYTHON_CMD" -m pip show nuitka >/dev/null 2>&1; then
missing_deps+=("Nuitka")
else
local nuitka_version=$("$PYTHON_CMD" -m nuitka --version 2>&1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
info "Nuitka version: $nuitka_version"
fi
# Check other required tools
local required_cmds=("zip")
if [[ "$CREATE_CHECKSUM" == "true" ]]; then
# Platform-specific checksum commands
if [[ "$PLATFORM" == "macos" ]]; then
# macOS uses different commands
if ! command -v shasum >/dev/null 2>&1; then
missing_deps+=("shasum")
fi
if ! command -v md5 >/dev/null 2>&1; then
missing_deps+=("md5")
fi
else
# Linux uses these
if ! command -v sha256sum >/dev/null 2>&1; then
missing_deps+=("sha256sum")
fi
if ! command -v md5sum >/dev/null 2>&1; then
missing_deps+=("md5sum")
fi
fi
fi
if [[ "$SIGN_RELEASE" == "true" ]]; then
required_cmds+=("gpg")
fi
for cmd in "${required_cmds[@]}"; do
if ! command -v "$cmd" >/dev/null 2>&1; then
missing_deps+=("$cmd")
fi
done
# Check required Python packages
local required_packages=("yaml" "requests" "cryptography")
for pkg in "${required_packages[@]}"; do
if ! "$PYTHON_CMD" -c "import $pkg" 2>/dev/null; then
missing_deps+=("Python package: $pkg")
fi
done
if [[ ${#missing_deps[@]} -gt 0 ]]; then
error "Missing dependencies:"
for dep in "${missing_deps[@]}"; do
echo " - $dep"
done
die "Please install missing dependencies"
fi
log "All requirements satisfied"
}
# Run tests
run_tests() {
if [[ "$SKIP_TESTS" == "true" ]]; then
warning "Skipping tests (SKIP_TESTS=true)"
return 0
fi
log "Running tests..."
# Check if test files exist
if [[ -d "${SCRIPT_DIR}/tests" ]]; then
if "$PYTHON_CMD" -m pytest tests/ -v; then
log "Tests passed"
else
die "Tests failed"
fi
else
warning "No tests directory found, skipping tests"
fi
}
# Clean build artifacts
clean_artifacts() {
log "Cleaning old build artifacts..."
local dirs_to_clean=(
"$BUILD_DIR"
"$RELEASE_DIR"
"$DIST_DIR"
"${SCRIPT_DIR}/logwhisperer.dist"
"${SCRIPT_DIR}/logwhisperer.build"
"${SCRIPT_DIR}/logwhisperer.onefile-build"
"${SCRIPT_DIR}/__pycache__"
"${SCRIPT_DIR}/modules/__pycache__"
)
for dir in "${dirs_to_clean[@]}"; do
if [[ -d "$dir" ]]; then
rm -rf "$dir"
info "Removed: $dir"
fi
done
# Clean old build files
find "$SCRIPT_DIR" -name "*.pyc" -delete
find "$SCRIPT_DIR" -name "*.pyo" -delete
find "$SCRIPT_DIR" -name "*.bin" -delete
find "$SCRIPT_DIR" -name "*.spec" -delete
# Clean old releases
rm -f "${SCRIPT_DIR}"/logwhisperer_*.zip
rm -f "${SCRIPT_DIR}"/logwhisperer_*.tar.gz
rm -f "${SCRIPT_DIR}"/logwhisperer_*.sha256
rm -f "${SCRIPT_DIR}"/logwhisperer_*.sig
}
# Build binary with Nuitka
build_binary() {
log "Building binary with Nuitka..."
mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR"
# Fix permissions for certifi cacert.pem before building (macOS only)
if [[ "$PLATFORM" == "macos" ]]; then
log "Fixing permissions for macOS build..."
local certifi_path=$("$PYTHON_CMD" -c "import certifi; import os; print(os.path.dirname(certifi.__file__))" 2>/dev/null || echo "")
if [[ -n "$certifi_path" ]] && [[ -f "$certifi_path/cacert.pem" ]]; then
chmod 644 "$certifi_path/cacert.pem" || true
info "Fixed permissions for certifi cacert.pem"
fi
fi
# Prepare Nuitka arguments
local nuitka_args=(
--standalone
--onefile
--assume-yes-for-downloads
--output-dir="$BUILD_DIR"
--include-package=yaml
--include-package=requests
--include-package=cryptography
--include-package=modules
--include-module=modules.monitor
--include-module=modules.discord_alert
--include-module=modules.summarizer
--include-module=modules.spinner
--include-module=modules.license
--include-module=logwhisperer_oss
--include-module=cryptography.hazmat
--include-module=cryptography.hazmat.backends
--include-module=cryptography.hazmat.backends.openssl
--include-data-files="${SCRIPT_DIR}/modules/*.py=modules/"
--include-data-files="${SCRIPT_DIR}/logwhisperer_oss.py=."
--include-data-dir="${SCRIPT_DIR}/modules=modules"
--follow-imports
--include-package-data=modules
--include-package-data=cryptography
--enable-plugin=no-qt
--show-progress
--show-memory
)
# Add platform-specific options
if [[ "$PLATFORM" == "linux" ]]; then
# Check if icon exists before adding it
if [[ -f "${SCRIPT_DIR}/assets/icon.png" ]]; then
nuitka_args+=(
--linux-onefile-icon="${SCRIPT_DIR}/assets/icon.png"
)
else
warning "Icon not found at ${SCRIPT_DIR}/assets/icon.png, building without icon"
fi
fi
# Add build type specific options
if [[ "$BUILD_TYPE" == "release" ]]; then
nuitka_args+=(
--python-flag=no_site
--python-flag=no_warnings
--remove-output
)
else
# Debug build - don't optimize, keep debug info
nuitka_args+=(
--python-flag=no_site
# Don't use optimize flag for debug builds
# Keep debug symbols
--debug
--trace-execution
)
fi
# Add compression if requested
if [[ "$COMPRESS_BINARY" == "true" ]]; then
if command -v upx >/dev/null 2>&1; then
nuitka_args+=(--enable-plugin=upx)
info "UPX compression enabled"
else
warning "UPX not found, skipping compression"
fi
fi
# Run Nuitka
"$PYTHON_CMD" -m nuitka "${nuitka_args[@]}" "${SCRIPT_DIR}/logwhisperer.py"
# Check if binary was created
local binary_name="logwhisperer.bin"
if [[ ! -f "$binary_name" ]]; then
die "Binary not created"
fi
# Make binary executable
chmod +x "$binary_name"
# Verify binary
if ./"$binary_name" --version >/dev/null 2>&1; then
log "Binary verification passed"
else
die "Binary verification failed"
fi
cd "$SCRIPT_DIR"
}
sign_macos_binary() {
if [[ "$PLATFORM" != "macos" ]]; then
return 0
fi
# Check if we have signing credentials
if [[ -z "${MACOS_IDENTITY:-}" ]]; then
warning "MACOS_IDENTITY not set, skipping code signing"
return 0
fi
log "Signing macOS binary..."
local binary_path="$BUILD_DIR/logwhisperer.bin"
if [[ ! -f "$binary_path" ]]; then
error "Binary not found for signing: $binary_path"
return 1
fi
# Sign the binary
if codesign --deep --force --verify --verbose \
--sign "$MACOS_IDENTITY" \
--options runtime \
--timestamp \
"$binary_path"; then
log "Binary signed successfully"
# Verify signature
if codesign --verify --verbose "$binary_path"; then
log "Signature verification passed"
else
error "Signature verification failed"
return 1
fi
else
error "Failed to sign binary"
return 1
fi
return 0
}
# Create default configuration file
create_default_config() {
cat > "$1" << 'EOF'
# LogWhisperer Configuration
# AI-powered log analysis and monitoring
# Model configuration
model: "mistral"
ollama_host: "http://localhost:11434"
# Default log source
source: "journalctl"
log_file_path: "/var/log/syslog"
priority: "err"
entries: 500
# Processing options
lines_per_prompt: 50
timeout: 60
# Monitor configuration (Pro only)
monitor:
enabled: true
escalation_level: "ERROR"
batch_size: 200
sleep_interval: 1.0
batch_timeout: 30.0
webhook_url: "" # Discord webhook URL
send_full_summary: false
discord_mentions: [] # List of user/role IDs to mention
# Web dashboard configuration (Pro only)
web:
enabled: true
host: "0.0.0.0"
port: 5123
api_url: "http://localhost:5124"
users:
admin: "changeme" # CHANGE THIS PASSWORD!
session_timeout: 3600
max_log_entries: 1000
update_interval: 1.0
# Custom prompt (optional)
# Use {{LOGS}} as placeholder for log entries
# prompt: |
# Analyze these logs and provide a concise summary:
# {{LOGS}}
# Report directory
report_dir: "reports"
EOF
}
# Prepare web components
prepare_web_components() {
log "Preparing web components..."
local web_dir="$RELEASE_DIR/web"
mkdir -p "$web_dir"
# Copy API server
if [[ -f "${SCRIPT_DIR}/api_server.py" ]]; then
cp "${SCRIPT_DIR}/api_server.py" "$web_dir/"
info "Copied API server"
else
warning "api_server.py not found"
fi
# Copy web dashboard
if [[ -f "${SCRIPT_DIR}/web/dashboard.py" ]]; then
cp "${SCRIPT_DIR}/web/dashboard.py" "$web_dir/"
elif [[ -f "${SCRIPT_DIR}/dashboard.py" ]]; then
cp "${SCRIPT_DIR}/dashboard.py" "$web_dir/"
else
warning "dashboard.py not found"
fi
# Copy templates
if [[ -d "${SCRIPT_DIR}/templates" ]]; then
cp -r "${SCRIPT_DIR}/templates" "$web_dir/"
info "Copied templates directory"
fi
# Copy static files
if [[ -d "${SCRIPT_DIR}/static" ]]; then
cp -r "${SCRIPT_DIR}/static" "$web_dir/"
info "Copied static directory"
fi
# Create web requirements file
cat > "$web_dir/requirements-web.txt" << 'EOF'
flask>=2.0.0
flask-socketio>=5.0.0
flask-compress>=1.10.0
python-socketio[client]>=5.0.0
werkzeug>=2.0.0
pyyaml>=5.4.0
requests>=2.25.0
EOF
# Copy systemd service files
mkdir -p "$RELEASE_DIR/systemd"
# Main service
cat > "$RELEASE_DIR/systemd/logwhisperer.service" << 'EOF'
[Unit]
Description=LogWhisperer - AI-powered log intelligence
After=network.target
[Service]
Type=simple
User=root
Group=root
WorkingDirectory=/opt/logwhisperer
ExecStart=/opt/logwhisperer/logwhisperer monitor
Restart=always
RestartSec=10
StandardOutput=journal
StandardError=journal
SyslogIdentifier=logwhisperer
[Install]
WantedBy=multi-user.target
EOF
# API service
cat > "$RELEASE_DIR/systemd/logwhisperer-api.service" << 'EOF'
[Unit]
Description=LogWhisperer API Server
After=network.target
Before=logwhisperer-web.service
[Service]
Type=simple
User=root
Group=root
WorkingDirectory=/opt/logwhisperer
ExecStart=/opt/logwhisperer/bin/logwhisperer-api
Restart=always
RestartSec=10
StandardOutput=journal
StandardError=journal
SyslogIdentifier=logwhisperer-api
Environment="PYTHONUNBUFFERED=1"
[Install]
WantedBy=multi-user.target
EOF
# Web service
cat > "$RELEASE_DIR/systemd/logwhisperer-web.service" << 'EOF'
[Unit]
Description=LogWhisperer Web Dashboard
After=network.target logwhisperer-api.service
Wants=logwhisperer-api.service
[Service]
Type=simple
User=root
Group=root
WorkingDirectory=/opt/logwhisperer/web
ExecStart=/opt/logwhisperer/bin/logwhisperer-web
Restart=always
RestartSec=10
StandardOutput=journal
StandardError=journal
SyslogIdentifier=logwhisperer-web
Environment="PYTHONUNBUFFERED=1"
[Install]
WantedBy=multi-user.target
EOF
info "Created systemd service files"
}
# Prepare release package
prepare_release() {
local version="$1"
log "Preparing release package..."
# Create release directory structure
mkdir -p "$RELEASE_DIR"/{bin,config,docs,modules}
# Copy binary
cp "$BUILD_DIR/logwhisperer.bin" "$RELEASE_DIR/bin/logwhisperer"
chmod +x "$RELEASE_DIR/bin/logwhisperer"
# Handle configuration file
if [[ -f "${SCRIPT_DIR}/config.yaml.example" ]]; then
cp "${SCRIPT_DIR}/config.yaml.example" "$RELEASE_DIR/config/config.yaml.example"
info "Copied existing config.yaml.example"
else
warning "config.yaml.example not found, creating default configuration"
create_default_config "$RELEASE_DIR/config/config.yaml.example"
fi
# Copy installer if it exists
if [[ -f "${SCRIPT_DIR}/install.sh" ]]; then
cp "${SCRIPT_DIR}/install.sh" "$RELEASE_DIR/"
chmod +x "$RELEASE_DIR/install.sh"
else
warning "install.sh not found, creating basic installer"
cat > "$RELEASE_DIR/install.sh" << 'EOF'
#!/bin/bash
# LogWhisperer Installer
set -euo pipefail
# See full install.sh for complete installer
echo "Please use the full installer from the LogWhisperer repository"
EOF
chmod +x "$RELEASE_DIR/install.sh"
fi
# Copy web installer
if [[ -f "${SCRIPT_DIR}/install-web.sh" ]]; then
cp "${SCRIPT_DIR}/install-web.sh" "$RELEASE_DIR/"
chmod +x "$RELEASE_DIR/install-web.sh"
info "Copied web installer"
fi
# Copy Python modules directory (needed for web components)
if [[ -d "${SCRIPT_DIR}/modules" ]]; then
cp -r "${SCRIPT_DIR}/modules" "$RELEASE_DIR/"
info "Copied modules directory for web components"
fi
# Prepare web components
prepare_web_components
# Copy activate script if it exists
if [[ -f "${SCRIPT_DIR}/activate.sh" ]]; then
cp "${SCRIPT_DIR}/activate.sh" "$RELEASE_DIR/"
chmod +x "$RELEASE_DIR/activate.sh"
info "Included activate.sh script"
fi
# Create comprehensive README
cat > "$RELEASE_DIR/README.md" << EOF
# LogWhisperer Pro v${version}
AI-powered log analysis and monitoring tool with web dashboard.
## Installation
### Basic Installation
\`\`\`bash
sudo ./install.sh
\`\`\`
### Web Dashboard Installation
\`\`\`bash
sudo ./install-web.sh
\`\`\`
## Activation
Activate your license:
\`\`\`bash
logwhisperer activate
\`\`\`
## Platform
- Platform: ${PLATFORM}
- Architecture: ${ARCH}
- Build Date: $(date -u +"%Y-%m-%d %H:%M:%S UTC")
- Build Type: ${BUILD_TYPE}
## Quick Start
1. Activate your license:
\`\`\`bash
logwhisperer activate
\`\`\`
2. Edit the configuration:
\`\`\`bash
sudo nano /etc/logwhisperer/config.yaml
\`\`\`
3. Test the installation:
\`\`\`bash
logwhisperer test
\`\`\`
4. Run LogWhisperer:
\`\`\`bash
logwhisperer summarize # One-time summary
logwhisperer monitor # Real-time monitoring (Pro)
\`\`\`
5. Access Web Dashboard (optional):
- Install: \`sudo ./install-web.sh\`
- Access: http://your-server:5123
- Default login: admin / changeme
## Features
### Core Features
- AI-powered log summarization
- Multiple log sources (journalctl, file, docker)
- Configurable Ollama models
### Pro Features
- Real-time monitoring with alerts
- Discord webhook integration
- Web dashboard with analytics
- Advanced pattern detection
- Performance optimization
## Service Management
\`\`\`bash
# Main service
sudo systemctl status logwhisperer
sudo journalctl -u logwhisperer -f
# API service (for web dashboard)
sudo systemctl status logwhisperer-api
# Web service
sudo systemctl status logwhisperer-web
\`\`\`
For support, visit: https://github.com/yourusername/logwhisperer
EOF
# Create version file
echo "$version" > "$RELEASE_DIR/VERSION"
# Create manifest
cat > "$RELEASE_DIR/MANIFEST.txt" << EOF
LogWhisperer Release Manifest
Version: ${version}
Platform: ${PLATFORM}
Architecture: ${ARCH}
Build Date: $(date -u +"%Y-%m-%d %H:%M:%S UTC")
Build Type: ${BUILD_TYPE}
Files:
$(cd "$RELEASE_DIR" && find . -type f | sort)
Checksums:
$(cd "$RELEASE_DIR" && find . -type f -exec sha256sum {} \; | sort)
EOF
}
# Create distribution archives
create_archives() {
local version="$1"
local base_name="logwhisperer_${version}_${PLATFORM}_${ARCH}"
log "Creating distribution archives..."
mkdir -p "$DIST_DIR"
cd "$RELEASE_DIR"
# Create ZIP archive
local zip_file="${DIST_DIR}/${base_name}.zip"
zip -r "$zip_file" ./* -x "*.pyc" -x "__pycache__/*"
info "Created: $zip_file"
# Create tar.gz archive
local tar_file="${DIST_DIR}/${base_name}.tar.gz"
tar czf "$tar_file" --exclude="*.pyc" --exclude="__pycache__" ./*
info "Created: $tar_file"
cd "$SCRIPT_DIR"
# Create checksums
if [[ "$CREATE_CHECKSUM" == "true" ]]; then
log "Creating checksums..."
cd "$DIST_DIR"
for file in *.{zip,tar.gz}; do
if [[ -f "$file" ]]; then
# Use platform-specific commands
if [[ "$PLATFORM" == "macos" ]]; then
shasum -a 256 "$file" > "${file}.sha256"
md5 -r "$file" > "${file}.md5"
else
sha256sum "$file" > "${file}.sha256"
md5sum "$file" > "${file}.md5"
fi
info "Created checksums for: $file"
fi
done
cd "$SCRIPT_DIR"
fi
# Sign releases
if [[ "$SIGN_RELEASE" == "true" ]] && [[ -n "$GPG_KEY" ]]; then
log "Signing releases..."
cd "$DIST_DIR"
for file in *.{zip,tar.gz}; do
if [[ -f "$file" ]]; then
gpg --armor --detach-sign --default-key "$GPG_KEY" "$file"
info "Signed: $file"
fi
done
cd "$SCRIPT_DIR"
fi
}
# Print build summary
print_summary() {
local version="$1"
local end_time=$(date +%s)
local duration=$((end_time - START_TIME))
echo
log "Build completed successfully!"
echo
echo "Summary:"
echo " Version: ${version}"
echo " Platform: ${PLATFORM}"
echo " Architecture: ${ARCH}"
echo " Build Type: ${BUILD_TYPE}"
echo " Duration: ${duration} seconds"
echo
echo "Components included:"
echo " ✓ Main binary (compiled with Nuitka)"
echo " ✓ Web dashboard components"
echo " ✓ API server"
echo " ✓ Systemd service files"
echo " ✓ Installation scripts"
echo
echo "Artifacts:"
ls -la "$DIST_DIR"
echo
# Show next steps
echo "Next steps:"
echo " 1. Test the binary: ${RELEASE_DIR}/bin/logwhisperer --version"
echo " 2. Install locally: sudo ${RELEASE_DIR}/install.sh"
echo " 3. Install web dashboard: sudo ${RELEASE_DIR}/install-web.sh"
echo " 4. Upload release: ${DIST_DIR}/logwhisperer_${version}_${PLATFORM}_${ARCH}.zip"
}
# Main build process
main() {
local START_TIME=$(date +%s)
log "$SCRIPT_NAME"
log "Starting build process..."
# Detect version
VERSION=$(detect_version)
log "Building LogWhisperer ${VERSION}"
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
--debug)
BUILD_TYPE="debug"
shift
;;
--skip-tests)
SKIP_TESTS="true"
shift
;;
--skip-cleanup)
SKIP_CLEANUP="true"
shift
;;
--no-compress)
COMPRESS_BINARY="false"
shift
;;
--sign)
SIGN_RELEASE="true"
shift
;;
--gpg-key)
GPG_KEY="$2"
shift 2
;;
--help)
cat << EOF
Usage: $0 [OPTIONS]
Options:
--debug Build debug version
--skip-tests Skip running tests
--skip-cleanup Skip cleaning build artifacts
--no-compress Disable binary compression
--sign Sign release files
--gpg-key KEY GPG key for signing
--help Show this help message
Environment variables:
PYTHON_CMD Python command (default: python3)
BUILD_TYPE Build type: release or debug (default: release)
SKIP_TESTS Skip tests: true or false (default: false)
COMPRESS_BINARY Compress binary: true or false (default: true)
EOF
exit 0
;;
*)
die "Unknown option: $1"
;;
esac
done
# Build steps
check_requirements
if [[ "$SKIP_CLEANUP" != "true" ]]; then
clean_artifacts
fi
run_tests
build_binary
if [[ "$PLATFORM" == "macos" ]] && [[ -n "${MACOS_IDENTITY:-}" ]]; then
sign_macos_binary || warning "Binary signing failed, continuing anyway"
fi
prepare_release "$VERSION"
create_archives "$VERSION"
if [[ "$SKIP_CLEANUP" != "true" ]]; then
log "Cleaning temporary build files..."
rm -rf "$BUILD_DIR"
rm -rf "${SCRIPT_DIR}/logwhisperer.dist"
rm -rf "${SCRIPT_DIR}/logwhisperer.build"
rm -rf "${SCRIPT_DIR}/logwhisperer.onefile-build"
fi
print_summary "$VERSION"
}
# Run main function
main "$@"