Skip to content

Instantly share code, notes, and snippets.

@justinleveck
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinleveck/ec7e1ce155830401d34f to your computer and use it in GitHub Desktop.
Save justinleveck/ec7e1ce155830401d34f to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment