Skip to content

Commit 355ee68

Browse files
committed
MDEV-13946 Server RPMs have dependency on "which"
cleanup. use "command -v" instead of "which" simplify some checks.
1 parent 2232784 commit 355ee68

File tree

8 files changed

+39
-121
lines changed

8 files changed

+39
-121
lines changed

cmake/cpack_rpm.cmake

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,6 @@ IF(WITH_WSREP)
168168
SETA(CPACK_RPM_server_PACKAGE_REQUIRES
169169
"galera" "rsync" "lsof" "grep" "gawk" "iproute"
170170
"coreutils" "findutils" "tar")
171-
IF (RPM MATCHES "sles11")
172-
SETA(CPACK_RPM_server_PACKAGE_REQUIRES "util-linux")
173-
ELSE()
174-
SETA(CPACK_RPM_server_PACKAGE_REQUIRES "which")
175-
ENDIF()
176171
ENDIF()
177172

178173
SET(CPACK_RPM_server_PRE_INSTALL_SCRIPT_FILE ${CMAKE_SOURCE_DIR}/support-files/rpm/server-prein.sh)
@@ -292,4 +287,3 @@ IF(compat53 AND compat101)
292287
ENDIF()
293288

294289
ENDIF(RPM)
295-

scripts/mysql_config.sh

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,6 @@
1717
# This script reports various configuration settings that may be needed
1818
# when using the MariaDB client library.
1919

20-
which ()
21-
{
22-
IFS="${IFS= }"; save_ifs="$IFS"; IFS=':'
23-
for file
24-
do
25-
for dir in $PATH
26-
do
27-
if test -f $dir/$file
28-
then
29-
echo "$dir/$file"
30-
continue 2
31-
fi
32-
done
33-
echo "which: no $file in ($PATH)"
34-
exit 1
35-
done
36-
IFS="$save_ifs"
37-
}
38-
3920
#
4021
# If we can find the given directory relatively to where mysql_config is
4122
# we should use this instead of the incompiled one.
@@ -70,7 +51,7 @@ get_full_path ()
7051
case $file in
7152
/*) echo "$file";;
7253
*/*) tmp=`pwd`/$file; echo $tmp | sed -e 's;/\./;/;' ;;
73-
*) which $file ;;
54+
*) command -v $file ;;
7455
esac
7556
}
7657

scripts/mysqld_safe.sh

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -103,35 +103,6 @@ EOF
103103
exit 1
104104
}
105105

