summaryrefslogtreecommitdiffstats
path: root/seed.sh
blob: 04412cf3927e4183065ea323086317ff1055a5ac (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
38
39
40
41
42
43
44
45
46
47
48
#!/bin/ksh

# Usage: ./seed.sh size filecount
# Example: ./seed.sh 4.1 500

INPUT_SIZE=$1
TOTAL=$2

if [[ -z "$INPUT_SIZE" || -z "$TOTAL" ]]; then
	echo "Usage: $0 <size_kb> <file_count>"
	exit 1
fi

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

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

# Convert KB to raw bytes for dd precision
CONTENT_SIZE=$(awk -v kb="$INPUT_SIZE" 'BEGIN { printf "%.0f", kb * 1024 }')

echo "Generating $TOTAL directories in $BASE_DIR (File size: $INPUT_SIZE KB)..."

i=1
while [[ $i -le $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
	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
	
	(( i += 1 ))
done

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