How To Edit ini & conf Files With Shell Scripts

I wrote some scripts to help editing ini files and conf files while reinstalling my servers.

The script is able to process multiple files at once and will add or edit the parameters you want automatically.

the configuration file looks like this :

:: GitHub File ::
[_www.conf] original = /etc/php/5.6/fpm/pool.d/www.conf keep_comments = 0 keep_empty_lines = 0 sort = 1 [_sysctl.conf] original = /etc/sysctl.conf keep_comments = 1 keep_empty_lines = 1 [_php-fpm.conf] original = /etc/php/5.6/fpm/php-fpm.conf keep_comments = 0 keep_empty_lines = 0 [_php.ini] original = /etc/php/5.6/fpm/php.ini keep_comments = 1 keep_empty_lines = 1

As you can see for each file I want to edit, there is a small file containing only the lines I need to be edited or added. For exxample the _php-fpm.conf file looks like this :

:: GitHub File ::
[global] error_log = /var/log/php/php-fpm.log emergency_restart_threshold = 10 emergency_restart_interval = 1m process_control_timeout = 20s

 

Command Lines :

php confeditor.php process_all [options]

This command will execute every entries in the confeditor-config.ini file

file options :

option values default description
keep_comments 1/0 0 keep comment lines in the target file
keep_empty_lines 1/0 0 keep empty lines in target file
sort 1/0 0 sort ini keys in each section
debug 1/0 0 do not write in files but create a ‘-new’ file instead
separator string ‘=’ separator for key & values
comment_regex regex ‘-^(;|#)-‘ what defines a comment
php confeditor.php process sample-file target-file [options]

This command will merge the target-file with the lines inside the data/sample-file

Cmd options :

option equivalent values default
-kc keep_comments 1/0 0
-kel keep_empty_lines 1/0 0
-sort sort 1/0 0
-d debug 1/0 0
-sep separator string ‘=’
-cr comment_regex string ‘-^(;|#)-‘

The main repository is here : https://github.com/anthonykozak/iniTools