<commit_before>#!/bin/sh

# Magento settings
DB_HOST="localhost"
DB_NAME="magento"
DB_USER="root"
DB_PASS=""
# Install Sample data (beware, takes a long time)
SAMPLE_DATA="no"
# Magento Version
MAGENTO_VERSION="magento-ce-1.9.1.1"

# Redis Cache
CACHE_DATABASE="0"
CACHE_PERSISTENT="cache-db$CACHE_DATABASE"
# Redis Sessions
SESSION_DB="1"
SESSION_PERSISTENT="session-db$SESSION_DB"

# Install dependencies from composer.
# Extensions from Composer will be deployed after Magento has been installed
cd /vagrant
sudo composer install --prefer-dist --no-interaction --no-scripts
cd ~

# link project modman packages (src/modman imports others)
modman link ./src
modman deploy src --force

# link n98-magerun Config overides
sudo ln -fs /vagrant/conf/n98-magerun.yaml /etc/n98-magerun.yaml

# Use n98-magerun to set up Magento (database and local.xml)
# use --noDownload if Magento core is deployed with modman or composer. Test if there already is a configured Magento installation and if so skip installation
if [ ! -e "~/www/app/etc/local.xml" ]; then
  n98-magerun install --dbHost="$DB_HOST" --dbUser="$DB_USER" --dbPass="$<PASSWORD>" --dbName="$DB_NAME" --installSampleData="$SAMPLE_DATA" --useDefaultConfigParams=yes --magentoVersionByName="$MAGENTO_VERSION" --installationFolder="www" --baseUrl="http://magento.local/"

  # Configure Redis on initial installation
  cd /vagrant/conf
  # Insert Redis Backend Cache config into local.xml
  # Get template
  # sed -n -i -e '/<\/global>/r Mage_Cache_Backend_Redis.xml' -e 1x -e '2,${x;p}' -e '${x;p}' /home/vagrant/www/app/etc/local.xml
  # # Insert Redis Session Handler config into local.xml
  # sed -e '/<\/session_save>/r Cm_RedisSession.xml' /home/vagrant/www/app/etc/local.xml

  # Configure Redis Backend Cache
  sed -e s/"{{PERSISTENT}}"/"$CACHE_PERSISTENT"/g -e s/"{{DATABASE}}"/"$CACHE_DATABASE"/g Mage_Cache_Backend_Redis.xml > Mage_Cache_Backend_Redis.xml.vagrant
  ln -s /vagrant/conf/Mage_Cache_Backend_Redis.xml.vagrant ~/www/app/etc/Mage_Cache_Backend_Redis.xml
  # Configure Redis Sessions
  sed -e s/"{{PERSISTENT}}"/"$SESSION_PERSISTENT"/g -e s/"{{DATABASE}}"/"$SESSION_DB"/g Cm_RedisSession.xml > Cm_RedisSession.xml.vagrant
    ln -s /vagrant/conf/Cm_RedisSession.xml.vagrant ~/www/app/etc/Cm_RedisSession.xml
  cd ~
fi

# Write permissions in media
chmod -R 0770 /home/vagrant/www/media

# Downloader no longer required really as modman should be used to install new
# extensions instead, however kept and secured by renaming
mv /home/vagrant/www/downloader /home/vagrant/www/.downloader
# Access to .downloader is resricted nginx conf. Generate password here
# to allow access magento connect downloader at http://magento.local/.downloader/
htpasswd -cb /home/vagrant/www/var/.htpasswd "$DB_USER" "$DB_PASS"

# Now after Magento has been installed, deploy all additional modules and run setup scripts
modman deploy-all --force
n98-magerun sys:setup:run
n98-magerun dev:symlinks --on --global

# Link local.xml from /etc, this overwrites the generated local.xml
# from the install script. If it does not exist, the generated file gets copied to /etc first
# This way you can put the devbox local.xml under version control
if [ ! -f "/vagrant/etc/local.xml" ]; then
	cp ~/www/app/etc/local.xml /vagrant/etc/local.xml
fi

ln -fs /vagrant/etc/local.xml ~/www/app/etc/local.xml

# Some devbox specific Magento settings
n98-magerun config:set dev/log/active 1<commit_msg>Tidied up and comment Redis Backend Cache and Sessions config creation<commit_after>#!/bin/sh

