cloudfoundry/stratos

View on GitHub
deploy/stratos-ui-release/jobs/backend/templates/pre-start.erb

Summary

Maintainability
Test Coverage
#!/bin/sh
set -e

# Step 1 - Set the lock file on the shared volume
mkdir -p <%= p('stratos_ui.backend.upgrade_volume_path') %>
<% if p('stratos_ui.backend.use_mysql') == true %>
touch <%= p('stratos_ui.backend.upgrade_volume_path') %>/<%= p('stratos_ui.backend.upgrade_volume_file') %>
chmod 440 <%= p('stratos_ui.backend.upgrade_volume_path') %>/<%= p('stratos_ui.backend.upgrade_volume_file') %>
echo "Created the upgrade lock file."
<% end %>

# Step 2 - Create an AES-256 compliant encryption key
# in a file on a shared volume.
echo "Checking to see if we need to generate the encryption key  <%= p('stratos_ui.backend.encryption_key_filename') %> file:"

if [ ! -d <%= p('stratos_ui.backend.encryption_key_volume') %> ]; then
  echo "Encryption key volume does not exist. Creating it!"
  mkdir -p <%= p('stratos_ui.backend.encryption_key_volume') %>
fi
if [ ! -e  <%= p('stratos_ui.backend.encryption_key_volume') %>/<%= p('stratos_ui.backend.encryption_key_filename') %> ]; then
  echo "-- Adding  <%= p('stratos_ui.backend.encryption_key_filename') %> file to the shared volume <%= p('stratos_ui.backend.encryption_key_volume') %>."
  keyfile=$(openssl enc -aes-256-cbc -k secret -P -md sha1 | grep key | cut -d '=' -f2)
  printf "%s" "$keyfile" >  <%= p('stratos_ui.backend.encryption_key_volume') %>/<%= p('stratos_ui.backend.encryption_key_filename') %>
  chmod 440  <%= p('stratos_ui.backend.encryption_key_volume') %>/<%= p('stratos_ui.backend.encryption_key_filename') %>
  echo "-- Done."
fi

exit 0