SCRIPT_DIR=$(cd $(dirname $0) && pwd)
source $SCRIPT_DIR/1453711833_mybase
echo "Attempting to prepare mysqld environment at /dev/shm/1453711833..."
rm -Rf /dev/shm/1453711833
mkdir -p /dev/shm/1453711833/tmp
BIN=`find ${MYBASE} -maxdepth 2 -name mysqld -type f -o -name mysqld-debug -type f | head -1`
if [ -n "$BIN"  ]; then
  if [ "$BIN" != "${MYBASE}/bin/mysqld" -a "$BIN" != "${MYBASE}/bin/mysqld-debug" ];then
    if [ ! -h ${MYBASE}/bin/mysqld -o ! -f ${MYBASE}/bin/mysqld ]; then mkdir -p ${MYBASE}/bin; ln -s $BIN ${MYBASE}/bin/mysqld; fi
    if [ ! -h ${MYBASE}/bin/mysql -o ! -f ${MYBASE}/bin/mysql ]; then ln -s ${MYBASE}/client/mysql ${MYBASE}/bin/mysql ; fi
    if [ ! -h ${MYBASE}/share -o ! -f ${MYBASE}/share ]; then ln -s ${SOURCE_DIR}/scripts ${MYBASE}/share ; fi
    if [ ! -h ${MYBASE}/share/errmsg.sys -o ! -f ${MYBASE}/share/errmsg.sys ]; then ln -s ${MYBASE}/sql/share/english/errmsg.sys ${MYBASE}/share/errmsg.sys ; fi;
  fi
else
  echo "Assert! mysqld binary '$BIN' could not be read";exit 1;
fi
MID=`find ${MYBASE} -maxdepth 2 -name mysql_install_db`;if [ -z $MID ]; then echo "Assert! mysql_install_db '$MID' could not be read";exit 1;fi
if [ "`$BIN --version | grep -oe '5\.[1567]' | head -n1`" == "5.7" ]; then MID_OPTIONS='--initialize-insecure'; elif [ "`$BIN --version | grep -oe '5\.[1567]' | head -n1`" == "5.6" ]; then MID_OPTIONS='--force'; elif [ "`$BIN --version| grep -oe '5\.[1567]' | head -n1`" == "5.5" ]; then MID_OPTIONS='--force';else MID_OPTIONS=''; fi
if [ "`$BIN --version | grep -oe '5\.[1567]' | head -n1`" == "5.7" ]; then $BIN  --no-defaults --basedir=${MYBASE} --datadir=/dev/shm/1453711833/data $MID_OPTIONS; else $MID --no-defaults --basedir=${MYBASE} --datadir=/dev/shm/1453711833/data $MID_OPTIONS; fi
mkdir -p /dev/shm/1453711833/data/test
