#!/bin/sh

MYSQL_CHECK="/usr/clearos/sandbox/usr/bin/mysqlcheck"
DB_CONFIG="/var/clearos/system_database/root"

# Grab root database password
#----------------------------

ROOTPASS=`grep ^password $DB_CONFIG 2>/dev/null | sed "s/^password[[:space:]]*=[[:space:]]*//"`

if [ -z "$ROOTPASS" ]; then
    echo "Unable to authenticate with database"
    exit 1;
fi

# Run repair
#-----------

/usr/clearos/sandbox/usr/bin/mysqlcheck -uroot -p"$ROOTPASS" -A --auto-repair | /usr/bin/logger -p local6.notice -t system-database
