summaryrefslogtreecommitdiff
path: root/hscript/meta.cc
diff options
context:
space:
mode:
Diffstat (limited to 'hscript/meta.cc')
-rw-r--r--hscript/meta.cc36
1 files changed, 36 insertions, 0 deletions
diff --git a/hscript/meta.cc b/hscript/meta.cc
index ee34372..8079b1a 100644
--- a/hscript/meta.cc
+++ b/hscript/meta.cc
@@ -708,6 +708,42 @@ bool Version::execute() const {
/* LCOV_EXCL_STOP */
+Key* RootShell::parseFromData(const std::string &data,
+ const ScriptLocation &pos, int *errors, int *,
+ const Script *script) {
+ if(data.at(0) != '/') {
+ if(errors) *errors += 1;
+ output_error(pos, "rootshell: invalid shell specified", data);
+ return nullptr;
+ }
+
+ return new RootShell(script, pos, data);
+}
+
+bool RootShell::execute() const {
+ auto target = script->targetDirectory();
+
+ if(script->options().test(Simulate)) {
+ std::cout << "[ -x " << target << _value << "] && "
+ << "sed -i 's#/root:/bin/sh$#/root:" << _value << "#' "
+ << target << "/etc/passwd" << std::endl;
+ }
+#ifdef HAS_INSTALL_ENV
+ else {
+ if(fs::exists(target + _value)) {
+ run_command("sed", {"-i", "s#/root:/bin/sh$#/root:" + _value + "#",
+ script->targetDirectory() + "/etc/passwd"});
+ } else {
+ output_warning(pos, "shell " + _value +
+ " not found; leaving root shell as /bin/sh");
+ }
+ }
+#endif /* HAS_INSTALL_ENV */
+
+ return true;
+}
+
+
const std::string my_arch(const Horizon::Script *script) {
const Key *arch_key = script->getOneValue("arch");
if(arch_key != nullptr) {