|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Exit on error |
| 4 | +set -e |
| 5 | + |
| 6 | +# Define variables |
| 7 | +DOCS_REPO_URL="https://github.com/dynamsoft-docs/web-twain-docs/archive/refs/heads/preview.zip" |
| 8 | +TEMPLATE_REPO_URL="https://github.com/dynamsoft-docs/Docs-Template-Repo/archive/refs/heads/preview.zip" |
| 9 | +TEMP_DIR="temp_docs" |
| 10 | +TEMPLATE_DIR="Docs-Template-Repo-preview" |
| 11 | +FINAL_DIR="web-twain-docs-preview" |
| 12 | + |
| 13 | +echo "=== Starting build script ===" |
| 14 | + |
| 15 | +# Clean up any existing temporary directories |
| 16 | +echo "Cleaning up old directories..." |
| 17 | +rm -rf "$TEMP_DIR" "$FINAL_DIR" "$TEMPLATE_DIR" |
| 18 | + |
| 19 | +# Create temporary directory |
| 20 | +echo "Creating temporary directory: $TEMP_DIR" |
| 21 | +mkdir -p "$TEMP_DIR" |
| 22 | +cd "$TEMP_DIR" |
| 23 | + |
| 24 | +# Download first repository (web-twain-docs) |
| 25 | +echo "Downloading web-twain-docs repository..." |
| 26 | +curl -L -o docs.zip "$DOCS_REPO_URL" |
| 27 | + |
| 28 | +# Extract first repository |
| 29 | +echo "Extracting web-twain-docs..." |
| 30 | +unzip -q docs.zip |
| 31 | + |
| 32 | +# Get the extracted directory name (dynamic detection) |
| 33 | +DOCS_EXTRACTED_DIR=$(find . -maxdepth 1 -type d -name "web-twain-docs-*" | head -1 | sed 's|^\./||') |
| 34 | +echo "Detected docs directory: $DOCS_EXTRACTED_DIR" |
| 35 | + |
| 36 | +if [ -z "$DOCS_EXTRACTED_DIR" ]; then |
| 37 | + echo "Error: Unable to find extracted docs directory" |
| 38 | + exit 1 |
| 39 | +fi |
| 40 | + |
| 41 | +# Create final directory and copy docs content into it |
| 42 | +echo "Creating final directory and copying docs content..." |
| 43 | +mkdir -p "../$FINAL_DIR" |
| 44 | +cp -rf "$DOCS_EXTRACTED_DIR"/* "../$FINAL_DIR"/ 2>/dev/null || true |
| 45 | + |
| 46 | +# Go back to parent directory |
| 47 | +cd .. |
| 48 | + |
| 49 | +# Download second repository (Docs-Template-Repo) |
| 50 | +echo "Downloading Docs-Template-Repo repository..." |
| 51 | +curl -L -o template.zip "$TEMPLATE_REPO_URL" |
| 52 | + |
| 53 | +# Extract second repository |
| 54 | +echo "Extracting Docs-Template-Repo..." |
| 55 | +unzip -q template.zip |
| 56 | + |
| 57 | +# Get the template extracted directory name |
| 58 | +TEMPLATE_EXTRACTED_DIR=$(find . -maxdepth 1 -type d -name "Docs-Template-Repo-*" | head -1 | sed 's|^\./||') |
| 59 | +echo "Detected template directory: $TEMPLATE_EXTRACTED_DIR" |
| 60 | + |
| 61 | +if [ -z "$TEMPLATE_EXTRACTED_DIR" ]; then |
| 62 | + echo "Error: Unable to find extracted template directory" |
| 63 | + exit 1 |
| 64 | +fi |
| 65 | + |
| 66 | +# Rename template directory to standard name |
| 67 | +if [ "$TEMPLATE_EXTRACTED_DIR" != "$TEMPLATE_DIR" ]; then |
| 68 | + echo "Renaming $TEMPLATE_EXTRACTED_DIR to $TEMPLATE_DIR" |
| 69 | + mv "$TEMPLATE_EXTRACTED_DIR" "$TEMPLATE_DIR" |
| 70 | +fi |
| 71 | + |
| 72 | +# Ensure final directory exists |
| 73 | +if [ ! -d "$FINAL_DIR" ]; then |
| 74 | + echo "Error: Final directory $FINAL_DIR does not exist" |
| 75 | + exit 1 |
| 76 | +fi |
| 77 | + |
| 78 | +# Overwrite operation: Copy template repository contents to final directory (overwrite) |
| 79 | +echo "Performing overwrite operation..." |
| 80 | +cp -rf "$TEMPLATE_DIR"/* "$FINAL_DIR"/ 2>/dev/null || echo "Warning: Some files may not have been copied during the process, but execution can continue" |
| 81 | + |
| 82 | +# Enter final directory |
| 83 | +cd "$FINAL_DIR" |
| 84 | + |
| 85 | +# Display current directory |
| 86 | +echo "Current working directory: $(pwd)" |
| 87 | +echo "Final directory contents:" |
| 88 | +ls -la |
| 89 | + |
| 90 | +# Replace strings in all files under _includes directory |
| 91 | +echo "Replacing assetsPath in _includes directory..." |
| 92 | +if [ -d "_includes" ]; then |
| 93 | + find _includes -type f -exec sed -i.bak "s|assetsPath = '/webres/wwwroot'|assetsPath = 'https://www.dynamsoft.com/webres/wwwroot'|g" {} \; |
| 94 | + find _includes -name "*.bak" -type f -delete |
| 95 | + echo "_includes directory processing completed" |
| 96 | +else |
| 97 | + echo "Warning: _includes directory does not exist" |
| 98 | +fi |
| 99 | + |
| 100 | +# Replace strings in all files under _layouts directory |
| 101 | +echo "Replacing assetsPath in _layouts directory..." |
| 102 | +if [ -d "_layouts" ]; then |
| 103 | + find _layouts -type f -exec sed -i.bak "s|assetsPath = '/webres/wwwroot'|assetsPath = 'https://www.dynamsoft.com/webres/wwwroot'|g" {} \; |
| 104 | + find _layouts -name "*.bak" -type f -delete |
| 105 | + echo "_layouts directory processing completed" |
| 106 | +else |
| 107 | + echo "Warning: _layouts directory does not exist" |
| 108 | +fi |
| 109 | + |
| 110 | +# Go back to parent directory |
| 111 | +cd .. |
| 112 | + |
| 113 | +# Clean up temporary files |
| 114 | +echo "Cleaning up temporary files..." |
| 115 | +rm -f template.zip |
| 116 | +rm -rf "$TEMP_DIR" "$TEMPLATE_DIR" |
| 117 | + |
| 118 | +echo "=== Build completed ===" |
| 119 | +echo "Final directory: $FINAL_DIR" |
| 120 | +echo "Final directory contents:" |
| 121 | +ls -la "$FINAL_DIR" |
0 commit comments