mirror of
https://github.com/CachyOS/New-Cli-Installer.git
synced 2025-01-23 22:42:31 +08:00
🧹 move hwclock into gucc
This commit is contained in:
parent
742022ec5c
commit
ec7b6f47c6
@ -29,6 +29,7 @@ add_library(${PROJECT_NAME} SHARED
|
|||||||
src/autologin.cpp include/gucc/autologin.hpp
|
src/autologin.cpp include/gucc/autologin.hpp
|
||||||
src/mtab.cpp include/gucc/mtab.hpp
|
src/mtab.cpp include/gucc/mtab.hpp
|
||||||
src/umount_partitions.cpp include/gucc/umount_partitions.hpp
|
src/umount_partitions.cpp include/gucc/umount_partitions.hpp
|
||||||
|
src/hwclock.cpp include/gucc/hwclock.hpp
|
||||||
#src/chwd_profiles.cpp src/chwd_profiles.hpp
|
#src/chwd_profiles.cpp src/chwd_profiles.hpp
|
||||||
#src/disk.cpp src/disk.hpp
|
#src/disk.cpp src/disk.hpp
|
||||||
)
|
)
|
||||||
|
16
gucc/include/gucc/hwclock.hpp
Normal file
16
gucc/include/gucc/hwclock.hpp
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#ifndef HWCLOCK_HPP
|
||||||
|
#define HWCLOCK_HPP
|
||||||
|
|
||||||
|
#include <string_view> // for string_view
|
||||||
|
|
||||||
|
namespace gucc::hwclock {
|
||||||
|
|
||||||
|
// set utc hwclock
|
||||||
|
auto set_hwclock_utc(std::string_view root_mountpoint) noexcept -> bool;
|
||||||
|
|
||||||
|
// set localtime hwclock
|
||||||
|
auto set_hwclock_localtime(std::string_view root_mountpoint) noexcept -> bool;
|
||||||
|
|
||||||
|
} // namespace gucc::hwclock
|
||||||
|
|
||||||
|
#endif // HWCLOCK_HPP
|
@ -19,6 +19,7 @@ gucc_lib = library('gucc',
|
|||||||
'src/autologin.cpp',
|
'src/autologin.cpp',
|
||||||
'src/mtab.cpp',
|
'src/mtab.cpp',
|
||||||
'src/umount_partitions.cpp',
|
'src/umount_partitions.cpp',
|
||||||
|
'src/hwclock.cpp',
|
||||||
],
|
],
|
||||||
include_directories : [include_directories('include')],
|
include_directories : [include_directories('include')],
|
||||||
dependencies: deps
|
dependencies: deps
|
||||||
|
42
gucc/src/hwclock.cpp
Normal file
42
gucc/src/hwclock.cpp
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
#include "gucc/hwclock.hpp"
|
||||||
|
#include "gucc/io_utils.hpp"
|
||||||
|
|
||||||
|
#include <fmt/compile.h>
|
||||||
|
#include <fmt/format.h>
|
||||||
|
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
|
using namespace std::string_view_literals;
|
||||||
|
|
||||||
|
namespace gucc::hwclock {
|
||||||
|
|
||||||
|
auto set_hwclock_utc(std::string_view root_mountpoint) noexcept -> bool {
|
||||||
|
// try default
|
||||||
|
static constexpr auto hwclock_cmd = "hwclock --systohc --utc"sv;
|
||||||
|
if (utils::arch_chroot_checked(hwclock_cmd, root_mountpoint)) {
|
||||||
|
spdlog::info("hwclock UTC set on '{}'", root_mountpoint);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// try fallback with direct ISA
|
||||||
|
static constexpr auto hwclock_isa_cmd = "hwclock --systohc --utc --directisa"sv;
|
||||||
|
if (utils::arch_chroot_checked(hwclock_isa_cmd, root_mountpoint)) {
|
||||||
|
spdlog::info("hwclock UTC set using direct ISA on '{}'", root_mountpoint);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto set_hwclock_localtime(std::string_view root_mountpoint) noexcept -> bool {
|
||||||
|
// try default
|
||||||
|
static constexpr auto hwclock_cmd = "hwclock --systohc --localtime"sv;
|
||||||
|
if (utils::arch_chroot_checked(hwclock_cmd, root_mountpoint)) {
|
||||||
|
spdlog::info("hwclock localtime set on '{}'", root_mountpoint);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace gucc::hwclock
|
@ -11,6 +11,7 @@
|
|||||||
#include "gucc/cpu.hpp"
|
#include "gucc/cpu.hpp"
|
||||||
#include "gucc/file_utils.hpp"
|
#include "gucc/file_utils.hpp"
|
||||||
#include "gucc/fs_utils.hpp"
|
#include "gucc/fs_utils.hpp"
|
||||||
|
#include "gucc/hwclock.hpp"
|
||||||
#include "gucc/initcpio.hpp"
|
#include "gucc/initcpio.hpp"
|
||||||
#include "gucc/io_utils.hpp"
|
#include "gucc/io_utils.hpp"
|
||||||
#include "gucc/locale.hpp"
|
#include "gucc/locale.hpp"
|
||||||
@ -432,7 +433,21 @@ void set_timezone(const std::string_view& timezone) noexcept {
|
|||||||
void set_hw_clock(const std::string_view& clock_type) noexcept {
|
void set_hw_clock(const std::string_view& clock_type) noexcept {
|
||||||
spdlog::info("Clock type is: {}", clock_type);
|
spdlog::info("Clock type is: {}", clock_type);
|
||||||
#ifdef NDEVENV
|
#ifdef NDEVENV
|
||||||
utils::arch_chroot(fmt::format(FMT_COMPILE("hwclock --systohc --{}"), clock_type), false);
|
auto* config_instance = Config::instance();
|
||||||
|
auto& config_data = config_instance->data();
|
||||||
|
const auto& mountpoint = std::get<std::string>(config_data["MOUNTPOINT"]);
|
||||||
|
|
||||||
|
if (clock_type == "utc"sv) {
|
||||||
|
if (!gucc::hwclock::set_hwclock_utc(mountpoint)) {
|
||||||
|
spdlog::error("Failed to set UTC hwclock");
|
||||||
|
}
|
||||||
|
} else if (clock_type == "localtime"sv) {
|
||||||
|
if (!gucc::hwclock::set_hwclock_localtime(mountpoint)) {
|
||||||
|
spdlog::error("Failed to set localtime hwclock");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
spdlog::error("Unknown clock type {}", clock_type);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user