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/cmd/safcm-remote/log"
26 "ruderich.org/simon/safcm/cmd/safcm-remote/run"
31 resp safcm.MsgSyncResp
37 triggersActive map[string]bool
43 const logPrefix = "sync remote:"
45 func Handle(req safcm.MsgSyncReq,
46 runner run.Runner, fun log.LogFunc) safcm.MsgSyncResp {
50 log: log.NewLogger(logPrefix, fun),
52 s.cmd = run.NewCmd(runner, s.log)
54 err := s.setDefaults()
56 s.resp.Error = fmt.Sprintf("%s %s", logPrefix, err)
62 s.resp.Error = fmt.Sprintf("%s files: %s", logPrefix, err)
65 err = s.syncPackages()
67 s.resp.Error = fmt.Sprintf("%s packages: %s", logPrefix, err)
70 err = s.syncServices()
72 s.resp.Error = fmt.Sprintf("%s services: %s", logPrefix, err)
75 err = s.syncCommands()
77 s.resp.Error = fmt.Sprintf("%s commands: %s", logPrefix, err)
83 func (s *Sync) setDefaults() error {
84 u, err := user.Current()
88 s.defaultUser = u.Username
89 g, err := user.LookupGroupId(u.Gid)
93 s.defaultGroup = g.Name
95 s.triggersActive = make(map[string]bool)