Question

What's the best approach to update an /etc/rc.conf configuration file programmatically?

Specifically, on an arch linux machine, I want to be able to programmatically update

DAEMONS=(syslog-ng network sshd ntpd netfs crond)

to

DAEMONS=(syslog-ng network sshd ntpd netfs crond postgresql)

after postgresql is successfully installed via pacman.

I presume I can write a function that does something like:

line="DAEMONS=(syslog-ng network sshd ntpd netfs crond)"

sed -i "/${line}/ s/)/ postgresql)/" /etc/rc.conf

specifically to handle this postgresql scenario.

However, going one step further, is there a more generic way (using a library if there's one you can recommend) that programmatically includes my service (such as memcached, or like a task server like zeromq etc) in the DAEMONS parameter in my /etc/rc.conf file?

Était-ce utile?

La solution

I wouldn't know about a generic way (there seems to be very few tools which do any parsing and modification of shell code), but one way to update a simple array like this one could be to actually read it, change it, then write back the whole line - Something like this:

source /etc/rc.conf
DAEMONS+=(postgresql)
sed -i -e s/'^DAEMONS=.*'/"DAEMONS=(${DAEMONS[@]})"/ /etc/rc.conf
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top