fourkitchens / pantheon-tools

Tools to run actions against a Pantheon site
GNU General Public License v3.0
16 stars 3 forks source link

Check if mysql is installed #18

Closed cbfannin closed 1 year ago

cbfannin commented 1 year ago

This will check if mysql is installed and exit if not when the pantheon-db-cli command is executed. I didn't have to have mysql enabled/running for the command to continue to work but please test that again.

cbfannin commented 1 year ago

@dalin- I read through the link you provided and it seems they are recommending the way we are already checking for mysql existence. The only thing that is different is how they handle the error. Rather than an if statement like we had, they use conditional or logic. They did mention the which command to see if the path exists but that is not recommended.

What am I overlooking?

dalin- commented 1 year ago

@cbfannin

I read through the link you provided and it seems they are recommending the way we are already checking for mysql existence.

My bad. I must've been reading too fast. Your method looks good.

cbfannin commented 1 year ago

@cbfannin

I read through the link you provided and it seems they are recommending the way we are already checking for mysql existence.

My bad. I must've been reading too fast. Your method looks good.

My confusion is I don't see much difference in what they recommended vs what I originally had. What I originally had:

command -v mysql >/dev/null 2>&1
  if [[ $? -ne 0 ]]; then
    echo "mysql is not installed."
      exit 1
  fi

VS what the post recommended:

command -v mysql >/dev/null 2>&1 || { echo >&2 "FAILURE. MySQL is required. Please install mysql locally and run the command again."; exit 1; }

The test is identical. command -v mysql >/dev/null 2>&1 The only difference I see is how the error message is handled. Are you saying both of these are acceptable?

dalin- commented 1 year ago

@cbfannin

My confusion is I don't see much difference in what they recommended vs what I originally had.

Exactly. For some reason when I read it the first time I thought you had done

mysql -v >/dev/null 2>&1
  if [[ $? -ne 0 ]]; then

What you've got here is great!