#!/bin/sh

soft() {
    export $(/usr/local/ispmgr/sbin/mgrctl dbconf.edit elid=MySQL | grep passwd)
    /usr/local/bin/mysqlcheck -p$passwd -A --auto-repair
}

hard() {
    /usr/local/etc/rc.d/mysql-server stop && find /var/db/mysql -name '*.MYI' |xargs myisamchk -o -r && /usr/local/etc/rc.d/mysql-server start
}

help() {
    echo "Use -h or --help to help"
    echo ""
    echo "Use --hard for hard check"
}

case "$1" in
    -h)
        help
        ;;

    --help)
        help
        ;;

    --hard)
        hard
        ;;

    *)
        soft
    ;;
esac
