Skip to content

Commit b9f9eaa

Browse files
committed
Silence MySQL password errors
no ref - Using a passsord on the CLI causes MySQL to print 'mysql: [Warning] Using a password on the command line interface can be insecure.' which doing via environment variables prevents - This also fixes our other `cut` usages in the event the string has a `=` in it not printing the whole string
1 parent c9b43fb commit b9f9eaa

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ services:
6767
MYSQL_ROOT_PASSWORD: ${DATABASE_ROOT_PASSWORD:?DATABASE_ROOT_PASSWORD environment variable is required}
6868
MYSQL_USER: ${DATABASE_USER:-ghost}
6969
MYSQL_PASSWORD: ${DATABASE_PASSWORD:?DATABASE_PASSWORD environment variable is required}
70+
MYSQL_PWD: ${DATABASE_PASSWORD:?DATABASE_PASSWORD environment variable is required}
7071
MYSQL_DATABASE: ghost
7172
MYSQL_MULTIPLE_DATABASES: activitypub
7273
volumes:

scripts/migrate.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ test_mysql_dump() {
208208
local password=$4
209209

210210
# Try a minimal dump to test permissions
211-
if mysqldump --no-tablespaces --no-data -h"$host" -u"$user" -p"$password" "$database" >/dev/null 2>&1; then
211+
if MYSQL_PWD="$password" mysqldump --no-tablespaces --no-data -h"$host" -u"$user" "$database" >/dev/null 2>&1; then
212212
return 0
213213
else
214214
return 1
@@ -227,7 +227,7 @@ migrate_database() {
227227
# Export database with proper error handling
228228
local dump_output
229229
local dump_status
230-
dump_output=$(mysqldump --no-tablespaces -h"$mysql_host" -u"$mysql_user" -p"$mysql_password" "$mysql_database" 2>&1 > "$TEMP_SQL_FILE")
230+
dump_output=$(MYSQL_PWD="$mysql_password" mysqldump --no-tablespaces -h"$mysql_host" -u"$mysql_user" "$mysql_database" 2>&1 > "$TEMP_SQL_FILE")
231231
dump_status=$?
232232

233233
# Check for errors in output (mysqldump may return 0 even with some errors)
@@ -286,7 +286,9 @@ migrate_database() {
286286

287287
# Import database
288288
echo "Importing database into Docker MySQL..."
289-
if ! docker compose exec -T db sh -c 'exec mysql -uroot -p"$MYSQL_ROOT_PASSWORD" $MYSQL_DATABASE' < "$TEMP_SQL_FILE"; then
289+
local MYSQL_ROOT_PASSWORD
290+
MYSQL_ROOT_PASSWORD=$(grep DATABASE_ROOT_PASSWORD "$PWD/.env" | cut -d '=' -f 2-)
291+
if ! docker compose exec -e MYSQL_PWD=$MYSQL_ROOT_PASSWORD -T db sh -c 'exec mysql -uroot $MYSQL_DATABASE' < "$TEMP_SQL_FILE"; then
290292
echo "ERROR: Failed to import database"
291293
exit 1
292294
fi
@@ -504,13 +506,13 @@ main() {
504506
docker compose up caddy -d
505507

506508
local domain
507-
domain=$(grep 'DOMAIN' "${PWD}/.env" | cut -d '=' -f 2)
509+
domain=$(grep 'DOMAIN' "${PWD}/.env" | cut -d '=' -f 2-)
508510
echo ""
509511
echo "✓ Caddy Webserver is running!"
510512
echo "✓ Your site is available at: https://${domain}"
511513
else
512514
local ghost_port
513-
ghost_port=$(grep 'GHOST_PORT' "${PWD}/.env" | cut -d '=' -f 2)
515+
ghost_port=$(grep 'GHOST_PORT' "${PWD}/.env" | cut -d '=' -f 2-)
514516
echo ""
515517
echo "✓ Ghost is now running"
516518
echo " To finish migration, configure your webserver to forward traffic to 127.0.0.1:${ghost_port}"

0 commit comments

Comments
 (0)