NUM_ERRS=0 if [ -z "$CLIENTBIN" ]; then echo "Meld client is not set" exit 1 fi TEST_BIN1=/tmp/meld_bin TEST_BIN2_PARENT=/tmp/meld_sub TEST_BIN2=/tmp/meld_sub/meld_bin check_valid_meld_bin() { # Check file and dir layout if [ ! -d "$1" ]; then echo "${1} not a dir" >&2 return 1 elif [ ! -f "$1/meld.db" ]; then echo "${1}/meld.db not a file" >&2 return 1 elif [ ! -d "$1/blobs" ]; then echo "${1}/blobs not a dir" >&2 return 1 elif [ ! -d "$1/maps" ]; then echo "${1}/blobs not a dir" >&2 return 1 fi # Check SQLite schema if [ ! "configs" = "$(sqlite3 "$1/meld.db" "SELECT name FROM sqlite_master WHERE type='table' AND name='configs';")" ]; then echo "could not find table configs" >&2 return 1 elif [ ! "versions" = "$(sqlite3 "$1/meld.db" "SELECT name FROM sqlite_master WHERE type='table' AND name='versions';")" ]; then echo "could not find table versions" >&2 return 1 elif [ ! "maps" = "$(sqlite3 "$1/meld.db" "SELECT name FROM sqlite_master WHERE type='table' AND name='maps';")" ]; then echo "could not find table maps" >&2 return 1 fi return 0 } # Cleanup Functionality to reset state cleanup() { rm -rf "$TEST_BIN1" rm -rf "$TEST_BIN2_PARENT" } # Check the base init functionality init_bin() { $CLIENTBIN $TEST_BIN1 init >/dev/null || return 1 check_valid_meld_bin $TEST_BIN1 || (echo "Failed to init valid bin" >&2 && return 1) return 0 } # Check init with parents (ensures parent dirs are actually created) init_bin_parents() { $CLIENTBIN $TEST_BIN2 init -p >/dev/null || return 1 if [ ! -d $TEST_BIN2_PARENT ]; then echo "Failed to create parent dir" return 1 fi check_valid_meld_bin $TEST_BIN2 || (echo "Failed to init valid bin w/ parents" >&2 && return 1) return 0 } # Check init with force (re-init an existing bin) init_bin_force() { $CLIENTBIN $TEST_BIN1 init -f >/dev/null || return 1 check_valid_meld_bin $TEST_BIN1 || (echo "Failed to init valid bin w/parents" >&2 && return 1) return 0 } cleanup init_bin || NUM_ERRS=$(( NUM_ERRS + $? )) init_bin_parents || NUM_ERRS=$(( NUM_ERRS + $? )) init_bin_force || NUM_ERRS=$(( NUM_ERRS + $? )) cleanup if [ $NUM_ERRS -eq 0 ]; then echo "[+] SUCCESS" else echo "[-] FAILURE" >&2 fi exit $NUM_ERRS