X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=cmd%2Fsafcm-remote%2Fsync%2Fsync.go;fp=cmd%2Fsafcm-remote%2Fsync%2Fsync.go;h=0000000000000000000000000000000000000000;hb=9269fa3c94e700afc0be823f58ea473a2db8f3dc;hp=6835ca48f7b177d09963bea8c1a9ea336221d709;hpb=fd97e8019e2ab166d9475ed59782c86247d8430b;p=safcm%2Fsafcm.git diff --git a/cmd/safcm-remote/sync/sync.go b/cmd/safcm-remote/sync/sync.go deleted file mode 100644 index 6835ca4..0000000 --- a/cmd/safcm-remote/sync/sync.go +++ /dev/null @@ -1,96 +0,0 @@ -// MsgSyncReq: sync data on 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 sync - -import ( - "fmt" - "os/user" - - "ruderich.org/simon/safcm" - "ruderich.org/simon/safcm/cmd/safcm-remote/log" - "ruderich.org/simon/safcm/cmd/safcm-remote/run" -) - -type Sync struct { - req safcm.MsgSyncReq - resp safcm.MsgSyncResp - - defaultUser string - defaultGroup string - - triggers []string - triggersActive map[string]bool - - cmd *run.Cmd - log *log.Logger -} - -func Handle(req safcm.MsgSyncReq, - runner run.Runner, fun log.LogFunc) safcm.MsgSyncResp { - - s := &Sync{ - req: req, - log: log.NewLogger(fun), - } - s.cmd = run.NewCmd(runner, s.log) - - err := s.setDefaults() - if err != nil { - s.resp.Error = fmt.Sprintf("%v", err) - return s.resp - } - - err = s.syncFiles() - if err != nil { - s.resp.Error = fmt.Sprintf("files: %v", err) - return s.resp - } - err = s.syncPackages() - if err != nil { - s.resp.Error = fmt.Sprintf("packages: %v", err) - return s.resp - } - err = s.syncServices() - if err != nil { - s.resp.Error = fmt.Sprintf("services: %v", err) - return s.resp - } - err = s.syncCommands() - if err != nil { - s.resp.Error = fmt.Sprintf("commands: %v", err) - return s.resp - } - return s.resp -} - -func (s *Sync) setDefaults() error { - u, err := user.Current() - if err != nil { - return err - } - s.defaultUser = u.Username - g, err := user.LookupGroupId(u.Gid) - if err != nil { - return err - } - s.defaultGroup = g.Name - - s.triggersActive = make(map[string]bool) - - return nil -}