Write a remote configuration utility called 'rconfig'. This initial
[dragonfly.git] / sbin / rconfig / rconfig.c
1 /*
2  * rconfig - Remote configurator
3  *
4  *      rconfig [-W workingdir] [server_ip[:tag]]
5  *      rconfig [-f configfile] -s
6  *
7  * $DragonFly: src/sbin/rconfig/rconfig.c,v 1.1 2004/06/18 02:46:46 dillon Exp $
8  */
9
10 #include "defs.h"
11
12 const char *WorkDir = "/tmp";
13 const char *ConfigFiles = "/etc/defaults/rconfig.conf:/etc/rconfig.conf";
14 const char *TagDir = "/usr/local/etc/rconfig";
15 tag_t AddrBase;
16 tag_t VarBase;
17 int VerboseOpt;
18
19 static void usage(int code);
20 static void addTag(tag_t *basep, const char *tag, int flags);
21
22 int
23 main(int ac, char **av)
24 {
25     int ch;
26     int i;
27     int serverMode = 0;
28     
29     while ((ch = getopt(ac, av, "aD:W:irt:f:sv")) != -1) {
30         switch(ch) {
31         case 'a':       /* auto tag / standard broadcast */
32             addTag(&AddrBase, NULL, 0);
33             break;
34         case 'W':       /* specify working directory */
35             WorkDir = optarg;
36             break;
37         case 'T':
38             TagDir = optarg;
39             break;
40         case 'C':       /* specify server config file(s) (colon delimited) */
41             ConfigFiles = optarg;
42             break;
43         case 's':       /* run as server using config file */
44             serverMode = 1;
45             break;
46         case 'v':
47             VerboseOpt = 1;
48             break;
49         default:
50             usage(1);
51             /* not reached */
52         }
53     }
54     for (i = optind; i < ac; ++i) {
55         if (strchr(av[i], '='))
56             addTag(&VarBase, av[i], 0);
57         else
58             addTag(&AddrBase, av[i], 0);
59     }
60     if (AddrBase == NULL)
61         usage(1);
62     if (serverMode)
63         doServer();
64     else
65         doClient();
66     return(0);
67 }
68
69 static
70 void
71 addTag(tag_t *basep, const char *name, int flags)
72 {
73     tag_t tag = calloc(sizeof(struct tag), 1);
74
75     while ((*basep) != NULL)
76         basep = &(*basep)->next;
77
78     tag->name = name;
79     tag->flags = flags;
80     *basep = tag;
81 }
82
83 static void
84 usage(int code)
85 {
86     fprintf(stderr, "rconfig [-W workdir] [-f servconfig] "
87                     "[-s] [var=data]* [server_ip[:tag]]* \n");
88     exit(code);
89 }
90