diff options
author | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2019-10-20 00:19:53 -0500 |
---|---|---|
committer | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2019-10-20 00:19:53 -0500 |
commit | 1fa3717743c217bb3dbe643a37a7ba96b5ff0ebd (patch) | |
tree | 07d68982ceb9c9201fe750d7f973012bb1eff133 /hscript/meta.cc | |
parent | f4202f7fcf0484b31e36db187de8557a8eba3065 (diff) | |
download | horizon-1fa3717743c217bb3dbe643a37a7ba96b5ff0ebd.tar.gz horizon-1fa3717743c217bb3dbe643a37a7ba96b5ff0ebd.tar.bz2 horizon-1fa3717743c217bb3dbe643a37a7ba96b5ff0ebd.tar.xz horizon-1fa3717743c217bb3dbe643a37a7ba96b5ff0ebd.zip |
Make Installation Environment code conditional
Diffstat (limited to 'hscript/meta.cc')
-rw-r--r-- | hscript/meta.cc | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/hscript/meta.cc b/hscript/meta.cc index b7da9d2..02b294d 100644 --- a/hscript/meta.cc +++ b/hscript/meta.cc @@ -13,7 +13,9 @@ #include <assert.h> #include <fstream> #include <regex> -#include <unistd.h> +#ifdef HAS_INSTALL_ENV +# include <unistd.h> +#endif /* HAS_INSTALL_ENV */ #include "meta.hh" #include "util/output.hh" @@ -87,14 +89,17 @@ bool Hostname::execute(ScriptOptions opts) const { "hostname: set hostname to '" + actual + "'"); if(opts.test(Simulate)) { std::cout << "hostname " << actual << std::endl; - } else { /* LCOV_EXCL_START */ + } +#ifdef HAS_INSTALL_ENV + else { if(sethostname(actual.c_str(), actual.size()) == -1) { output_error("installfile:" + std::to_string(this->lineno()), "hostname: failed to set host name", std::string(strerror(errno))); return false; } - } /* LCOV_EXCL_STOP */ + } +#endif /* HAS_INSTALL_ENV */ /* Runner.Execute.hostname.Write. */ output_info("installfile:" + std::to_string(this->lineno()), @@ -102,7 +107,9 @@ bool Hostname::execute(ScriptOptions opts) const { if(opts.test(Simulate)) { std::cout << "printf '%s' " << actual << " > /target/etc/hostname" << std::endl; - } else { /* LCOV_EXCL_START */ + } +#ifdef HAS_INSTALL_ENV + else { std::ofstream hostname_f("/target/etc/hostname"); if(!hostname_f) { output_error("installfile:" + std::to_string(this->lineno()), @@ -110,7 +117,8 @@ bool Hostname::execute(ScriptOptions opts) const { return false; } hostname_f << actual; - } /* LCOV_EXCL_STOP */ + } +#endif /* HAS_INSTALL_ENV */ /* The second condition ensures that it isn't a single dot that simply * terminates the nodename. */ @@ -121,7 +129,9 @@ bool Hostname::execute(ScriptOptions opts) const { if(opts.test(Simulate)) { std::cout << "printf 'dns_domain_lo=\"" << domain << "\"\\" << "n' >> /target/etc/conf.d/net" << std::endl; - } else { /* LCOV_EXCL_START */ + } +#ifdef HAS_INSTALL_ENV + else { std::ofstream net_conf_f("/target/etc/conf.d/net"); if(!net_conf_f) { output_error("installfile:" + std::to_string(this->lineno()), @@ -130,7 +140,8 @@ bool Hostname::execute(ScriptOptions opts) const { return false; } net_conf_f << "dns_domain_lo\"" << domain << "\"" << std::endl; - } /* LCOV_EXCL_STOP */ + } +#endif /* HAS_INSTALL_ENV */ } return true; @@ -242,7 +253,7 @@ bool Repository::execute(ScriptOptions opts) const { return true; } - /* LCOV_EXCL_START */ +#ifdef HAS_INSTALL_ENV std::ofstream repo_f("/target/etc/apk/repositories", std::ios_base::ate); if(!repo_f) { @@ -255,5 +266,7 @@ bool Repository::execute(ScriptOptions opts) const { repo_f << this->value() << std::endl; return true; - /* LCOV_EXCL_STOP */ +#else + return false; +#endif /* HAS_INSTALL_ENV */ } |