Permalink
Browse files

Initial commit.

  • Loading branch information...
0 parents commit 286348f10be3b692dcea6bf53076cf28f3dafbfc @mzeis committed Mar 4, 2012
Showing with 452 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +138 −0 README.markdown
  3. +18 −0 config.conf.sample
  4. +194 −0 install
  5. +101 −0 remove
@@ -0,0 +1 @@
+config.conf
@@ -0,0 +1,138 @@
+# MageSpawner
+
+This is a little handy shell script that I am using for quite a while now.
+The goal is to quickly create new (and remove) Magento installations for testing purposes. Testing as in "I want to try something", not as in Unit Testing.
+
+*Before you start, let me state something:*
+
+**Do not use this on a production machine. Ideally, use it on a machine where you don't care about losing everything.** The remove script uses a "rm -rf" command, so if something goes wrong, it could go awfully wrong. I solely use this on a VM where everything important is backed up regularily.
+
+## Requirements
+
+ * Linux/Unix (tested on Debian)
+ * bash
+ * These commands must be available:
+ * basename
+ * mysql
+ * php
+ * sed
+ * tar
+ * wget
+ * which
+
+## Installation
+
+ * Get the files from Github.
+ * Copy config.conf.sample to config.conf and adjust the settings as needed.
+ * Make the files ./install and ./remove executable.
+
+## Getting started
+
+Call `./install` and follow the instructions. At the moment, you have to enter the details in an interactive mode (= no command line automatisation).
+
+This is how it looks like on my VM:
+
+ Welcome to MageSpawner.
+
+ Which version do you want to install?
+ 1) None, abort installation
+ 2) CE 1.5.0.1
+ 3) CE 1.5.1.0
+ 4) CE 1.6.0.0
+ 5) CE 1.6.1.0
+ 6) CE 1.6.2.0
+ 7) CE 1.7.0.0 alpha1
+ 8) CE 1.7.0.0 beta1
+ Enter the number (e.g. 1): 8
+ CE 1.7.0.0 beta1 selected.
+
+ Specify the shop name. It may be used for the URL, directory and database name, so don't use spaces, special characters or the like.
+ Shop name (default: shop): 1700beta1
+ Thanks, the required information was provided. The installation will now begin.
+
+ Downloading Magento package...
+ --2012-03-04 12:32:13-- http://www.magentocommerce.com/downloads/assets/1.7.0.0-beta1/magento-1.7.0.0-beta1.tar.gz
+ Auflösen des Hostnamen www.magentocommerce.com... 209.15.239.51
+ Verbindungsaufbau zu www.magentocommerce.com|209.15.239.51|:80... verbunden.
+ HTTP-Anforderung gesendet, warte auf Antwort... 200 OK
+ Länge: 17653068 (17M) [application/x-gzip]
+ In »magento-1.7.0.0-beta1.tar.gz« speichern.
+
+ 100%[===================================================================================================================>] 17.653.068 1,75M/s in 15s
+
+ 2012-03-04 12:32:28 (1,13 MB/s) - »magento-1.7.0.0-beta1.tar.gz« gespeichert [17653068/17653068]
+
+ Package downloaded.
+
+ Unpacking package and setting permissions.
+ Package unpacked and permssions set.
+
+ Creating database...
+ Database created.
+
+ Executing Magento setup script...
+ SUCCESS: 9a96247823ea7c2cd8f3ebff7db0a544
+ Setup script executed. Please write down the encryption key provided above.
+
+ Reindexing Magento indexes...
+ Product Attributes index was rebuilt successfully
+ Product Prices index was rebuilt successfully
+ Catalog URL Rewrites index was rebuilt successfully
+ Product Flat Data index was rebuilt successfully
+ Category Flat Data index was rebuilt successfully
+ Category Products index was rebuilt successfully
+ Catalog Search Index index was rebuilt successfully
+ Stock Status index was rebuilt successfully
+ Tag Aggregation Data index was rebuilt successfully
+ Indexes reindexed.
+
+ Editing .htaccess for VirtualDocumentRoot configuration (setting RewriteBase)...
+ .htaccess edited.
+
+ Final permission settings...
+ Done.
+
+ If you didn't see any error messages, everything went fine.
+ Set up your vhost config and host entries (if needed) and you are ready to go!
+ The frontend shop URL is http://1700beta1.magentoshops.vm.
+
+
+After the script has finished, you may be two steps away from using the new Magento installation:
+
+ 1. **Add an entry two your hosts file**. Your browser has to know which server the domain (e.g. 1700beta1.magentoshops.vom) belongs to. If you use a real domain and have set an wildcard DNS record, then you are good to go. Otherwise, open your hosts file and a line like `192.168.1.2 1700beta1.magentoshops.vm` (don't forget to change this to the correct IP and domain).
+
+ 2. **Add an entry to your server configuration**. Your web server has to know how to handle the request. Normally, you would have to add a [Virtual Host](http://httpd.apache.org/docs/2.2/vhosts/name-based.html) every single time you setup a new Magento installation.
+
+ As programmers don't like to repeat themselves an I'm a programmer, I'm using the [Apache Module mod_vhost_alias](http://httpd.apache.org/docs/2.0/mod/mod_vhost_alias.html) and the nifty `VirtualDocumentRoot` directive.
+
+ This is what my configuration looks like:
+
+ <VirtualHost *:80>
+ ServerAdmin my@email.com
+ ServerName magentoshops.vm
+ ServerAlias *.magentoshops.vm
+ UseCanonicalName Off
+ VirtualDocumentRoot /var/www/magento/shops/%0/
+ # Some more settings
+ # Magento development settings
+ SetEnv MAGE_IS_DEVELOPER_MODE 1
+ </VirtualHost>
+
+ The VirtualDocumentRoot path /var/www/magento/shops/ has to match the MAGE_BASE_DIR setting in config.conf.
+ The script automatically edits Magentos .htaccess so that the RewriteBase is adjusted for this setup.
+
+## License
+
+ Copyright 2011-2012 Matthias Zeis
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
@@ -0,0 +1,18 @@
+MAGE_DOMAIN="magentoshops.vm" # The shops will be created under this subdomain
+MAGE_DEFAULT_NAME="shop" # Preset for the shop name. The shop name is used
+ # as part of the domain, directory and database name.
+MAGE_BASE_DIR="/var/www/magento/shops/" # Base directory for the Magento installations
+LINUX_USER="www-data" # File owner for the Magento installation
+LINUX_GROUP="www-data" # File group for the Magento installation
+ADMIN_FRONTNAME="admin" # Path to the admin panel
+ADMIN_FIRSTNAME="" # Admin user first name
+ADMIN_LASTNAME="" # Admin user last name
+ADMIN_EMAIL="" # Admin user e-mail
+ADMIN_USERNAME="" # Admin user login
+ADMIN_PASSWORD="" # Admin user password
+DB_HOST="localhost" # Database host
+DB_USER="root" # Database user. Needs privileges for creating databases.
+DB_PASS="" # Database user password
+DB_NAMEPREFIX="magento_shops_" # Database name prefix (pseudo namespace for all
+ # Spawner installations)
+DB_TABLEPREFIX="" # Database table prefix
194 install
@@ -0,0 +1,194 @@
+#!/bin/bash
+# MageSpawner
+#
+# Copyright 2011-2012 Matthias Zeis
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# System Requirements:
+# - bash
+# - The following commands must be locatable in your $PATH
+# basename mysql php sed tar wget which
+
+version="0.1"
+usage="\
+MageSpawner (v$version)
+
+MageSpawner is a tool for quick setup of multiple Magento test installations.
+THIS IS NOT MEANT TO BE USED ON PRODUCTION ENVIORNMENTS!
+
+Usage:
+./install
+Then follow the instructions on the screen.
+
+Consult the README for further information.
+
+Options:
+
+ --help display this help message
+ --usage display this help message
+ --version display the version of this script
+
+Get more information at
+http://matthias-zeis.com"
+
+###########################
+## Common options: help, usage and version number
+
+if [ "$1" = "--help" ]; then
+ echo "$usage"
+ exit 0
+elif [ "$1" = "--usage" ]; then
+ echo "$usage"
+ exit 0
+elif [ "$1" = "--version" ]; then
+ echo "$version"
+ exit 0
+fi
+
+###########################
+## Main script
+
+echo -e 'Welcome to MageSpawner.\n'
+
+if [[ ! -f ${0%/*}/config.conf ]]; then
+ echo -e 'config.conf not found.\nPlease copy config.conf.sample to config.conf and adjust your settings.'
+ exit 1
+fi
+. ${0%/*}/config.conf
+
+if [[ $MAGE_BASE_DIR = "" || $MAGE_BASE_DIR = "/" ]]; then
+ echo "Base directory '$MAGE_BASE_DIR' is not allowed. Please change in configuration."
+ exit 1
+fi
+
+MYSQL=$(which mysql) || { echo 'MySQL executable not found'; exit 1; }
+PHP=$(which php) || { echo 'PHP executable not found'; exit 1; }
+SED=$(which sed) || { echo 'sed command not found'; exit 1; }
+
+
+
+echo "Which version do you want to install?"
+echo "1) None, abort installation"
+echo "2) CE 1.5.0.1"
+echo "3) CE 1.5.1.0"
+echo "4) CE 1.6.0.0"
+echo "5) CE 1.6.1.0"
+echo "6) CE 1.6.2.0"
+echo "7) CE 1.7.0.0 alpha1"
+echo "8) CE 1.7.0.0 beta1"
+
+while true; do
+ read -p "Enter the number (e.g. 1): " MAGE_VERSION
+
+ case "$MAGE_VERSION" in
+ 1)
+ echo "Aborting installation."
+ exit;
+ ;;
+ 2)
+ echo -e "CE 1.5.0.1 selected.\n"
+ MAGE_DOWNLOAD_URL="http://www.magentocommerce.com/downloads/assets/1.5.0.1/magento-1.5.0.1.tar.gz"
+ break
+ ;;
+ 3)
+ echo -e "CE 1.5.1.0 selected.\n"
+ MAGE_DOWNLOAD_URL="http://www.magentocommerce.com/downloads/assets/1.5.1.0/magento-1.5.1.0.tar.gz"
+ break
+ ;;
+ 4)
+ echo -e "CE 1.6.0.0 selected.\n"
+ MAGE_DOWNLOAD_URL="http://www.magentocommerce.com/downloads/assets/1.6.0.0/magento-1.6.0.0.tar.gz"
+ break
+ ;;
+ 5)
+ echo -e "CE 1.6.1.0 selected.\n"
+ MAGE_DOWNLOAD_URL="http://www.magentocommerce.com/downloads/assets/1.6.1.0/magento-1.6.1.0.tar.gz"
+ break
+ ;;
+ 6)
+ echo -e "CE 1.6.2.0 selected.\n"
+ MAGE_DOWNLOAD_URL="http://www.magentocommerce.com/downloads/assets/1.6.2.0/magento-1.6.2.0.tar.gz"
+ break
+ ;;
+ 7)
+ echo -e "CE 1.7.0.0 alpha1 selected.\n"
+ MAGE_DOWNLOAD_URL="http://www.magentocommerce.com/downloads/assets/1.7.0.0-alpha1/magento-1.7.0.0-alpha1.tar.gz"
+ break
+ ;;
+ 8)
+ echo -e "CE 1.7.0.0 beta1 selected.\n"
+ MAGE_DOWNLOAD_URL="http://www.magentocommerce.com/downloads/assets/1.7.0.0-beta1/magento-1.7.0.0-beta1.tar.gz"
+ break
+ ;;
+ *)
+ echo -e "Invalid option, please try again.\n"
+ ;;
+ esac
+done
+
+echo "Specify the shop name. It may be used for the URL, directory and database name, so don't use spaces, special characters or the like."
+read -p "Shop name (default: ${MAGE_DEFAULT_NAME}): " MAGE_NAME
+MAGE_NAME=${MAGE_NAME:-${MAGE_DEFAULT_NAME}}
+MAGE_SHOPDOMAIN="${MAGE_NAME}.${MAGE_DOMAIN}"
+
+# Use information for setting variables
+MAGE_UNSECURE_URL="http://${MAGE_SHOPDOMAIN}"
+MAGE_SECURE_URL="http://${MAGE_SHOPDOMAIN}"
+MAGE_DOWNLOAD_FILENAME=$(basename $MAGE_DOWNLOAD_URL)
+DB_NAME="${DB_NAMEPREFIX}${MAGE_NAME}"
+DB_SQL="CREATE DATABASE IF NOT EXISTS ${DB_NAME} CHARACTER SET utf8 COLLATE utf8_general_ci;"
+
+echo -e "Thanks, the required information was provided. The installation will now begin.\n"
+
+cd $MAGE_BASE_DIR
+echo "Downloading Magento package..."
+wget $MAGE_DOWNLOAD_URL
+echo -e "Package downloaded.\n"
+
+echo "Unpacking package and setting permissions."
+tar -zxf $MAGE_DOWNLOAD_FILENAME
+mv magento/ "$MAGE_SHOPDOMAIN"/
+rm -f $MAGE_DOWNLOAD_FILENAME
+chown -R ${LINUX_USER}:${LINUX_GROUP} "$MAGE_SHOPDOMAIN"/
+cd "$MAGE_SHOPDOMAIN"/
+chmod 777 app/etc var/ media/
+echo -e "Package unpacked and permssions set.\n"
+
+echo "Creating database..."
+$MYSQL -u${DB_USER} -p${DB_PASS} -e "${DB_SQL}"
+echo -e "Database created.\n"
+
+echo "Executing Magento setup script..."
+$PHP -f install.php -- --license_agreement_accepted "yes" --locale "de_DE" --timezone "Europe/Berlin" --default_currency "EURO" --db_host "${DB_HOST}" --db_name "${DB_NAME}" --db_user "${DB_USER}" --db_pass "${DB_PASS}" \ db_prefix "${DB_TABLEPREFIX}" --session_save "files" --admin_frontname "${ADMIN_FRONTNAME}" --url "${MAGE_UNSECURE_URL}" --skip_url_validation --use_rewrites "yes" --use_secure "no" --secure_base_url "${MAGE_SECURE_URL}" --use_secure_admin "no" --admin_firstname "${ADMIN_FIRSTNAME}" --admin_lastname "${ADMIN_LASTNAME}" --admin_email "${ADMIN_EMAIL}" --admin_username "${ADMIN_USERNAME}" --admin_password "${ADMIN_PASSWORD}"
+echo -e "Setup script executed. Please write down the encryption key provided above.\n"
+
+echo "Reindexing Magento indexes..."
+$PHP -f shell/indexer.php reindexall
+echo -e "Indexes reindexed.\n"
+
+echo "Editing .htaccess for VirtualDocumentRoot configuration (setting RewriteBase)..."
+cp .htaccess .htaccess.backup
+$SED "s/#RewriteBase \/magento\//RewriteBase \//" ${MAGE_BASE_DIR}${MAGE_SHOPDOMAIN}/.htaccess.backup >.htaccess
+rm .htaccess.backup
+echo -e ".htaccess edited.\n"
+
+# Adjust permissions
+echo "Final permission settings..."
+chmod 644 app/etc/local.xml
+chown ${LINUX_USER}:${LINUX_GROUP} app/etc/local.xml
+echo -e "Done.\n"
+
+echo "If you didn't see any error messages, everything went fine."
+echo "Set up your vhost config and host entries (if needed) and you are ready to go!"
+echo "The frontend shop URL is ${MAGE_UNSECURE_URL}."
Oops, something went wrong.

0 comments on commit 286348f

Please sign in to comment.