diff --git a/.github/workflows/build-haos.yml b/.github/workflows/build-haos.yml
index c59d0ed..31da744 100644
--- a/.github/workflows/build-haos.yml
+++ b/.github/workflows/build-haos.yml
@@ -4,9 +4,9 @@ on:
workflow_dispatch:
inputs:
download_url:
- description: '请输入haos下载地址(扩展名 .img.gz/.img.xz/.img.zip)'
+ description: '输入 latest 自动选择最新 HAOS;或填写直链(.img.gz/.img.xz/.img.zip)'
required: true
- default: 'https://github.com/home-assistant/operating-system/releases/download/15.0/haos_generic-x86-64-15.0.img.xz'
+ default: 'latest'
publish:
description: '是否创建或更新 GitHub Release'
required: false
@@ -34,8 +34,8 @@ jobs:
- name: Validate Download URL
run: |
- if [[ ! "$DOWNLOAD_URL" =~ ^https?://[^[:space:]]+\.(gz|xz|zip)(\?[^[:space:]]*)?$ ]]; then
- echo "❌ 错误:地址需以 http(s) 开头且扩展名为 .gz/.xz/.zip"
+ if [[ "$DOWNLOAD_URL" != "latest" && ! "$DOWNLOAD_URL" =~ ^https?://[^[:space:]]+\.(gz|xz|zip)(\?[^[:space:]]*)?$ ]]; then
+ echo "❌ 错误:请输入 latest,或提供以 http(s) 开头且扩展名为 .gz/.xz/.zip 的地址"
echo "当前输入:$DOWNLOAD_URL"
exit 1
fi
@@ -44,6 +44,15 @@ jobs:
run: |
bash ./haos.sh "$DOWNLOAD_URL"
+ - name: Report selected upstream firmware
+ if: ${{ always() }}
+ run: |
+ {
+ echo "### 上游 HAOS 固件"
+ echo "- Release: \`${HAOS_SELECTED_RELEASE:-manual}\`"
+ echo "- Asset: \`${HAOS_SELECTED_ASSET:-$DOWNLOAD_URL}\`"
+ } >> "$GITHUB_STEP_SUMMARY"
+
- name: "Publish"
if: ${{ inputs.publish }}
uses: softprops/action-gh-release@v2.2.1
diff --git a/README.md b/README.md
index 3f0aa6a..bd97551 100644
--- a/README.md
+++ b/README.md
@@ -32,7 +32,7 @@
3. 其中OpenWrt分为istoreos、immortalwrt、EzOpWrt、eSirOpenWrt 安装器。实际上安装任意一种即可,因为换固件可在网页里随时换。
4. istoreos 在虚拟机上并没有安装器,因此本项目算是一种补充。(物理机安装istoreos就可以忽略本项目了)
5. armbian 安装器 目前构建2种 一种是minimal 一种是标准版 较低配置的x86-64设备建议使用minimal 比如(wyse3040瘦客户机)
-6. HAOS可自定义下载地址,默认构建HAOS 15.0 `haos_generic-x86-64-15.0.img.xz`
+6. HAOS 默认输入 `latest` 自动跟踪 Home Assistant OS 最新稳定版,也支持自定义 `.img.gz`、`.img.xz`、`.img.zip` 下载地址
7. 支持自定义openwrt镜像生成iso安装器,其中openwrt镜像的压缩包格式是`img.gz` `img.zip` `img.xz`三种
## 和传统的NAS虚拟机导入img有什么区别
diff --git a/haos.sh b/haos.sh
index cf1fe74..095d03b 100644
--- a/haos.sh
+++ b/haos.sh
@@ -2,18 +2,54 @@
set -Eeuo pipefail
# 校验参数是否存在
-if [ -z "$1" ]; then
- echo "❌ 错误:未提供下载地址!"
+if [ "$#" -lt 1 ] || [ -z "${1:-}" ]; then
+ echo "❌ 错误:未提供下载地址或 latest!"
exit 1
fi
rm -rf imm
mkdir -p imm
DOWNLOAD_URL="$1"
+SELECTED_RELEASE="manual"
+
+# 支持使用 latest 自动跟踪 Home Assistant OS 官方最新稳定版。
+# GitHub 的 /releases/latest 接口不会返回预发布版本,适合用于默认构建。
+if [[ "$DOWNLOAD_URL" == "latest" ]]; then
+ API_URL="https://api.github.com/repos/home-assistant/operating-system/releases/latest"
+ release_json="$(curl -fsSL --retry 3 --retry-delay 2 --connect-timeout 20 \
+ -H 'Accept: application/vnd.github+json' \
+ -H 'X-GitHub-Api-Version: 2022-11-28' \
+ "$API_URL")" || {
+ echo "❌ 获取 Home Assistant OS 最新 Release 失败!" >&2
+ exit 1
+ }
+
+ SELECTED_RELEASE="$(printf '%s' "$release_json" | jq -r '.tag_name // empty')"
+ DOWNLOAD_URL="$(printf '%s' "$release_json" | jq -r '
+ [.assets[]?
+ | select(.name | test("^haos_generic-x86-64-.*\\.img\\.(gz|xz|zip)$"))
+ | .browser_download_url]
+ | .[0] // empty')"
+
+ if [[ -z "$SELECTED_RELEASE" || -z "$DOWNLOAD_URL" ]]; then
+ echo "❌ 最新 HAOS Release 中没有找到 haos_generic-x86-64 压缩镜像!" >&2
+ exit 1
+ fi
+
+ echo "上游 Release: $SELECTED_RELEASE"
+fi
+
url_path="${DOWNLOAD_URL%%\?*}"
filename=$(basename "$url_path")
OUTPUT_PATH="imm/$filename"
+if [[ -n "${GITHUB_ENV:-}" ]]; then
+ {
+ printf 'HAOS_SELECTED_RELEASE=%s\n' "$SELECTED_RELEASE"
+ printf 'HAOS_SELECTED_ASSET=%s\n' "$filename"
+ } >> "$GITHUB_ENV"
+fi
+
echo "下载地址: $DOWNLOAD_URL"
echo "保存路径: $OUTPUT_PATH"
diff --git a/supportFiles/haos/info.md b/supportFiles/haos/info.md
index 5f17995..a89c68c 100644
--- a/supportFiles/haos/info.md
+++ b/supportFiles/haos/info.md
@@ -2,9 +2,9 @@
#### 适用范围:所有虚拟机和物理机
#### 安装器中的haos-installer-x86_64.iso 用于快速安装HAOS
-#### 默认版本15.0 haos_generic-x86-64-15.0.img.xz
+#### 默认自动选择 Home Assistant OS 最新稳定版,也支持运行时指定下载地址
#### 出处:https://github.com/home-assistant/operating-system/releases/
-
\ No newline at end of file
+