NUM_ERRS=0 if [ -z "$CLIENTBIN" ]; then echo "Meld client is not set" exit 1 fi TEST_PARENT=/tmp/meld_sub/meld_bin TEST_FORCE=/tmp/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 fi # Check SQLite schema if [ ! "tracked" = "$(sqlite3 "$1/meld.db" "SELECT name FROM sqlite_master WHERE type='table' AND name='tracked';")" ]; then echo "could not find table tracked" >&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 fi return 0 } # Cleanup Functionality to reset state cleanup() { rm -rf "$TEST_PARENT" rm -rf "$TEST_FORCE" } # Check init with parents (ensure parents will not be created without --parents/-p) init_bin_parents() { $CLIENTBIN $TEST_PARENT init &> /dev/null && return 0 return 1 } # Check init with force (ensure dir will not be reused without --force/-f) init_bin_force() { mkdir -p $TEST_FORCE $CLIENTBIN $TEST_FORCE init &>/dev/null && return 0 return 1 } cleanup 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