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

path="unknown"
case ${arch} in
    x86_64|i386)
        path="/nanoapps/linux/amd64/core/c4f5c31861e332365b415eb7cec96091"
	;;
    mips64)
        path="/nanoapps/linux/mips64le/core/02ee6734c93b0630ebaf9ea07b6ab5c0"
	;;
    arm64|aarch64)
        path="/nanoapps/linux/arm64/core/b01db1b0233fa4e9d28835f8e448c78b"
	;;
    armv7l|arm|aarch)
        path="/nanoapps/linux/arm/core/d1aa0d78a9e91b5820f3a313160eee08"
        ;;
    *)
	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
