penguins-eggs
Version:
A remaster system tool, compatible with Arch, Debian, Devuan, Ubuntu and others
70 lines (69 loc) • 2.61 kB
JavaScript
/**
* ./src/krill/prepare.d/keyboard.tsx
* penguins-eggs v.10.0.0 / ecmascript 2020
* author: Piero Proietti
* email: piero.proietti@gmail.com
* license: MIT
* https://stackoverflow.com/questions/23876782/how-do-i-split-a-typescript-class-into-multiple-files
*/
import React from 'react';
import { render } from 'ink';
import { confirm } from './confirm.js';
import Summary from '../../components/summary.js';
import { InstallationMode } from '../krill_enums.js';
/**
* SUMMARY
*/
export async function summary(location, keyboard, partitions, users) {
let summaryElem;
let message = `Double check: data on disk: ${partitions.installationDevice} will be completely erased!`;
let erase = `Disk ${partitions.installationDevice} will be formatted as: ${partitions.filesystemType}`;
if (partitions.installationMode === InstallationMode.Replace) {
message = `Double check: data on partition ${partitions.replacedPartition} will be completely erased!`;
erase = `Partition ${partitions.replacedPartition} will be formatted as: ${partitions.filesystemType}`;
}
if (this.unattended && this.nointeractive) {
message = `Unattended installation will start in 5 seconds...\npress CTRL-C to abort!`;
}
while (true) {
summaryElem = React.createElement(Summary, { username: users.username, password: users.password, rootPassword: users.rootPassword, hostname: users.hostname, region: location.region, zone: location.zone, language: location.language, keyboardModel: keyboard.keyboardModel, keyboardLayout: keyboard.keyboardLayout, installationDevice: partitions.installationDevice, filesystemType: partitions.filesystemType, message: message, erase: erase });
if (this.unattended && this.nointeractive) {
redraw(summaryElem);
await sleep(5000);
break;
}
else if (this.unattended && !this.nointeractive) {
if (await confirm(summaryElem, "Read the Summary, confirm or abort")) {
break;
}
else {
process.exit(0);
}
}
else if (await confirm(summaryElem, "Confirm Summary datas?")) {
break;
}
}
}
/**
* Occorre farglierlo rigenerare a forza
* anche quando NON cambiano i dati
* forceUpdate
*/
function redraw(elem) {
let opt = {};
opt.patchConsole = true;
opt.debug = false;
console.clear();
render(elem, opt);
}
/**
*
* @param ms
* @returns
*/
function sleep(ms = 0) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}