Created
April 17, 2020 12:07
-
-
Save zecka/0855a7aed2f0b8ae083a94fc1380a8b2 to your computer and use it in GitHub Desktop.
Create a new drupal site on Valet with MAMP on Mac OS
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
# ============================= | |
# CHECK REQUIREMENTS | |
# ============================= | |
requirement=1; | |
#check if pv command exist | |
if ! which pv >/dev/null; then | |
echo "You need to install pv" | |
requirement=0 | |
fi | |
#check if pv command exist | |
if ! which valet >/dev/null; then | |
echo "you need to install valet" | |
requirement=0 | |
fi | |
#check if wget command exist | |
if ! which wget >/dev/null; then | |
echo "you need to install wget" | |
requirement=0 | |
fi | |
if [ "$requirement" -eq "0" ]; then | |
echo 'Install requirement first' | |
exit | |
fi | |
# ============================= | |
# FUNCTIONS | |
# ============================= | |
function punzip { | |
unzip $1 | pv -l -s $(unzip -Z -1 $1 | wc -l) > /dev/null; | |
} | |
# ============================= | |
# VARIOUS CHECK | |
# ============================= | |
# CHECK IF USER PROVIDE CORRECT ARGUMENT | |
echo $1 | |
if [ $# -eq 0 ] | |
then | |
echo "You must provide your site name p.ex drupal-test" | |
exit | |
fi | |
if [[ "$1" =~ [^-a-zA-Z0-9] ]]; then | |
echo "Site name must respect following regex [^-a-zA-Z0-9]" | |
exit | |
fi | |
# CHECK IF VALET SYMLINK EXIT | |
if [ -L "$HOME/.config/valet/Sites/"$1 ] | |
then | |
echo "$1 valet site already exist" | |
exit; | |
fi | |
# DEFINE DB NAME | |
DB_NAME=$(echo "$1" | sed "s/-/_/") | |
# CHECK IF DB EXIT | |
if /Applications/MAMP/Library/bin/mysql -uroot -proot -e 'use '$DB_NAME; | |
then | |
echo "$DB_NAME database already exist, choose another name"; | |
exit | |
fi | |
# USER AVERTISSEMENT | |
read -p "Are you sure, this action will delete everything in the current folder? (Y/n) " -n 1 -r | |
echo # (optional) move to a new line | |
if [[ $REPLY =~ ^[Yy]$ ]] | |
then | |
# do dangerous stuff | |
echo "Let's GO !" | |
else | |
echo "No im not" | |
exit | |
fi | |
# ============================= | |
# EXECUTE | |
# ============================= | |
# Clean Folder | |
rm -rf ./* | |
# Download Drupal | |
wget https://www.drupal.org/download-latest/zip | |
# unzip Drupal | |
echo "UNZIP FILE" | |
punzip zip | |
# rename first folder as donloadfiles | |
mv $(ls -d */|head -n 1) ./downloadfiles | |
# move all content into current directory | |
mv ./downloadfiles/* ./ | |
# remove downloadfiles folder and zip file | |
rm -rf ./downloadfiles && rm -f zip | |
# Create valet link | |
valet link $1 | |
# CREATE DATABASE | |
/Applications/MAMP/Library/bin/mysql -uroot -proot -e "CREATE DATABASE $DB_NAME" | |
echo "Your website is accessible at http://$1.test" | |
echo "DB_NAME: $DB_NAME" | |
echo "DB_USER: root" | |
echo "DB_PASSWORD: root" | |
echo "DB_HOST: 127.0.0.1:8889" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment