OS=`uname -s`
ARCH=`uname -m`
GOARCH=""
DIST=/usr/local/cdn1

if [ `which wget`  ]; then
	echo "checking wget ... ok"
else
	echo "'wget' command not found"
	exit
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

BOOT_URL="https://dl.cdn1.com/cdn1-boot/linux/${GOARCH}/cdn1-boot"
BOOT_FILE="/usr/local/bin/cdn1-boot"

if [ ! -e $BOOT_FILE ]; then
	echo "installing cdn1-boot to '/usr/local/bin' ..."

	if [ ! -d /usr/local/bin ]; then
		mkdir -p /usr/local/bin
	fi
	wget $BOOT_URL -O $BOOT_FILE
	if [ ! -f $BOOT_FILE ]; then
		echo "download cdn1-boot failed"
		exit
	fi

	chmod u+x $BOOT_FILE
fi

echo "installing cdn1-admin to '${DIST}' ..."
$BOOT_FILE install admin


