Make MosDNS run files #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#================================================= | |
# https://github.com/wukongdaily/RunFilesBuilder | |
# Description: Build RunFiles using GitHub Actions | |
# Lisence: MIT | |
# Author: wukongdaily | |
# Blog: wkdaily.cpolar.top | |
#================================================= | |
name: Make MosDNS run files | |
on: | |
workflow_dispatch: | |
jobs: | |
build: | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Fetch latest release tag from mosdns | |
id: fetch_latest_tag | |
run: | | |
latest_tag=$(curl -sk https://api.github.com/repos/sbwml/luci-app-mosdns/releases | grep "tag_name" | grep v5 | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//;s/ //') | |
echo "LATEST_TAG=$latest_tag" >> $GITHUB_ENV | |
- name: Clone makeself repository | |
run: git clone https://github.com/megastep/makeself.git | |
- name: Download latest mosdns files | |
run: | | |
echo "Downloading MosDNS IPK files..." | |
# 获取下载链接 | |
curl -sk --connect-timeout 10 "https://api.github.com/repos/sbwml/luci-app-mosdns/releases" | grep "browser_download_url" | grep "$latest_tag" > releases.txt | |
if [ $? -ne 0 ]; then | |
echo "Failed to get version information, please check the network status." | |
exit 1 | |
fi | |
# 创建存放目录 | |
mkdir -p mosdns_x86_64 mosdns_aarch64_cortex-a53 | |
# 下载文件函数 | |
download_file() { | |
local url=$1 | |
local output_dir=$2 | |
local filename=$(basename "$url") | |
echo "Downloading $filename to $output_dir..." | |
curl --connect-timeout 30 -m 600 -kLo "$output_dir/$filename" "$url" | |
if [ $? -ne 0 ]; then | |
echo "Error! Download $filename failed." | |
exit 1 | |
fi | |
} | |
# 提取下载链接 | |
mosdns_x86_64=$(grep "browser_download_url" releases.txt | grep "mosdns_5" | grep "x86_64.ipk" | head -1 | awk -F '"' '{print $4}') | |
mosdns_aarch64_cortex_a53=$(grep "browser_download_url" releases.txt | grep "mosdns_5" | grep "aarch64_cortex-a53.ipk" | head -1 | awk -F '"' '{print $4}') | |
v2dat_x86_64=$(grep "browser_download_url" releases.txt | grep "v2dat_" | grep "x86_64.ipk" | head -1 | awk -F '"' '{print $4}') | |
v2dat_aarch64_cortex_a53=$(grep "browser_download_url" releases.txt | grep "v2dat_" | grep "aarch64_cortex-a53.ipk" | head -1 | awk -F '"' '{print $4}') | |
luci_app=$(grep "browser_download_url" releases.txt | grep "luci-app-mosdns_" | head -1 | awk -F '"' '{print $4}') | |
luci_i18n=$(grep "browser_download_url" releases.txt | grep "luci-i18n-mosdns-zh-cn" | head -1 | awk -F '"' '{print $4}') | |
geoip=$(grep "browser_download_url" releases.txt | grep "v2ray-geoip" | head -1 | awk -F '"' '{print $4}') | |
geosite=$(grep "browser_download_url" releases.txt | grep "v2ray-geosite" | head -1 | awk -F '"' '{print $4}') | |
# 下载文件到对应目录 | |
download_file "$mosdns_x86_64" "mosdns_x86_64" | |
download_file "$mosdns_aarch64_cortex_a53" "mosdns_aarch64_cortex-a53" | |
download_file "$v2dat_x86_64" "mosdns_x86_64" | |
download_file "$v2dat_aarch64_cortex_a53" "mosdns_aarch64_cortex-a53" | |
download_file "$luci_app" "mosdns_x86_64" | |
download_file "$luci_app" "mosdns_aarch64_cortex-a53" | |
download_file "$luci_i18n" "mosdns_x86_64" | |
download_file "$luci_i18n" "mosdns_aarch64_cortex-a53" | |
download_file "$geoip" "mosdns_x86_64" | |
download_file "$geoip" "mosdns_aarch64_cortex-a53" | |
download_file "$geosite" "mosdns_x86_64" | |
download_file "$geosite" "mosdns_aarch64_cortex-a53" | |
echo "Download completed." | |
- name: Create install.sh scripts | |
run: | | |
cat <<EOF > mosdns_x86_64/install.sh | |
#!/bin/sh | |
opkg update | |
if [ $? -ne 0 ]; then | |
echo "update failed。" | |
exit 1 | |
fi | |
opkg install *.ipk | |
EOF | |
chmod +x mosdns_x86_64/install.sh | |
cp mosdns_x86_64/install.sh mosdns_aarch64_cortex-a53/install.sh | |
- name: Move mosdns directories to makeself | |
run: | | |
mv mosdns_x86_64 makeself/ | |
mv mosdns_aarch64_cortex-a53 makeself/ | |
- name: Create self-extracting packages | |
run: | | |
cd makeself | |
./makeself.sh mosdns_x86_64/ mosdns_${{ env.LATEST_TAG }}_x86_64.run "by github action" ./install.sh | |
./makeself.sh mosdns_aarch64_cortex-a53/ mosdns_${{ env.LATEST_TAG }}_aarch64_cortex-a53.run "by github action" ./install.sh | |
- name: Check file sizes | |
run: | | |
ls -lh makeself/mosdns_*.run | |
- name: Fetch latest release details | |
id: fetch_release_details | |
run: | | |
extra_content="![Github](https://img.shields.io/badge/mosdns.run-123456?logo=github&logoColor=fff&labelColor=yellow&style=for-the-badge) [![Github](https://img.shields.io/badge/国内加速站下载-FC7C0D?logo=github&logoColor=fff&labelColor=000&style=for-the-badge)](https://wkdaily.cpolar.top/archives/1) ![GitHub Downloads (all assets, specific tag)](https://img.shields.io/github/downloads/wukongdaily/RunFilesBuilder/${{ env.LATEST_TAG }}/total?style=for-the-badge&labelColor=black&color=%2325c2a0)" | |
sed -i "1i$extra_content" "${{ github.workspace }}/common.md" | |
- name: Upload run files as release assets | |
uses: softprops/[email protected] | |
with: | |
tag_name: ${{ env.LATEST_TAG }} | |
name: "mosdns-${{ env.LATEST_TAG }}" | |
files: makeself/mosdns_*.run | |
body_path: ${{ github.workspace }}/common.md | |
token: ${{ secrets.GITHUB_TOKEN }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |