forked from CachyOS/kernel-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaur_kernel.cpp
More file actions
88 lines (70 loc) · 2.92 KB
/
aur_kernel.cpp
File metadata and controls
88 lines (70 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright (C) 2022-2025 Vladislav Nepogodin
//
// This file is part of CachyOS kernel manager.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include "aur_kernel.hpp"
#include "utils.hpp"
#include <cstdio> // for perror
#include <cstdlib> // for system
#include <algorithm> // for search
#include <filesystem> // for path, exists
#include <ranges> // for ranges::*
#include <fmt/format.h>
namespace fs = std::filesystem;
namespace {
void prepare_build_environment(const std::string_view& package_name) noexcept {
static const fs::path app_path = utils::fix_path("~/.cache/arch-kernel-manager");
static const fs::path pkgbuilds_path = utils::fix_path("~/.cache/arch-kernel-manager/aur_pkgbuilds");
static const fs::path package_path = utils::fix_path(fmt::format("~/.cache/arch-kernel-manager/aur_pkgbuilds/{}", package_name));
if (!fs::exists(app_path)) {
fs::create_directories(app_path);
}
fs::current_path(app_path);
if (!fs::exists(pkgbuilds_path)) {
fs::create_directories(pkgbuilds_path);
}
fs::current_path(pkgbuilds_path);
// Check if folder exits, but .git doesn't.
if (fs::exists(package_path) && !fs::exists(package_path / ".git")) {
fs::remove_all(package_path);
}
std::int32_t cmd_status{};
if (!fs::exists(package_path)) {
const auto& clone_cmd = fmt::format("git clone https://aur.archlinux.org/{}.git", package_name);
cmd_status = std::system(clone_cmd.c_str());
}
fs::current_path(package_path);
cmd_status += std::system("git checkout --force master");
cmd_status += std::system("git clean -fd");
cmd_status += std::system("git pull");
if (cmd_status != 0) {
std::perror("prepare_build_environment");
}
}
} // namespace
namespace detail {
void install_aur_kernels(std::span<std::string_view> kernel_list) noexcept {
using namespace std::literals;
for (auto&& kernel_name : kernel_list) {
if (auto found = std::ranges::search(kernel_name, "headers"sv); !found.empty()) {
continue;
}
prepare_build_environment(kernel_name);
// Run our build command!
utils::runCmdTerminal("makepkg -sicf --cleanbuild --skipchecksums", false);
}
}
} // namespace detail