🧹 drivers: cleanup

This commit is contained in:
Vladislav Nepogodin 2023-12-15 01:15:38 +04:00
parent a17a230dcc
commit b7c1649c82
No known key found for this signature in database
GPG Key ID: B62C3D10C54D5DA9

View File

@ -23,40 +23,13 @@ using namespace std::string_view_literals;
namespace tui {
static void install_ati() noexcept {
#ifdef NDEVENV
auto* config_instance = Config::instance();
auto& config_data = config_instance->data();
const auto& mountpoint = std::get<std::string>(config_data["MOUNTPOINT"]);
utils::exec(fmt::format(FMT_COMPILE("sed -i 's/MODULES=\"\"/MODULES=\"radeon\"/' {}/etc/mkinitcpio.conf"), mountpoint));
#endif
}
#ifdef NDEVENV
static void install_all_drivers() noexcept {
static constexpr auto packages = "xf86-input-libinput xf86-video-fbdev xf86-video-vesa xf86-video-amdgpu xf86-video-ati xf86-video-intel xf86-video-nouveau"sv;
auto* config_instance = Config::instance();
auto& config_data = config_instance->data();
const auto& mountpoint = std::get<std::string>(config_data["MOUNTPOINT"]);
const auto& hostcache = std::get<std::int32_t>(config_data["hostcache"]);
if (hostcache) {
detail::follow_process_log_widget({"/bin/sh", "-c", fmt::format(FMT_COMPILE("pacstrap {} {}"), mountpoint, packages)});
return;
}
detail::follow_process_log_widget({"/bin/sh", "-c", fmt::format(FMT_COMPILE("pacstrap -c {} {}"), mountpoint, packages)});
}
#endif
static void setup_graphics_card() noexcept {
std::string_view driver{};
std::string driver{};
/// TODO(vnepogodin): parse toml DBs
{
static constexpr auto UseSpaceBar = "\nUse [Spacebar] to de/select options listed.\n"sv;
const auto& profile_names = ::detail::chwd::get_available_profile_names("graphic_drivers"sv);
static constexpr auto use_spacebar = "\nUse [Spacebar] to de/select options listed.\n"sv;
const auto& profile_names = ::detail::chwd::get_available_profile_names("graphic_drivers"sv);
if (!profile_names.has_value()) {
spdlog::error("failed to get profile names");
return;
@ -69,34 +42,24 @@ static void setup_graphics_card() noexcept {
driver = radiobox_list[static_cast<size_t>(selected)];
screen.ExitLoopClosure()();
};
detail::radiolist_widget(radiobox_list, ok_callback, &selected, &screen, {.text = UseSpaceBar}, {.text_size = nothing});
detail::radiolist_widget(radiobox_list, ok_callback, &selected, &screen, {.text = use_spacebar}, {.text_size = nothing});
}
/* clang-format off */
if (driver.empty()) { return; }
/* clang-format on */
auto* config_instance = Config::instance();
auto& config_data = config_instance->data();
auto& graphics_card = std::get<std::string>(config_data["GRAPHIC_CARD"]);
auto* config_instance = Config::instance();
auto& config_data = config_instance->data();
const auto& mountpoint = std::get<std::string>(config_data["MOUNTPOINT"]);
const auto& cachepath = std::get<std::string>(config_data["cachepath"]);
#ifdef NDEVENV
const auto& mountpoint = std::get<std::string>(config_data["MOUNTPOINT"]);
const auto& cachepath = std::get<std::string>(config_data["cachepath"]);
const auto& cmd_formatted = fmt::format(FMT_COMPILE("chwd --pmcachedir \"{}\" --pmroot {} -f -i pci {} 2>>/tmp/cachyos-install.log 2>&1"), cachepath, mountpoint, driver);
tui::detail::follow_process_log_widget({"/bin/sh", "-c", cmd_formatted});
std::ofstream{fmt::format(FMT_COMPILE("{}/.video_installed"), mountpoint)};
#else
spdlog::debug("chwd --pmcachedir \"{}\" --pmroot {} -f -i pci {} 2>>/tmp/cachyos-install.log 2>&1", cachepath, mountpoint, driver);
#endif
graphics_card = utils::exec("lspci | grep -i \"vga\" | sed 's/.*://' | sed 's/(.*//' | sed 's/^[ \\t]*//'"sv);
// All non-NVIDIA cards / virtualization
if (!(utils::exec(fmt::format(FMT_COMPILE("echo \"{}\" | grep -i 'ati'"), graphics_card)).empty())) {
install_ati();
#ifdef NDEVENV
} else if (driver == "video-nouveau"sv) {
utils::exec(fmt::format(FMT_COMPILE("sed -i 's/MODULES=\"\"/MODULES=\"nouveau\"/' {}/etc/mkinitcpio.conf"), mountpoint));
#endif
}
}
static void install_graphics_menu() noexcept {
@ -108,7 +71,6 @@ static void install_graphics_menu() noexcept {
"Auto-install free drivers",
"Auto-install proprietary drivers",
"Select Display Driver",
"Install all free drivers",
"Back",
};
@ -129,12 +91,6 @@ static void install_graphics_menu() noexcept {
case 2:
setup_graphics_card();
break;
#ifdef NDEVENV
case 3:
install_all_drivers();
std::ofstream{fmt::format(FMT_COMPILE("{}/.video_installed"), mountpoint)};
break;
#endif
default:
screen.ExitLoopClosure()();
break;