-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathvalidate_docx.sh
More file actions
executable file
·57 lines (49 loc) · 1.93 KB
/
validate_docx.sh
File metadata and controls
executable file
·57 lines (49 loc) · 1.93 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
#!/bin/bash
# Script to validate the integrity of all generated .docx files
echo "🔍 Validating .docx file integrity..."
echo ""
VALID=0
INVALID=0
for file in /Users/mmonterroca/code/go-docx/examples/*/*.docx; do
# Skip temp files
if [[ "$file" =~ ~\$ ]]; then
continue
fi
filename=$(basename "$file")
# Test ZIP integrity
if unzip -t "$file" > /dev/null 2>&1; then
# Check for required OOXML files
has_content_types=$(unzip -l "$file" | grep -q "\[Content_Types\].xml" && echo "yes" || echo "no")
has_rels=$(unzip -l "$file" | grep -q "_rels/.rels" && echo "yes" || echo "no")
has_document=$(unzip -l "$file" | grep -q "word/document.xml" && echo "yes" || echo "no")
has_styles=$(unzip -l "$file" | grep -q "word/styles.xml" && echo "yes" || echo "no")
if [[ "$has_content_types" == "yes" && "$has_rels" == "yes" && "$has_document" == "yes" && "$has_styles" == "yes" ]]; then
echo "✅ $filename - VALID"
((VALID++))
else
echo "⚠️ $filename - INCOMPLETE (missing required files)"
echo " [Content_Types].xml: $has_content_types"
echo " _rels/.rels: $has_rels"
echo " word/document.xml: $has_document"
echo " word/styles.xml: $has_styles"
((INVALID++))
fi
else
echo "❌ $filename - CORRUPTED (invalid ZIP)"
((INVALID++))
fi
done
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "📊 VALIDATION SUMMARY"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "✅ Valid: $VALID"
echo "❌ Invalid: $INVALID"
echo ""
if [ $INVALID -gt 0 ]; then
echo "❌ Some files are invalid or corrupted"
exit 1
else
echo "✅ All .docx files are valid OOXML documents!"
exit 0
fi