Skip to content

Commit 118fd8e

Browse files
committed
CA-405864: Fix shellcheck warnings
Signed-off-by: Lin Liu <[email protected]>
1 parent d4cc475 commit 118fd8e

File tree

5 files changed

+28
-162
lines changed

5 files changed

+28
-162
lines changed

ocaml/xcp-rrdd/bin/rrdp-scripts/rrdd-plugins-init

-120
This file was deleted.

scripts/attach-static-vdis

+11-16
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,27 @@ STATE_DIR=/etc/xensource/static-vdis
88
[ -e /opt/xensource/bin/static-vdis ] || exit 0
99

1010
clear_stale_state(){
11-
for i in $(ls -1 ${STATE_DIR}); do
11+
for i in "${STATE_DIR}"/*; do
1212
# Clear the now-stale symlink to the attached disk. From this point the disk will
1313
# be considered 'currently-attached=false'
14-
rm -f ${STATE_DIR}/${i}/disk
14+
rm -f "${i}"/disk
1515

1616
# If the disk was supposed to be deleted altogether on reboot then do it now
17-
UUID=$(cat ${STATE_DIR}/${i}/vdi-uuid)
18-
if [ -e ${STATE_DIR}/${i}/delete-next-boot ]; then
17+
UUID=$(cat "${i}"/vdi-uuid)
18+
if [ -e "${i}"/delete-next-boot ]; then
1919
logger "Deleting stale static-configured state for VDI: ${UUID}"
20-
rm -rf ${STATE_DIR}/${i}
20+
rm -rf "${i}"
2121
fi;
2222
done
2323
}
2424

2525
attach_all(){
2626
RC=0
27-
ALL=$(ls -1 ${STATE_DIR})
2827

29-
for i in ${ALL}; do
30-
UUID=$(cat ${STATE_DIR}/${i}/vdi-uuid)
28+
for i in "${STATE_DIR}"/*; do
29+
UUID=$(cat "${i}"/vdi-uuid)
3130
logger "Attempting to attach VDI: ${UUID}"
32-
OUTPUT=$(/opt/xensource/bin/static-vdis attach ${UUID} 2>&1)
33-
if [ $? -ne 0 ]; then
31+
if ! OUTPUT=$(/opt/xensource/bin/static-vdis attach "${UUID}" 2>&1); then
3432
RC=1
3533
logger "Attempt to attach VDI: ${UUID} failed -- skipping (Error was: ${OUTPUT})"
3634
return $RC
@@ -40,13 +38,10 @@ attach_all(){
4038
}
4139

4240
detach_all(){
43-
ALL=$(ls -1 ${STATE_DIR})
44-
45-
for i in ${ALL}; do
46-
UUID=$(cat ${STATE_DIR}/${i}/vdi-uuid)
41+
for i in "${STATE_DIR}"/*; do
42+
UUID=$(cat "${i}"/vdi-uuid)
4743
logger "Attempting to detach VDI: ${UUID}"
48-
OUTPUT=$(/opt/xensource/bin/static-vdis detach ${UUID} 2>&1)
49-
if [ $? -ne 0 ]; then
44+
if ! OUTPUT=$(/opt/xensource/bin/static-vdis detach "${UUID}" 2>&1); then
5045
logger "Attempt to detach VDI: ${UUID} failed -- skipping (Error was: ${OUTPUT})"
5146
fi
5247
done

scripts/on-master-start

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
# Example on-master-start script
44
#
55
start() {
6-
echo -n $"Assuming role of master: "
6+
printf "%s" "Assuming role of master: "
77
touch /tmp/master
8-
echo $"OK"
8+
echo "OK"
99
return 0
1010
}
1111

1212
stop() {
13-
echo $"Dropping role of master: "
13+
echo "Dropping role of master: "
1414
rm -f /tmp/master
1515
return 0
1616
}
@@ -31,6 +31,6 @@ case "$1" in
3131
restart
3232
;;
3333
*)
34-
echo $"Usage: $0 {start|stop|restart}"
34+
echo "Usage: $0 {start|stop|restart}"
3535
exit 1
3636
esac

scripts/xapi-init

+12-21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#! /bin/bash
22

33
if [ -f /etc/sysconfig/xapi ]; then
4+
# shellcheck disable=SC1091
5+
# disalbe the check as not available on checking machine
46
. /etc/sysconfig/xapi
57
fi
68

@@ -19,7 +21,7 @@ start() {
1921
rm -rf /var/xapi/debug
2022

2123
if [ -e /var/lock/subsys/xapi ]; then
22-
if [ -e /var/run/xapi.pid ] && [ -e /proc/`cat /var/run/xapi.pid` ]; then
24+
if [ -e /var/run/xapi.pid ] && [ -e "/proc/$(cat /var/run/xapi.pid)" ]; then
2325
echo $"cannot start xapi: already running.";
2426
logger "cannot start xapi: already running.";
2527
return 1
@@ -50,11 +52,18 @@ start() {
5052
# want to avoid collisions with new domains. CA-375992
5153
rm -rf /var/lib/xcp/run/*
5254
echo
55+
# shellcheck disable=SC2154
56+
# xapiflags may come from sourced files
57+
#
58+
# shellcheck disable=SC2086
59+
# quote introduce invalid argument on empty
5360
exec "@OPTDIR@/bin/xapi" -nowatchdog ${xapiflags} \
5461
-writereadyfile ${XAPI_STARTUP_COOKIE} -writeinitcomplete ${XAPI_INIT_COMPLETE_COOKIE} -onsystemboot
5562
RETVAL=$?
5663
else
5764
echo
65+
# shellcheck disable=SC2154
66+
# shellcheck disable=SC2086
5867
exec "@OPTDIR@/bin/xapi" -nowatchdog ${xapiflags} \
5968
-writereadyfile ${XAPI_STARTUP_COOKIE} -writeinitcomplete ${XAPI_INIT_COMPLETE_COOKIE}
6069
RETVAL=$?
@@ -89,7 +98,7 @@ stop() {
8998
fi
9099
sleep 1
91100
echo -n .
92-
RETRIES=$(( ${RETRIES} - 1 ))
101+
RETRIES=$(( RETRIES - 1 ))
93102
done
94103

95104
killproc xapi
@@ -106,32 +115,14 @@ stop() {
106115
return $RETVAL
107116
}
108117

109-
rhstatus() {
110-
status xapi
111-
}
112-
113-
restart() {
114-
stop
115-
start
116-
}
117-
118118
case "$1" in
119119
start)
120120
start
121121
;;
122122
stop)
123123
stop
124124
;;
125-
restart)
126-
restart
127-
;;
128-
status)
129-
rhstatus
130-
;;
131-
condrestart)
132-
[ -f /var/lock/subsys/xapi ] && restart || :
133-
;;
134125
*)
135-
echo $"Usage: $0 {start|stop|status|restart|condrestart}"
126+
echo $"Usage: $0 {start|stop}"
136127
exit 1
137128
esac

scripts/xe-toolstack-restart

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# GNU Lesser General Public License for more details.
1313
#
1414

15-
FILENAME=`basename $0`
15+
FILENAME=$(basename "$0")
1616
LOCKFILE='/dev/shm/xe_toolstack_restart.lock'
1717

1818
(

0 commit comments

Comments
 (0)