feat(scan): add guided Linux agent setup in administration
This commit is contained in:
40
agents/fedeo-device-agent/scripts/build-installer.mjs
Normal file
40
agents/fedeo-device-agent/scripts/build-installer.mjs
Normal file
@@ -0,0 +1,40 @@
|
||||
import { readFile, readdir, mkdir, writeFile } from 'node:fs/promises'
|
||||
import path from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
|
||||
const output = path.resolve(root, '../../frontend/assets/device-agent/bundle.json')
|
||||
async function filesUnder(directory) {
|
||||
const entries = await readdir(path.join(root, directory), { withFileTypes: true })
|
||||
const paths = await Promise.all(entries.map(entry => entry.isDirectory()
|
||||
? filesUnder(`${directory}/${entry.name}`)
|
||||
: [`${directory}/${entry.name}`]))
|
||||
return paths.flat().sort()
|
||||
}
|
||||
const packageJson = JSON.parse(await readFile(path.join(root, 'package.json'), 'utf8'))
|
||||
const paths = [
|
||||
...(await filesUnder('dist')).filter(file => file.endsWith('.js')),
|
||||
'scripts/scan_document.py', 'scripts/opencv_postprocess.py', 'scripts/setup-opencv.sh',
|
||||
'requirements-opencv.txt',
|
||||
]
|
||||
const files = Object.fromEntries(await Promise.all(paths.map(async file => [file, (await readFile(path.join(root, file))).toString('base64')])))
|
||||
files['package.json'] = Buffer.from(JSON.stringify({
|
||||
name: packageJson.name, version: packageJson.version, type: 'module', engines: packageJson.engines,
|
||||
scripts: { start: 'node dist/main.js', 'setup:opencv': 'sh scripts/setup-opencv.sh' },
|
||||
}, null, 2) + '\n').toString('base64')
|
||||
const bundle = JSON.stringify({
|
||||
version: packageJson.version,
|
||||
installerTemplate: await readFile(path.join(root, 'scripts/install-linux.sh'), 'utf8'),
|
||||
files,
|
||||
}, null, 2) + '\n'
|
||||
|
||||
if (process.argv.includes('--check')) {
|
||||
if (await readFile(output, 'utf8') !== bundle) {
|
||||
throw new Error('Das Installationspaket ist veraltet. Bitte npm run build:installer ausführen und bundle.json mitcommitten.')
|
||||
}
|
||||
console.log('Installationspaket entspricht dem aktuellen Agenten.')
|
||||
} else {
|
||||
await mkdir(path.dirname(output), { recursive: true })
|
||||
await writeFile(output, bundle)
|
||||
console.log(`Installationspaket erstellt: ${output}`)
|
||||
}
|
||||
Reference in New Issue
Block a user