mirror of
https://github.com/CachyOS/New-Cli-Installer.git
synced 2025-02-02 22:07:13 +08:00
👷 push v3 repo as first repo natively
This commit is contained in:
parent
e132a4a79c
commit
5551f2b7b4
@ -96,6 +96,7 @@ add_executable(${PROJECT_NAME}
|
|||||||
src/config.cpp src/config.hpp
|
src/config.cpp src/config.hpp
|
||||||
src/utils.cpp src/utils.hpp
|
src/utils.cpp src/utils.hpp
|
||||||
src/cpu.cpp src/cpu.hpp
|
src/cpu.cpp src/cpu.hpp
|
||||||
|
src/pacmanconf_repo.cpp src/pacmanconf_repo.hpp
|
||||||
src/initcpio.cpp src/initcpio.hpp
|
src/initcpio.cpp src/initcpio.hpp
|
||||||
src/disk.cpp src/disk.hpp
|
src/disk.cpp src/disk.hpp
|
||||||
src/drivers.cpp src/drivers.hpp
|
src/drivers.cpp src/drivers.hpp
|
||||||
|
64
src/pacmanconf_repo.cpp
Normal file
64
src/pacmanconf_repo.cpp
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
#include "pacmanconf_repo.hpp"
|
||||||
|
#include "utils.hpp"
|
||||||
|
|
||||||
|
#include <fstream> // for ofstream
|
||||||
|
#include <string> // for string
|
||||||
|
#include <vector> // for vector
|
||||||
|
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
|
#if defined(__clang__)
|
||||||
|
#pragma clang diagnostic push
|
||||||
|
#pragma clang diagnostic ignored "-Wold-style-cast"
|
||||||
|
#elif defined(__GNUC__)
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wnull-dereference"
|
||||||
|
#pragma GCC diagnostic ignored "-Wuseless-cast"
|
||||||
|
#pragma GCC diagnostic ignored "-Wold-style-cast"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <range/v3/range/conversion.hpp>
|
||||||
|
#include <range/v3/view/join.hpp>
|
||||||
|
#include <range/v3/view/split.hpp>
|
||||||
|
|
||||||
|
#if defined(__clang__)
|
||||||
|
#pragma clang diagnostic pop
|
||||||
|
#elif defined(__GNUC__)
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace detail::pacmanconf {
|
||||||
|
|
||||||
|
bool push_repos_front(const std::string_view& file_path, const std::string_view& value) noexcept {
|
||||||
|
using StringVec = std::vector<std::string>;
|
||||||
|
auto&& file_content = utils::read_whole_file(file_path);
|
||||||
|
if (file_content.empty()) {
|
||||||
|
spdlog::error("[PACMANCONFREPO] '{}' error occurred!", file_path);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
auto&& content_lines = file_content | ranges::views::split('\n') | ranges::to<std::vector<std::string>>();
|
||||||
|
for (std::size_t i = 1; i < content_lines.size(); ++i) {
|
||||||
|
const std::string_view current_line{content_lines[i - 1]};
|
||||||
|
if (current_line.empty() || current_line.starts_with("#") || !current_line.starts_with("[") || current_line.starts_with("[options]")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto&& to_be_inserted = value | ranges::views::split('\n') | ranges::to<std::vector<std::string>>();
|
||||||
|
to_be_inserted.emplace_back("\n");
|
||||||
|
content_lines.insert(content_lines.begin() + static_cast<StringVec::iterator::difference_type>(i - 1),
|
||||||
|
std::move_iterator(to_be_inserted.begin()), std::move_iterator(to_be_inserted.end()));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string&& result = content_lines | ranges::views::join('\n') | ranges::to<std::string>();
|
||||||
|
|
||||||
|
std::ofstream pacmanconf_file{file_path.data()};
|
||||||
|
if (!pacmanconf_file.is_open()) {
|
||||||
|
spdlog::error("[PACMANCONFREPO] '{}' open failed: {}", file_path, std::strerror(errno));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
pacmanconf_file << result;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace detail::pacmanconf
|
10
src/pacmanconf_repo.hpp
Normal file
10
src/pacmanconf_repo.hpp
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#ifndef PACMANCONF_REPO_HPP
|
||||||
|
#define PACMANCONF_REPO_HPP
|
||||||
|
|
||||||
|
#include <string_view> // for string_view
|
||||||
|
|
||||||
|
namespace detail::pacmanconf {
|
||||||
|
bool push_repos_front(const std::string_view& file_path, const std::string_view& value) noexcept;
|
||||||
|
} // namespace detail::pacmanconf
|
||||||
|
|
||||||
|
#endif // PACMANCONF_REPO_HPP
|
@ -4,6 +4,7 @@
|
|||||||
#include "definitions.hpp"
|
#include "definitions.hpp"
|
||||||
#include "follow_process_log.hpp"
|
#include "follow_process_log.hpp"
|
||||||
#include "initcpio.hpp"
|
#include "initcpio.hpp"
|
||||||
|
#include "pacmanconf_repo.hpp"
|
||||||
#include "subprocess.h"
|
#include "subprocess.h"
|
||||||
#include "tui.hpp"
|
#include "tui.hpp"
|
||||||
#include "widgets.hpp"
|
#include "widgets.hpp"
|
||||||
@ -1512,7 +1513,7 @@ void id_system() noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void install_cachyos_repo() noexcept {
|
void install_cachyos_repo() noexcept {
|
||||||
const auto& add_arch_specific_repo = [](auto&& isa_level, [[maybe_unused]] auto&& repo_name, const auto& isa_levels, [[maybe_unused]] const auto& functor) {
|
const auto& add_arch_specific_repo = [](auto&& isa_level, [[maybe_unused]] auto&& repo_name, const auto& isa_levels, [[maybe_unused]] auto&& repos_data) {
|
||||||
if (ranges::contains(isa_levels, isa_level)) {
|
if (ranges::contains(isa_levels, isa_level)) {
|
||||||
spdlog::warn("{} is not supported", isa_level);
|
spdlog::warn("{} is not supported", isa_level);
|
||||||
return;
|
return;
|
||||||
@ -1521,11 +1522,16 @@ void install_cachyos_repo() noexcept {
|
|||||||
|
|
||||||
#ifdef NDEVENV
|
#ifdef NDEVENV
|
||||||
static constexpr auto pacman_conf = "/etc/pacman.conf";
|
static constexpr auto pacman_conf = "/etc/pacman.conf";
|
||||||
static constexpr auto pacman_conf_cachyos = "/etc/pacman-more.conf";
|
static constexpr auto pacman_conf_cachyos = "./pacman.conf";
|
||||||
static constexpr auto pacman_conf_path_backup = "/etc/pacman.conf.bak";
|
static constexpr auto pacman_conf_path_backup = "/etc/pacman.conf.bak";
|
||||||
std::error_code err{};
|
std::error_code err{};
|
||||||
|
|
||||||
functor(pacman_conf_cachyos);
|
if (!fs::copy_file(pacman_conf, pacman_conf_cachyos, err)) {
|
||||||
|
spdlog::error("Failed to copy pacman config [{}]", err.message());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
detail::pacmanconf::push_repos_front(pacman_conf_cachyos, repos_data);
|
||||||
|
|
||||||
spdlog::info("backup old config");
|
spdlog::info("backup old config");
|
||||||
fs::rename(pacman_conf, pacman_conf_path_backup, err);
|
fs::rename(pacman_conf, pacman_conf_path_backup, err);
|
||||||
@ -1550,9 +1556,16 @@ void install_cachyos_repo() noexcept {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
const auto& isa_levels = utils::get_isa_levels();
|
const auto& isa_levels = utils::get_isa_levels();
|
||||||
add_arch_specific_repo("x86-64-v3", "cachyos-v3", isa_levels, [](auto&& target_config) {
|
|
||||||
utils::exec(fmt::format(FMT_COMPILE("sed -i 's/#<disabled_v3>//g' {}"), target_config));
|
static constexpr auto CACHYOS_V3_REPO_STR = R"(
|
||||||
});
|
[cachyos-v3]
|
||||||
|
Include = /etc/pacman.d/cachyos-v3-mirrorlist
|
||||||
|
|
||||||
|
[cachyos]
|
||||||
|
Include = /etc/pacman.d/cachyos-mirrorlist
|
||||||
|
)";
|
||||||
|
|
||||||
|
add_arch_specific_repo("x86-64-v3", "cachyos-v3", isa_levels, CACHYOS_V3_REPO_STR);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool handle_connection() noexcept {
|
bool handle_connection() noexcept {
|
||||||
|
Loading…
Reference in New Issue
Block a user