X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=remote%2Finfo%2Finfo.go;fp=remote%2Finfo%2Finfo.go;h=b58752d3931b91e0d711a282e341f89bb29abf47;hb=9269fa3c94e700afc0be823f58ea473a2db8f3dc;hp=0000000000000000000000000000000000000000;hpb=fd97e8019e2ab166d9475ed59782c86247d8430b;p=safcm%2Fsafcm.git diff --git a/remote/info/info.go b/remote/info/info.go new file mode 100644 index 0000000..b58752d --- /dev/null +++ b/remote/info/info.go @@ -0,0 +1,67 @@ +// MsgInfoReq: collect information about the remote host + +// Copyright (C) 2021 Simon Ruderich +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +package info + +import ( + "fmt" + "runtime" + + "ruderich.org/simon/safcm" + "ruderich.org/simon/safcm/remote/log" + "ruderich.org/simon/safcm/remote/run" +) + +type Info struct { + req safcm.MsgInfoReq + resp safcm.MsgInfoResp + + cmd *run.Cmd + logger *log.Logger +} + +func Handle(req safcm.MsgInfoReq, + runner run.Runner, fun log.LogFunc) safcm.MsgInfoResp { + + i := Info{ + req: req, + logger: log.NewLogger(fun), + } + i.cmd = run.NewCmd(runner, i.logger) + + err := i.handle() + if err != nil { + i.resp.Error = fmt.Sprintf("%v", err) + } + return i.resp +} + +func (i *Info) handle() error { + i.resp.Goos = runtime.GOOS + i.resp.Goarch = runtime.GOARCH + + for _, x := range i.req.DetectGroups { + stdout, _, err := i.cmd.Run("detect group", + "/bin/sh", "-c", x) + if err != nil { + return err + } + i.resp.Output = append(i.resp.Output, string(stdout)) + } + + return nil +}