From 34edc84dab09b9e28a63dc1e73197acf50a4611e Mon Sep 17 00:00:00 2001 From: root Date: Thu, 15 Feb 2024 09:48:48 -0500 Subject: clean up the devnulls etc --- src/mariadb-push-replica.sh | 67 ++++++++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 25 deletions(-) diff --git a/src/mariadb-push-replica.sh b/src/mariadb-push-replica.sh index 535ef61..140fb2e 100755 --- a/src/mariadb-push-replica.sh +++ b/src/mariadb-push-replica.sh @@ -42,18 +42,38 @@ else fi replication_user=replication -run_primary() +without_tty_input() +{ + if [ -t 0 ] + then + "$@" < /dev/null + else + "$@" + fi +} + +run_() { + case "$1" in + primary_host | replica_host ) ;; + *_host ) return 54 ;; # lol wut + * ) return 53 ;; + esac (set -x - : primary : $1 $2 ${3:+ ...}) - BASH_RPC_REMOTE_DEST=$primary_host remote_run_function "$@" + : ${1%_host} : $2 $3 ${4:+ ...}) + BASH_RPC_REMOTE_DEST=${!1} \ + without_tty_input \ + remote_run_function "${@:2}" +} + +run_primary() +{ + run_ primary_host "$@" } run_replica() { - (set -x - : replica : $1 $2 ${3:+ ...}) - BASH_RPC_REMOTE_DEST=$replica_host remote_run_function "$@" + run_ replica_host "$@" } show_hostnames() @@ -137,7 +157,8 @@ create_replication_user() create or replace user '$2'@'$1' -identified by +identified +by '$3' ; grant replication slave @@ -213,9 +234,9 @@ mariadb_enable_semi_sync() set -e [ "$1" = off ] || set -- on mariadb -v --skip-reconnect -t <<. -stop slave io_thread; -set global rpl_semi_sync_master_enabled = $1; -set global rpl_semi_sync_slave_enabled = $1; +stop slave io_thread ; +set global rpl_semi_sync_master_enabled = $1 ; +set global rpl_semi_sync_slave_enabled = $1 ; . mariadb_show_vars_like 'rpl_%' } @@ -228,7 +249,9 @@ select @@hostname , @@server_id ; -use information_schema; +use + information_schema +; select variable_name , variable_value @@ -243,11 +266,12 @@ where mariadb_list_databases() { show_all_databases >&2 - mariadb --skip-reconnect -Bsss "$@" <<. + mariadb --skip-reconnect -B -s <<. select schema_name from - information_schema.schemata; + information_schema.schemata +; . } @@ -319,15 +343,13 @@ mariadb_scan_databases() set -- "$(mktemp)" declare -g -a primary_dbs save_array primary_dbs from lines <( - run_primary mariadb_list_databases \ - "$1" | + run_primary mariadb_list_databases 2>"$1" | sort -u ) declare -g -a replica_dbs save_array replica_dbs from lines <( - run_replica mariadb_list_databases \ - >"$1" | + run_replica mariadb_list_databases 2>>"$1" | sort -u ) @@ -414,11 +436,8 @@ main() run_replica \ show_all_databases fi - if gtid=$(\ - run_primary \ - mariadb_get_primary_gtid \ -