Firstly, I can replace text in a text file using bash, the problem I have is that I have two pieces of text that need replacing but they are named the same but will require different information. So, to replace one piece of text is pretty simple, I just used (from users input):
clear
echo "Configuration of Radman properties file starting:"
read -p "Please enter the password utilised for radman in mysql configuration:" <password>
read -p "Please enter the password utilised for radius in mysql configuration:" <password>
VAR1="database.radman.datasource.password=<password>"
VAR2="database.radman.datasource.password=$<password>"
VAR3="database.radius.datasource.password=<password>"
VAR4="database.radius.datasource.password=$password>"
VAR5="/etc/radman/radman.properties"
sed -i.bak "s/${VAR1}/${VAR2}/g" ${VAR5}
sed -i.bak1 "s/${VAR3}/${VAR4}/g" ${VAR5}
But here is the issue I have with the second file (two databases):
sql raddb1 {
dialect = "mysql"
driver = "rlm_sql_${dialect}"
#mysql {
# tls {
# ca_file = "/etc/ssl/certs/my_ca.crt"
# ca_path = "/etc/ssl/certs/"
# certificate_file = "/etc/ssl/certs/private/client.crt"
# private_key_file = "/etc/ssl/certs/private/client.key"
# cipher = "DHE-RSA-AES256-SHA:AES128-SHA"
# tls_required = yes
# tls_check_cert = no
# tls_check_cert_cn = no
# }
# warnings = auto
#}
server = "server1"
port = 3306
login = "radius"
password = "<password>"
I need to change the "Server = " section and the "password = " section. This by itself is no problem. But there is a second database shown below:
sql raddb2 {
dialect = "mysql"
driver = "rlm_sql_${dialect}"
#mysql {
# tls {
# ca_file = "/etc/ssl/certs/my_ca.crt"
# ca_path = "/etc/ssl/certs/"
# certificate_file = "/etc/ssl/certs/private/client.crt"
# private_key_file = "/etc/ssl/certs/private/client.key"
# cipher = "DHE-RSA-AES256-SHA:AES128-SHA"
# tls_required = yes
# tls_check_cert = no
# tls_check_cert_cn = no
# }
# warnings = auto
#}
server = "server2"
port = 3306
login = "radius"
password = "<password>"
That has the same pattern. So if the user inputs the corect server name and password for raddb1 it will change it (as requried). But when they input the second set of variables, the pattern will be the same for raddb2. How can I change to the correct user input values for the same pattern in a single file? (This will only be the password as the server = is a different pattern for the two databases)