summaryrefslogtreecommitdiff
path: root/hscript
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2020-03-24 08:53:46 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2020-03-24 08:53:46 -0500
commitaf4440337fa03df944afce3a6e0de8f277d15216 (patch)
tree41cd9fc874964460578ef9e2e9bb4a7fef4fad21 /hscript
parentf72d30cf04308309bee4728fabb3e746236b2a98 (diff)
downloadhorizon-af4440337fa03df944afce3a6e0de8f277d15216.tar.gz
horizon-af4440337fa03df944afce3a6e0de8f277d15216.tar.bz2
horizon-af4440337fa03df944afce3a6e0de8f277d15216.tar.xz
horizon-af4440337fa03df944afce3a6e0de8f277d15216.zip
hscript: Implement 'Image' script option
This option is for generating images using Horizon. It skips most disk-related operations, except for preparing /etc/fstab. It also skips setting the running system's hostname.
Diffstat (limited to 'hscript')
-rw-r--r--hscript/disk.cc5
-rw-r--r--hscript/meta.cc4
-rw-r--r--hscript/script.cc2
-rw-r--r--hscript/script.hh2
-rw-r--r--hscript/script_e.cc76
5 files changed, 49 insertions, 40 deletions
diff --git a/hscript/disk.cc b/hscript/disk.cc
index 225148b..b0608b3 100644
--- a/hscript/disk.cc
+++ b/hscript/disk.cc
@@ -792,7 +792,7 @@ bool Mount::execute() const {
#endif
/* We have to get the filesystem for the node. */
- if(script->options().test(Simulate)) {
+ if(script->options().test(Simulate) || script->options().test(Image)) {
fstype = "auto";
}
#ifdef HAS_INSTALL_ENV
@@ -818,6 +818,9 @@ bool Mount::execute() const {
std::cout << this->device() << " " << actual_mount << std::endl;
}
#ifdef HAS_INSTALL_ENV
+ else if(script->options().test(Image)) {
+ /* no-op; we don't mount during image creation (but we want fstab) */
+ }
else {
/* mount */
if(!fs::exists(actual_mount, ec)) {
diff --git a/hscript/meta.cc b/hscript/meta.cc
index 2f4e4eb..e0c2b52 100644
--- a/hscript/meta.cc
+++ b/hscript/meta.cc
@@ -95,7 +95,9 @@ bool Hostname::execute() const {
std::cout << "hostname " << actual << std::endl;
}
#ifdef HAS_INSTALL_ENV
- else {
+ else if(script->options().test(Image)) {
+ /* no-op; we don't want to set the image builder's hostname */
+ } else {
if(sethostname(actual.c_str(), actual.size()) == -1) {
output_error("installfile:" + std::to_string(this->lineno()),
"hostname: failed to set host name",
diff --git a/hscript/script.cc b/hscript/script.cc
index 70381d7..cac5f3e 100644
--- a/hscript/script.cc
+++ b/hscript/script.cc
@@ -299,7 +299,7 @@ Script *Script::load(std::istream &sstream, const ScriptOptions &opts) {
if(!the_script->internal->rootpw) {
MISSING_ERROR("rootpw")
}
- if(the_script->internal->mounts.size() == 0) {
+ if(the_script->internal->mounts.size() == 0 && !opts.test(Image)) {
MISSING_ERROR("mount")
}
}
diff --git a/hscript/script.hh b/hscript/script.hh
index 31e486d..5cb6db2 100644
--- a/hscript/script.hh
+++ b/hscript/script.hh
@@ -41,6 +41,8 @@ enum ScriptOptionFlags {
Pretty,
/*! Just print commands that would be run, for testing/debug */
Simulate,
+ /*! Installing to an image; don't mount anything */
+ Image,
/*! Count of flags */
NumFlags
};
diff --git a/hscript/script_e.cc b/hscript/script_e.cc
index 775f93a..91ebe0f 100644
--- a/hscript/script_e.cc
+++ b/hscript/script_e.cc
@@ -96,53 +96,55 @@ bool Script::execute() const {
/**************** DISK SETUP ****************/
output_step_start("disk");
+ if(!opts.test(Image)) {
#ifdef HAS_INSTALL_ENV
- if(opts.test(InstallEnvironment)) ped_device_probe_all();
+ if(opts.test(InstallEnvironment)) ped_device_probe_all();
#endif /* HAS_INSTALL_ENV */
- /* REQ: Runner.Execute.diskid */
- for(auto &diskid : internal->diskids) {
- EXECUTE_OR_FAIL("diskid", diskid)
- }
+ /* REQ: Runner.Execute.diskid */
+ for(auto &diskid : internal->diskids) {
+ EXECUTE_OR_FAIL("diskid", diskid)
+ }
- /* REQ: Runner.Execute.disklabel */
- for(auto &label : internal->disklabels) {
- EXECUTE_OR_FAIL("disklabel", label)
- }
+ /* REQ: Runner.Execute.disklabel */
+ for(auto &label : internal->disklabels) {
+ EXECUTE_OR_FAIL("disklabel", label)
+ }
- /* REQ: Runner.Execute.partition */
- /* Ensure partitions are created in on-disk order. */
- std::sort(internal->partitions.begin(), internal->partitions.end(),
- [](std::unique_ptr<Partition> const &e1,
- std::unique_ptr<Partition> const &e2) {
- return (e1->device() + "p" + std::to_string(e1->partno())) <
- (e2->device() + "p" + std::to_string(e2->partno()));
- });
- for(auto &part : internal->partitions) {
- EXECUTE_OR_FAIL("partition", part)
- }
+ /* REQ: Runner.Execute.partition */
+ /* Ensure partitions are created in on-disk order. */
+ std::sort(internal->partitions.begin(), internal->partitions.end(),
+ [](std::unique_ptr<Partition> const &e1,
+ std::unique_ptr<Partition> const &e2) {
+ return (e1->device() + "p" + std::to_string(e1->partno())) <
+ (e2->device() + "p" + std::to_string(e2->partno()));
+ });
+ for(auto &part : internal->partitions) {
+ EXECUTE_OR_FAIL("partition", part)
+ }
- /* encrypt PVs */
+ /* encrypt PVs */
- /* REQ: Runner.Execute.lvm_pv */
- for(auto &pv : internal->lvm_pvs) {
- EXECUTE_OR_FAIL("lvm_pv", pv)
- }
+ /* REQ: Runner.Execute.lvm_pv */
+ for(auto &pv : internal->lvm_pvs) {
+ EXECUTE_OR_FAIL("lvm_pv", pv)
+ }
- /* REQ: Runner.Execute.lvm_vg */
- for(auto &vg : internal->lvm_vgs) {
- EXECUTE_OR_FAIL("lvm_vg", vg)
- }
+ /* REQ: Runner.Execute.lvm_vg */
+ for(auto &vg : internal->lvm_vgs) {
+ EXECUTE_OR_FAIL("lvm_vg", vg)
+ }
- /* REQ: Runner.Execute.lvm_lv */
- for(auto &lv : internal->lvm_lvs) {
- EXECUTE_OR_FAIL("lvm_lv", lv)
- }
+ /* REQ: Runner.Execute.lvm_lv */
+ for(auto &lv : internal->lvm_lvs) {
+ EXECUTE_OR_FAIL("lvm_lv", lv)
+ }
- /* encrypt */
+ /* encrypt */
- /* REQ: Runner.Execute.fs */
- for(auto &fs : internal->fses) {
- EXECUTE_OR_FAIL("fs", fs)
+ /* REQ: Runner.Execute.fs */
+ for(auto &fs : internal->fses) {
+ EXECUTE_OR_FAIL("fs", fs)
+ }
}
/* REQ: Runner.Execute.mount */