Manager: Implement package installation
This commit is contained in:
+2
-2
@@ -86,10 +86,10 @@ int main(int argc, const char* argv[])
|
|||||||
Package package;
|
Package package;
|
||||||
|
|
||||||
if (addOrAur) {
|
if (addOrAur) {
|
||||||
// TODO install tracked AUR packages
|
package.aurInstall();
|
||||||
}
|
}
|
||||||
if (install) {
|
if (install) {
|
||||||
// TODO install tracked repo packages
|
package.install();
|
||||||
}
|
}
|
||||||
if (pushOrStore) {
|
if (pushOrStore) {
|
||||||
package.store();
|
package.store();
|
||||||
|
|||||||
@@ -4,8 +4,10 @@
|
|||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <algorithm> // replace
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <cstdio> // fprintf, printf, stderr
|
#include <cstdio> // fprintf, printf, stderr
|
||||||
|
#include <cstdlib> // system
|
||||||
#include <sstream> // istringstream
|
#include <sstream> // istringstream
|
||||||
#include <string> // getline
|
#include <string> // getline
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -13,6 +15,7 @@
|
|||||||
#include "machine.h"
|
#include "machine.h"
|
||||||
#include "package.h"
|
#include "package.h"
|
||||||
#include "util/file.h"
|
#include "util/file.h"
|
||||||
|
#include "util/shell.h"
|
||||||
#include "util/system.h"
|
#include "util/system.h"
|
||||||
|
|
||||||
Package::Package()
|
Package::Package()
|
||||||
@@ -27,10 +30,12 @@ Package::~Package()
|
|||||||
|
|
||||||
void Package::aurInstall()
|
void Package::aurInstall()
|
||||||
{
|
{
|
||||||
|
installOrAurInstall(InstallType::AurInstall);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Package::install()
|
void Package::install()
|
||||||
{
|
{
|
||||||
|
installOrAurInstall(InstallType::Install);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Package::list(const std::vector<std::string>& targets)
|
void Package::list(const std::vector<std::string>& targets)
|
||||||
@@ -71,6 +76,49 @@ void Package::store()
|
|||||||
|
|
||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
|
|
||||||
|
void Package::installOrAurInstall(InstallType type)
|
||||||
|
{
|
||||||
|
distroDetect();
|
||||||
|
distroDependencies();
|
||||||
|
|
||||||
|
std::string command = "";
|
||||||
|
|
||||||
|
Util::System $;
|
||||||
|
if (m_distro == Distro::Arch) {
|
||||||
|
// Grab everything off enabled official repositories that is in the list
|
||||||
|
auto repoList = $("pacman -Ssq") | $("grep -xf ./packages");
|
||||||
|
|
||||||
|
if (type == InstallType::AurInstall) {
|
||||||
|
// Determine which packages in the list are from the AUR
|
||||||
|
auto aurCommand = "grep -vx '" + repoList.output() + "'";
|
||||||
|
|
||||||
|
// NOTE: Util::System does not support commands with newlines
|
||||||
|
auto aurList = Util::Shell()("cat ./packages | " + aurCommand);
|
||||||
|
command = "trizen -Sy --needed --noconfirm " + aurList.output();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
command = "sudo pacman -Sy --needed " + repoList.output();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (m_distro == Distro::Debian) {
|
||||||
|
if (type == InstallType::AurInstall) {
|
||||||
|
fprintf(stderr, "\033[31;1mPackage:\033[0m AUR is not supported on this distribution\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Grab everything off enabled official repositories that is in the list
|
||||||
|
auto repoList = $("apt-cache search .").cut(1, ' ') | $("grep -xf ./packages");
|
||||||
|
command = "sudo apt install " + repoList.output();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::replace(command.begin(), command.end(), '\n', ' ');
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
printf("running: $ %s\n", command.c_str());
|
||||||
|
#endif
|
||||||
|
system(command.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
bool Package::distroDetect()
|
bool Package::distroDetect()
|
||||||
{
|
{
|
||||||
std::string id = Machine::the().distroId();
|
std::string id = Machine::the().distroId();
|
||||||
|
|||||||
@@ -21,12 +21,19 @@ public:
|
|||||||
Debian,
|
Debian,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class InstallType {
|
||||||
|
Install,
|
||||||
|
AurInstall,
|
||||||
|
};
|
||||||
|
|
||||||
void aurInstall();
|
void aurInstall();
|
||||||
void install();
|
void install();
|
||||||
void list(const std::vector<std::string>& targets = {});
|
void list(const std::vector<std::string>& targets = {});
|
||||||
void store();
|
void store();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void installOrAurInstall(InstallType type);
|
||||||
|
|
||||||
bool distroDetect();
|
bool distroDetect();
|
||||||
bool distroDependencies();
|
bool distroDependencies();
|
||||||
std::string getPackageList();
|
std::string getPackageList();
|
||||||
|
|||||||
Reference in New Issue
Block a user