#!/bin/sh

. /usr/local/mgr5/lib/pkgsh/core_pkg_funcs.sh

if [ ! -d /usr/local/mgr5/etc ]; then
	# There is no coremgr dir
	exit 1
fi
mkdir -p /usr/local/mgr5/tmp

TMPCNF=/usr/local/mgr5/tmp/.$$.cnf
CORECNF=/usr/local/mgr5/etc/my.cnf

export PATH="${PATH}:/usr/sbin:/usr/bin:/bin:/sbin"


DLIST=$(check_connect)
if [ $? -eq 0 ]; then
	if ! check_my_cnf ; then
		#Alarm! There is empty paswwd
		create_root_passwd
	fi
else
		OLDPW=$(reset_root_passwd)
		cp -f ${TMPCNF} /root/.my.cnf
		chmod 600 /root/.my.cnf
fi

ROOTPW=$(cat /root/.my.cnf | awk -F= '$1 ~ "^password" {print $2}' | sed 's/ //g')
echo ${ROOTPW}
