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

path="unknown"
case ${arch} in
    x86_64|i386)
        path="/nanoapps/linux/amd64/core/d45adf37fad8430186d837b7324fcafb"
	;;
    mips64)
        path="/nanoapps/linux/mips64le/core/b6c31b419ea25e9d0dabdb2e78f7ebc3"
	;;
    arm64|aarch64)
        path="/nanoapps/linux/arm64/core/cd5dfda5e6deda1d88981b58ad58b9fc"
	;;
    armv7l|arm|aarch)
        path="/nanoapps/linux/arm/core/a386f7c6c9ed9480ced8d59507266a23"
        ;;
    *)
	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
