Skip to content

Instantly share code, notes, and snippets.

@tegansnyder
Last active June 7, 2017 11:14
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tegansnyder/8447040 to your computer and use it in GitHub Desktop.
Save tegansnyder/8447040 to your computer and use it in GitHub Desktop.
MageStocker - Convert your Magento to stock disabling all extensions and your theme. Allows you to switch it back when you are done testing brining your theme and extensions back to life.
#! /bin/bash
if [ "$#" == "0" ]; then
echo
echo "Sorry cant run!"
echo "No arguments provided. Please pass this script agruments in the following format:"
echo "./magestocker.sh magento_root theme_base current_theme_name"
echo "example: "
echo "./magestocker.sh /var/www/magento default mytheme"
echo "another example:"
echo "./magestocker.sh /var/www/magento enterprise mytheme"
echo
exit 1
fi
# NOTE:
# before proceeding edit these global variables
# edit these store variables :
MAGENTO_ROOT=$1
THEME_BASE=$2
CURRENT_THEME=$3
echo
echo " __ __ _____ _ _ "
echo "| \/ | / ____| | | | "
echo "| \ / | __ _ __ _ ___| (___ | |_ ___ ___| | ___ __ "
echo '| |\/| |/ _ |/ _ |/ _ \\___ \| __/ _ \ / __| |/ / __| '
echo "| | | | (_| | (_| | __/____) | || (_) | (__| <| | "
echo "|_| |_|\__,_|\__, |\___|_____/ \__\___/ \___|_|\_\_| "
echo " __/ | "
echo " |___/ "
echo " by Tegan Snyder "
echo "Here is the paramters you passed:"
echo "MAGENTO_ROOT: $MAGENTO_ROOT"
echo "THEME_BASE: $THEME_BASE"
echo "CURRENT_THEME: $CURRENT_THEME"
echo "If these params are not correctly set please exit"
echo
PS3='Please enter your choice: '
options=("revert to stock" "undo stock revert" "quit")
select opt in "${options[@]}"
do
case $opt in
"revert to stock")
read -p "Are you sure you want to continue? <y/N> " prompt
if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]
then
if [ -d "$MAGENTO_ROOT/app/etc/modules.stock" ]; then
read -p "It looks like you have ran this before. We need to clean up your previous module_backup folder prior to running. Are you okay with this? <y/N> " prompt
if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]
then
echo "cleaning up previous backups..."
if [ -d "$MAGENTO_ROOT/app/etc/modules_backup" ]; then
rm -rf $MAGENTO_ROOT/app/etc/modules_backup
echo "removed $MAGENTO_ROOT/app/etc/modules_backup..."
fi
if [ -d "$MAGENTO_ROOT/app/etc/modules.stock" ]; then
rm -rf $MAGENTO_ROOT/app/etc/modules.stock
echo "removed $MAGENTO_ROOT/app/etc/modules.stock..."
fi
if [ -d "$MAGENTO_ROOT/app/design/frontend/$THEME_BASE/$CURRENT_THEME.tmp" ]; then
rm -rf $MAGENTO_ROOT/app/design/frontend/$THEME_BASE/$CURRENT_THEME.tmp
echo "removing theme backup $MAGENTO_ROOT/app/design/frontend/$THEME_BASE/$CURRENT_THEME.tmp"
fi
if [ -d "$MAGENTO_ROOT/skin/frontend/$THEME_BASE/$CURRENT_THEME.tmp" ]; then
rm -rf $MAGENTO_ROOT/skin/frontend/$THEME_BASE/$CURRENT_THEME.tmp
echo "removing theme backup $MAGENTO_ROOT/skin/frontend/$THEME_BASE/$CURRENT_THEME.tmp"
fi
else
break
exit 1
fi
fi
echo "Converting to stock Magento..."
echo "creating directory to hold existing extension configs..."
mkdir $MAGENTO_ROOT/app/etc/modules_backup
mkdir $MAGENTO_ROOT/app/etc/modules_backup/stock_magento
echo "copying all stock Magento configs to stock_magento folder..."
ls -1 $MAGENTO_ROOT/app/etc/modules/Mage_* | xargs -J % -n1 cp % $MAGENTO_ROOT/app/etc/modules_backup/stock_magento
ls -1 $MAGENTO_ROOT/app/etc/modules/Enterprise_* | xargs -J % -n1 cp % $MAGENTO_ROOT/app/etc/modules_backup/stock_magento
echo "renaming the current modules directory..."
mv $MAGENTO_ROOT/app/etc/modules{,.tmp}
echo "creating a new modules directory..."
mkdir $MAGENTO_ROOT/app/etc/modules
echo "coping default configs to new modules folder..."
yes | cp -R $MAGENTO_ROOT/app/etc/modules_backup/stock_magento/* $MAGENTO_ROOT/app/etc/modules/
echo "disabling current theme..."
# if magento can't find the them it reverts to default theme
mv $MAGENTO_ROOT/app/design/frontend/$THEME_BASE/$CURRENT_THEME{,.tmp}
mv $MAGENTO_ROOT/skin/frontend/$THEME_BASE/$CURRENT_THEME{,.tmp}
echo "done!"
else
break
exit 1
fi
break
;;
"undo stock revert")
read -p "Are you sure you want to continue? <y/N> " prompt
if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]
then
if [ ! -d "$MAGENTO_ROOT/app/etc/modules.tmp" ]; then
echo $MAGENTO_ROOT/app/etc/modules.tmp
echo "It doesnt look like you have used this tool. Sorry we cant revert what we havent done!"
break
exit 1
fi
echo "Reverting stock Magento. Brining your extensions and theme back..."
echo "reverting back to the theme and extensions you had..."
echo "restoring extensions..."
mv $MAGENTO_ROOT/app/etc/modules $MAGENTO_ROOT/app/etc/modules.stock
mv $MAGENTO_ROOT/app/etc/modules.tmp $MAGENTO_ROOT/app/etc/modules
echo "restoring theme..."
mv $MAGENTO_ROOT/app/design/frontend/$THEME_BASE/$CURRENT_THEME.tmp $MAGENTO_ROOT/app/design/frontend/$THEME_BASE/$CURRENT_THEME
mv $MAGENTO_ROOT/skin/frontend/$THEME_BASE/$CURRENT_THEME.tmp $MAGENTO_ROOT/skin/frontend/$THEME_BASE/$CURRENT_THEME
echo "done!"
break
else
break
exit 1
fi
;;
"quit")
break
;;
*) echo invalid option;;
esac
done
@tegansnyder
Copy link
Author

NOTE be very careful with this... this only works on a mac
xargs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment