2020-11-16 18:01:03 +01:00
|
|
|
/****************************************************************************
|
|
|
|
** Modern Linbo GUI
|
|
|
|
** Copyright (C) 2020 Dorian Zedler <dorian@itsblue.de>
|
|
|
|
**
|
|
|
|
** This program is free software: you can redistribute it and/or modify
|
|
|
|
** it under the terms of the GNU Affero General Public License as published
|
|
|
|
** by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
|
|
|
** This program is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU Affero General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU Affero General Public License
|
|
|
|
** along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "linbobackend.h"
|
|
|
|
|
2020-11-20 15:09:36 +01:00
|
|
|
#define LINBO_CMD(arg) QStringList("linbo_cmd") << (arg)
|
2020-11-16 18:01:03 +01:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
LinboBackend::LinboBackend(QObject *parent) : QObject(parent)
|
|
|
|
{
|
2020-11-23 11:57:51 +01:00
|
|
|
this->setState(Initializing);
|
2020-11-24 20:25:39 +01:00
|
|
|
this->logger = new LinboLogger(this);
|
2020-11-16 18:01:03 +01:00
|
|
|
this->config = new LinboConfig(this);
|
2020-11-24 21:42:47 +01:00
|
|
|
this->autostartTimer = new QTimer();
|
2020-11-24 20:25:39 +01:00
|
|
|
this->autostartTimer->setSingleShot(true);
|
2020-11-24 21:42:47 +01:00
|
|
|
connect(this->autostartTimer, SIGNAL(timeout()), this, SLOT(handleAutostartTimerTimeout()));
|
|
|
|
this->autostartRemainingTimeRefreshTimer = new QTimer();
|
|
|
|
this->autostartRemainingTimeRefreshTimer->setSingleShot(false);
|
2020-11-24 20:25:39 +01:00
|
|
|
this->autostartRemainingTimeRefreshTimer->setInterval(10);
|
2020-11-24 21:42:47 +01:00
|
|
|
connect(this->autostartRemainingTimeRefreshTimer, SIGNAL(timeout()), this, SIGNAL(autostartTimeoutProgressChanged()));
|
2020-11-24 20:25:39 +01:00
|
|
|
this->autostartElapsedTimer = new QElapsedTimer();
|
2020-11-23 11:57:51 +01:00
|
|
|
this->currentOs = nullptr;
|
2020-11-16 18:01:03 +01:00
|
|
|
|
|
|
|
// read start.conf
|
2020-11-24 20:25:39 +01:00
|
|
|
this->logger->log("Starting to parse start.conf", LinboLogger::LinboGuiInfo);
|
2020-11-16 18:01:03 +01:00
|
|
|
ifstream input;
|
|
|
|
input.open( "start.conf", ios_base::in );
|
|
|
|
|
|
|
|
QString tmp_qstring;
|
|
|
|
|
|
|
|
while( !input.eof() ) {
|
|
|
|
// *** Image description section ***
|
|
|
|
|
|
|
|
// entry in start tab
|
2020-11-23 11:57:51 +01:00
|
|
|
char line[500];
|
|
|
|
input.getline(line,500,'\n');
|
|
|
|
tmp_qstring = QString::fromAscii( line, -1 ).stripWhiteSpace();
|
|
|
|
|
2020-11-16 18:01:03 +01:00
|
|
|
if ( tmp_qstring.startsWith("#") || tmp_qstring.isEmpty() ) continue;
|
|
|
|
|
|
|
|
tmp_qstring = tmp_qstring.section("#",0,0).stripWhiteSpace(); // Strip comment
|
|
|
|
if(tmp_qstring.lower().compare("[os]") == 0) {
|
|
|
|
LinboOs* tmpOs = read_os(&input);
|
|
|
|
if(!tmpOs->getName().isEmpty()) {
|
|
|
|
this->operatingSystems.append(tmpOs);
|
2020-11-23 11:57:51 +01:00
|
|
|
|
|
|
|
if(tmpOs->getAutostart() && this->currentOs == nullptr)
|
|
|
|
this->currentOs = tmpOs;
|
|
|
|
|
2020-11-16 18:01:03 +01:00
|
|
|
// check if this is an additional/incremental image for an existing OS
|
|
|
|
/* TODO unsigned int i; // Being checked later.
|
2020-11-23 11:57:51 +01:00
|
|
|
for(i = 0; i < elements.size(); i++ ) {
|
|
|
|
if(tmp_os.get_name().lower().compare(elements[i].get_name().lower()) == 0) {
|
|
|
|
elements[i].image_history.push_back(tmp_image); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(i==elements.size()) { // Not included yet -> new image
|
|
|
|
tmp_os.image_history.push_back(tmp_image);
|
|
|
|
elements.push_back(tmp_os);
|
|
|
|
}*/
|
2020-11-16 18:01:03 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
tmpOs->deleteLater();
|
|
|
|
}
|
|
|
|
} else if(tmp_qstring.lower().compare("[linbo]") == 0) {
|
|
|
|
read_globals(&input, config);
|
|
|
|
} else if(tmp_qstring.lower().compare("[partition]") == 0) {
|
|
|
|
LinboDiskPartition* tmpPartition = read_partition(&input);
|
|
|
|
if(!tmpPartition->getPath().isEmpty()) {
|
|
|
|
diskPartitions.append(tmpPartition);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tmpPartition->deleteLater();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
input.close();
|
|
|
|
|
2020-11-24 20:25:39 +01:00
|
|
|
this->logger->log("Finished to parsing start.conf", LinboLogger::LinboGuiInfo);
|
|
|
|
this->logger->log("Loading global configuration", LinboLogger::LinboGuiInfo);
|
2020-11-16 18:01:03 +01:00
|
|
|
|
|
|
|
// load global config
|
|
|
|
QStringList command;
|
2020-11-23 11:57:51 +01:00
|
|
|
// ascynchorons commands are logged to logger
|
|
|
|
this->asynchronosProcess = new QProcess();
|
|
|
|
connect( asynchronosProcess, SIGNAL(readyReadStandardOutput()),
|
2020-11-19 14:39:32 +01:00
|
|
|
this, SLOT(readFromStdout()) );
|
2020-11-23 11:57:51 +01:00
|
|
|
connect( asynchronosProcess, SIGNAL(readyReadStandardError()),
|
2020-11-19 14:39:32 +01:00
|
|
|
this, SLOT(readFromStderr()) );
|
2020-11-23 11:57:51 +01:00
|
|
|
|
|
|
|
// synchronos commands are not logged
|
|
|
|
this->synchronosProcess = new QProcess();
|
2020-11-16 18:01:03 +01:00
|
|
|
|
|
|
|
// client ip
|
2020-11-20 15:09:36 +01:00
|
|
|
this->config->setIpAddress(this->executeCommand(true, "ip"));
|
2020-11-16 18:01:03 +01:00
|
|
|
|
|
|
|
// mac address
|
2020-11-20 15:09:36 +01:00
|
|
|
this->config->setMacAddress(this->executeCommand(true, "mac"));
|
2020-11-16 18:01:03 +01:00
|
|
|
|
|
|
|
// Version
|
2020-11-20 15:09:36 +01:00
|
|
|
this->config->setVersion(this->executeCommand(true, "version").stripWhiteSpace());
|
2020-11-16 18:01:03 +01:00
|
|
|
|
|
|
|
// hostname
|
2020-11-20 15:09:36 +01:00
|
|
|
this->config->setHostname(this->executeCommand(true, "hostname"));
|
2020-11-16 18:01:03 +01:00
|
|
|
|
|
|
|
// CPU
|
2020-11-20 15:09:36 +01:00
|
|
|
this->config->setCpu(this->executeCommand(true, "cpu"));
|
2020-11-16 18:01:03 +01:00
|
|
|
|
|
|
|
// Memory
|
2020-11-20 15:09:36 +01:00
|
|
|
this->config->setRamSize(this->executeCommand(true, "memory"));
|
2020-11-16 18:01:03 +01:00
|
|
|
|
|
|
|
// Cache Size
|
2020-11-20 15:09:36 +01:00
|
|
|
this->config->setCacheSize(this->executeCommand(true, "size"));
|
2020-11-16 18:01:03 +01:00
|
|
|
|
|
|
|
// Harddisk Size
|
2020-11-24 21:42:47 +01:00
|
|
|
QRegExp *removePartition = new QRegExp("[0-9]{1,2}");
|
2020-11-16 18:01:03 +01:00
|
|
|
QString hd = this->config->getCache();
|
2020-11-20 15:09:36 +01:00
|
|
|
// e.g. turn /dev/sda1 into /dev/sda
|
2020-11-16 18:01:03 +01:00
|
|
|
hd.remove( *removePartition );
|
2020-11-20 15:09:36 +01:00
|
|
|
this->config->setHddSize(this->executeCommand(true, "size", hd));
|
2020-11-23 11:57:51 +01:00
|
|
|
|
2020-11-24 20:25:39 +01:00
|
|
|
|
|
|
|
this->logger->log("Finished loading global configuration", LinboLogger::LinboGuiInfo);
|
|
|
|
|
|
|
|
// default select first OS if no other OS has been selected yet
|
|
|
|
if(this->operatingSystems.length() > 0 && this->currentOs == nullptr)
|
|
|
|
this->currentOs = this->operatingSystems[0];
|
|
|
|
|
|
|
|
// triger autostart
|
|
|
|
if(this->currentOs->getAutostart())
|
|
|
|
this->executeAutostart();
|
|
|
|
else
|
|
|
|
this->setState(Idle);
|
2020-11-16 18:01:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------
|
|
|
|
// - Public functions -
|
|
|
|
// --------------------
|
|
|
|
|
|
|
|
void LinboBackend::executeAutostart() {
|
2020-11-24 21:42:47 +01:00
|
|
|
if(this->currentOs->getDefaultAction() == LinboOs::UnknownAction) {
|
|
|
|
this->setState(Idle);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->setState(Autostarting);
|
|
|
|
this->logger->log("Beginning autostart timeout for " + this->currentOs->getName(), LinboLogger::LinboGuiInfo);
|
2020-11-24 20:25:39 +01:00
|
|
|
this->autostartTimer->setInterval(this->currentOs->getAutostartTimeout() * 1000);
|
2020-11-24 21:42:47 +01:00
|
|
|
this->autostartTimer->start();
|
2020-11-24 20:25:39 +01:00
|
|
|
this->autostartElapsedTimer->restart();
|
2020-11-24 21:42:47 +01:00
|
|
|
this->autostartRemainingTimeRefreshTimer->start();
|
2020-11-24 20:25:39 +01:00
|
|
|
}
|
|
|
|
|
2020-11-24 21:42:47 +01:00
|
|
|
void LinboBackend::handleAutostartTimerTimeout() {
|
|
|
|
this->autostartElapsedTimer->invalidate();
|
|
|
|
this->autostartRemainingTimeRefreshTimer->stop();
|
|
|
|
this->logger->log("Executing autostart for " + this->currentOs->getName(), LinboLogger::LinboGuiInfo);
|
|
|
|
|
|
|
|
LinboOs::LinboOsStartAction defaultAction = this->currentOs->getDefaultAction();
|
|
|
|
bool wasSuccessfull = false;
|
|
|
|
switch (defaultAction) {
|
|
|
|
case LinboOs::StartOs:
|
|
|
|
wasSuccessfull = this->startCurrentOs();
|
|
|
|
break;
|
|
|
|
case LinboOs::SyncOs:
|
|
|
|
wasSuccessfull = this->syncCurrentOs();
|
|
|
|
break;
|
|
|
|
case LinboOs::ReinstallOs:
|
|
|
|
wasSuccessfull = this->reinstallCurrentOs();
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
2020-11-16 18:01:03 +01:00
|
|
|
|
2020-11-24 21:42:47 +01:00
|
|
|
if(wasSuccessfull)
|
|
|
|
this->logger->log("Executed autostart successfully!", LinboLogger::LinboGuiInfo);
|
|
|
|
else
|
|
|
|
this->logger->log("An error occured when executing autostart for " + this->currentOs->getName(), LinboLogger::LinboGuiError);
|
2020-11-16 18:01:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void LinboBackend::shutdown() {
|
2020-11-20 15:09:36 +01:00
|
|
|
this->executeCommand(false, "busybox", QStringList("poweroff"));
|
2020-11-16 18:01:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void LinboBackend::reboot() {
|
2020-11-20 15:09:36 +01:00
|
|
|
this->executeCommand(false, "busybox", QStringList("reboot"));
|
2020-11-16 18:01:03 +01:00
|
|
|
}
|
|
|
|
|
2020-11-23 11:57:51 +01:00
|
|
|
bool LinboBackend::startCurrentOs() {
|
|
|
|
LinboOs* os = this->currentOs;
|
|
|
|
|
2020-11-24 21:42:47 +01:00
|
|
|
if(os == nullptr || (this->state != Idle && this->state != Autostarting) || !os->getStartbutton())
|
2020-11-16 18:01:03 +01:00
|
|
|
return false;
|
|
|
|
|
2020-11-20 15:09:36 +01:00
|
|
|
this->setState(Starting);
|
2020-11-16 18:01:03 +01:00
|
|
|
|
2020-11-20 15:09:36 +01:00
|
|
|
this->executeCommand(
|
|
|
|
false,
|
|
|
|
"start",
|
|
|
|
os->getBootPartition(),
|
|
|
|
os->getRootPartition(),
|
|
|
|
os->getKernel(),
|
|
|
|
os->getInitrd(),
|
|
|
|
os->getKernelOptions(),
|
|
|
|
this->config->getCache()
|
|
|
|
);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-11-23 11:57:51 +01:00
|
|
|
bool LinboBackend::syncCurrentOs() {
|
|
|
|
LinboOs* os = this->currentOs;
|
|
|
|
|
2020-11-24 21:42:47 +01:00
|
|
|
if(os == nullptr || (this->state != Idle && this->state != Autostarting) || !os->getSyncbutton())
|
2020-11-20 15:09:36 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
this->setState(Syncing);
|
|
|
|
|
|
|
|
this->executeCommand(
|
|
|
|
false,
|
|
|
|
"syncstart",
|
|
|
|
this->config->getServer(),
|
|
|
|
this->config->getCache(),
|
|
|
|
os->getBaseImage()->getName(),
|
|
|
|
os->getDifferentialImage()->getName(),
|
|
|
|
os->getBootPartition(),
|
|
|
|
os->getRootPartition(),
|
|
|
|
os->getKernel(),
|
|
|
|
os->getInitrd(),
|
|
|
|
os->getKernelOptions()
|
|
|
|
);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-11-23 11:57:51 +01:00
|
|
|
bool LinboBackend::reinstallCurrentOs() {
|
|
|
|
LinboOs* os = this->currentOs;
|
|
|
|
|
2020-11-24 21:42:47 +01:00
|
|
|
if(os == nullptr || (this->state != Idle && this->state != Autostarting) || !os->getNewbutton())
|
2020-11-20 15:09:36 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
this->setState(Reinstalling);
|
|
|
|
|
|
|
|
this->executeCommand(
|
|
|
|
false,
|
|
|
|
"syncr",
|
|
|
|
this->config->getServer(),
|
|
|
|
this->config->getCache(),
|
|
|
|
os->getBaseImage()->getName(),
|
|
|
|
os->getDifferentialImage()->getName(),
|
|
|
|
os->getBootPartition(),
|
|
|
|
os->getRootPartition(),
|
|
|
|
os->getKernel(),
|
|
|
|
os->getInitrd(),
|
|
|
|
os->getKernelOptions(),
|
|
|
|
QString("force")
|
|
|
|
);
|
2020-11-16 18:01:03 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-11-23 11:57:51 +01:00
|
|
|
bool LinboBackend::partitionDrive(bool format) {
|
|
|
|
if(this->state != Root)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
this->setState(Partitioning);
|
|
|
|
|
|
|
|
QStringList commandArgs = QStringList(format ? "partition":"partition_noformat");
|
|
|
|
for( int i=0; i < this->diskPartitions.length(); i++) {
|
|
|
|
LinboDiskPartition* p = this->diskPartitions[i];
|
|
|
|
commandArgs.append(
|
|
|
|
this->buildCommand(
|
|
|
|
p->getPath(),
|
|
|
|
QString::number(p->getSize()),
|
|
|
|
p->getId(),
|
|
|
|
QString((p->getBootable())?"bootable":"\" \""),
|
|
|
|
p->getFstype()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
this->executeCommand(false, this->linboCmdCommand, commandArgs);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LinboBackend::initializeCache() {
|
|
|
|
if(this->state != Root)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
this->setState(InitializingCache);
|
|
|
|
|
|
|
|
QStringList commandArgs = this->buildCommand("initcache", config->getServer(), config->getCache());
|
|
|
|
|
|
|
|
if( this->config->getDownloadType().isEmpty() )
|
|
|
|
commandArgs.append(this->config->getDownloadType());
|
|
|
|
else
|
|
|
|
commandArgs.append("rsync");
|
|
|
|
|
|
|
|
for(int i = 0; i < this->operatingSystems.length(); i++) {
|
|
|
|
LinboOs* os = this->operatingSystems[i];
|
|
|
|
commandArgs.append(this->buildCommand(os->getBaseImage()->getName(), os->getDifferentialImage()->getName()));
|
|
|
|
/* TODO ?? for(unsigned int j = 0; j < os[i].image_history.size(); j++) {
|
|
|
|
saveappend( command, os[i].image_history[j].get_image() );
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
|
|
|
|
this->executeCommand(false, this->linboCmdCommand, commandArgs);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LinboBackend::updateLinbo() {
|
|
|
|
if(this->state != Root)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
this->executeCommand("update", this->config->getServer(), this->config->getCache());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-11-24 20:25:39 +01:00
|
|
|
LinboLogger* LinboBackend::getLogger() {
|
|
|
|
return this->logger;
|
|
|
|
}
|
|
|
|
|
2020-11-16 18:01:03 +01:00
|
|
|
LinboConfig* LinboBackend::getConfig() {
|
|
|
|
return this->config;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<LinboOs*> LinboBackend::getOperatingSystems() {
|
|
|
|
return this->operatingSystems;
|
|
|
|
}
|
|
|
|
|
2020-11-23 11:57:51 +01:00
|
|
|
LinboOs* LinboBackend::getCurrentOs() {
|
|
|
|
return this->currentOs;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LinboBackend::setCurrentOs(LinboOs* os) {
|
|
|
|
if(this->state != Idle || !this->operatingSystems.contains(os) || this->currentOs == os)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this->currentOs = os;
|
|
|
|
emit this->currentOsChanged(os);
|
|
|
|
}
|
2020-11-16 18:01:03 +01:00
|
|
|
|
2020-11-24 20:25:39 +01:00
|
|
|
|
|
|
|
double LinboBackend::getAutostartTimeoutProgress() {
|
2020-11-24 21:42:47 +01:00
|
|
|
return this->autostartTimer->isActive() ? double(this->autostartElapsedTimer->elapsed()) / double(this->autostartTimer->interval()) : 1;
|
2020-11-24 20:25:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int LinboBackend::getAutostartTimeoutRemainingSeconds() {
|
2020-11-24 21:42:47 +01:00
|
|
|
return this->autostartTimer->isActive() ? (this->autostartTimer->interval() - this->autostartElapsedTimer->elapsed()) / 1000 : 0;
|
2020-11-24 20:25:39 +01:00
|
|
|
}
|
|
|
|
|
2020-11-16 18:01:03 +01:00
|
|
|
// -----------
|
|
|
|
// - Helpers -
|
|
|
|
// -----------
|
|
|
|
|
2020-11-20 15:09:36 +01:00
|
|
|
QString LinboBackend::executeCommand(bool waitForFinished, QString command, QStringList commandArgs) {
|
2020-11-16 18:01:03 +01:00
|
|
|
|
2020-11-24 20:25:39 +01:00
|
|
|
this->logger->log("Executing " + QString(waitForFinished ? "synchronos":"asynchronos") + ": " + command + " " + commandArgs.join(" "), LinboLogger::LinboGuiInfo);
|
2020-11-23 11:57:51 +01:00
|
|
|
|
|
|
|
if(waitForFinished) {
|
2020-11-20 15:09:36 +01:00
|
|
|
// clear old output
|
2020-11-23 11:57:51 +01:00
|
|
|
this->synchronosProcess->readAll();
|
2020-11-20 15:09:36 +01:00
|
|
|
|
2020-11-24 21:42:47 +01:00
|
|
|
this->synchronosProcess->start(command, commandArgs);
|
|
|
|
this->synchronosProcess->waitForStarted();
|
2020-11-19 14:39:32 +01:00
|
|
|
|
2020-11-24 21:42:47 +01:00
|
|
|
this->synchronosProcess->waitForFinished(10000);
|
2020-11-23 11:57:51 +01:00
|
|
|
return this->synchronosProcess->readAllStandardOutput();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
asynchronosProcess->start(command, commandArgs);
|
|
|
|
asynchronosProcess->waitForStarted();
|
2020-11-16 18:01:03 +01:00
|
|
|
|
2020-11-23 11:57:51 +01:00
|
|
|
return "";
|
2020-11-20 15:09:36 +01:00
|
|
|
}
|
2020-11-23 11:57:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LinboBackend::readFromStdout() {
|
2020-11-24 20:25:39 +01:00
|
|
|
QString stdOut = this->asynchronosProcess->readAllStandardOutput();
|
|
|
|
QStringList lines = stdOut.split("\n");
|
|
|
|
for(QString line : lines) {
|
|
|
|
this->logger->log(line, LinboLogger::StdOut);
|
|
|
|
}
|
2020-11-23 11:57:51 +01:00
|
|
|
}
|
2020-11-20 15:09:36 +01:00
|
|
|
|
2020-11-23 11:57:51 +01:00
|
|
|
void LinboBackend::readFromStderr() {
|
2020-11-24 20:25:39 +01:00
|
|
|
QString stdOut = this->asynchronosProcess->readAllStandardError();
|
|
|
|
QStringList lines = stdOut.split("\n");
|
|
|
|
for(QString line : lines) {
|
|
|
|
this->logger->log(line, LinboLogger::StdErr);
|
|
|
|
}
|
2020-11-20 15:09:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
LinboBackend::LinboState LinboBackend::getState() {
|
|
|
|
return this->state;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LinboBackend::setState(LinboState state) {
|
|
|
|
if(this->state == state)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this->state = state;
|
2020-11-23 11:57:51 +01:00
|
|
|
emit this->stateChanged(this->state);
|
2020-11-16 18:01:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return true unless beginning of new section '[' is found.
|
|
|
|
bool LinboBackend::read_pair(ifstream* input, QString& key, QString& value) {
|
|
|
|
char line[1024];
|
|
|
|
if(input->peek() == '[') return false; // Next section found.
|
|
|
|
input->getline(line,1024,'\n');
|
|
|
|
QString s = QString::fromAscii( line, -1 ).stripWhiteSpace();
|
|
|
|
key = s.section("=",0,0).stripWhiteSpace().lower();
|
|
|
|
if(s.startsWith("#")||key.isEmpty()) {
|
|
|
|
key = QString(""); value = QString("");
|
|
|
|
} else {
|
|
|
|
value=s.section("=",1).section("#",0,0).stripWhiteSpace();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LinboBackend::toBool(const QString& value) {
|
|
|
|
if(value.startsWith("yes",false)) return true;
|
|
|
|
if(value.startsWith("true",false)) return true;
|
|
|
|
if(value.startsWith("enable",false)) return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
LinboOs* LinboBackend::read_os(ifstream* input) {
|
|
|
|
LinboOs* os = new LinboOs(this);
|
|
|
|
QString key, value;
|
|
|
|
while(!input->eof() && read_pair(input, key, value)) {
|
|
|
|
if(key.compare("name") == 0) os->setName(value);
|
|
|
|
else if(key.compare("description") == 0) os->setDescription(value);
|
|
|
|
else if(key.compare("version") == 0) os->setVersion(value);
|
|
|
|
else if(key.compare("iconname") == 0) os->setIconName(value);
|
|
|
|
else if(key.compare("image") == 0) os->setDifferentialImage(new LinboImage(value, os));
|
|
|
|
else if(key.compare("baseimage") == 0) os->setBaseImage(new LinboImage(value, os));
|
|
|
|
else if(key.compare("boot") == 0) os->setBootPartition(value);
|
|
|
|
else if(key.compare("root") == 0) os->setRootPartition(value);
|
|
|
|
else if(key.compare("kernel") == 0) os->setKernel(value);
|
|
|
|
else if(key.compare("initrd") == 0) os->setInitrd(value);
|
|
|
|
else if(key.compare("append") == 0) os->setKernelOptions(value);
|
|
|
|
else if(key.compare("syncenabled") == 0) os->setSyncButton(toBool(value));
|
|
|
|
else if(key.compare("startenabled") == 0) os->setStartButton(toBool(value));
|
|
|
|
else if((key.compare("remotesyncenabled") == 0) || (key.compare("newenabled") == 0)) os->setNewButton(toBool(value));
|
2020-11-20 15:09:36 +01:00
|
|
|
else if(key.compare("defaultaction") == 0) os->setDefaultAction(os->startActionFromString(value));
|
2020-11-16 18:01:03 +01:00
|
|
|
else if(key.compare("autostart") == 0) os->setAutostart(toBool(value));
|
|
|
|
else if(key.compare("autostarttimeout") == 0) os->setAutostartTimeout(value.toInt());
|
|
|
|
else if(key.compare("hidden") == 0) os->setHidden(toBool(value));
|
|
|
|
}
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
|
|
|
LinboDiskPartition* LinboBackend::read_partition(ifstream* input) {
|
|
|
|
LinboDiskPartition* partition = new LinboDiskPartition(this);
|
|
|
|
QString key, value;
|
|
|
|
while(!input->eof() && read_pair(input, key, value)) {
|
|
|
|
if(key.compare("dev") == 0) partition->setPath(value);
|
|
|
|
else if(key.compare("size") == 0) partition->setSize(value.toInt());
|
|
|
|
else if(key.compare("id") == 0) partition->setId(value);
|
|
|
|
else if(key.compare("fstype") == 0) partition->setFstype(value);
|
|
|
|
else if(key.startsWith("bootable", false)) partition->setBootable(toBool(value));
|
|
|
|
}
|
|
|
|
return partition;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LinboBackend::read_globals( ifstream* input, LinboConfig* config ) {
|
|
|
|
QString key, value;
|
|
|
|
while(!input->eof() && read_pair(input, key, value)) {
|
|
|
|
if(key.compare("server") == 0) config->setServer(value);
|
|
|
|
else if(key.compare("cache") == 0) config->setCache(value);
|
|
|
|
else if(key.compare("roottimeout") == 0) config->setRootTimeout((unsigned int)value.toInt());
|
|
|
|
else if(key.compare("group") == 0) config->setHostgroup(value);
|
|
|
|
else if(key.compare("autopartition") == 0) config->setAutopartition(toBool(value));
|
|
|
|
else if(key.compare("autoinitcache") == 0) config->setAutoInitCache(toBool(value));
|
|
|
|
else if(key.compare("autoformat") == 0) config->setAutoFormat(toBool(value));
|
|
|
|
else if(key.compare("backgroundfontcolor") == 0) config->setBackgroundFontcolor(value);
|
|
|
|
else if(key.compare("consolefontcolorstdout") == 0) config->setConsoleFontcolorStdout(value);
|
|
|
|
else if(key.compare("consolefontcolorstderr") == 0) config->setConsoleFontcolorStderr(value);
|
|
|
|
else if(key.compare("usemulticast") == 0) {
|
|
|
|
if( (unsigned int)value.toInt() == 0 )
|
|
|
|
config->setDownloadType("rsync");
|
|
|
|
else
|
|
|
|
config->setDownloadType("multicast");
|
|
|
|
}
|
|
|
|
else if(key.compare("downloadtype") == 0) config->setDownloadType(value);
|
|
|
|
}
|
|
|
|
}
|