Skip to content

Instantly share code, notes, and snippets.

@ylkyrg
Created March 6, 2020 16:02
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 ylkyrg/ce309e6ab4e0c88a171dd2cd27a5c3d8 to your computer and use it in GitHub Desktop.
Save ylkyrg/ce309e6ab4e0c88a171dd2cd27a5c3d8 to your computer and use it in GitHub Desktop.
Script to add a new site to Homestead.yaml
#!/bin/sh
#####################################################
# Add new site to Homestead.yaml
#####################################################
#
# This scipt assumes the new site is already in a
# mapped directory and that is that its parent
# directory is the same as the domain.
#
# E.g. ~/code/foo.org
#
# Ensure homestead_path is correct. If you want to
# reprovision Homesated uncomment the last command.
#
# The path to the global Homestead install
homestead_path="$HOME/Homestead"
# The time to append to the Homestead.yaml backup
time_now=$(date +%s)
# Prompt for the site url
read -r -p "Domain (example.test): " domain
# Prompt for the database name
read -r -p "Database name: " db_name
# Backup Homestead.yaml
mv "$homestead_path"/Homestead.yaml "$homestead_path"/Homestead_"$time_now".yaml
# Add new setting to Homestead.yaml
awk -v db=$db_name -v ft=$folder_to -v d=$domain \
'/databases:/ {
print;
print " - " db;
next
}
/sites:/ {
print;
print " - map: " d;
print " to: /home/vagrant/code/" d "/public\n";
next
}
{ print }' \
"$homestead_path"/Homestead_"$time_now".yaml > "$homestead_path"/Homestead.yaml
# Provision Homestead
# cd "$homestead_path" && vagrant reload --provision
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment