#!/bin/bash
#Install Latest Stable 1Panel Release

osCheck=`uname -a`
if [[ $osCheck =~ 'x86_64' ]];then
    architecture="x86_64"
elif [[ $osCheck =~ 'arm64' ]] || [[ $osCheck =~ 'aarch64' ]];then
    architecture="aarch64"
else
    echo "暂不支持的系统架构，请参阅官方文档，选择受支持的系统。"
    exit 1
fi

download_dir="https://resource.dztec.cn/client/linux/${architecture}/"

latest_file=$(curl -s "$download_dir" | grep -oP "sgc-V1.0.\d{8}-linux-${architecture}" | sort -r | head -n 1)

# 判断是否找到了文件
if [ -z "$latest_file" ]; then
    echo "没有找到安装包文件！"
    exit 1
fi

package_download_url="${download_dir}${latest_file}"

echo "${package_download_url}"

echo "开始下载安装包"

curl -LOk ${package_download_url}
if [ ! -f ${latest_file} ];then
	echo "下载安装包失败，请稍候重试。"
	exit 1
fi

chmod +x ${latest_file}
./${latest_file}
