applemysqlcheckcnf [plain text]
#!/bin/sh
__cnfname="my.cnf"
__defcnfname="${__cnfname}.default"
__altcnfdir="/usr/share/mysql"
__hugecnf="${__altcnfdir}/my-huge.cnf"
__largecnf="${__altcnfdir}/my-large.cnf"
__destdir="/etc"
__homedir="/var/root"
__progname=`/usr/bin/basename ${0}`
__datadir=`/usr/libexec/mysqld --verbose --help | grep datadir | grep \/ | sed s/datadir\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ //`
__found=0
__cnfdirs="${__destdir} ${__datadir} ${__homedir}"
for __cnfdir in ${__cnfdirs}; do
if ( test -e "${__cnfdir}/${__cnfname}" ); then
__oldcnf="${__cnfdir}/${__cnfname}"
__found=1
break
fi
done
if ( test ${__found} == 1 ); then
__newcnf="${__defcnfname}"
else
__newcnf="${__cnfname}"
fi
if ( test -e "${__destdir}/${__newcnf}" ); then
exit
fi
if ( ! test -e "${__altcnfdir}" ); then
logger -t ${__progname} "Error -- unable to upgrade MySQL configuration. Required directory ${__altcnfdir} cannot be found."
exit
fi
__memsize=`sysctl hw.memsize | sed s/hw\.memsize\:\ //`
if ( test ${__memsize} -lt 1073741824 ); then
__altcnf="${__largecnf}"
else
__altcnf="${__hugecnf}"
fi
if ( test -e "${__destdir}/${__cnfname}" ); then
__diff=`diff "${__destdir}/${__cnfname}" "${__altcnf}"`
if ( test -z "${__diff}" ); then
exit
fi
fi
cp ${__altcnf} ${__destdir}/${__newcnf}
chown mysql:admin ${__destdir}/${__newcnf}
chmod 750 ${__destdir}/${__newcnf}
logger -t ${__progname} "A new MySQL configuration (${__destdir}/${__newcnf}) has been installed to improve performance."
if ( test "${__newcnf}" == "${__defcnfname}" ); then
logger -t ${__progname} "WARNING -- The previous MySQL configuration (${__oldcnf}) is still in effect. "
logger -t ${__progname} "To activate the new MySLQ settings, rename ${__destdir}/${__defcnfname}"
logger -t ${__progname} "to ${__destdir}/${__cnfname} and restart the MySQL service."
fi
exit