|
|
@ -1,5 +1,5 @@ |
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2021-2022 Riyyi |
|
|
|
* Copyright (C) 2021-2022,2025 Riyyi |
|
|
|
* |
|
|
|
* |
|
|
|
* SPDX-License-Identifier: MIT |
|
|
|
* SPDX-License-Identifier: MIT |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -14,12 +14,12 @@ |
|
|
|
#include <string> // getline |
|
|
|
#include <string> // getline |
|
|
|
#include <vector> |
|
|
|
#include <vector> |
|
|
|
|
|
|
|
|
|
|
|
#include "machine.h" |
|
|
|
|
|
|
|
#include "package.h" |
|
|
|
|
|
|
|
#include "ruc/file.h" |
|
|
|
|
|
|
|
#include "ruc/shell.h" |
|
|
|
#include "ruc/shell.h" |
|
|
|
#include "ruc/system.h" |
|
|
|
#include "ruc/system.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "machine.h" |
|
|
|
|
|
|
|
#include "package.h" |
|
|
|
|
|
|
|
|
|
|
|
Package::Package(s) |
|
|
|
Package::Package(s) |
|
|
|
{ |
|
|
|
{ |
|
|
|
} |
|
|
|
} |
|
|
@ -30,17 +30,27 @@ Package::~Package() |
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------
|
|
|
|
// -----------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
void Package::aurInstall() |
|
|
|
void Package::aurInstall(const std::vector<std::string>& targets) |
|
|
|
{ |
|
|
|
{ |
|
|
|
installOrAurInstall(InstallType::AurInstall); |
|
|
|
if (targets.size() > 1) { |
|
|
|
|
|
|
|
fprintf(stderr, "\033[31;1mPackage:\033[0m only 1 file can be read packages from at a time\n"); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
installOrAurInstall(InstallType::AurInstall, targets.size() != 0 ? targets.front() : PACKAGE_FILE); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Package::install() |
|
|
|
void Package::install(const std::vector<std::string>& targets) |
|
|
|
{ |
|
|
|
{ |
|
|
|
installOrAurInstall(InstallType::Install); |
|
|
|
if (targets.size() > 1) { |
|
|
|
|
|
|
|
fprintf(stderr, "\033[31;1mPackage:\033[0m only 1 file can be read packages from at a time\n"); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
installOrAurInstall(InstallType::Install, targets.size() != 0 ? targets.front() : PACKAGE_FILE); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Package::list(const std::vector<std::string>& targets) |
|
|
|
void Package::list(const std::vector<std::string>& targets, bool partialMatch) |
|
|
|
{ |
|
|
|
{ |
|
|
|
auto packagesOrEmpty = getPackageList(); |
|
|
|
auto packagesOrEmpty = getPackageList(); |
|
|
|
|
|
|
|
|
|
|
@ -62,7 +72,7 @@ void Package::list(const std::vector<std::string>& targets) |
|
|
|
std::string line; |
|
|
|
std::string line; |
|
|
|
while (std::getline(stream, line)) { |
|
|
|
while (std::getline(stream, line)) { |
|
|
|
for (const auto& target : targets) { |
|
|
|
for (const auto& target : targets) { |
|
|
|
if (line.find(target) != std::string::npos) { |
|
|
|
if (line == target || (partialMatch && line.find(target) != std::string::npos)) { |
|
|
|
packages.append(line + '\n'); |
|
|
|
packages.append(line + '\n'); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
@ -72,20 +82,6 @@ void Package::list(const std::vector<std::string>& targets) |
|
|
|
printf("%s", packages.c_str()); |
|
|
|
printf("%s", packages.c_str()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Package::store() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
auto packagesOrEmpty = getPackageList(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!packagesOrEmpty.has_value()) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto packageFile = ruc::File::create("./packages"); |
|
|
|
|
|
|
|
packageFile.clear(); |
|
|
|
|
|
|
|
packageFile.append(packagesOrEmpty.value()); |
|
|
|
|
|
|
|
packageFile.flush(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------
|
|
|
|
// -----------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
std::optional<std::string> Package::fetchAurHelper() |
|
|
|
std::optional<std::string> Package::fetchAurHelper() |
|
|
@ -105,7 +101,7 @@ std::optional<std::string> Package::fetchAurHelper() |
|
|
|
return {}; |
|
|
|
return {}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Package::installOrAurInstall(InstallType type) |
|
|
|
void Package::installOrAurInstall(InstallType type, const std::string& file) |
|
|
|
{ |
|
|
|
{ |
|
|
|
distroDetect(); |
|
|
|
distroDetect(); |
|
|
|
distroDependencies(); |
|
|
|
distroDependencies(); |
|
|
@ -129,12 +125,12 @@ void Package::installOrAurInstall(InstallType type) |
|
|
|
ruc::System $; |
|
|
|
ruc::System $; |
|
|
|
if (m_distro == Distro::Arch) { |
|
|
|
if (m_distro == Distro::Arch) { |
|
|
|
// Grab everything off enabled official repositories that is in the list
|
|
|
|
// Grab everything off enabled official repositories that is in the list
|
|
|
|
auto repoList = $("pacman -Ssq") | $("grep -xf ./packages"); |
|
|
|
auto repoList = $("pacman -Ssq") | $("grep -xf " + file); |
|
|
|
|
|
|
|
|
|
|
|
if (type == InstallType::AurInstall) { |
|
|
|
if (type == InstallType::AurInstall) { |
|
|
|
// Determine which packages in the list are from the AUR
|
|
|
|
// Determine which packages in the list are from the AUR
|
|
|
|
// NOTE: ruc::System does not support commands with newlines
|
|
|
|
// NOTE: ruc::System does not support commands with newlines
|
|
|
|
auto aurList = ruc::Shell()("grep -vx '" + repoList.output() + "' ./packages"); |
|
|
|
auto aurList = ruc::Shell()("grep -vx '" + repoList.output() + "' " + file); |
|
|
|
command = aurHelper.value() + " -Sy --devel --needed --noconfirm " + aurList.output(); |
|
|
|
command = aurHelper.value() + " -Sy --devel --needed --noconfirm " + aurList.output(); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
@ -143,7 +139,7 @@ void Package::installOrAurInstall(InstallType type) |
|
|
|
} |
|
|
|
} |
|
|
|
else if (m_distro == Distro::Debian) { |
|
|
|
else if (m_distro == Distro::Debian) { |
|
|
|
// Grab everything off enabled official repositories that is in the list
|
|
|
|
// Grab everything off enabled official repositories that is in the list
|
|
|
|
auto repoList = $("apt-cache search .").cut(1, ' ') | $("grep -xf ./packages"); |
|
|
|
auto repoList = $("apt-cache search .").cut(1, ' ') | $("grep -xf " + file); |
|
|
|
command = "apt install " + repoList.output(); |
|
|
|
command = "apt install " + repoList.output(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|