]> ruderich.org/simon Gitweb - safcm/safcm.git/blob - cmd/safcm/main.go
Use SPDX license identifiers
[safcm/safcm.git] / cmd / safcm / main.go
1 // Command line tool to manage remote hosts
2
3 // SPDX-License-Identifier: GPL-3.0-or-later
4 // Copyright (C) 2021-2024  Simon Ruderich
5
6 package main
7
8 import (
9         "log"
10         "os"
11
12         "ruderich.org/simon/safcm/cmd/safcm/config"
13 )
14
15 func usage() {
16         log.SetFlags(0)
17         log.Fatalf("usage: %[1]s sync [<options>] <host|group...>\n"+
18                 "       %[1]s fixperms\n"+
19                 "       %[1]s version\n"+
20                 "", os.Args[0])
21 }
22
23 func main() {
24         if len(os.Args) < 2 {
25                 usage()
26         }
27
28         var err error
29         switch os.Args[1] {
30         case "sync":
31                 err = MainSync(os.Args)
32         case "fixperms":
33                 if len(os.Args) != 2 {
34                         usage()
35                 }
36                 err = MainFixperms()
37         case "version":
38                 if len(os.Args) != 2 {
39                         usage()
40                 }
41                 err = MainVersion()
42         default:
43                 usage()
44         }
45         if err != nil {
46                 log.Fatal(err)
47         }
48 }
49
50 func LoadBaseFiles() (*config.Config, *config.Hosts, map[string][]string,
51         error) {
52
53         cfg, err := config.LoadConfig()
54         if err != nil {
55                 return nil, nil, nil, err
56         }
57         hosts, err := config.LoadHosts()
58         if err != nil {
59                 return nil, nil, nil, err
60         }
61         groups, err := config.LoadGroups(cfg, hosts)
62         if err != nil {
63                 return nil, nil, nil, err
64         }
65         return cfg, hosts, groups, nil
66 }