summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-21 00:32:48 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-21 00:32:48 -0500
commit790217353e94a4a9ee14d51b8a9e6c2dafc6377d (patch)
treed877cba13687f165e39a08027829f3075ca8ca12
parent25750e7495e178fc22a07cd1d9dcfd34c7141036 (diff)
downloadhorizon-790217353e94a4a9ee14d51b8a9e6c2dafc6377d.tar.gz
horizon-790217353e94a4a9ee14d51b8a9e6c2dafc6377d.tar.bz2
horizon-790217353e94a4a9ee14d51b8a9e6c2dafc6377d.tar.xz
horizon-790217353e94a4a9ee14d51b8a9e6c2dafc6377d.zip
hscript: Implement Language::execute
-rw-r--r--hscript/meta.cc37
-rw-r--r--hscript/script.cc7
2 files changed, 42 insertions, 2 deletions
diff --git a/hscript/meta.cc b/hscript/meta.cc
index e5e0ba4..79881f4 100644
--- a/hscript/meta.cc
+++ b/hscript/meta.cc
@@ -16,6 +16,9 @@
#include <set>
#include <sstream>
#ifdef HAS_INSTALL_ENV
+# include <cstring> /* strerror */
+# include <errno.h> /* errno */
+# include <sys/stat.h> /* chmod */
# include <unistd.h>
#endif /* HAS_INSTALL_ENV */
#include "meta.hh"
@@ -246,8 +249,38 @@ Key *Language::parseFromData(const std::string &data, int lineno, int *errors,
}
-bool Language::execute(ScriptOptions) const {
- return false;
+bool Language::execute(ScriptOptions opts) const {
+ if(opts.test(Simulate)) {
+ std::cout << "printf '#!/bin/sh\\" << "nexport LANG=\"%s\"\\" << "n'"
+ << this->value() << " > /target/etc/profile.d/language.sh"
+ << std::endl
+ << "chmod a+x /target/etc/profile.d/language.sh"
+ << std::endl;
+ return true;
+ }
+
+#ifdef HAS_INSTALL_ENV
+ const char *lang_path = "/target/etc/profile.d/language.sh";
+ std::ofstream lang_f(lang_path);
+ if(!lang_f) {
+ output_error("installfile:" + std::to_string(this->lineno()),
+ "language: could not open /etc/profile.d/language.sh "
+ "for writing");
+ return false;
+ }
+ lang_f << "#!/bin/sh" << std::endl << "export LANG=\""
+ << this->value() << "\"" << std::endl;
+ lang_f.close();
+
+ if(chmod(lang_path,
+ S_IRUSR | S_IWUSR | S_IXUSR | S_IXGRP | S_IXOTH) != 0) {
+ output_error("installfile:" + std::to_string(this->lineno()),
+ "language: could not set /etc/profile.d/language.sh "
+ "as executable", strerror(errno));
+ return false;
+ }
+#endif /* HAS_INSTALL_ENV */
+ return true;
}
diff --git a/hscript/script.cc b/hscript/script.cc
index 69a46cc..785e40e 100644
--- a/hscript/script.cc
+++ b/hscript/script.cc
@@ -865,10 +865,17 @@ bool Script::execute() const {
/**************** POST PACKAGE METADATA ****************/
output_step_start("post-metadata");
+
if(!this->internal->rootpw->execute(opts)) {
EXECUTE_FAILURE("post-metadata");
return false;
}
+
+ if(this->internal->lang && !this->internal->lang->execute(opts)) {
+ EXECUTE_FAILURE("post-metadata");
+ return false;
+ }
+
output_step_end("post-metadata");
return true;
}