summaryrefslogtreecommitdiffstats
path: root/seed.sh
blob: f6f817d7282551b49d19340862a0a06551da6f34 (plain)
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
#!/bin/ksh

# Accept directory count as an argument, default to 500
TOTAL=${1:-500}

# Define the base path relative to the script location
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
BASE_DIR="$SCRIPT_DIR/_site/log"

# Target size: 16000 bytes is ~15.6 KB
CONTENT_SIZE=16000 

# Ensure the target directory exists
mkdir -p "$BASE_DIR"

for i in $(seq 1 $TOTAL); do
    DIR="$BASE_DIR/site_$i"
    mkdir -p "$DIR"
    
    # Start the file structure
    echo "<html><head><title>Site $i</title></head><body><main><p>" > "$DIR/index.html"
    
    # Generate random text using dd for byte-level precision
    # We read 32KB of raw data to account for characters filtered out by tr,
    # then use dd again to trim the result to exactly CONTENT_SIZE bytes.
    dd if=/dev/urandom bs=32768 count=1 2>/dev/null | tr -dc 'a-zA-Z0-9 ' | dd bs=1 count=$CONTENT_SIZE 2>/dev/null >> "$DIR/index.html"
    
    # Append keyword and close tags
    echo " Searchable content here for keyword_$i. </p></main></body></html>" >> "$DIR/index.html"
    
    # Print progress every 100 files
    if [ $((i % 100)) -eq 0 ]; then
        echo "Created $i files..."
    fi
done

echo "Done! $TOTAL directories created in $BASE_DIR."