From 8fd273ac2810c4ffed616877b191dba86355ca6c Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Mon, 4 Nov 2019 18:15:50 -0600 Subject: hscript: Implement Keymap::execute --- hscript/meta.cc | 36 +++++++++++++++++++++++++++++++++++- hscript/script_e.cc | 5 ++++- 2 files changed, 39 insertions(+), 2 deletions(-) (limited to 'hscript') diff --git a/hscript/meta.cc b/hscript/meta.cc index 4cb25bb..b5c2beb 100644 --- a/hscript/meta.cc +++ b/hscript/meta.cc @@ -339,7 +339,41 @@ bool Keymap::validate(ScriptOptions) const { return true; } -bool Keymap::execute(ScriptOptions) const { +bool Keymap::execute(ScriptOptions opts) const { + const std::string conf("# KEYBOARD CONFIGURATION FILE\n\ +\n\ +# Consult the keyboard(5) manual page.\n\ +\n\ +XKBMODEL=pc105\n\ +XKBLAYOUT=" + _value + "\n\ +XKBVARIANT=\n\ +XKBOPTIONS=\n\ +\n\ +BACKSPACE=guess" + ); + + output_info("installfile:" + std::to_string(line), + "keymap: setting system keyboard map to " + _value); + + if(opts.test(Simulate)) { + std::cout << "cat >/target/etc/default/keyboard <<-KEYCONF" + << std::endl; + std::cout << conf << std::endl; + std::cout << "KEYCONF" << std::endl; + return true; + } + +#ifdef HAS_INSTALL_ENV + std::ofstream keyconf("/target/etc/default/keyboard", + std::ios_base::trunc); + if(!keyconf) { + output_error("installfile:" + std::to_string(line), + "keymap: cannot write target keyboard configuration"); + return false; + } + + keyconf << conf; +#endif /* HAS_INSTALL_ENV */ return true; } diff --git a/hscript/script_e.cc b/hscript/script_e.cc index ef43bba..e03b4ad 100644 --- a/hscript/script_e.cc +++ b/hscript/script_e.cc @@ -455,7 +455,10 @@ bool Script::execute() const { return false; } - /* keymap */ + if(internal->keymap && !internal->keymap->execute(opts)) { + EXECUTE_FAILURE("keymap"); + return false; + } /* UserAccounts */ if(!internal->tzone->execute(opts)) { -- cgit v1.2.3-60-g2f50