summaryrefslogtreecommitdiff
path: root/hscript/meta.cc
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 /hscript/meta.cc
parent25750e7495e178fc22a07cd1d9dcfd34c7141036 (diff)
downloadhorizon-790217353e94a4a9ee14d51b8a9e6c2dafc6377d.tar.gz
horizon-790217353e94a4a9ee14d51b8a9e6c2dafc6377d.tar.bz2
horizon-790217353e94a4a9ee14d51b8a9e6c2dafc6377d.tar.xz
horizon-790217353e94a4a9ee14d51b8a9e6c2dafc6377d.zip
hscript: Implement Language::execute
Diffstat (limited to 'hscript/meta.cc')
-rw-r--r--hscript/meta.cc37
1 files changed, 35 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;
}