From 755b4024270dcc7a70d0269a9e39c9455139ccb1 Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Sun, 20 Oct 2019 03:02:08 -0500 Subject: hscript: Implement DiskId::execute --- hscript/CMakeLists.txt | 2 +- hscript/disk.cc | 40 ++++++++++++++++++++++++++++++++++++++-- hscript/script.cc | 50 ++++++++++++++++++++++++++++++++++---------------- 3 files changed, 73 insertions(+), 19 deletions(-) diff --git a/hscript/CMakeLists.txt b/hscript/CMakeLists.txt index 046b1ff..036fa34 100644 --- a/hscript/CMakeLists.txt +++ b/hscript/CMakeLists.txt @@ -21,7 +21,7 @@ ENDIF(INSTALL) add_library(hscript ${HSCRIPT_LIBRARY_TYPE} ${HSCRIPT_SOURCE}) target_compile_features(hscript PRIVATE cxx_nullptr) target_compile_features(hscript PUBLIC cxx_unicode_literals) -target_link_libraries(hscript ${BLKID_LIBRARIES}) +target_link_libraries(hscript ${BLKID_LIBRARIES} ${LIBUDEV_LIBRARIES}) install(TARGETS hscript DESTINATION lib) install(FILES ${HSCRIPT_INCLUDE} DESTINATION include/hscript) diff --git a/hscript/disk.cc b/hscript/disk.cc index 5d3112f..7773467 100644 --- a/hscript/disk.cc +++ b/hscript/disk.cc @@ -16,6 +16,7 @@ #include #ifdef HAS_INSTALL_ENV # include /* blkid_get_tag_value */ +# include /* udev_* */ # include /* mount */ # include /* mkdir, stat */ # include /* S_* */ @@ -67,8 +68,43 @@ bool DiskId::validate(ScriptOptions options) const { return true; } -bool DiskId::execute(ScriptOptions) const { - return false; +bool DiskId::execute(ScriptOptions options) const { + bool match = false; + if(!options.test(InstallEnvironment)) return true; + +#ifdef HAS_INSTALL_ENV + struct udev *udev; + struct udev_device *device; + const char *serial; + + udev = udev_new(); + if(!udev) { + output_error("installfile:" + std::to_string(line), + "diskid: failed to communicate with udevd", + "cannot read disk information"); + return false; + } + device = udev_device_new_from_syspath(udev, _block.c_str()); + if(!device) { + udev_unref(udev); + output_error("installfile:" + std::to_string(line), + "diskid: failed to communicate with udevd", + "cannot read disk information"); + return false; + } + + serial = udev_device_get_property_value(device, "ID_SERIAL"); + /* If we can't get the serial for this device, it's not a disk */ + if(serial) { + std::string full_str(serial); + match = (full_str.find(_ident) != std::string::npos); + } + + udev_device_unref(device); + udev_unref(udev); +#endif /* HAS_INSTALL_ENV */ + + return match; } Key *Mount::parseFromData(const std::string &data, int lineno, int *errors, diff --git a/hscript/script.cc b/hscript/script.cc index f9f16f5..5af0fd4 100644 --- a/hscript/script.cc +++ b/hscript/script.cc @@ -171,8 +171,8 @@ struct Script::ScriptPrivate { "duplicate value for key '" + std::string(KEY) + "'",\ err_str); - bool store_network(Keys::Key* obj, int lineno, int *errors, int *warnings, - ScriptOptions opts) { + bool store_network(Keys::Key* obj, int lineno, int *errors, int *, + ScriptOptions) { if(this->network) { DUPLICATE_ERROR(this->network, "network", this->network->test() ? "true" : "false") @@ -183,8 +183,8 @@ struct Script::ScriptPrivate { return true; } - bool store_hostname(Keys::Key* obj, int lineno, int *errors, int *warnings, - ScriptOptions opts) { + bool store_hostname(Keys::Key* obj, int lineno, int *errors, int *, + ScriptOptions) { if(this->hostname) { DUPLICATE_ERROR(this->hostname, "hostname", this->hostname->value()) @@ -212,8 +212,8 @@ struct Script::ScriptPrivate { return true; } - bool store_rootpw(Keys::Key* obj, int lineno, int *errors, int *warnings, - ScriptOptions opts) { + bool store_rootpw(Keys::Key* obj, int lineno, int *errors, int *, + ScriptOptions) { if(this->rootpw) { DUPLICATE_ERROR(this->rootpw, std::string("rootpw"), "an encrypted passphrase") @@ -224,8 +224,8 @@ struct Script::ScriptPrivate { return true; } - bool store_firmware(Keys::Key *obj, int lineno, int *errors, int *warnings, - ScriptOptions opts) { + bool store_firmware(Keys::Key *obj, int lineno, int *errors, int *, + ScriptOptions) { std::unique_ptr f(dynamic_cast(obj)); #ifdef NON_LIBRE_FIRMWARE if(this->firmware) { @@ -241,8 +241,8 @@ struct Script::ScriptPrivate { #endif } - bool store_username(Keys::Key *obj, int lineno, int *errors, int *warnings, - ScriptOptions opts) { + bool store_username(Keys::Key *obj, int lineno, int *errors, int *, + ScriptOptions) { if(accounts.size() >= 255) { if(errors) *errors += 1; output_error("installfile:" + std::to_string(lineno), @@ -274,7 +274,7 @@ struct Script::ScriptPrivate { UserDetail *detail = (*accounts.find(OBJ->username())).second.get(); bool store_useralias(Keys::Key* obj, int lineno, int *errors, - int *warnings, ScriptOptions opts) { + int *, ScriptOptions) { std::unique_ptr alias(dynamic_cast(obj)); GET_USER_DETAIL(alias, "useralias") /* REQ: Runner.Validate.useralias.Unique */ @@ -286,8 +286,8 @@ struct Script::ScriptPrivate { return true; } - bool store_userpw(Keys::Key *obj, int lineno, int *errors, int *warnings, - ScriptOptions opts) { + bool store_userpw(Keys::Key *obj, int lineno, int *errors, int *, + ScriptOptions) { std::unique_ptr pw(dynamic_cast(obj)); GET_USER_DETAIL(pw, "userpw") /* REQ: Runner.Validate.userpw.Unique */ @@ -300,8 +300,8 @@ struct Script::ScriptPrivate { return true; } - bool store_usericon(Keys::Key *obj, int lineno, int *errors, int *warnings, - ScriptOptions opts) { + bool store_usericon(Keys::Key *obj, int lineno, int *errors, int *, + ScriptOptions) { std::unique_ptr icon(dynamic_cast(obj)); GET_USER_DETAIL(icon, "usericon") /* REQ: Runner.Validate.usericon.Unique */ @@ -314,7 +314,7 @@ struct Script::ScriptPrivate { } bool store_usergroups(Keys::Key* obj, int lineno, int *errors, - int *warnings, ScriptOptions opts) { + int *, ScriptOptions) { std::unique_ptr grp(dynamic_cast(obj)); GET_USER_DETAIL(grp, "usergroups") detail->groups.push_back(std::move(grp)); @@ -726,6 +726,24 @@ bool Script::execute() const { /**************** DISK SETUP ****************/ output_step_start("disk"); + /* REQ: Runner.Execute.diskid */ + for(auto &diskid : this->internal->diskids) { + if(!diskid->execute(opts)) { + EXECUTE_FAILURE("disk"); + return false; + } + } + + /* disklabel */ + /* partition */ + /* encrypt PVs */ + /* lvm_pv */ + /* lvm_vg */ + /* lvm_lv */ + /* encrypt */ + /* fs */ + + /* REQ: Runner.Execute.mount */ /* Sort by mountpoint. * This ensures that any subdirectory mounts come after their parent. */ std::sort(this->internal->mounts.begin(), this->internal->mounts.end(), -- cgit v1.2.3-70-g09d2