-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·329 lines (267 loc) · 10.2 KB
/
build.sh
File metadata and controls
executable file
·329 lines (267 loc) · 10.2 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
#!/bin/bash
#
# Secure build script for LensLogic executable
# Creates a single-file executable respecting .gitignore exclusions
#
set -e # Exit on any error
echo "Building LensLogic executable (GITIGNORE-AWARE)..."
echo "=================================================="
# Function to parse .gitignore and create find exclusions
parse_gitignore() {
if [ ! -f ".gitignore" ]; then
echo "❌ .gitignore file not found!" >&2
exit 1
fi
# Create temporary file for find exclusions
local temp_file
temp_file=$(mktemp)
# Parse .gitignore line by line
while IFS= read -r line; do
# Skip empty lines and comments
if [[ -z "$line" || "$line" =~ ^[[:space:]]*# ]]; then
continue
fi
# Remove leading/trailing whitespace
pattern=$(echo "$line" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
# Skip empty patterns after cleaning
if [[ -z "$pattern" ]]; then
continue
fi
# Handle different gitignore pattern types
if [[ "$pattern" == "/"* ]]; then
# Pattern starts with / - root relative
pattern_clean=${pattern#/}
echo "! -path \"./$pattern_clean\" ! -path \"./$pattern_clean/*\"" >> "$temp_file"
elif [[ "$pattern" == *"/" ]]; then
# Pattern ends with / - directory only
pattern_clean=${pattern%/}
echo "! -path \"*/$pattern_clean\" ! -path \"*/$pattern_clean/*\" ! -name \"$pattern_clean\"" >> "$temp_file"
elif [[ "$pattern" == *"*"* ]]; then
# Pattern contains wildcards
echo "! -name \"$pattern\" ! -path \"*/$pattern\" ! -path \"*/$pattern/*\"" >> "$temp_file"
else
# Simple filename or directory pattern
echo "! -name \"$pattern\" ! -path \"*/$pattern\" ! -path \"*/$pattern/*\"" >> "$temp_file"
fi
done < .gitignore
echo "$temp_file"
}
# Security check function using gitignore-based exclusions
check_security_with_gitignore() {
echo "🔍 Performing .gitignore-based security scan..."
echo "📄 Reading .gitignore patterns..."
# Count patterns being read
local pattern_count=0
while IFS= read -r line; do
# Skip empty lines and comments
if [[ -z "$line" || "$line" =~ ^[[:space:]]*# ]]; then
continue
fi
# Remove leading/trailing whitespace
pattern=$(echo "$line" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
# Skip empty patterns after cleaning
if [[ -z "$pattern" ]]; then
continue
fi
echo " 📝 $pattern"
((pattern_count++))
done < .gitignore
echo "✅ Loaded $pattern_count exclusion patterns from .gitignore"
# Get gitignore exclusions
local exclusions_file
exclusions_file=$(parse_gitignore)
# Build find command to check for files that would be included
local find_cmd="find . -type f"
# Add gitignore exclusions
while read -r exclusion; do
find_cmd="$find_cmd $exclusion"
done < "$exclusions_file"
# Look for potentially sensitive files that aren't excluded by gitignore
# Exclude default config files as they are templates, not sensitive
local sensitive_files
sensitive_files=$(eval "$find_cmd" 2>/dev/null | grep -E '\.(key|secret|private|credential)$|\.env\.|config.*\.(yaml|yml|json)$|api.*key|token.*\.|password.*\.' | grep -v '__pycache__' | grep -v 'default_config\.' | grep -v 'config/default' | head -10)
# Clean up temp file
rm -f "$exclusions_file"
if [[ -n "$sensitive_files" ]]; then
echo "⚠️ WARNING: Found potentially sensitive files not excluded by .gitignore:"
echo "$sensitive_files"
echo ""
echo "These files would be included in the build. Consider adding them to .gitignore."
echo ""
echo "Continue anyway? (type 'yes' to proceed, anything else to abort)"
read -r response
if [ "$response" != "yes" ]; then
echo "Build aborted for security."
exit 1
fi
echo "⚠️ User chose to proceed despite security warnings!"
else
echo "🔒 Security scan passed - no sensitive files detected outside .gitignore exclusions"
fi
}
# Clean any previous builds
echo "🧹 Cleaning previous builds..."
rm -rf build/ dist/
# Only remove auto-generated spec files, keep our custom lenslogic.spec
find . -name "*.spec" -not -name "lenslogic.spec" -delete
# Security scan using gitignore patterns
check_security_with_gitignore
# Check for required dependencies
echo "🔍 Checking dependencies..."
MISSING_DEPS=""
if ! python -c "import PyInstaller" &> /dev/null; then
MISSING_DEPS="$MISSING_DEPS pyinstaller"
fi
if ! python -c "import rich" &> /dev/null; then
MISSING_DEPS="$MISSING_DEPS rich"
fi
if ! python -c "import questionary" &> /dev/null; then
MISSING_DEPS="$MISSING_DEPS questionary"
fi
if ! python -c "import exiftool" &> /dev/null; then
MISSING_DEPS="$MISSING_DEPS pyexiftool"
fi
if [[ -n "$MISSING_DEPS" ]]; then
echo "Missing dependencies:$MISSING_DEPS"
echo "Installing missing dependencies..."
pip install $MISSING_DEPS
fi
# Create temporary directory for safe file collection
echo "Creating secure build environment..."
TEMP_BUILD_DIR=$(mktemp -d)
echo "Temporary build directory: $TEMP_BUILD_DIR"
# Function to copy files respecting .gitignore exclusions
copy_with_gitignore_exclusions() {
local src_pattern="$1"
local dest_base="$2"
local description="$3"
echo "📂 $description"
# Get gitignore exclusions
local exclusions_file
exclusions_file=$(parse_gitignore)
# Build find command with gitignore exclusions
local find_cmd="find . -type f -path \"$src_pattern\""
# Add gitignore exclusions
while read -r exclusion; do
find_cmd="$find_cmd $exclusion"
done < "$exclusions_file"
# Execute find and copy matching files
local copied_count=0
local files_found
files_found=$(eval "$find_cmd" 2>/dev/null)
if [[ -z "$files_found" ]]; then
echo " ⚠️ No files found matching pattern: $src_pattern"
else
while IFS= read -r file; do
# Skip the current file if it starts with ./
file_clean=${file#./}
# Create directory structure in destination
dest_dir="$dest_base/$(dirname "$file_clean")"
mkdir -p "$dest_dir"
cp "$file" "$dest_dir/"
echo " ✅ $file_clean"
((copied_count++))
done <<< "$files_found"
fi
# Clean up temp file
rm -f "$exclusions_file"
echo " 📊 Copied $copied_count files"
}
# Copy files using .gitignore exclusions
echo "📦 Collecting files (respecting .gitignore exclusions)..."
# Copy main entry point
if [ -f "src/main.py" ]; then
mkdir -p "$TEMP_BUILD_DIR/src"
cp src/main.py "$TEMP_BUILD_DIR/src/"
echo " ✅ src/main.py"
else
echo "❌ ERROR: src/main.py not found!"
exit 1
fi
# Copy all source files from src/ directory
copy_with_gitignore_exclusions "./src/*.py" "$TEMP_BUILD_DIR" "Copying main source files..."
copy_with_gitignore_exclusions "./src/*/*.py" "$TEMP_BUILD_DIR" "Copying module files..."
copy_with_gitignore_exclusions "./src/*/*/*.py" "$TEMP_BUILD_DIR" "Copying nested module files..."
# Copy configuration files
copy_with_gitignore_exclusions "./config/*.yaml" "$TEMP_BUILD_DIR" "Copying configuration files..."
copy_with_gitignore_exclusions "./config/*.yml" "$TEMP_BUILD_DIR" "Copying YAML configuration files..."
# Copy requirements.txt if it exists
if [ -f "requirements.txt" ]; then
cp requirements.txt "$TEMP_BUILD_DIR/"
echo " ✅ requirements.txt"
fi
# Verify essential files exist
echo "🔍 Verifying essential files..."
if [ ! -f "$TEMP_BUILD_DIR/src/main.py" ]; then
echo "❌ ERROR: src/main.py not found in build!"
rm -rf "$TEMP_BUILD_DIR"
exit 1
fi
if [ ! -f "$TEMP_BUILD_DIR/config/default_config.yaml" ]; then
echo "❌ ERROR: config/default_config.yaml not found in build!"
rm -rf "$TEMP_BUILD_DIR"
exit 1
fi
echo "✅ All essential files verified"
# Create __init__.py files for proper Python module structure
find "$TEMP_BUILD_DIR/src" -type d -exec touch {}/__init__.py \;
# Show what's being included
echo ""
echo "Files to be included in executable:"
echo "===================================="
find "$TEMP_BUILD_DIR" -type f | sort
echo ""
echo "Building executable with PyInstaller..."
# Save current directory and Python path
ORIGINAL_DIR=$(pwd)
PYTHON_PATH=$(python -c "import sys; print(sys.executable)")
cd "$TEMP_BUILD_DIR"
# Create a launch script in the temp directory
cat > lenslogic_launcher.py << 'EOF'
#!/usr/bin/env python3
"""
LensLogic launcher script for PyInstaller
"""
import sys
import os
from pathlib import Path
# Add src directory to Python path
src_dir = Path(__file__).parent / 'src'
sys.path.insert(0, str(src_dir))
# Import and run main
from main import main
if __name__ == "__main__":
main()
EOF
# Use our custom spec file with all Rich modules properly configured
echo "📦 Using custom lenslogic.spec with comprehensive module support..."
"$PYTHON_PATH" -m PyInstaller "$ORIGINAL_DIR/lenslogic.spec" --clean --distpath "$ORIGINAL_DIR/dist"
# Return to original directory
cd "$ORIGINAL_DIR"
# Clean up temporary directory
echo "Cleaning up temporary files..."
rm -rf "$TEMP_BUILD_DIR"
echo ""
if [ -f "./dist/LensLogic" ]; then
echo "✅ Build completed successfully!"
echo "=================================="
echo "Executable location: ./dist/LensLogic"
echo "File size: $(du -h ./dist/LensLogic | cut -f1)"
echo ""
echo "Test with: ./dist/LensLogic --help"
echo "Run with: ./dist/LensLogic --interactive"
echo ""
echo "🎯 LensLogic Features Available:"
echo " • Smart photo & video organization"
echo " • Professional XMP sidecar generation"
echo " • Camera slug naming (iPhone, DSLR, etc.)"
echo " • Comprehensive metadata extraction"
echo " • XMP library analysis and reporting"
echo " • Geolocation and GPS support"
echo " • Interactive mode with Rich console"
echo ""
echo "📸🎬 Ready for professional photo & video workflows!"
else
echo "❌ Build failed - executable not found"
exit 1
fi