Solved Editing Config Files

robb

New Member

Reaction score: 2
Messages: 3

I was wondering if there was a command that came standard with FreeBSD for editing configuration files much like sysrc(8) or sysctl(8) that work on other config files that follow the same parameter=value format. I'd like to ultimately modify other config files like /boot/loader.conf, /etc/jail.conf, etc. in the same or similar manor as /etc/sysctl.conf and /etc/rc.conf.

I was able to use sysrc(8) on /boot/loader.conf:
Bash:
# sysrc -f /boot/loader.conf loader_delay=2
loader_delay: 2 -> 2

However, whenever I try a parameter that has a namespace, sysrc(8) doesn't care for that too much:
Bash:
# sysrc -f /boot/loader.conf kern.vty=vt
sysrc: kern.vty: name contains characters not allowed in shell

Thanks in advance!
 

vigole

Daemon

Reaction score: 1,601
Messages: 1,413

sysrc(8) is only for rc files. You shouldn't use it to manipulate other files e.g. /boot/loader.conf. Please don't do that.
Try this one. it will show you what is wrong with your approach:
sysrc -f /boot/loader.conf GIT=IS_BAD.
Now check the result in /boot/loader.conf (open in editor).
Before using sysrc(8) , dump a list of all configuration variables which it could access/change including defaults:
sysrc -A
Admins with large servers manage their stuffs including confs with programs like sysutils/puppet6. I never used such programs. Do your research.
 

Mjölnir

Daemon

Reaction score: 1,519
Messages: 2,114

There are many libraries (C, Perl, Python etc.pp.) to handle key=value syntax. The benefit of sysrc(8) is that it checks for duplicates & does some other limited checks like the one you ran into. You may want to search the web for some shell script (or scriptlets) library site. This would be my 1st attempt.
 

vigole

Daemon

Reaction score: 1,601
Messages: 1,413

It's recommended to use sysrc(8) to edit rc.conf because it's safer and easier. The length of command, short or long is not an issue. There're different ways to add entry to rc.conf: editor, echo, .... sysrc(8) is one of them. I personally use cat(1) to append backed-up setting to config files, including rc.conf; and I use nvi(1) to edit them. There's going to be syntax error and/or mistakes. but that's on me.
 

Mjölnir

Daemon

Reaction score: 1,519
Messages: 2,114

...and using a tool like sysrc(8) can detect many of such human errors. If I got it right, the OP wants to find or write a more general tool, for safety & probably automation, which are two good reasons.
 
OP
R

robb

New Member

Reaction score: 2
Messages: 3

Thanks everyone for your responses!

the OP wants to find or write a more general tool, for safety & probably automation, which are two good reasons.

You are correct. I wanted to have both safety and automation. A consistent way to edit all, or most, config files with some high level syntax checks.

I have looked into sysutils/puppet6 and sysutils/ansible, but not textproc/augeas (yet).

I was hoping to find a solution that was part of FreeBSD's base system. And to answer my original question, there isn't one. But I think my options are either to write a script, or install a package. I'll do some more research on my options. Thanks again!
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 13,119
Messages: 39,712

The reason I use augeas with Puppet is because you can only define a file resource once, either with a full config file or a template for a full config file. So if you have two modules that need to modify the same config file you have a problem. With augeas you can simply define what settings you want changed and leave the rest of the file as-is. Also useful if you need to allow people to edit configuration files but still want to make sure certain parameters have specific values. A regular file resource with Puppet would simply overwrite the user-made changes.
 

rihad

Active Member

Reaction score: 14
Messages: 206

The reason I use augeas with Puppet is because you can only define a file resource once, either with a full config file or a template for a full config file. So if you have two modules that need to modify the same config file you have a problem. With augeas you can simply define what settings you want changed and leave the rest of the file as-is. Also useful if you need to allow people to edit configuration files but still want to make sure certain parameters have specific values. A regular file resource with Puppet would simply overwrite the user-made changes.

Just tried it. Unforunately augeas (augtool print) doesn't recognize the format of /etc/pkg/FreeBSD.conf or /etc/freebsd-update.conf or /usr/local/etc/tarsnap.conf and probably many others, which limits its usefulness in our case.
 
Top