Last active
July 19, 2016 08:46
-
-
Save Kreshnik/26565f2d04251e55322e4bc6a6eee5f6 to your computer and use it in GitHub Desktop.
A bash function to setup Laravel & DB.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function lara(){ | |
RED='\033[0;31m' | |
GREEN='\033[0;32m' | |
NC='\033[0m' | |
printf "${GREEN}What is the name of the project:${NC}" | |
read PROJECT_NAME | |
if [ ! -z $PROJECT_NAME ]; # Check if project name is set. | |
then | |
SECONDS=0 | |
# Prompt user for db details. | |
printf "${GREEN}Specify database name:${NC}" | |
read DATABASE_NAME | |
printf "${GREEN}Specify database user:${NC}" | |
read DATABASE_USER | |
printf "${GREEN}Specify database password:${NC}" | |
read DATABASE_PASS | |
# Run laravel installer. | |
laravel new $PROJECT_NAME | |
cd $PROJECT_NAME | |
# Chmod storage directory. | |
chmod -R 775 storage/ | |
# Init git and perform first commit. | |
git init | |
git add -A | |
git commit -m "Initial commit." | |
if [ ! -z $DATABASE_USER ] && [ ! -z $DATABASE_NAME ] && [ ! -z $DATABASE_PASS ] ; # Check if db details are set. | |
then | |
# Create the database. | |
mysql -u $DATABASE_USER -p${DATABASE_USER} -e "CREATE DATABASE IF NOT EXISTS ${DATABASE_NAME}; " | |
if [ -f ./.env ]; | |
then | |
# Set properties in .env file. | |
sed -i '' -e "s/DB_DATABASE=.*/DB_DATABASE=${DATABASE_NAME}/" ./.env | |
sed -i '' -e "s/DB_USERNAME=.*/DB_USERNAME=${DATABASE_USER}/" ./.env | |
sed -i '' -e "s/DB_PASSWORD=.*/DB_PASSWORD=${DATABASE_PASS}/" ./.env | |
fi | |
fi | |
echo "$(($SECONDS / 60)) minutes and $(($SECONDS % 60)) seconds elapsed." | |
else | |
printf "${RED}No project name specified.${NC}" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment