summaryrefslogtreecommitdiff
path: root/hscript/meta.cc
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-08 21:19:13 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-08 21:19:13 -0500
commit7c1efb0e68e7decd2d5276e7ff02f65bde9bbf9a (patch)
tree4d11018a7dda0c5ba6b1c1e6bb1eaa86de6db026 /hscript/meta.cc
parentbe1cc09981d24c94a07f08c615e66e3a261294af (diff)
downloadhorizon-7c1efb0e68e7decd2d5276e7ff02f65bde9bbf9a.tar.gz
horizon-7c1efb0e68e7decd2d5276e7ff02f65bde9bbf9a.tar.bz2
horizon-7c1efb0e68e7decd2d5276e7ff02f65bde9bbf9a.tar.xz
horizon-7c1efb0e68e7decd2d5276e7ff02f65bde9bbf9a.zip
hscript: Initial attempt at handling 'pkginstall' key
Diffstat (limited to 'hscript/meta.cc')
-rw-r--r--hscript/meta.cc31
1 files changed, 29 insertions, 2 deletions
diff --git a/hscript/meta.cc b/hscript/meta.cc
index 83c6269..f333f0b 100644
--- a/hscript/meta.cc
+++ b/hscript/meta.cc
@@ -19,8 +19,7 @@ using namespace Horizon::Keys;
Key *Hostname::parseFromData(const std::string data, int lineno, int *errors,
int *warnings) {
std::regex valid_re("[A-Za-z0-9.]*");
- bool valid = std::regex_match(data, valid_re);
- if(!valid) {
+ if(!std::regex_match(data, valid_re)) {
if(errors) *errors += 1;
output_error("installfile:" + std::to_string(lineno),
"hostname: expected machine or DNS name",
@@ -39,3 +38,31 @@ bool Hostname::execute() const {
/* Write the hostname to /etc/hostname in the target environment. */
return false;
}
+
+
+Key *PkgInstall::parseFromData(const std::string data, int lineno, int *errors,
+ int *warnings) {
+ std::regex valid_pkg("[0-9A-Za-z_-]*((>?<|[<>]?=|[~>])[0-9A-Za-z-_.]+)?");
+ std::string next_pkg;
+ std::istringstream stream(data);
+ std::set<std::string> all_pkgs;
+
+ while(stream >> next_pkg) {
+ if(!std::regex_match(next_pkg, valid_pkg)) {
+ if(errors) *errors += 1;
+ output_error("installfile:" + std::to_string(lineno),
+ "pkginstall: expected package name",
+ "'" + next_pkg + "' is not a valid package or atom");
+ return nullptr;
+ }
+ if(all_pkgs.find(next_pkg) != all_pkgs.end()) {
+ if(warnings) *warnings += 1;
+ output_warning("installfile:" + std::to_string(lineno),
+ "pkginstall: package '" + next_pkg +
+ "' is already in the target package set");
+ continue;
+ }
+ all_pkgs.insert(next_pkg);
+ }
+ return new PkgInstall(lineno, all_pkgs);
+}