1 // MsgSyncReq: sync data on the 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/>.
24 "ruderich.org/simon/safcm"
25 "ruderich.org/simon/safcm/remote/log"
26 "ruderich.org/simon/safcm/remote/run"
31 resp safcm.MsgSyncResp
37 triggersActive map[string]bool
43 func Handle(req safcm.MsgSyncReq,
44 runner run.Runner, fun log.LogFunc) safcm.MsgSyncResp {
48 log: log.NewLogger(fun),
50 s.cmd = run.NewCmd(runner, s.log)
52 err := s.setDefaults()
54 s.resp.Error = fmt.Sprintf("%v", err)
60 s.resp.Error = fmt.Sprintf("files: %v", err)
63 err = s.syncPackages()
65 s.resp.Error = fmt.Sprintf("packages: %v", err)
68 err = s.syncServices()
70 s.resp.Error = fmt.Sprintf("services: %v", err)
73 err = s.syncCommands()
75 s.resp.Error = fmt.Sprintf("commands: %v", err)
81 func (s *Sync) setDefaults() error {
82 u, err := user.Current()
86 s.defaultUser = u.Username
87 g, err := user.LookupGroupId(u.Gid)
91 s.defaultGroup = g.Name
93 s.triggersActive = make(map[string]bool)