
set -e

"/opt/lampp/bin/mysql" -h '127.0.0.1' -u root < "/home/tc/etc/db/tc.sql"
"/opt/lampp/bin/mysql" -h '127.0.0.1' -u root < "/home/tc/etc/db/account.sql"

cd /opt/lampp
bin/mysql_secure_installation

systemctl restart tcs-delivery-server
echo "done" > /home/tc/etc/done

exit

echo "Set root password for MySQL"
echo -n "New password: "
read -s mysqlpass
echo
echo -n "Retype new password: "
read -s mysqlpass2
echo

len=${#mysqlpass}
echo $len
if [ $len -lt 10 ]; then
    echo "Error: Password length is 10 - 32"
    exit 1
fi
if [ $len -gt 32 ]; then
    echo "Error: Password length is 10 - 32"
    exit 1
fi


if [ -z $mysqlpass2 ]; then
    echo "Error: Passwords do not match"
    exit 1
fi
if [ $mysqlpass != $mysqlpass2 ]; then
    echo "Error: Passwords do not match"
    exit 1
fi

#
# Import TC database tables
#
"/opt/lampp/bin/mysqladmin" -h '127.0.0.1' -u root password $mysqlpass
