Skip to content

Commit 5587706

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

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

scripts/attach-static-vdis

Lines changed: 11 additions & 16 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 10 additions & 5 deletions
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,12 +52,15 @@ start() {
5052
# want to avoid collisions with new domains. CA-375992
5153
rm -rf /var/lib/xcp/run/*
5254
echo
53-
exec "@OPTDIR@/bin/xapi" -nowatchdog ${xapiflags} \
55+
# shellcheck disable=SC2154
56+
# xapiflags may come from sourced files
57+
exec "@OPTDIR@/bin/xapi" -nowatchdog "${xapiflags}" \
5458
-writereadyfile ${XAPI_STARTUP_COOKIE} -writeinitcomplete ${XAPI_INIT_COMPLETE_COOKIE} -onsystemboot
5559
RETVAL=$?
5660
else
5761
echo
58-
exec "@OPTDIR@/bin/xapi" -nowatchdog ${xapiflags} \
62+
# shellcheck disable=SC2154
63+
exec "@OPTDIR@/bin/xapi" -nowatchdog "${xapiflags}" \
5964
-writereadyfile ${XAPI_STARTUP_COOKIE} -writeinitcomplete ${XAPI_INIT_COMPLETE_COOKIE}
6065
RETVAL=$?
6166
fi
@@ -89,7 +94,7 @@ stop() {
8994
fi
9095
sleep 1
9196
echo -n .
92-
RETRIES=$(( ${RETRIES} - 1 ))
97+
RETRIES=$(( RETRIES - 1 ))
9398
done
9499

95100
killproc xapi
@@ -129,7 +134,7 @@ case "$1" in
129134
rhstatus
130135
;;
131136
condrestart)
132-
[ -f /var/lock/subsys/xapi ] && restart || :
137+
[ -f /var/lock/subsys/xapi ] && restart
133138
;;
134139
*)
135140
echo $"Usage: $0 {start|stop|status|restart|condrestart}"

scripts/xe-toolstack-restart

Lines changed: 1 addition & 1 deletion
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)