summaryrefslogtreecommitdiff
path: root/hscript
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-20 03:02:08 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-20 03:02:08 -0500
commit755b4024270dcc7a70d0269a9e39c9455139ccb1 (patch)
tree645bb2c2d2efda903e138f0b0971bf66433822f5 /hscript
parent7bfb0ad102bef9810a685393490f4f9d8497b978 (diff)
downloadhorizon-755b4024270dcc7a70d0269a9e39c9455139ccb1.tar.gz
horizon-755b4024270dcc7a70d0269a9e39c9455139ccb1.tar.bz2
horizon-755b4024270dcc7a70d0269a9e39c9455139ccb1.tar.xz
horizon-755b4024270dcc7a70d0269a9e39c9455139ccb1.zip
hscript: Implement DiskId::execute
Diffstat (limited to 'hscript')
-rw-r--r--hscript/CMakeLists.txt2
-rw-r--r--hscript/disk.cc40
-rw-r--r--hscript/script.cc50
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 <string>
#ifdef HAS_INSTALL_ENV
# include <blkid/blkid.h> /* blkid_get_tag_value */
+# include <libudev.h> /* udev_* */
# include <sys/mount.h> /* mount */
# include <sys/stat.h> /* mkdir, stat */
# include <sys/types.h> /* 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<Firmware> f(dynamic_cast<Firmware *>(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<UserAlias> alias(dynamic_cast<UserAlias *>(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<UserPassphrase> pw(dynamic_cast<UserPassphrase *>(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<UserIcon> icon(dynamic_cast<UserIcon *>(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<UserGroups> grp(dynamic_cast<UserGroups *>(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(),