123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- #!/bin/bash
- set -e
- if [ -z $1 ]; then
- echo "usage: addlua.sh path"
- exit -1;
- fi
- IFS=$'\n'
- ROOT=$1
- DIR=`dirname "$0"`
- if [ -f "$DIR/dictionary.txt" ]; then
- WORDs=(`cat "$DIR/dictionary.txt" | cut -d ' ' -f1`)
- fi
- function RANDOM_NAME_FM() {
- if [ -n $WORDs ]; then
- local name=
- while [ ${#name} -lt 16 ]; do
- local index=$(($RANDOM%${#WORDs[@]}))
- name="$name${WORDs[${index}]}"
- done
-
- echo ${name:1}
- else
-
- echo `openssl rand -hex 8`
- fi
- }
- function RANDOM_NAME() {
- if [ -n $WORDs ]; then
- local name=
- while [ ${#name} -lt 16 ]; do
- local index=$(($RANDOM%${#WORDs[@]}))
- name="$name-${WORDs[${index}]}"
- done
-
- echo ${name:1} | awk -F[-] '{for(i=1;i<=NF;i++) printf toupper(substr($i,1,1)) substr($i,2); printf "\n";}'
- else
-
- echo `openssl rand -hex 8`
- fi
- };
- function RANDOM_LUA_CALL() {
- local current=0
- local count=$(($RANDOM%20))
- printf "print('" >> "$1"
-
- while [ $current -lt $total ]; do
- if [ ! $current -eq 0 ]; then
- printf "," >> "$1"
- fi
- printf "%s" "`RANDOM_NAME_FM`" >> "$1"
- let current=current+1
- done
- printf "')\n" >> "$1"
- };
- function RANDOM_LUA_VARIABLE() {
- printf "local `RANDOM_NAME` = '`echo "$RANDOM-$RANDOM-$RANDOM" | base64`'\n" >> "$1"
- };
- function RANDOM_LUA_FUNCATION() {
- local current=0
- local total=$(($RANDOM%20))
- printf "local function `RANDOM_NAME_FM`()\n" >> "$1"
-
- while [ $current -lt $total ]; do
- if [ $(($RANDOM%2)) -eq 0 ]; then
- RANDOM_LUA_VARIABLE $1
- fi
- if [ $(($RANDOM%2)) -eq 0 ]; then
- RANDOM_LUA_CALL $1
- fi
-
-
-
-
-
- let current=current+1
- done
- printf "end\n" >> "$1"
- };
- function RANDOM_LUA_FILE() {
- local name=`RANDOM_NAME`
- while [ -f "$ROOT/$1/${name}.lua" ]; do
- name=`RANDOM_NAME`
- done
- echo "add to $1/${name}.lua"
- local current=0
- local total=$(($RANDOM%20))
-
-
- while [ $current -lt $total ]; do
- if [ $(($RANDOM%5)) -eq 0 ]; then
- RANDOM_LUA_VARIABLE "$ROOT/$1/${name}.lua"
- fi
- if [ $(($RANDOM%5)) -eq 0 ]; then
- RANDOM_LUA_CALL "$ROOT/$1/${name}.lua"
- fi
- if [ $(($RANDOM%5)) -eq 0 ]; then
- RANDOM_LUA_FUNCATION "$ROOT/$1/${name}.lua"
- fi
- let current=current+1
- done
- };
- function RANDOM_LUA_FILES() {
- local files=(`ls "$ROOT/$1"`)
- local current=0
- local total=$((${#files[@]} / 2))
-
- while [ $current -lt $total ]; do
- RANDOM_LUA_FILE "$1"
- let current=current+1
- done
-
- for file in ${files[@]}; do
- if [ -d "$ROOT/$file" ]; then
- RANDOM_LUA_FILES "$1/$file"
- fi
- done
- };
- RANDOM_LUA_FILES "."
|