-
Notifications
You must be signed in to change notification settings - Fork 2
/
README
101 lines (74 loc) · 2.69 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
Usage
=====
Confctl is a tool designed for easy access to configuration files in C-like
syntax from shell scripts. For example, say you have a configuration file
that looks like this:
interfaces {
eth0 {
ip-address 192.168.1.1
mtu 9000
}
eth1 {
ip-address 192.168.2.1
description "Uplink to Telia"
}
}
You can access all the variables like this (note the "-a" option):
% confctl -a config-file
interfaces.eth0.ip-address=192.168.1.1
interfaces.eth0.mtu=9000
interfaces.eth1.ip-address=192.168.2.1
interfaces.eth1.description="Uplink to Telia"
You can also query individual variables:
% confctl config-file interfaces.eth0.ip-address interfaces.eth1.ip-address
interfaces.eth0.ip-address=192.168.1.1
interfaces.eth1.ip-address=192.168.2.1
To modify a variable, use the "-w" option:
% confctl -w interfaces.eth0.ip-address=192.168.1.2 config-file
You may pass the "-w" option multiple times to set several variables at once.
You use exactly the same syntax to add new variables:
% confctl -w interfaces.eth2.ip-address=10.0.0.1 -w interfaces.eth2.netmask=24 config-file
% confctl config-file interfaces.eth2
interfaces.eth2.ip-address=10.0.0.1
interfaces.eth2.netmask=24
% cat config-file
interfaces {
eth0 {
ip-address 192.168.1.1
mtu 9000
}
eth1 {
ip-address 192.168.2.1
description "Uplink to Telia"
}
eth2 {
ip-address 10.0.0.1
netmask 24
}
}
Note that file modification preserves formatting and indentation. It also
preserves all the comments, including ones for variables modified in place.
Also note that by default, modification is done by writing a temporary
copy of the file, in the same parent directory, and then renaming it,
replacing the old file. This will fail if it's impossible to create
new files, and won't do the right thing when the file name is a symlink.
In that case, use "-I" option to rewrite configuration file in place.
There are several options to modify the confctl behaviour to adapt to common
file formats, such as the ones used by dhcpd.conf or jail.conf. See files
in the test/ subdirectory to see how to handle these files.
Code
====
The code is distributed under the terms of two-clause BSD license. This means
you can do pretty much whatever you like, including using it in closed-source
software.
The whole thing is written in C. The only dependency is libc. It doesn't
require any additional libraries; it doesn't even require C++ runtime.
Installation
============
Confctl uses standard autotools setup. To build it, do:
./configure
make all install
If there is no configure script (i.e. because you pulled it from the Git repo),
you have to generate it using:
autoreconf -i
For this to work, you need to have autoconf and automake installed.