1 // "sync" sub-command: collect information from remote host
3 // Copyright (C) 2021 Simon Ruderich
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
25 "ruderich.org/simon/safcm"
26 "ruderich.org/simon/safcm/cmd/safcm/config"
27 "ruderich.org/simon/safcm/rpc"
30 func (s *Sync) hostInfo(conn *rpc.Conn) ([]string, error) {
31 resp, err := s.loop.HostInfoMsg(s, conn, safcm.MsgInfoReq{
32 LogLevel: s.config.LogLevel,
33 DetectGroups: s.config.DetectGroups,
39 return nil, fmt.Errorf("%s", resp.Error)
41 return hostInfoRespToGroups(resp), nil
44 // Keep in sync with cmd/safcm/config/groups.go:groupNameRegexp
45 var infoGroupDetectedRegexp = regexp.MustCompile(`[^a-z0-9_-]+`)
47 func hostInfoRespToGroups(resp safcm.MsgInfoResp) []string {
49 hostInfoDetectedGroupName(resp.Goos),
50 hostInfoDetectedGroupName(resp.Goarch),
52 for _, x := range resp.Output {
53 groups = append(groups, hostInfoDetectedGroupName(x))
58 func hostInfoDetectedGroupName(x string) string {
59 x = strings.TrimSpace(x)
60 x = strings.ToLower(x)
61 x = infoGroupDetectedRegexp.ReplaceAllString(x, "_")
62 x = config.GroupDetectedPrefix + "_" + x