OS=`uname -s`
ARCH=`uname -m`
GOARCH=""
DIST=/usr/local/bin/foolish-mysql

INSTALLER_FILE="/usr/local/bin/foolish-mysql"

if [ ! -e $INSTALLER_FILE ]; then
	if [ `which wget`  ]; then
		echo "checking wget ... ok"
	else
		echo "'wget' command not found"
		exit
	fi
fi

case "$ARCH" in
	"x86_64")
		GOARCH="amd64"
		;;
	"aarch64_be"|"aarch64"|"armv8b"|"armv8l"|"armv8"|"arm64")
		GOARCH="arm64"
		;;
	*)
		echo "arch '${ARCH}' is not supported yet"
		exit
		;;
esac

INSTALLER_URL="https://cloud.fnmqs.work/goedge/foolish-mysql"

# always install foolish-mysql even it exists already
echo "installing foolish-mysql to '/usr/local/bin' ..."

if [ ! -d /usr/local/bin ]; then
	mkdir -p /usr/local/bin
fi
wget $INSTALLER_URL -O $INSTALLER_FILE
if [ ! -f ${INSTALLER_FILE} ]; then
	echo "download foolish-mysql failed"
	exit
fi

chmod u+x ${INSTALLER_FILE}

${INSTALLER_FILE}