# Magento settings
DB_HOST="localhost"
DB_NAME="magento"
DB_USER="root"
DB_PASS=""
# Install Sample data (beware, takes a long time)
SAMPLE_DATA="no"
# Magento Version
MAGENTO_VERSION="magento-ce-1.9.1.1"

# Redis Cache
CACHE_DATABASE="0"
CACHE_PERSISTENT="cache-db$CACHE_DATABASE"
# Redis Sessions
SESSION_DB="1"
SESSION_PERSISTENT="session-db$SESSION_DB"

# Install dependencies from composer.
# Extensions from Composer will be deployed after Magento has been installed
cd /vagrant
sudo composer install --prefer-dist --no-interaction --no-scripts
cd ~

# link project modman packages (src/modman imports others)
modman link ./src
modman deploy src --force

# link n98-magerun Config overides
sudo ln -fs /vagrant/conf/n98-magerun.yaml /etc/n98-magerun.yaml

# Use n98-magerun to set up Magento (database and local.xml)
# use --noDownload if Magento core is deployed with modman or composer. Test if there already is a configured Magento installation and if so skip installation
if [ ! -e "~/www/app/etc/local.xml" ]; then
  n98-magerun install --dbHost="$DB_HOST" --dbUser="$DB_USER" --dbPass="$DB_PASS" --dbName="$DB_NAME" --installSampleData="$SAMPLE_DATA" --useDefaultConfigParams=yes --magentoVersionByName="$MAGENTO_VERSION" --installationFolder="www" --baseUrl="http://magento.local/"
fi

# #
# Configure Redis on initial installation
# #
if [ ! -e "~/www/app/etc/Mage_Cache_Backend_Redis.xml" || ! -e "~/www/app/etc/Cm_RedisSession.xml" ]; then
  cd /vagrant/conf

  # The sed commands below create the required Redis configuration files
  # from default templates and symlink them to app/etc/. {{XXXXX}} represents
  # placeholders in the source xml files

  # Redis Backend Cache
  sed -e s/"{{PERSISTENT}}"/"$CACHE_PERSISTENT"/g -e s/"{{DATABASE}}"/"$CACHE_DATABASE"/g Mage_Cache_Backend_Redis.xml > Mage_Cache_Backend_Redis.xml.vagrant
  ln -s /vagrant/conf/Mage_Cache_Backend_Redis.xml.vagrant ~/www/app/etc/Mage_Cache_Backend_Redis.xml

  # Redis Sessions
  sed -e s/"{{PERSISTENT}}"/"$SESSION_PERSISTENT"/g -e s/"{{DB}}"/"$SESSION_DB"/g Cm_RedisSession.xml > Cm_RedisSession.xml.vagrant
  ln -s /vagrant/conf/Cm_RedisSession.xml.vagrant ~/www/app/etc/Cm_RedisSession.xml

  # Enable Redis sessions (disabled by default)
  n98-magerun dev:module:enable Cm_RedisSession

  cd ~
fi

# Write permissions in media
chmod -R 0770 /home/vagrant/www/media

# Downloader no longer required really as modman should be used to install new
# extensions instead, however kept and secured by renaming
mv /home/vagrant/www/downloader /home/vagrant/www/.downloader
# Access to .downloader is resricted nginx conf. Generate password here
# to allow access magento connect downloader at http://magento.local/.downloader/
htpasswd -cb /home/vagrant/www/var/.htpasswd "$DB_USER" "$DB_PASS"

# Now after Magento has been installed, deploy all additional modules and run setup scripts
modman deploy-all --force
n98-magerun sys:setup:run
n98-magerun dev:symlinks --on --global

# Link local.xml from /etc, this overwrites the generated local.xml
# from the install script. If it does not exist, the generated file gets copied to /etc first
# This way you can put the devbox local.xml under version control
if [ ! -f "/vagrant/etc/local.xml" ]; then
	cp ~/www/app/etc/local.xml /vagrant/etc/local.xml
fi

ln -fs /vagrant/etc/local.xml ~/www/app/etc/local.xml

# Some devbox specific Magento settings
n98-magerun config:set dev/log/active 1
{'fraction_non_alphanumeric': 0.11843238587424634, 'fraction_numerical': 0.008326155612977318, 'mean_word_length': 4.43871975019516, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 24, 'xml': 45}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '732469', 'n_tokens_mistral': 2460, 'n_tokens_neox': 2412, 'n_words': 677}