Skip to content

Commit

Permalink
Initial fix for vbox v6
Browse files Browse the repository at this point in the history
  • Loading branch information
gjabell committed Mar 29, 2019
1 parent 5e565cd commit faeb715
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions lib/VBoxProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@ const isPortAvailable = require('is-port-available');

class VBoxProvider {

// Returns the major version of the VirtualBox instance
async majorVersion() {
let version = await execute("--version", "", false);

return Number(version.split('.')[0]);
}

// Returns the correct serial port settings based on version.
async serialOut(name) {
let version = await this.majorVersion();

if (version < 6) { return 'disconnected'; }

let logPath = path.join(os.homedir(),'.baker',`${name}.log`);

return `file ${logPath}`;
}

/**
* Get default run command.
*
Expand All @@ -44,7 +62,8 @@ class VBoxProvider {
await execute("storagectl", `"${name}" --name IDE --add ide`, verbose);
await execute("storageattach", `${name} --storagectl IDE --port 0 --device 0 --type dvddrive --medium "${iso}"`, verbose);

await execute("modifyvm", `${name} --uart1 0x3f8 4 --uartmode1 disconnected`, verbose);
let serial = await this.serialOut(name);
await execute("modifyvm", `${name} --uart1 0x3f8 4 --uartmode1 ${serial}`, verbose);

// NIC1 =======
await execute("modifyvm", `${name} --nic1 nat`, verbose);
Expand Down Expand Up @@ -93,15 +112,16 @@ class VBoxProvider {
let sshConfig = {port: ssh_port, user: 'root', private_key: sshKeyPath};
//let cmd = 'echo -e "o\nn\np\n1\n\n\nw" | fdisk /dev/sda && /sbin/mkfs.ext4 /dev/sda1';
let cmd = `/sbin/mkfs.ext4 /dev/sda; mount -t ext4 /dev/sda /mnt/disk`;
console.log('Formating virtual drive');
console.log('Formatting virtual drive');

await util.sshExec(cmd, sshConfig, 60000, verbose).catch( e => {console.log(e)});;
}
}

async customize(name, ip, ssh_port, forward_ports=[], syncs, verbose) {
// modifyvm ${VM} --uart1 0x3f8 4 --uartmode1 disconnected
await execute("modifyvm", `${name} --uart1 0x3f8 4 --uartmode1 disconnected`, verbose);
let serial = await this.serialOut(name);
await execute("modifyvm", `${name} --uart1 0x3f8 4 --uartmode1 ${serial}`, verbose);

// syncs
if( syncs.length > 0 )
Expand Down

0 comments on commit faeb715

Please sign in to comment.