1 // Main file for nsscash
3 // Copyright (C) 2019 Simon Ruderich
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Affero 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 Affero General Public License for more details.
15 // You should have received a copy of the GNU Affero General Public License
16 // along with this program. If not, see <https://www.gnu.org/licenses/>.
31 fmt.Fprintf(os.Stderr,
32 "usage: %[1]s [options] fetch <config>\n"+
33 "usage: %[1]s [options] convert <type> <src> <dst>\n"+
52 cfg, err := LoadConfig(args[1])
56 state, err := LoadState(cfg.StatePath)
60 err = handleFiles(cfg, state)
64 // NOTE: Make sure to call WriteState() only if there were no
65 // errors (see WriteState() and README)
66 err = WriteState(cfg.StatePath, state)
78 err := t.UnmarshalText([]byte(args[1]))
83 src, err := ioutil.ReadFile(args[2])
88 if t == FileTypePlain {
90 } else if t == FileTypePasswd {
91 pws, err := ParsePasswds(bytes.NewReader(src))
95 err = SerializePasswds(&x, pws)
99 } else if t == FileTypeGroup {
100 grs, err := ParseGroups(bytes.NewReader(src))
104 err = SerializeGroups(&x, grs)
109 log.Fatalf("unsupported file type %v", t)
112 // We must create the file first or deployFile() will abort
113 f, err := os.Create(args[3])
119 err = deployFile(&File{