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