summaryrefslogblamecommitdiffstats
path: root/server/lib/shell.js
blob: 2b1ea0baf7c1042972fe4e5f370c145edebde2f1 (plain) (tree)
1
2
3
4
5
6
7
8
9
                     


                                           

                  
                                  

                                                                                                                
     







                                                                                 

                                                                                                                               
                                                                                 








                                                                                                                                                                                       
                                                                                                                                                          

                                                        




                                                                                                     





                                                          

                                   
                               
/* global __appdir */
var path = require('path')
var shell = require('shelljs')
var ipxeGIT = 'git://git.ipxe.org/ipxe.git'

module.exports = {
  buildIpxe: function (req, res) {
    if (!shell.which('git')) {
      return res.status(500).send({ status: 'GIT_MISSING', error_message: 'Please install git on the server.' })
    }

    var gitclone = 'git clone ' + ipxeGIT
    shell.cd(path.join(__appdir, 'ipxe'))
    shell.exec(gitclone, function (code, stdout, stderr) {
      shell.cd(path.join(__appdir, 'ipxe', 'ipxe', 'src'))

      // Remove the general config and paste in the own one
      shell.rm(path.join(__appdir, 'ipxe', 'ipxe', 'src', 'config', 'general.h'))
      // shell.cp(path.join(__appdir, 'ipxe', 'general.h'), path.join(__appdir, 'ipxe', 'ipxe', 'src', 'config'))
      shell.cp(path.join(__appdir, 'ipxe', 'general_efi.h'), path.join(__appdir, 'ipxe', 'ipxe', 'src', 'config', 'general.h'))
      shell.rm(path.join(__appdir, 'ipxe', 'ipxe', 'src', 'config', 'console.h'))
      // shell.cp(path.join(__appdir, 'ipxe', 'console.h'), path.join(__appdir, 'ipxe', 'ipxe', 'src', 'config'))
      shell.cp(path.join(__appdir, 'ipxe', 'console_efi.h'), path.join(__appdir, 'ipxe', 'ipxe', 'src', 'config', 'console.h'))
      // PCBIOS Variant
      // var make = 'make EMBED=' + path.join(__appdir, 'ipxe', 'main.ipxe') + ' TRUST=' + path.join(__appdir, 'bin', 'fullchain.pem')// + ' bin/undionly.kpxe'

      // EFI Variant
      var make = 'make bin-x86_64-efi/snponly.efi EMBED=' + path.join(__appdir, 'ipxe', 'main.ipxe') + ' TRUST=' + path.join(__appdir, 'bin', 'fullchain.pem')// + ' bin/undionly.kpxe'

      // USB
      // var make = 'make EMBED=' + path.join(__appdir, 'ipxe', 'reboot.ipxe') + ' TRUST=' + path.join(__appdir, 'bin', 'fullchain.pem') + ' bin/ipxe.usb'
      shell.env.DEBUG = ''
      shell.exec(make, function (code, stdout, stderr) {
        // shell.rm(path.join(__appdir, 'tftp', 'ipxe.0'))
        shell.rm(path.join(__appdir, 'ipxe', 'ipxe.0'))
        // shell.cp('bin/undionly.kpxe', path.join(__appdir, 'tftp'))
        shell.cp('bin/undionly.kpxe', path.join(__appdir, 'ipxe'))
        shell.mv(path.join(__appdir, 'ipxe', 'undionly.kpxe'), path.join(__appdir, 'ipxe', 'ipxe.0'))
        // shell.rm('-rf', 'ipxe');
        return res.status(200).send({ status: 'success' })
      })
    })
  }
}

// sudo apt-get install liblzma-dev
// sudo apt-get install mkisofs