106-
my_which ()
107-
{
108-
save_ifs="${IFS-UNSET}"
109-
IFS=:
110-
ret=0
111-
for file
112-
do
113-
for dir in $PATH
114-
do
115-
if [ -f "$dir/$file" ]
116-
then
117-
echo "$dir/$file"
118-
continue 2
119-
fi
120-
done
121-
122-
ret=1 #signal an error
123-
break
124-
done
125-
126-
if [ "$save_ifs" = UNSET ]
127-
then
128-
unset IFS
129-
else
130-
IFS="$save_ifs"
131-
fi
132-
return $ret # Success
133-
}
134-
135106
find_in_bin() {
136107
if test -x "$MY_BASEDIR_VERSION/bin/$1"
137108
then
@@ -220,7 +191,8 @@ wsrep_pick_url() {
220191

221192
log_error "WSREP: 'wsrep_urls' is DEPRECATED! Use wsrep_cluster_address to specify multiple addresses instead."
222193

223-
if ! which nc >/dev/null; then
194+
if ! command -v nc >/dev/null
195+
then
224196
log_error "ERROR: nc tool not found in PATH! Make sure you have it installed."
225197
return 1
226198
fi
@@ -646,8 +618,7 @@ plugin_dir="${plugin_dir}${PLUGIN_VARIANT}"
646618
# Ensure that 'logger' exists, if it's requested
647619
if [ $want_syslog -eq 1 ]
648620
then
649-
my_which logger > /dev/null 2>&1
650-
if [ $? -ne 0 ]
621+
if ! command -v logger > /dev/null
651622
then
652623
log_error "--syslog requested, but no 'logger' program found. Please ensure that 'logger' is in your PATH, or do not specify the --syslog option to mysqld_safe."
653624
exit 1
@@ -878,7 +849,7 @@ fi
878849
if @TARGET_LINUX@ && test $flush_caches -eq 1
879850
then
880851
# Locate sync, ensure it exists.
881-
if ! my_which sync > /dev/null 2>&1
852+
if ! command -v sync > /dev/null
882853
then
883854
log_error "sync command not found, required for --flush-caches"
884855
exit 1
@@ -890,7 +861,7 @@ then
890861
fi
891862

892863
# Locate sysctl, ensure it exists.
893-
if ! my_which sysctl > /dev/null 2>&1
864+
if ! command -v sysctl > /dev/null
894865
then
895866
log_error "sysctl command not found, required for --flush-caches"
896867
exit 1
@@ -934,7 +905,7 @@ cmd="`mysqld_ld_preload_text`$NOHUP_NICENESS"
934905
if @TARGET_LINUX@ && test $numa_interleave -eq 1
935906
then
936907
# Locate numactl, ensure it exists.
937-
if ! my_which numactl > /dev/null 2>&1
908+
if ! command -v numactl > /dev/null
938909
then
939910
log_error "numactl command not found, required for --numa-interleave"
940911
exit 1

scripts/wsrep_sst_common.sh

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,21 +144,21 @@ CLIENT_DIR="$SCRIPTS_DIR/../client"
144144
if [ -x "$CLIENT_DIR/mysql" ]; then
145145
MYSQL_CLIENT="$CLIENT_DIR/mysql"
146146
else
147-
MYSQL_CLIENT=$(which mysql)
147+
MYSQL_CLIENT=mysql
148148
fi
149149

150150
if [ -x "$CLIENT_DIR/mysqldump" ]; then
151151
MYSQLDUMP="$CLIENT_DIR/mysqldump"
152152
else
153-
MYSQLDUMP=$(which mysqldump)
153+
MYSQLDUMP=mysqldump
154154
fi
155155

156156
if [ -x "$SCRIPTS_DIR/my_print_defaults" ]; then
157157
MY_PRINT_DEFAULTS="$SCRIPTS_DIR/my_print_defaults"
158158
elif [ -x "$EXTRA_DIR/my_print_defaults" ]; then
159159
MY_PRINT_DEFAULTS="$EXTRA_DIR/my_print_defaults"
160160
else
161-
MY_PRINT_DEFAULTS=$(which my_print_defaults)
161+
MY_PRINT_DEFAULTS=my_print_defaults
162162
fi
163163

164164
readonly WSREP_SST_OPT_CONF="$WSREP_SST_OPT_DEFAULT $WSREP_SST_OPT_EXTRA_DEFAULT"
@@ -226,10 +226,10 @@ wsrep_check_program()
226226
{
227227
local prog=$1
228228

229-
if ! which $prog >/dev/null
229+
if ! command -v $prog >/dev/null
230230
then
231231
echo "'$prog' not found in PATH"
232-
return 2 # no such file or directory
232+
exit 2 # ENOENT no such file or directory
233233
fi
234234
}
235235

@@ -239,11 +239,9 @@ wsrep_check_programs()
239239

240240
while [ $# -gt 0 ]
241241
do
242-
wsrep_check_program $1 || ret=$?
242+
wsrep_check_program $1
243243
shift
244244
done
245-
246-
return $ret
247245
}
248246

249247
#

scripts/wsrep_sst_mariabackup.sh

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ sdecomp=""
7777
# 5.6.21 PXC and later can't donate to an older joiner
7878
sst_ver=1
7979

80-
if which pv &>/dev/null && pv --help | grep -q FORMAT;then
80+
if pv --help 2>/dev/null | grep -q FORMAT;then
8181
pvopts+=$pvformat
8282
fi
8383
pcmd="pv $pvopts"
@@ -172,10 +172,7 @@ get_transfer()
172172
fi
173173

174174
if [[ $tfmt == 'nc' ]];then
175-
if [[ ! -x `which nc` ]];then
176-
wsrep_log_error "nc(netcat) not found in path: $PATH"
177-
exit 2
178-
fi
175+
wsrep_check_programs nc
179176
wsrep_log_info "Using netcat as streamer"
180177
if [[ "$WSREP_SST_OPT_ROLE" == "joiner" ]];then
181178
if nc -h 2>&1 | grep -q ncat;then
@@ -188,11 +185,8 @@ get_transfer()
188185
fi
189186
else
190187
tfmt='socat'
188+
wsrep_check_programs socat
191189
wsrep_log_info "Using socat as streamer"
192-
if [[ ! -x `which socat` ]];then
193-
wsrep_log_error "socat not found in path: $PATH"
194-
exit 2
195-
fi
196190

197191
if [[ $encrypt -eq 2 || $encrypt -eq 3 ]] && ! socat -V | grep -q "WITH_OPENSSL 1";then
198192
wsrep_log_error "Encryption requested, but socat is not OpenSSL enabled (encrypt=$encrypt)"
@@ -281,7 +275,7 @@ get_footprint()
281275
adjust_progress()
282276
{
283277

284-
if [[ ! -x `which pv` ]];then
278+
if ! command -v pv >/dev/null;then
285279
wsrep_log_error "pv not found in path: $PATH"
286280
wsrep_log_error "Disabling all progress/rate-limiting"
287281
pcmd=""
@@ -571,7 +565,7 @@ recv_joiner()
571565
pushd ${dir} 1>/dev/null
572566
set +e
573567

574-
if [[ $tmt -gt 0 && -x `which timeout` ]];then
568+
if [[ $tmt -gt 0 ]] && command -v timeout >/dev/null;then
575569
if timeout --help | grep -q -- '-k';then
576570
ltcmd="timeout -k $(( tmt+10 )) $tmt $tcmd"
577571
else
@@ -630,10 +624,7 @@ send_donor()
630624

631625
}
632626

633-
if [[ ! -x `which $INNOBACKUPEX_BIN` ]];then
634-
wsrep_log_error "${INNOBACKUPEX_BIN} not in path: $PATH"
635-
exit 2
636-
fi
627+
wsrep_check_programs "$INNOBACKUPEX_BIN"
637628

638629
rm -f "${MAGIC_FILE}"
639630

@@ -659,7 +650,7 @@ INNOEXTRA=""
659650

660651
if [[ $ssyslog -eq 1 ]];then
661652

662-
if [[ ! -x `which logger` ]];then
653+
if ! command -v logger >/dev/null;then
663654
wsrep_log_error "logger not in path: $PATH. Ignoring"
664655
else
665656

@@ -943,7 +934,7 @@ then
943934

944935
wsrep_log_info "Compressed qpress files found"
945936

946-
if [[ ! -x `which qpress` ]];then
937+
if ! command -v qpress >/dev/null;then
947938
wsrep_log_error "qpress not found in path: $PATH"
948939
exit 22
949940
fi

scripts/wsrep_sst_rsync.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ check_pid_and_port()
7171
grep '[[:space:]]\+rsync[[:space:]]\+'"$rsync_pid" 2>/dev/null)"
7272
;;
7373
*)
74-
if ! which lsof > /dev/null; then
74+
if ! command -v lsof > /dev/null; then
7575
wsrep_log_error "lsof tool not found in PATH! Make sure you have it installed."
7676
exit 2 # ENOENT
7777
fi
@@ -102,17 +102,18 @@ check_pid_and_port()
102102
is_local_ip()
103103
{
104104
local address="$1"
105-
local get_addr_bin=`which ifconfig`
106-
if [ -z "$get_addr_bin" ]
105+
local get_addr_bin
106+
if ! command -v ifconfig > /dev/null
107107
then
108-
get_addr_bin=`which ip`
108+
get_addr_bin=ip
109109
get_addr_bin="$get_addr_bin address show"
110110
# Add an slash at the end, so we don't get false positive : 172.18.0.4 matches 172.18.0.41
111111
# ip output format is "X.X.X.X/mask"
112112
address="${address}/"
113113
else
114114
# Add an space at the end, so we don't get false positive : 172.18.0.4 matches 172.18.0.41
115115
# ifconfig output format is "X.X.X.X "
116+
get_addr_bin=ifconfig
116117
address="$address "
117118
fi
118119

scripts/wsrep_sst_xtrabackup-v2.sh

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ ssl_key=""
8282
# 5.6.21 PXC and later can't donate to an older joiner
8383
sst_ver=1
8484

85-
if which pv &>/dev/null && pv --help | grep -q FORMAT;then
85+
if pv --help 2>/dev/null | grep -q FORMAT;then
8686
pvopts+=$pvformat
8787
fi
8888
pcmd="pv $pvopts"
@@ -258,10 +258,7 @@ get_transfer()
258258
fi
259259

260260
if [[ $tfmt == 'nc' ]];then
261-
if [[ ! -x `which nc` ]];then
262-
wsrep_log_error "nc(netcat) not found in path: $PATH"
263-
exit 2
264-
fi
261+
wsrep_check_programs nc
265262

266263
if [[ $encrypt -eq 2 || $encrypt -eq 3 || $encrypt -eq 4 ]]; then
267264
wsrep_log_error "******** FATAL ERROR *********************** "
@@ -285,10 +282,7 @@ get_transfer()
285282
else
286283
tfmt='socat'
287284
wsrep_log_info "Using socat as streamer"
288-
if [[ ! -x `which socat` ]];then
289-
wsrep_log_error "socat not found in path: $PATH"
290-
exit 2
291-
fi
285+
wsrep_check_programs socat
292286

293287
donor_extra=""
294288
joiner_extra=""
@@ -414,7 +408,7 @@ get_footprint()
414408
adjust_progress()
415409
{
416410

417-
if [[ ! -x `which pv` ]];then
411+
if ! command -v pv >/dev/null;then
418412
wsrep_log_error "pv not found in path: $PATH"
419413
wsrep_log_error "Disabling all progress/rate-limiting"
420414
pcmd=""
@@ -705,7 +699,7 @@ recv_joiner()
705699
pushd ${dir} 1>/dev/null
706700
set +e
707701

708-
if [[ $tmt -gt 0 && -x `which timeout` ]];then
702+
if [[ $tmt -gt 0 ]] && command -v timeout >/dev/null;then
709703
if timeout --help | grep -q -- '-k';then
710704
ltcmd="timeout -k $(( tmt+10 )) $tmt $tcmd"
711705
else
@@ -801,10 +795,7 @@ check_for_version()
801795
}
802796

803797

804-
if [[ ! -x `which $INNOBACKUPEX_BIN` ]];then
805-
wsrep_log_error "innobackupex not in path: $PATH"
806-
exit 2
807-
fi
798+
wsrep_check_programs "$INNOBACKUPEX_BIN"
808799

809800
# check the version, we require XB-2.4 to ensure that we can pass the
810801
# datadir via the command-line option
@@ -846,7 +837,7 @@ INNOEXTRA=""
846837

847838
if [[ $ssyslog -eq 1 ]];then
848839

849-
if [[ ! -x `which logger` ]];then
840+
if ! command -v logger >/dev/null;then
850841
wsrep_log_error "logger not in path: $PATH. Ignoring"
851842
else
852843

@@ -1119,7 +1110,7 @@ then
11191110

11201111
wsrep_log_info "Compressed qpress files found"
11211112

1122-
if [[ ! -x `which qpress` ]];then
1113+
if ! command -v qpress >/dev/null;then
11231114
wsrep_log_error "qpress not found in path: $PATH"
11241115
exit 22
11251116
fi

0 commit comments

Comments
 (0)