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 x, err := s.loop.SendRecv(s, conn, safcm.MsgInfoReq{
32 LogLevel: s.config.LogLevel,
33 DetectGroups: s.config.DetectGroups,
38 resp, ok := x.(safcm.MsgInfoResp)
40 return nil, fmt.Errorf("unexpected response %v", x)
43 return nil, fmt.Errorf("%s", resp.Error)
45 return hostInfoRespToGroups(resp), nil
48 // Keep in sync with cmd/safcm/config/groups.go:groupNameRegexp
49 var infoGroupDetectedRegexp = regexp.MustCompile(`[^a-z0-9_-]+`)
51 func hostInfoRespToGroups(resp safcm.MsgInfoResp) []string {
53 hostInfoDetectedGroupName(resp.Goos),
54 hostInfoDetectedGroupName(resp.Goarch),
56 for _, x := range resp.Output {
57 groups = append(groups, hostInfoDetectedGroupName(x))
62 func hostInfoDetectedGroupName(x string) string {
63 x = strings.TrimSpace(x)
64 x = strings.ToLower(x)
65 x = infoGroupDetectedRegexp.ReplaceAllString(x, "_")
66 x = config.GroupDetectedPrefix + "_" + x