Last active
June 5, 2017 02:42
-
-
Save michael34435/e2289d135ca408b7d97ae72c5a86b03a to your computer and use it in GitHub Desktop.
Laravel Bootstrap Script(v5.3 or above)
This file contains hidden or 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
#!/bin/bash | |
function ansi() { | |
bold= | |
color= | |
if [[ -z "$2" ]]; then | |
color="0" | |
else | |
color="$2" | |
fi | |
if [[ -z "$3" ]]; then | |
bold="0" | |
else | |
bold="$3" | |
fi | |
echo -e "\033[${bold};${color}m$1\033[0;0m" | |
} | |
if [[ -z $(which npm) ]] || [[ -z $(which node) ]]; then | |
ansi "You have to install node.js and npm first" 33 1 | |
exit 1 | |
fi | |
if [[ -z $(which gulp) ]]; then | |
ansi "Install global gulp now" 36 | |
npm install -g gulp | |
fi | |
ansi "Install npm package now" 36 | |
npm install | |
ansi "Pre-compile sass and ES6(or above) javascript" 36 | |
npm run prod | |
composer="composer" | |
if [[ -z $(which composer) ]]; then | |
ansi "Install composer now" 36 | |
curl -O https://getcomposer.org/composer.phar | |
composer="php composer.phar" | |
fi | |
$composer install | |
temp= | |
if [[ -f .env ]] && [[ -z $LARAVEL_CREATE_ENV ]]; then | |
while true; do | |
read -r -p "Enviroment configuration is exists, do you want to overwrite it? [Y/N] " response | |
case "$response" in | |
[Yy]*) | |
break | |
;; | |
[Nn]*) | |
temp=$(<.env) | |
break | |
;; | |
esac | |
done | |
fi | |
if [[ ! -z $LARAVEL_CREATE_ENV ]]; then | |
temp=$(<.env) | |
fi | |
>.env | |
ansi "Prepare configuration..." 36 | |
while IFS='' read -r line || [[ -n "$line" ]]; do | |
IFS='=' read -r -a line <<< "$line" | |
if [[ ! -z ${line[0]} ]]; then | |
if [[ ! -z $(printenv ${line[0]}) ]]; then | |
line[1]=$(printenv ${line[0]}) | |
fi | |
variable="${line[0]}=${line[1]}" | |
echo "${variable}" >> .env | |
export ${variable} | |
fi | |
done < .env.example | |
if [[ ! -z ${temp} ]]; then | |
>.env | |
echo "${temp}" >> .env | |
fi | |
if [[ -f database.sql ]]; then | |
ansi "Prepare db schema..." 36 | |
if [[ -z $(echo "$(<database.sql)" | grep "CREATE SCHEMA") ]]; then | |
mysql -u${DB_USERNAME} -p${DB_PASSWORD} -h${DB_HOST} --port=${DB_PORT} ${DB_DATABASE} < database.sql | |
else | |
mysql -u${DB_USERNAME} -p${DB_PASSWORD} -h${DB_HOST} --port=${DB_PORT} < database.sql | |
fi | |
fi | |
ansi "Artisan your app now" 36 | |
php artisan key:generate | |
php artisan migrate | |
php artisan db:seed | |
php artisan vendor:publish | |
ansi "Your laravel app finish bootstrapping now" 32 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment