Last active
April 18, 2022 03:44
-
-
Save DevJonTaylor/fad738afdf3edebbb3f967f216165618 to your computer and use it in GitHub Desktop.
Prompts for MySQL Username and Password. Then creates a .env file in the PWD. Be sure to fill out the _SQL_FILE variable and DB_NAME variable at the top.
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 | |
_ENV="./.env" | |
_SQL_FILE="./db/schema.sql" | |
DB_NAME='shebang_db' | |
create_env() | |
{ | |
echo "Lets setup your .env" | |
read -p "Username: " DB_USER | |
read -sp "Password: " DB_PW | |
echo "" | |
printf "DB_NAME='%s'\nDB_USER='%s'\nDB_PW='%s'\n" "$DB_NAME" "$DB_USER" "$DB_PW" > "$_ENV" | |
} | |
broken() | |
{ | |
echo 'There was an issue getting your credentials' | |
return 0 | |
} | |
create_schema() | |
{ | |
mysql -u $DB_USER -p$DB_PW < $_SQL_FILE >/dev/null 2>&1 | |
echo "----- SCHEMA CREATED -----" | |
} | |
[ ! -f $_ENV ] && create_env || echo 'Getting your credentials from .env' | |
source ./.env | |
[ -z $DB_USER ] && broken || create_schema |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Making public