forked from yury-sannikov/awg-openwrt
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1c17d9b
commit 226ae60
Showing
6 changed files
with
536 additions
and
4 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: OpenWRT Data Fetch | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v*.*.*' | ||
|
||
jobs: | ||
fetch-data: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: '20.16.0' | ||
|
||
- name: Get OpenWRT version from tag | ||
id: get_version | ||
run: echo "VERSION=${GITHUB_REF/refs\/tags\/v/}" >> $GITHUB_ENV | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Run script with version | ||
run: node index.js ${{ env.VERSION }} | ||
|
||
- name: Upload results.json | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: results | ||
path: results.json |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
.idea/ | ||
node_modules/ | ||
results.json |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
const axios = require('axios'); | ||
const cheerio = require('cheerio'); | ||
const fs = require('fs'); | ||
|
||
const version = process.argv[2]; // Получение версии OpenWRT из аргумента командной строки | ||
const url = `https://downloads.openwrt.org/releases/${version}/targets/`; | ||
|
||
async function fetchHTML(url) { | ||
try { | ||
const { data } = await axios.get(url); | ||
return cheerio.load(data); | ||
} catch (error) { | ||
console.error(`Error fetching HTML for ${url}: ${error}`); | ||
throw error; | ||
} | ||
} | ||
|
||
async function getTargets() { | ||
const $ = await fetchHTML(url); | ||
const targets = []; | ||
$('table tr td.n a').each((index, element) => { | ||
const name = $(element).attr('href'); | ||
if (name && name.endsWith('/')) { | ||
targets.push(name.slice(0, -1)); | ||
} | ||
}); | ||
return targets; | ||
} | ||
|
||
async function getSubtargets(target) { | ||
const $ = await fetchHTML(`${url}${target}/`); | ||
const subtargets = []; | ||
$('table tr td.n a').each((index, element) => { | ||
const name = $(element).attr('href'); | ||
if (name && name.endsWith('/')) { | ||
subtargets.push(name.slice(0, -1)); | ||
} | ||
}); | ||
return subtargets; | ||
} | ||
|
||
async function getDetails(target, subtarget) { | ||
const packagesUrl = `${url}${target}/${subtarget}/packages/`; | ||
const $ = await fetchHTML(packagesUrl); | ||
let vermagic = ''; | ||
let pkgarch = ''; | ||
|
||
$('a').each((index, element) => { | ||
const name = $(element).attr('href'); | ||
if (name && name.startsWith('kernel_')) { | ||
const vermagicMatch = name.match(/kernel_5\.\d+\.\d+-\d+-([a-f0-9]+)_([a-zA-Z0-9_-]+)\.ipk$/); | ||
if (vermagicMatch) { | ||
vermagic = vermagicMatch[1]; | ||
pkgarch = vermagicMatch[2]; | ||
} | ||
} | ||
}); | ||
|
||
return { vermagic, pkgarch }; | ||
} | ||
|
||
async function main() { | ||
const targets = await getTargets(); | ||
const results = []; | ||
|
||
for (const target of targets) { | ||
const subtargets = await getSubtargets(target); | ||
for (const subtarget of subtargets) { | ||
const { vermagic, pkgarch } = await getDetails(target, subtarget); | ||
results.push({ | ||
tag: version, | ||
target, | ||
subtarget, | ||
vermagic, | ||
pkgarch, | ||
}); | ||
} | ||
} | ||
|
||
fs.writeFileSync('results.json', JSON.stringify(results, null, 2), 'utf-8'); | ||
console.log('Results written to results.json'); | ||
} | ||
|
||
main().catch(console.error); |
Oops, something went wrong.