summaryrefslogtreecommitdiffstats
path: root/seed.sh
diff options
context:
space:
mode:
authorSadeep Madurange <sadeep@asciimx.com>2026-05-07 14:18:23 +0800
committerSadeep Madurange <sadeep@asciimx.com>2026-05-07 15:00:10 +0800
commitf6d7c3fdbecbcb880c0c02fdffefa1f467c46b03 (patch)
tree78d51e5a08f01f2312b30092df647213bbaf249e /seed.sh
parentde9d82e8074c9b67a04989f9b6be62890b7c95bb (diff)
downloadsite-search-bm-f6d7c3fdbecbcb880c0c02fdffefa1f467c46b03.tar.gz
Allow specifying file size via CLI.HEADmaster
Diffstat (limited to 'seed.sh')
-rwxr-xr-xseed.sh58
1 files changed, 35 insertions, 23 deletions
diff --git a/seed.sh b/seed.sh
index bdfe71e..04412cf 100755
--- a/seed.sh
+++ b/seed.sh
@@ -1,36 +1,48 @@
#!/bin/ksh
-# Accept directory count as an argument, default to 500
-TOTAL=${1:-500}
+# 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"
-CONTENT_SIZE=8000
-
# 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
+# 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."