From 5fbd058f8ac7e13d1593dde996715cf534edec8b Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Mon, 31 Aug 2020 17:33:34 +0000 Subject: npm install needed [ipxe builder] Rework to link directorys instead of single files --- server/lib/shell.js | 59 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 6 deletions(-) (limited to 'server/lib') diff --git a/server/lib/shell.js b/server/lib/shell.js index ed2f4cd..29986de 100644 --- a/server/lib/shell.js +++ b/server/lib/shell.js @@ -6,7 +6,7 @@ const fs = require('fs') // Only one building process per version at a time. module.exports = { - buildIpxe: async function (buildParameter = '', gitURL = 'http://git.ipxe.org/ipxe.git', gitBranch = '') { + buildIpxe: async function (buildParameters = [], gitURL = 'http://git.ipxe.org/ipxe.git', gitBranch = '') { var makeCmd = '' // Only one building process can be running. (lock the ipxe directory) @@ -14,7 +14,7 @@ module.exports = { // If file is already locked // if (false) return { status: 'ALREADY_BUILDING', error: 'iPXE-building process is already in progress.' } - makeCmd = 'make ' + buildParameter + makeCmd = 'make ' + buildParameters.join(' ') makeCmd += ' EMBED=' + path.join(__appdir, 'ipxe', 'embedded.ipxe') makeCmd += ' TRUST=' + path.join(__appdir, 'bin', 'fullchain.pem') @@ -53,11 +53,21 @@ module.exports = { } else sendToLog(data, 'error') }) }) - // Copy and rename the ipxe file. - // sendToLog('Copying ipxe file ...\n', 'primary') - // shell.cp('bin/undionly.kpxe', path.join(__appdir, 'ipxe')) - // shell.mv(path.join(__appdir, 'ipxe', 'undionly.kpxe'), path.join(__appdir, 'ipxe', 'ipxe.' + ipxeVersion)) + + // Copy and rename the ipxe file to the __appdir/ipxe/builds/ dir. + sendToLog('Copying ipxe file(s) ...\n', 'primary') + const date = new Date() + const timestamp = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + '_' + date.getHours() + '-' + date.getMinutes() + '-' + date.getSeconds() + + for (let buildtarget of buildParameters) { + const target = buildtarget.split('/') + shell.mkdir('-p', path.join(__appdir, 'ipxe', 'builds', timestamp, target[0])) + shell.cp(path.join(__appdir, 'ipxe', 'ipxeGIT', 'src', buildtarget), path.join(__appdir, 'ipxe', 'builds', timestamp, target[0], target[1])) + sendToLog('Copyed ' + buildtarget, 'success') + } + sendToLog('Finished copying\n', 'success') // sendToLog(ipxeVersion, 'done\n', 'success') + // shell.mv(path.join(__appdir, 'ipxe', 'undionly.kpxe'), path.join(__appdir, 'ipxe', 'ipxe.' + ipxeVersion)) // updateInProgress(ipxeVersion, false) }, @@ -88,6 +98,43 @@ module.exports = { status: function (ipxeVersion) { return false + }, + + /* Changes or creates a symbolic link to a builded ipxe */ + forceSymlink: function (source, dest) { + // Because of the shelljs lib is bugged handle broken links deletetion myself + var destinationExists + try { + fs.lstatSync(dest) + destinationExists = true + } catch (err) { + destinationExists = false + } + + if (destinationExists) { + fs.unlinkSync(dest) + } + + const ln = shell.ln('-sf', source, dest) + if (ln.stderr) return { status: 'ERROR', error: ln.stderr } + else return { status: 'SUCCESS' } + }, + + readdirRecursive: function (buildsPath) { + let structure = [] + const directory = fs.readdirSync(buildsPath) + for (let obj of directory) { + if (!fs.lstatSync(path.join(buildsPath, obj)).isDirectory()) { + structure.push({ name: obj, type: 'file' }) + } else { + structure.push({ name: obj, type: 'directory', children: this.readdirRecursive(path.join(buildsPath, obj)) }) + } + } + return structure + }, + + forceDeleteBuild: function (buildsPath) { + shell.rm('-rf', path.join(buildsPath)) } } -- cgit v1.2.3-55-g7522