Compare commits
2
Commits
592ee124cb
...
50c98b1482
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
50c98b1482 | ||
|
|
42b34aad61 |
+2
-2
@@ -86,10 +86,10 @@ int main(int argc, const char* argv[])
|
||||
Package package;
|
||||
|
||||
if (addOrAur) {
|
||||
// TODO install tracked AUR packages
|
||||
package.aurInstall();
|
||||
}
|
||||
if (install) {
|
||||
// TODO install tracked repo packages
|
||||
package.install();
|
||||
}
|
||||
if (pushOrStore) {
|
||||
package.store();
|
||||
|
||||
+49
-1
@@ -4,8 +4,10 @@
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include <algorithm> // replace
|
||||
#include <array>
|
||||
#include <cstdio> // fprintf, printf, stderr
|
||||
#include <cstdlib> // system
|
||||
#include <sstream> // istringstream
|
||||
#include <string> // getline
|
||||
#include <vector>
|
||||
@@ -13,6 +15,7 @@
|
||||
#include "machine.h"
|
||||
#include "package.h"
|
||||
#include "util/file.h"
|
||||
#include "util/shell.h"
|
||||
#include "util/system.h"
|
||||
|
||||
Package::Package()
|
||||
@@ -27,10 +30,12 @@ Package::~Package()
|
||||
|
||||
void Package::aurInstall()
|
||||
{
|
||||
installOrAurInstall(InstallType::AurInstall);
|
||||
}
|
||||
|
||||
void Package::install()
|
||||
{
|
||||
installOrAurInstall(InstallType::Install);
|
||||
}
|
||||
|
||||
void Package::list(const std::vector<std::string>& targets)
|
||||
@@ -63,7 +68,7 @@ void Package::store()
|
||||
{
|
||||
std::string packages = getPackageList();
|
||||
|
||||
auto packageFile = Util::File("./packages");
|
||||
auto packageFile = Util::File::create("./packages");
|
||||
packageFile.clear();
|
||||
packageFile.append(packages);
|
||||
packageFile.flush();
|
||||
@@ -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()
|
||||
{
|
||||
std::string id = Machine::the().distroId();
|
||||
|
||||
@@ -21,12 +21,19 @@ public:
|
||||
Debian,
|
||||
};
|
||||
|
||||
enum class InstallType {
|
||||
Install,
|
||||
AurInstall,
|
||||
};
|
||||
|
||||
void aurInstall();
|
||||
void install();
|
||||
void list(const std::vector<std::string>& targets = {});
|
||||
void store();
|
||||
|
||||
private:
|
||||
void installOrAurInstall(InstallType type);
|
||||
|
||||
bool distroDetect();
|
||||
bool distroDependencies();
|
||||
std::string getPackageList();
|
||||
|
||||
Reference in New Issue
Block a user