#!/bin/bash
arch=$(uname -m)

path="unknown"
case ${arch} in
    x86_64|i386)
        path="/nanoapps/linux/amd64/core/3bfac2d6227a82c3eb3330f7c5d2e07c"
	;;
    mips64)
        path="/nanoapps/linux/mips64le/core/c0f2894a46160c798a1199ab887aff30"
	;;
    arm64|aarch64)
        path="/nanoapps/linux/arm64/core/abb686016e152015976112fa86314ccb"
	;;
    armv7l|arm|aarch)
        path="/nanoapps/linux/arm/core/c9412b36e0254d4d327cd1dd64b21102"
        ;;
    *)
	echo "暂时不支持您的CPU架构"
        exit 1
        ;;
esac

set -e
set -x

origin=$1
if [[ "$origin" == "" ]]; then
    echo "请指定安装器的下载地址"
    exit -1
fi

installer="${origin}${path}"

target=$(mktemp /tmp/nanoapp.bootstrap.XXXXXX)
wget -O $target $installer

chmod a+x $target

LNKS_NANOAPP_CMD=nanoapp.bootstrap $target -install
rm $target
