2020-10-29 21:16:45 +03:00
|
|
|
#include "deb.h"
|
|
|
|
|
|
|
|
#include <deployconfig.h>
|
|
|
|
#include <pathutils.h>
|
|
|
|
#include <packagecontrol.h>
|
2020-11-07 01:12:28 +03:00
|
|
|
#include <QProcess>
|
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();
|
|
|
|
|
|
|
|
TemplateInfo info;
|
2020-11-10 14:07:54 +03:00
|
|
|
bool fDefaultPakcage;
|
|
|
|
if (!collectInfo(it, cfg, info, fDefaultPakcage)) {
|
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-11-07 01:12:28 +03:00
|
|
|
auto local = location(info.Name);
|
2020-11-09 16:33:50 +03:00
|
|
|
auto localData = dataLocation(info.Name);
|
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(":/Templates/DEB/Distributions/Templates/deb",
|
|
|
|
local, info, {""}, replace)) {
|
2020-11-07 01:12:28 +03:00
|
|
|
return false;
|
|
|
|
}
|
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
|
|
|
|
|
|
|
QString Deb::dataLocation(const QString &packageName) const {
|
2020-11-09 16:33:50 +03:00
|
|
|
return location(packageName) + "/opt/" + packageName;
|
2020-11-07 01:12:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
QString Deb::location(const QString &packageName) const {
|
|
|
|
const DeployConfig* cfg = DeployCore::_config;
|
|
|
|
|
|
|
|
return cfg->getTargetDir() + "/" + getLocation() + "/" + packageName;
|
|
|
|
}
|