summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominique Martinet <dominique.martinet@cea.fr>2020-05-24 10:57:19 +0200
committerDominique Martinet <dominique.martinet@cea.fr>2020-05-24 11:00:04 +0200
commit21a0783cd7ff8f11b4f658b04f1219e15d0c0e2c (patch)
treeae759afada30628ee0c9b7f759297416726acbfa
parent6fcaf15c9ba83234c9107c6d6d539de390710a76 (diff)
shellcheck cleanups
-rwxr-xr-xkvm-wrapper.sh26
1 files changed, 14 insertions, 12 deletions
diff --git a/kvm-wrapper.sh b/kvm-wrapper.sh
index 9f8100c..54d018a 100755
--- a/kvm-wrapper.sh
+++ b/kvm-wrapper.sh
@@ -14,7 +14,7 @@ CONFFILE="$ROOTDIR/kvm-wrapper.conf"
function canonpath ()
{
- echo $(cd $(dirname "$1"); pwd -P)/$(basename "$1")
+ readlink -e "$1"
}
# Exit on fail and print a nice message
@@ -78,7 +78,7 @@ function test_pid ()
function test_pid_from_file ()
{
local PID_FILE="$1"
- test_file "$PID_FILE" && test_pid `cat "$PID_FILE"`
+ test_file "$PID_FILE" && test_pid "$(cat "$PID_FILE")"
}
function test_socket ()
@@ -114,12 +114,12 @@ function test_exec ()
function test_nodename ()
{
local NODE="$1"
- [[ -n "$NODE" && "$NODE" != "`hostname -s`" && -n "`get_cluster_host $NODE`" ]]
+ [[ -n "$NODE" && "$NODE" != "$(hostname -s)" && -n "$(get_cluster_host "$NODE")" ]]
}
function require_exec ()
{
- test_exec "$(which $1)" || fail_exit "$1 not found or not executable"
+ test_exec "$(which "$1")" || fail_exit "$1 not found or not executable"
}
function check_create_dir ()
@@ -137,7 +137,7 @@ function wait_test_timelimit ()
local EVAL_EXPR=$2
while [[ $ELAPSED -le $TIMELIMIT ]]
do
- ELAPSED=$(($ELAPSED+1))
+ ELAPSED=$((ELAPSED+1))
eval "$EVAL_EXPR" && PROPER=1;
[[ $PROPER -eq 1 ]] && break
sleep 1
@@ -155,7 +155,8 @@ function kvm_init_env ()
MONITOR_FILE="$MONITOR_DIR/$VM_NAME.unix"
SERIAL_FILE="$SERIAL_DIR/$VM_NAME.unix"
- local vmnamehash=$(echo $VM_NAME|md5sum)
+ local vmnamehash
+ vmnamehash=$(hash_string "$VM_NAME")
vmnamehash=${vmnamehash:0:5}
SCREEN_SESSION_NAME="${SCREEN_NAME_PREFIX}kvm-$VM_NAME-$vmnamehash"
@@ -168,12 +169,13 @@ function kvm_init_env ()
function random_mac ()
{
+ local MACADDR
BASE_MAC=${BASE_MAC:-"52:54:00:ff"}
- local MACADDR=`printf "$BASE_MAC:%02x:%02x" $((RANDOM % 256)) $((RANDOM % 256))`
+ MACADDR=$(printf "$BASE_MAC:%02x:%02x" $((RANDOM % 256)) $((RANDOM % 256)))
# check if it's not already used..
- grep -qre "KVM_MACADDR.*=\"$MACADDR\"" $VM_DIR \
+ grep -qre "KVM_MACADDR.*=\"$MACADDR\"" "$VM_DIR" \
&& random_mac \
- || echo -n $MACADDR
+ || echo -n "$MACADDR"
}
# stores FD in global variable LOCKFD_${VARIANT}
@@ -224,12 +226,12 @@ hash_string ()
set_cluster_host ()
{
- eval KVM_CLUSTER_HOSTS_`hash_string $1`="$2"
+ eval KVM_CLUSTER_HOSTS_$(hash_string $1)="$2"
}
get_cluster_host ()
{
- eval echo '${KVM_CLUSTER_HOSTS_'`hash_string "$1"`'}'
+ eval echo '${KVM_CLUSTER_HOSTS_'$(hash_string "$1")'}'
}
run_remote ()
@@ -247,7 +249,7 @@ run_remote ()
function nbd_img_link ()
{
KVM_IMAGE="$1"
- echo "$NBD_IMG_LINK_DIR/$(basename $KVM_IMAGE)-$(canonpath "$KVM_IMAGE" | md5sum | awk '{print $1}')"
+ echo "$NBD_IMG_LINK_DIR/$(basename "$KVM_IMAGE")-$(hash_string "$(canonpath "$KVM_IMAGE")")"
}
function kvm_nbd_connect ()