|
| 1 | +# |
| 2 | +# Copyright (C) 2022 Ing <https://github.com/wjz304> |
| 3 | +# |
| 4 | +# This is free software, licensed under the MIT License. |
| 5 | +# See /LICENSE for more information. |
| 6 | +# |
| 7 | + |
| 8 | +name: Get |
| 9 | + |
| 10 | +on: |
| 11 | + schedule: |
| 12 | + - cron: "0 12 * * *" # 每天 12:00 UTC 时间运行一次 (北京时间每天 20:00) |
| 13 | + workflow_dispatch: |
| 14 | + |
| 15 | +jobs: |
| 16 | + build: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + steps: |
| 19 | + - name: Checkout |
| 20 | + uses: actions/checkout@main |
| 21 | + |
| 22 | + - name: Init Env |
| 23 | + run: | |
| 24 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 25 | + git config --global user.name "github-actions[bot]" |
| 26 | + sudo timedatectl set-timezone "Asia/Shanghai" |
| 27 | +
|
| 28 | + - name: Get fnOS ISO |
| 29 | + run: | |
| 30 | + OLD="$(jq 'if type=="array" then . else [] end' "fnOS.json" 2>/dev/null || echo '[]')" |
| 31 | + OLD="${OLD:-[]}" |
| 32 | + NEW="[]" |
| 33 | + # x86_64 |
| 34 | + FNNAS=("https://www.fnnas.com/download?key=fnos" "https://www.fnnas.com/download-arm") |
| 35 | + for url in "${FNNAS[@]}"; do |
| 36 | + DATAS=$(curl -sL "${url}" | grep -oP '{[^{}]*fnos[^,]*[\.iso|\.img\.gz][^}]*thunder[^}]*"}' | sort -u | sed 's/\\\"/"/g' | jq -s .) |
| 37 | +
|
| 38 | + while IFS= read -r data; do |
| 39 | + BASE=$(echo "${data}" | jq -r '.url') |
| 40 | + ARCH="$(echo "${BASE}" | awk -F'/' '{print $4}' | sed 's/.*/\L&/' | sed 's/^arm$/aarch64/')" |
| 41 | + NAME="" |
| 42 | + VER="" |
| 43 | + if [ "${ARCH}" == "x86_64" ]; then |
| 44 | + NAME="fnOS-${ARCH}" |
| 45 | + VER="$(echo "${data}" | jq -r '.version')" |
| 46 | + fi |
| 47 | + if [ "${ARCH}" == "aarch64" ]; then |
| 48 | + NAME="$(echo "${data}" | jq -r '.name')" |
| 49 | + VER="$(echo "${BASE}" | awk -F'/' '{print $6}')" |
| 50 | + fi |
| 51 | + if [ -z "${NAME}" ] || [ -z "${VER}" ]; then |
| 52 | + continue |
| 53 | + fi |
| 54 | + URL="$(echo "${data}" | jq -r '.thunder' | sed 's/^thunder:\/\///' | base64 -d 2>/dev/null | sed 's/^AA//; s/ZZ$//')" |
| 55 | + HASH="$(echo "${data}" | jq -r '.hash')" |
| 56 | + # build compact JSON object (includes name) and add only if not present in OLD |
| 57 | + JSON=$(jq -n --arg arch "${ARCH}" --arg name "${NAME}" --arg ver "${VER}" --arg url "${URL}" --arg hash "${HASH}" '{arch:$arch,name:$name,version:$ver,url:$url,hash:$hash}' | jq -c .) |
| 58 | +
|
| 59 | + if [ -z "${JSON}" ] || ! printf '%s' "${JSON}" | jq -e . >/dev/null 2>&1; then |
| 60 | + continue |
| 61 | + fi |
| 62 | + if printf '%s' "${OLD}" | jq -e --argjson obj "${JSON}" 'index($obj) | not' >/dev/null 2>&1; then |
| 63 | + NEW=$(printf '%s' "${NEW}" | jq -c --argjson obj "${JSON}" '. + [$obj]') |
| 64 | + fi |
| 65 | + done <<<"$(printf '%s' "${DATAS}" | jq -c '.[]')" |
| 66 | + done |
| 67 | +
|
| 68 | + ALL=$(printf '%s' "${OLD}" "${NEW}" | jq -s '.[0] + .[1] | sort_by(.arch, .name, ([.version | scan("[0-9]+") | tonumber]), .version)') |
| 69 | + printf '%s' "${ALL}" | jq -S . >"fnOS.json" |
| 70 | +
|
| 71 | + - name: Check and Push |
| 72 | + if: success() |
| 73 | + run: | |
| 74 | + echo "Git push ..." |
| 75 | + # git checkout main |
| 76 | + git pull |
| 77 | + status=$(git status -s | grep -E "fnOS.json" | awk '{printf " %s", $2}') |
| 78 | + if [ -n "${status}" ]; then |
| 79 | + git add ${status} |
| 80 | + git commit -m "update $(date +%Y-%m-%d" "%H:%M:%S)" |
| 81 | + git push -f |
| 82 | + fi |
0 commit comments