summaryrefslogtreecommitdiffstats
path: root/server/lib
diff options
context:
space:
mode:
authorJannik Schönartz2020-08-31 19:33:34 +0200
committerJannik Schönartz2020-08-31 19:33:34 +0200
commit5fbd058f8ac7e13d1593dde996715cf534edec8b (patch)
tree2c80b3e025d8855adfc0fe233c447e211066caca /server/lib
parent[server/embedded-script] Move the bas wallpaper to a later point in the process (diff)
downloadbas-5fbd058f8ac7e13d1593dde996715cf534edec8b.tar.gz
bas-5fbd058f8ac7e13d1593dde996715cf534edec8b.tar.xz
bas-5fbd058f8ac7e13d1593dde996715cf534edec8b.zip
npm install needed [ipxe builder] Rework to link directorys instead of single files
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/shell.js59
1 files changed, 53 insertions, 6 deletions
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/<date> 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))
}
}