summaryrefslogtreecommitdiffstats
path: root/server/lib/shell.js
diff options
context:
space:
mode:
authorJannik Schönartz2019-01-15 04:42:45 +0100
committerJannik Schönartz2019-01-15 04:42:45 +0100
commit64e9a8ec113805b97d24b3301e88eb2b68edee8a (patch)
treee4102ce411f19408335de4c7beb5da7eccc955ee /server/lib/shell.js
parent[ipxe builder] Add ipxe builder module (diff)
downloadbas-64e9a8ec113805b97d24b3301e88eb2b68edee8a.tar.gz
bas-64e9a8ec113805b97d24b3301e88eb2b68edee8a.tar.xz
bas-64e9a8ec113805b97d24b3301e88eb2b68edee8a.zip
eslint fixes :|
Diffstat (limited to 'server/lib/shell.js')
-rw-r--r--server/lib/shell.js35
1 files changed, 17 insertions, 18 deletions
diff --git a/server/lib/shell.js b/server/lib/shell.js
index 09a3ae2..080e5d6 100644
--- a/server/lib/shell.js
+++ b/server/lib/shell.js
@@ -12,7 +12,7 @@ const fs = require('fs')
module.exports = {
buildIpxe: async function (req, res) {
const ipxeVersion = req.params.version
-
+
// Cloning git.
sendToLog(ipxeVersion, 'Cloning git ...\n', 'primary')
await cloneIpxe(ipxeVersion)
@@ -24,7 +24,7 @@ module.exports = {
// Make ipxe.
sendToLog(ipxeVersion, 'Make iPXE ...\n', 'primary')
shell.cd(path.join(__appdir, 'ipxe', 'ipxe_' + ipxeVersion, 'src'))
-
+
// Different make command for efi / bios are needed.
var makeCmd = ''
if (ipxeVersion === 'efi') makeCmd = 'make bin-x86_64-efi/snponly.efi EMBED=' + path.join(__appdir, 'ipxe', 'embedded_' + ipxeVersion + '.ipxe') + ' TRUST=' + path.join(__appdir, 'bin', 'fullchain.pem')// + ' bin/undionly.kpxe'
@@ -33,7 +33,7 @@ module.exports = {
var make = shell.exec(makeCmd, { async: true }, () => {
resolve()
})
-
+
// Send the output to the frontend log.
make.stdout.on('data', data => {
sendToLog(ipxeVersion, data, 'normal')
@@ -57,12 +57,12 @@ module.exports = {
}
}
-async function cloneIpxe(ipxeVersion) {
+async function cloneIpxe (ipxeVersion) {
// Check if git is installed on the server.
if (!shell.which('git')) {
return { status: 'GIT_MISSING', error_message: 'Please install git on the server.' }
}
-
+
shell.cd(path.join(__appdir, 'ipxe'))
return new Promise((resolve, reject) => {
var clone = shell.exec('git clone ' + ipxeGIT + ' ipxe_' + ipxeVersion, { async: true }, () => {
@@ -77,44 +77,43 @@ async function cloneIpxe(ipxeVersion) {
})
}
-function copyConfigs(ipxeVersion) {
+function copyConfigs (ipxeVersion) {
// Remove the default configs and paste in the customized ones.
shell.rm(path.join(__appdir, 'ipxe', 'ipxe_' + ipxeVersion, 'src', 'config', 'general.h'))
shell.rm(path.join(__appdir, 'ipxe', 'ipxe_' + ipxeVersion, 'src', 'config', 'console.h'))
shell.cp(path.join(__appdir, 'ipxe', 'general_' + ipxeVersion + '.h'), path.join(__appdir, 'ipxe', 'ipxe_' + ipxeVersion, 'src', 'config', 'general.h'))
shell.cp(path.join(__appdir, 'ipxe', 'console_' + ipxeVersion + '.h'), path.join(__appdir, 'ipxe', 'ipxe_' + ipxeVersion, 'src', 'config', 'console.h'))
- return
}
-function sendToLog(ipxeVersion, msg, status, writeLog = true) {
- var date = new Date();
+function sendToLog (ipxeVersion, msg, status, log = true) {
+ var date = new Date()
var dateString = '[' + date.getFullYear() + '-'
-
+
var month = parseInt(date.getMonth()) + 1
if (month < 10) dateString += '0' + month + '-'
else dateString += month + '-'
-
+
if (parseInt(date.getDate()) < 10) dateString += '0' + date.getDate() + ' '
else dateString += date.getDate() + ' '
-
+
if (parseInt(date.getHours()) < 10) dateString += '0' + date.getHours() + ':'
else dateString += date.getHours() + ':'
-
+
if (parseInt(date.getMinutes()) < 10) dateString += '0' + date.getMinutes() + ':'
else dateString += date.getMinutes() + ':'
-
+
if (parseInt(date.getSeconds()) < 10) dateString += '0' + date.getSeconds()
else dateString += date.getSeconds()
dateString += ']'
-
+
var logEntry = { date: dateString, status: status, msg: msg }
-
+
var socket = ipxeVersion + ' log'
io.in('broadcast ipxeBuild').emit(socket, logEntry)
- if (writeLog) writeLog(ipxeVersion, logEntry)
+ if (log) writeLog(ipxeVersion, logEntry)
}
-function writeLog(ipxeVersion, logEntry) {
+function writeLog (ipxeVersion, logEntry) {
fs.writeFile(path.join(__appdir, 'ipxe', 'log_' + ipxeVersion + '.txt'), logEntry.date + '\t' + logEntry.status + '\t' + logEntry.msg, { flag: 'a+' }, (err) => {
if (err) throw err
})