memgraph/release/examples/build_examples
Matej Ferencevic 02d3a04ffa Add Marvel Comic Universe tutorial data
Reviewers: buda, jseljan

Reviewed By: jseljan

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D2783
2020-07-01 10:41:47 +02:00

98 lines
2.1 KiB
Bash
Executable File

#!/bin/bash -e
function print_help () {
echo "Usage: $0 MEMGRAPH_EXE MG_CLIENT_EXE"
echo "Build example snapshots using the compiled memgraph."
}
if [[ $# -ne 2 ]]; then
print_help
exit 1
fi
memgraph_exe="$1"
if [[ ! -x ${memgraph_exe} ]]; then
echo "Expected memgraph executable at '${memgraph_exe}'"
exit 1
fi
mg_client_exe="$2"
if [[ ! -x ${mg_client_exe} ]]; then
echo "Expected mg_client executable at '${mg_client_exe}'"
exit 1
fi
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
build_dir="build"
query="populate.cyp"
query_gz="populate.cyp.gz"
cd $script_dir
if [ -d "$build_dir" ]; then
rm -rf "$build_dir"
fi
mkdir "$build_dir"
for dir in queries/*/
do
cd $script_dir # position to script execution dir
dir=${dir%*/}
example=${dir#*/}
# create snapshots directory for each example
snapshots_dir="$build_dir/$example"
mkdir -p "$snapshots_dir"
# run memgraph with durability_directory pointing
# to examples snapshots_dir
${memgraph_exe} --data-directory "$script_dir/$snapshots_dir/" \
--storage-snapshot-on-exit \
--storage-properties-on-edges &
memgraph_pid=$!
sleep 2 # wait for memgraph to start
# create data using mg_client
set +e
if [ -f "$script_dir/$dir/$query" ]; then
${mg_client_exe} --use-ssl=false < "$script_dir/$dir/$query"
elif [ -f "$script_dir/$dir/$query_gz" ]; then
zcat "$script_dir/$dir/$query_gz" | ${mg_client_exe} --use-ssl=false
else
echo "Missing \"$dir/$query\" or \"$dir/$query_gz\"!"
exit 1
fi
code=$?
set -e
if [ $code -eq 0 ]; then
# terminate memgraph
kill $memgraph_pid
# wait for memgraph to terminate
wait $memgraph_pid
else
# kill memgraph
kill -9 $memgraph_pid
# abort
exit $code
fi
pushd "$script_dir/$snapshots_dir/" >/dev/null
# remove all unnecessary directories
for name in * .[a-zA-Z0-9]*; do
if [ "$name" == "snapshots" ]; then
continue
fi
rm -r "$name"
done
# rename the generated snapshot file
mv snapshots/* snapshots/$example
popd >/dev/null
done