Skip to content

Instantly share code, notes, and snippets.

@DevJonTaylor
Last active April 18, 2022 03:44
Show Gist options
  • Save DevJonTaylor/fad738afdf3edebbb3f967f216165618 to your computer and use it in GitHub Desktop.
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.
#!/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
@DevJonTaylor
Copy link
Author

Making public

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment