#!/bin/bash

package_file="http://sarah.hepforge.org/Diphoton_Models.tar.gz"
package_dir="diphotonModels"

if test $# -gt 0; then
    package_file="$1"
    echo "Using: ${package_file}"
fi

# download package if file name starts with http
if [[ ${package_file} == http* ]] ; then
    echo "Downloading: ${package_file}"
    wget "${package_file}"
    package_file=$(basename "${package_file}")
fi

echo "Extracting: ${package_file}"
tar -xf "${package_file}"
cp -r ${package_dir}/* sarah/

# find FS-model_file/ directories
FS_dirs=$(find ${package_dir} -type d -name "FS-model_file")

for d in ${FS_dirs}; do
    # create FS model name
    FS_model_name=$(dirname ${d} | sed "s/${package_dir}//" | sed 's|[./+-]||g' | sed 's/^[0-9]/Model\0/')

    # model directory
    FS_model_dir="model_files/${FS_model_name}"

    mkdir -p ${FS_model_dir}
    echo "Copying ${d}/* -> ${FS_model_dir}"
    cp ${d}/* ${FS_model_dir}
done
