fixed and updated db_assembler to even support old bash v3 ( osx )

we're emulating associative array
This commit is contained in:
Yehonal
2016-08-25 19:06:51 +02:00
parent b211edb6c0
commit 5b3c776f9c
2 changed files with 116 additions and 101 deletions
+55 -43
View File
@@ -19,39 +19,39 @@ else
MD5_CMD="md5sum" MD5_CMD="md5sum"
fi fi
reg_file="$OUTPUT_FOLDER/.zzz_db_assembler_registry.sh" reg_file="$OUTPUT_FOLDER/__db_assembler_registry"
registry=()
if [ -f "$reg_file" ]; then if [ -f "$reg_file" ]; then
source "$reg_file" source "$reg_file"
fi fi
echo "===== STARTING PROCESS ====="
function assemble() { function assemble() {
database=$1 # to lowercase
database=${1,,}
start_sql=$2 start_sql=$2
with_base=$3
with_updates=$4
with_custom=$5
var_base="DB_"$database"_PATHS" var_base="DB_"$1"_PATHS"
base=${!var_base} base=${!var_base}
var_updates="DB_"$database"_UPDATE_PATHS" var_updates="DB_"$1"_UPDATE_PATHS"
updates=${!var_updates} updates=${!var_updates}
var_custom="DB_"$database"_CUSTOM_PATHS" var_custom="DB_"$1"_CUSTOM_PATHS"
custom=${!var_custom} custom=${!var_custom}
echo $updates
suffix_base=""
suffix_upd=""
suffix_custom=""
if (( $ALL_IN_ONE == 0 )); then
suffix_base="_base" suffix_base="_base"
fi; suffix_upd="_update"
suffix_custom="_custom"
curTime=`date +%Y_%m_%d_%H_%M_%S`
if [ $with_base = true ]; then
echo "" > $OUTPUT_FOLDER$database$suffix_base".sql" echo "" > $OUTPUT_FOLDER$database$suffix_base".sql"
@@ -60,6 +60,7 @@ function assemble() {
for d in "${base[@]}" for d in "${base[@]}"
do do
echo "Searching on $d ..."
if [ ! -z $d ]; then if [ ! -z $d ]; then
for entry in "$d"/*.sql "$d"/**/*.sql for entry in "$d"/*.sql "$d"/**/*.sql
do do
@@ -70,18 +71,17 @@ function assemble() {
fi fi
done done
fi fi
fi
if (( $ALL_IN_ONE == 0 )); then if [ $with_updates = true ]; then
suffix_upd="_updates" updFile=$OUTPUT_FOLDER$database$suffix_upd"_"$curTime".sql"
echo "" > $OUTPUT_FOLDER$database$suffix_upd".sql"
fi;
if [ ! ${#updates[@]} -eq 0 ]; then if [ ! ${#updates[@]} -eq 0 ]; then
echo "Generating $OUTPUT_FOLDER$database$suffix_upd ..." echo "Generating $OUTPUT_FOLDER$database$suffix_upd ..."
for d in "${updates[@]}" for d in "${updates[@]}"
do do
echo "Searching on $d ..."
if [ ! -z $d ]; then if [ ! -z $d ]; then
for entry in "$d"/*.sql "$d"/**/*.sql for entry in "$d"/*.sql "$d"/**/*.sql
do do
@@ -92,29 +92,31 @@ function assemble() {
file=$(basename "$entry") file=$(basename "$entry")
hash=$($MD5_CMD "$entry") hash=$($MD5_CMD "$entry")
hash="${hash%% *}" #remove file path hash="${hash%% *}" #remove file path
if [[ -z ${registry[$hash]} ]]; then n="registry__$hash"
registry["$hash"]="$file" if [[ -z ${!n} ]]; then
if [ ! -e $updFile ]; then
echo "" > $updFile
fi
printf -v "registry__${hash}" %s "$file"
echo "-- New update sql: "$file echo "-- New update sql: "$file
cat "$entry" >> $OUTPUT_FOLDER$database$suffix_upd".sql" cat "$entry" >> $updFile
fi fi
done done
fi fi
done done
fi fi
fi
if (( $ALL_IN_ONE == 0 )); then if [ $with_custom = true ]; then
suffix_custom="_custom" custFile=$OUTPUT_FOLDER$database$suffix_custom"_"$curTime".sql"
echo "" > $OUTPUT_FOLDER$database$suffix_custom".sql"
fi;
if [ ! ${#custom[@]} -eq 0 ]; then if [ ! ${#custom[@]} -eq 0 ]; then
echo "Generating $OUTPUT_FOLDER$database$suffix_custom ..." echo "Generating $OUTPUT_FOLDER$database$suffix_custom ..."
for d in "${custom[@]}" for d in "${custom[@]}"
do do
echo "Searching on $d ..."
if [ ! -z $d ]; then if [ ! -z $d ]; then
for entry in "$d"/*.sql "$d"/**/*.sql for entry in "$d"/*.sql "$d"/**/*.sql
do do
@@ -125,29 +127,39 @@ function assemble() {
file=$(basename "$entry") file=$(basename "$entry")
hash=$($MD5_CMD "$entry") hash=$($MD5_CMD "$entry")
hash="${hash%% *}" #remove file path hash="${hash%% *}" #remove file path
if [[ -z ${registry[$hash]} ]]; then n="registry__$hash"
registry["$hash"]="$file" if [[ -z ${!n} ]]; then
if [ ! -e $custFile ]; then
echo "" > $custFile
fi
printf -v "registry__${hash}" %s "$file"
echo "-- New custom sql: "$file echo "-- New custom sql: "$file
cat "$entry" >> $OUTPUT_FOLDER$database$suffix_custom".sql" cat "$entry" >> $custFile
fi fi
done done
fi fi
done done
fi fi
fi
} }
mkdir -p $OUTPUT_FOLDER
for db in ${DATABASES[@]} echo "===== STARTING PROCESS ====="
do
assemble "$db" $version".sql"
done
echo "" > $reg_file mkdir -p $OUTPUT_FOLDER
for i in "${!registry[@]}" for db in ${DATABASES[@]}
do do
echo "registry['"$i"']='"${registry[$i]}"'" >> "$reg_file" assemble "$db" $version".sql" true true true
done done
echo "" > $reg_file
for k in "${!registry__*}"
do
n=$k
echo "$k='${!n}'" >> "$reg_file"
done
echo "===== DONE =====" echo "===== DONE ====="
+9 -6
View File
@@ -92,7 +92,7 @@ OUTPUT_FOLDER="output/"
# FULL DB # FULL DB
DB_CHARACTERS_PATHS=( DB_CHARACTERS_PATHS=(
$SRCPATH"/data/sql/base/characters" $SRCPATH"/data/sql/base/db_characters"
) )
DB_CHARACTERS_NAME="characters" DB_CHARACTERS_NAME="characters"
@@ -103,7 +103,7 @@ DB_CHARACTERS_CONF="MYSQL_USER='root'; \
" "
DB_AUTH_PATHS=( DB_AUTH_PATHS=(
$SRCPATH"/data/sql/base/auth/" $SRCPATH"/data/sql/base/db_auth/"
) )
DB_AUTH_NAME="auth" DB_AUTH_NAME="auth"
@@ -114,7 +114,7 @@ DB_AUTH_CONF="MYSQL_USER='root'; \
" "
DB_WORLD_PATHS=( DB_WORLD_PATHS=(
$SRCPATH"/data/sql/base/world/" $SRCPATH"/data/sql/base/db_world/"
) )
DB_WORLD_NAME="world" DB_WORLD_NAME="world"
@@ -126,23 +126,26 @@ DB_WORLD_CONF="MYSQL_USER='root'; \
# UPDATES # UPDATES
DB_CHARACTERS_UPDATE_PATHS=( DB_CHARACTERS_UPDATE_PATHS=(
$SRCPATH"/data/sql/updates/characters/" $SRCPATH"/data/sql/updates/db_characters/"
) )
DB_AUTH_UPDATE_PATHS=( DB_AUTH_UPDATE_PATHS=(
$SRCPATH"/data/sql/updates/auth/" $SRCPATH"/data/sql/updates/db_auth/"
) )
DB_WORLD_UPDATE_PATHS=( DB_WORLD_UPDATE_PATHS=(
$SRCPATH"/data/sql/updates/world/" $SRCPATH"/data/sql/updates/db_world/"
) )
# CUSTOM # CUSTOM
DB_CHARACTERS_CUSTOM_PATHS=( DB_CHARACTERS_CUSTOM_PATHS=(
$SRCPATH"/data/sql/custom/db_characters/"
) )
DB_AUTH_CUSTOM_PATHS=( DB_AUTH_CUSTOM_PATHS=(
$SRCPATH"/data/sql/custom/db_auth/"
) )
DB_WORLD_CUSTOM_PATHS=( DB_WORLD_CUSTOM_PATHS=(
$SRCPATH"/data/sql/custom/db_world/"
) )