The purpose of this bash script is to automataclly start up or shutdown a laravel sail project with docker.
To run this script follow these instructions:
$ chmod +x laravel.sh
./laravel.sh
laravel.sh
#!/bin/bash
clear
APPNAME_DEFAULT="api"
read -p "Enter The App you want to Start: [$APPNAME_DEFAULT/] " APPNAME
if [[ $APPNAME == "" ]]
then
APPNAME=$APPNAME_DEFAULT
set -e
fi
#https://stackoverflow.com/questions/59838/how-can-i-check-if-a-directory-exists-in-a-bash-shell-script
# check if directory exists
if [ ! -d "$APPNAME" ]; then
echo "FATAL FERROR: $APPNAME DOES NOT EXIST. Try Again."
set -e
exit
fi
echo "[OK] App was found: $APPNAME"
STATUS_DEFAULT="up -d"
read -p "App Action: up/down [$STATUS_DEFAULT/] " STATUS
if [[ $STATUS == "" ]]
then
STATUS=$STATUS_DEFAULT
set -e
fi
cd $APPNAME
./vendor/bin/sail $STATUS
if [[ $STATUS == STATUS_DEFAULT ]]
then
# ALWAYS PUT THIS AT THE END OF THE SCRIPT
echo "Opening browser with localhost"
xdg-open http://localhost
fi