summaryrefslogtreecommitdiff
path: root/hscript/meta.cc
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2019-11-02 17:33:28 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2019-11-02 17:33:28 -0500
commitdd7559561a8a7f4fef7a4bb8b23e2894eca4594c (patch)
treea9feba9457e0d05eb6da967e3134f355e738e51f /hscript/meta.cc
parent8270ab3308f2522d0150e9040ea44883ce175e70 (diff)
downloadhorizon-dd7559561a8a7f4fef7a4bb8b23e2894eca4594c.tar.gz
horizon-dd7559561a8a7f4fef7a4bb8b23e2894eca4594c.tar.bz2
horizon-dd7559561a8a7f4fef7a4bb8b23e2894eca4594c.tar.xz
horizon-dd7559561a8a7f4fef7a4bb8b23e2894eca4594c.zip
hscript: Add download_file helper and implement SigningKey::execute0.1.0
Diffstat (limited to 'hscript/meta.cc')
-rw-r--r--hscript/meta.cc47
1 files changed, 45 insertions, 2 deletions
diff --git a/hscript/meta.cc b/hscript/meta.cc
index d664992..1124988 100644
--- a/hscript/meta.cc
+++ b/hscript/meta.cc
@@ -20,6 +20,7 @@
#endif /* HAS_INSTALL_ENV */
#include <unistd.h> /* access - used by tz code even in RT env */
#include "meta.hh"
+#include "util.hh"
#include "util/output.hh"
using namespace Horizon::Keys;
@@ -511,6 +512,48 @@ bool SigningKey::validate(ScriptOptions) const {
return true;
}
-bool SigningKey::execute(ScriptOptions) const {
- return false;
+bool SigningKey::execute(ScriptOptions opts) const {
+ /* everything after the last / in the value is the filename */
+ const std::string name(_value.substr(_value.find_last_of('/') + 1));
+
+ const std::string target("/target/etc/apk/keys/" + name);
+
+ output_info("installfile:" + std::to_string(line),
+ "signingkey: trusting " + name + " for repository signing");
+
+ if(opts.test(Simulate)) {
+ std::cout << "mkdir -p /target/etc/apk/keys" << std::endl;
+ if(_value[0] == '/') {
+ std::cout << "cp " << _value << " " << target << std::endl;
+ } else {
+ std::cout << "curl -L -o " << target << " " << _value << std::endl;
+ }
+ return true;
+ }
+
+#ifdef HAS_INSTALL_ENV
+ error_code ec;
+ if(!fs::exists("/target/etc/apk/keys")) {
+ fs::create_directory("/target/etc/apk/keys", ec);
+ if(ec) {
+ output_error("installfile:" + std::to_string(line),
+ "signingkey: could not initialise target repository "
+ "keys directory", ec.message());
+ return false;
+ }
+ }
+
+ if(_value[0] == '/') {
+ fs::copy_file(_value, target, fs_overwrite, ec);
+ if(ec) {
+ output_error("installfile:" + std::to_string(line),
+ "signingkey: could not copy signing key to target",
+ ec.message());
+ return false;
+ }
+ } else {
+ return download_file(_value, target);
+ }
+#endif /* HAS_INSTALL_ENV */
+ return true;
}