#!/bin/bash
# This script installs Spark
# More documentation in the README.md file

if [ "${DIB_DEBUG_TRACE:-0}" -gt 0 ]; then
    set -x
fi
set -eu
set -o pipefail

tmp_dir=/tmp/spark
pushd $tmp_dir


echo "Extracting SPARK"
spark_url=$(cat spark_url.txt)
spark_file=$(basename $spark_url)
extract_folder=$(tar tzf $spark_file | sed -e 's@/.*@@' | uniq)
echo "Decompressing Spark..."
tar xzf $spark_file
rm $spark_file

echo "Moving SPARK to /opt/"
# Placing spark in /opt/spark
mv $extract_folder /opt/spark/
mv spark_url.txt /opt/spark/

popd
rm -Rf $tmp_dir
