Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ychadwick
Created July 14, 2015 13:07
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 ychadwick/e7f9a9a1c08ee2cd019e to your computer and use it in GitHub Desktop.
Save ychadwick/e7f9a9a1c08ee2cd019e to your computer and use it in GitHub Desktop.
To be used with an initcms and symfony2 based project. Simple script for pulling changes from git, updating dependencies, clearing caches, installing and compiling assets.
#!/bin/bash
#########################################
#
# Make sure the script is executable by
# running chmod u+x initcms-deploy.sh
# To run this command, change to same
# directory as this file, and on the
# command line type the following:
# ./initcms-deploy.sh
#
#########################################
#########################################
#Black 0;30 Dark Gray 0;30
#Red 0;31 Light Red 0;31
#Green 0;32 Light Green 0;32
#Brown/Orange 0;33 Yellow 0;33
#Blue 0;34 Light Blue 0;34
#Purple 0;35 Light Purple 0;35
#Cyan 0;36 Light Cyan 0;36
#Light Gray 0;37 White 0;37
#########################################
YELLOW='\033[0;33m'
CYAN='\033[0;36m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
INSTALL=''
ENV=$1
#check if should install dependencies
install_composer(){
echo -e "${YELLOW}Do you want to do a composer install?${NC} ${CYAN}y/n${NC}"
read INSTALL
#validate input
if [ "$INSTALL" != "y" ] && [ "$INSTALL" != "n" ]; then
install_composer
fi
}
#check env parameter
check_env(){
echo -e "${YELLOW}Which environment do you want to update?${NC} ${CYAN}dev/prod${NC}"
read ENV
#validate input
if [ "$ENV" != "prod" ] && [ "$ENV" != "dev" ]; then
check_env
fi
}
#run all
run(){
if [ -z "$ENV" ]; then
echo -e "${YELLOW}Deploy symfony project${NC}";
else
echo -e "${YELLOW}Deploy symfony project in ${GREEN}$ENV${NC} ${YELLOW}environment${NC}";
fi
echo "Git pull from repository"
git pull
install_composer
#Ask if the user wants to do a composer install
if [ "$INSTALL" == "y" ]; then
php -d memory_limit=512M composer.phar install --no-dev --optimize-autoloader
fi
#if no environment is given, ask wich to use
if [ "$ENV" != "prod" ] && [ "$ENV" != "dev" ]; then
check_env
fi
if [ "$INSTALL" == "y" ] && [ "$ENV" == "prod" ]; then
php -d memory_limit=512M app/console --env=$ENV cache:clear
elif [ "$INSTALL" != "y" ]; then
#if a composer install was not made, then install assets
php -d memory_limit=512M app/console --env=$ENV cache:clear
app/console --env=$ENV assets:install
fi
app/console --env=$ENV assetic:dump
echo -e "${GREEN}All set and ready to go! Have fun :) ${NC}"
}
if [ "$ENV" == "-h" ]; then
#help text
echo -e "${YELLOW}To run the script, enter the following:${NC} ./initcms-deploy.sh"
echo -e "${YELLOW}You can also add the environment directly to the command, for example:${NC} ./initcms-deploy.sh prod"
else
run
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment