Created
March 3, 2016 15:29
-
-
Save multiarts/3fb6febd0a0b8f316b99 to your computer and use it in GitHub Desktop.
Homestead
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
#!/bin/bash | |
home=~/ | |
if [ -z "$1" ] | |
then | |
echo -n "Informe o nome do projeto (Ex.: homestead): " | |
read answer | |
else | |
answer="$1" | |
fi | |
project="$answer" | |
vagrant_dir="/home/vagrant/Code/"$project"/" | |
base_path=$home"Code/"$project"/" | |
echo $base_path | |
if [ -z "$2" ] | |
then | |
echo -n "Informe a pasta pública do projeto: (Ela será baseada em $base_path) " | |
read answer | |
else | |
answer="$2" | |
fi | |
base_path=$base_path"$answer" | |
vagrant_dir=$vagrant_dir"$answer" | |
# Remove barra final se existir | |
if [ ${base_path:(-1)} == "/" ] | |
then | |
base_path=${base_path%?} | |
vagrant_dir=${vagrant_dir%?} | |
fi | |
# Criando pasta do projeto se nao existir | |
echo | |
echo "Criando pasta $base_path ..." | |
mkdir -p "$base_path" | |
cd $base_path | |
echo "<h1>$project</h1>" >> index.php | |
# Editando arquivo de hosts | |
echo -e "192.168.10.10 $project.app" | sudo tee -a /etc/hosts | |
# Editando Homestead.yaml | |
echo "Editando arquivo Homestead.yaml ..." | |
file="$home.homestead/Homestead.yaml" | |
awk -v from="sites:.*$" -v to="sites:\n - map: $project.app\n to: $vagrant_dir" '{gsub(from,to,$0); print $0}' $file > ${file}.new | |
echo "Removendo arquivos temporários ..." | |
mv ${file}.new $file | |
echo "Reiniciando homestead ..." | |
cd ~/Homestead | |
vagrant halt && vagrant up --provision | |
echo "Tudo certo! Até breve!" | |
echo | |
open "http://$project.app" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment