139 lines
3.7 KiB
C++
Raw Normal View History

2020-10-29 21:16:45 +03:00
#include "deb.h"
#include <deployconfig.h>
#include <pathutils.h>
#include <packagecontrol.h>
#include <quasarapp.h>
2020-10-29 21:16:45 +03:00
Deb::Deb(FileManager *fileManager):
iDistribution(fileManager)
{
setLocation("tmp DEB");
2020-10-29 21:16:45 +03:00
}
bool Deb::deployTemplate(PackageControl &pkg) {
// default template
const DeployConfig *cfg = DeployCore::_config;
for (auto it = cfg->packages().begin();
it != cfg->packages().end(); ++it) {
auto package = it.value();
QString defaultPackageTempalte = ":/Templates/DEB/Distributions/Templates/deb";
auto customTemplate = QuasarAppUtils::Params::getStrArg("deb", "");
QHash<QString, QString> pakcagesTemplates;
if (!customTemplate.isEmpty()) {
QuasarAppUtils::Params::log("Using custom template for installer: " + customTemplate,
QuasarAppUtils::Info);
auto availablePacakages = QDir(customTemplate).entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
for (const auto& pkg: availablePacakages) {
pakcagesTemplates.insert(pkg.fileName(), pkg.absoluteFilePath());
}
}
2020-10-29 21:16:45 +03:00
TemplateInfo info;
2020-12-03 20:00:14 +03:00
if (!collectInfoWithDeployIcons(package, info)) {
return false;
2020-11-09 16:33:50 +03:00
}
2020-10-29 21:16:45 +03:00
2020-12-03 20:00:14 +03:00
auto local = location(package);
auto localData = dataLocation(package);
2020-10-29 21:16:45 +03:00
2020-11-09 16:33:50 +03:00
if (!pkg.movePackage(it.key(), localData)) {
2020-10-29 21:16:45 +03:00
return false;
}
2020-11-09 16:33:50 +03:00
QHash<QString, QString> replace = {
{"default", info.Name}
};
if (!unpackDir(pakcagesTemplates.value(info.Name, defaultPackageTempalte),
2020-11-09 16:33:50 +03:00
local, info, {""}, replace)) {
return false;
}
2020-11-09 16:33:50 +03:00
if (!QFile::setPermissions(local + "/DEBIAN", static_cast<QFile::Permission>(0x7775))) {
QuasarAppUtils::Params::log("permishens set fail", QuasarAppUtils::Warning);
}
2020-11-09 16:33:50 +03:00
outFiles.push_back(info.Name + ".deb");
packageFolders.push_back(local);
2020-10-29 21:16:45 +03:00
}
return true;
}
bool Deb::removeTemplate() const {
2020-11-09 16:33:50 +03:00
const DeployConfig *cfg = DeployCore::_config;
2020-10-29 21:16:45 +03:00
2020-11-09 16:33:50 +03:00
registerOutFiles();
return QDir(cfg->getTargetDir() + "/" + getLocation()).removeRecursively();
2020-10-29 21:16:45 +03:00
}
Envirement Deb::toolKitEnv() const {
Envirement result;
result.addEnv(QProcessEnvironment::systemEnvironment().value("PATH"));
2020-10-29 21:16:45 +03:00
return result;
2020-10-29 21:16:45 +03:00
}
QProcessEnvironment Deb::processEnvirement() const {
return QProcessEnvironment::systemEnvironment();
2020-10-29 21:16:45 +03:00
}
QList<SystemCommandData> Deb::runCmd() {
QList<SystemCommandData> res;
for (const auto& dir: packageFolders) {
res.push_back({"dpkg-deb", QStringList{"--build", "--verbose"} << dir});
}
2020-10-29 21:16:45 +03:00
return res;
2020-10-29 21:16:45 +03:00
}
QStringList Deb::outPutFiles() const {
2020-11-09 16:33:50 +03:00
return outFiles;
}
2020-10-29 21:16:45 +03:00
2020-11-09 16:33:50 +03:00
bool Deb::cb() const {
const DeployConfig* cfg = DeployCore::_config;
QString from = cfg->getTargetDir() + "/" + getLocation() + "/";
QString to = cfg->getTargetDir() + "/" + getLocation() + "/../";
for (const QString& file : outPutFiles()) {
if(!moveData(from + file, to, "")) {
return false;
}
}
return true;
2020-10-29 21:16:45 +03:00
}
2020-12-03 20:00:14 +03:00
QString Deb::dataLocation(const DistroModule &module) const {
return location(module) + "/opt/" + releativeLocation(module);
}
2020-12-03 20:00:14 +03:00
QString Deb::location(const DistroModule &module) const {
const DeployConfig* cfg = DeployCore::_config;
2020-12-03 20:00:14 +03:00
auto name = getName(module);
if (name.isEmpty())
return cfg->getTargetDir() + "/" + getLocation() + "/" + module.key();
return cfg->getTargetDir() + "/" + getLocation() + "/" + name;
}
QString Deb::releativeLocation(const DistroModule &module) const {
if (module.prefix().isEmpty()) {
return module.key();
}
return module.prefix();
}