Script to set CS-Cart config.local.php values using environment variable values
#!/usr/bin/env ruby
file_names = ['path/to/config.local.php']
config_values = [
'CS_CART_DB_HOST',
'CS_CART_DB_NAME',
'CS_CART_DB_USER',
'CS_CART_DB_PASSWORD',
'CS_CART_HTTP_HOST',
'CS_CART_HTTP_PATH',
'CS_CART_HTTPS_HOST',
'CS_CART_HTTPS_PATH',
'CS_CART_CUSTOMER_INDEX',
'CS_CART_ADMIN_INDEX'
]
file_names.each do |file_name|
text = File.read(file_name)
config_values.each do |config_value|
search_regexp = /%#{Regexp.quote(config_value)}%/
next if ENV[config_value].nil?
p ENV[config_value]
text = text.gsub(search_regexp, ENV[config_value])
end
# To write changes to the file, use:
File.open(file_name, "w") {|file| file.puts text }
end