2020-10-29 21:16:45 +03:00
|
|
|
#include "deb.h"
|
|
|
|
|
|
|
|
#include <deployconfig.h>
|
|
|
|
#include <pathutils.h>
|
|
|
|
#include <packagecontrol.h>
|
2020-11-11 11:09:10 +03:00
|
|
|
#include <quasarapp.h>
|
2020-10-29 21:16:45 +03:00
|
|
|
|
|
|
|
Deb::Deb(FileManager *fileManager):
|
|
|
|
iDistribution(fileManager)
|
|
|
|
{
|
2020-11-07 01:12:28 +03:00
|
|
|
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();
|
|
|
|
|
2020-11-11 11:09:10 +03:00
|
|
|
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)) {
|
2020-11-07 01:12:28 +03:00
|
|
|
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}
|
|
|
|
};
|
|
|
|
|
2020-11-11 11:09:10 +03:00
|
|
|
if (!unpackDir(pakcagesTemplates.value(info.Name, defaultPackageTempalte),
|
2020-11-09 16:33:50 +03:00
|
|
|
local, info, {""}, replace)) {
|
2020-11-07 01:12:28 +03:00
|
|
|
return false;
|
|
|
|
}
|
2020-11-09 16:33:50 +03:00
|
|
|
|
2020-11-12 17:07:35 +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 {
|
2020-11-07 01:12:28 +03:00
|
|
|
Envirement result;
|
|
|
|
result.addEnv(QProcessEnvironment::systemEnvironment().value("PATH"));
|
2020-10-29 21:16:45 +03:00
|
|
|
|
2020-11-07 01:12:28 +03:00
|
|
|
return result;
|
2020-10-29 21:16:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
QProcessEnvironment Deb::processEnvirement() const {
|
2020-11-07 01:12:28 +03:00
|
|
|
return QProcessEnvironment::systemEnvironment();
|
2020-10-29 21:16:45 +03:00
|
|
|
}
|
|
|
|
|
2020-11-10 11:50:54 +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
|
|
|
|
2020-11-10 11:50:54 +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-11-07 01:12:28 +03:00
|
|
|
|
2020-12-03 20:00:14 +03:00
|
|
|
QString Deb::dataLocation(const DistroModule &module) const {
|
|
|
|
return location(module) + "/opt/" + releativeLocation(module);
|
|
|
|
|
2020-11-07 01:12:28 +03:00
|
|
|
}
|
|
|
|
|
2020-12-03 20:00:14 +03:00
|
|
|
QString Deb::location(const DistroModule &module) const {
|
2020-11-07 01:12:28 +03:00
|
|
|
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();
|
2020-11-07 01:12:28 +03:00
|
|
|
}
|