Skip to content

Commit c008072

Browse files
committed
run shellcheck on all bash scripts
Signed-off-by: Diana Popa <[email protected]>
1 parent 24acf10 commit c008072

11 files changed

+77
-46
lines changed

0.initial-setup.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
#!/bin/bash
22

3+
set -euo pipefail
4+
35
COUNT="${1:-4000}" # Default to 4000
46

57
RES=scripts
68

79
rm -rf output
810
mkdir output
911
USR=${SUDO_USER:-$USER}
10-
chown -R $USR. output
1112

12-
pushd $RES > /dev/null
13+
chown -R "$USR" output
14+
15+
pushd "$RES" > /dev/null
1316

1417
./one-time-setup.sh
15-
./setup-network-taps.sh 0 $COUNT 100
18+
./setup-network-taps.sh 0 "$COUNT" 100
1619

1720
popd > /dev/null

9.cleanup.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
#!/bin/bash
22

3-
COUNT=`ls /sys/class/net/ | wc -l`
3+
set -euo pipefail
4+
5+
COUNT=$(find /sys/class/net/* | wc -l)
46

57
killall iperf3
68
killall firecracker
79

810
for ((i=0; i<COUNT; i++))
911
do
10-
ip link del fc-$i-tap0 2> /dev/null &
12+
ip link del fc-"$i"-tap0 2> /dev/null &
1113
done
1214

1315
rm -rf output/*

extract-times.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
#!/bin/bash
22

3-
#DATA_DIR=${1:-.}
3+
set -euo pipefail
4+
45
DATA_DIR="output"
56
DEST="$PWD/data.log"
67

7-
rm -f $DEST
8+
rm -f "$DEST"
89

910
pushd $DATA_DIR > /dev/null
1011

11-
COUNT=`ls fc-sb* | sort -V | tail -1 | cut -d '-' -f 2 | cut -f 2 -d 'b'`
12+
COUNT=$(find . -type f -name "fc-sb*" | sort -V | tail -1 | cut -d '-' -f 2 | cut -f 2 -d 'b')
1213

13-
for i in `seq 0 $COUNT`
14+
for i in $(seq 0 "$COUNT")
1415
do
15-
boot_time=`grep Guest-boot fc-sb${i}-log | cut -f 2 -d '=' | cut -f 4 -d ' '`
16-
echo "$i boot $boot_time ms" >> $DEST
16+
boot_time=$(grep Guest-boot fc-sb"${i}"-log | cut -f 2 -d '=' | cut -f 4 -d ' ')
17+
echo "$i boot $boot_time ms" >> "$DEST"
1718
done
1819

1920
popd > /dev/null

parallel-start-many.sh

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,44 @@
11
#!/bin/bash
22

3-
#Usage
3+
set -euo pipefail
4+
5+
# Usage
46
## ./parallel-start-many.sh 0 100 5 # Will start VM#0 to VM#99 5 at a time.
57

68
start="${1:-0}"
79
upperlim="${2:-1}"
810
parallel="${3:-1}"
911

10-
echo Start @ `date`.
11-
START_TS=`date +%s%N | cut -b1-13`
12+
FAIL=0
13+
14+
echo "Start @ $(date)".
15+
START_TS=$(date +%s%N | cut -b1-13)
16+
1217
for ((i=0; i<parallel; i++)); do
13-
s=$((i * upperlim / parallel))
14-
e=$(((i+1) * upperlim / parallel))
15-
./start-many.sh $s $e &
16-
pids[${i}]=$!
18+
echo "i is $i"
19+
s=$((i * upperlim / parallel))
20+
e=$(((i+1) * upperlim / parallel))
21+
./start-many.sh $s $e &
22+
pids[$i]=$!
1723
done
1824

1925
# wait for all pids
20-
for pid in ${pids[*]}; do
21-
wait $pid
26+
for pid in "${pids[@]}"; do
27+
wait $pid || (( FAIL+=1 ))
2228
done
2329

24-
END_TS=`date +%s%N | cut -b1-13`
25-
END_DATE=`date`
30+
if [ "$FAIL" != "0" ]; then
31+
echo "Could not run start_many.sh!"
32+
exit 1
33+
fi
34+
35+
END_TS=$(date +%s%N | cut -b1-13)
36+
END_DATE=$(date)
2637

2738
total=$((upperlim-start))
2839
delta_ms=$((END_TS-START_TS))
2940
delta=$((delta_ms/1000))
30-
rate=`bc -l <<< "$total/$delta"`
41+
rate=$(bc -l <<< "$total/$delta")
3142

3243
cat << EOL
3344
Done @ $END_DATE.

run-multiple-seq.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#!/bin/bash
22

3+
set -euo pipefail
4+
35
COUNT="${1:-1}"
46

5-
let total=0
7+
total=0
68

7-
for i in `seq 1 $COUNT`
9+
for i in $(seq 1 "$COUNT")
810
do
911
LOG="output/fc-sb0-log"
1012
rm -f $LOG

scripts/ensure_resources.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash
22

3+
set -euo pipefail
4+
35
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
46
TEST_RES="$SCRIPT_DIR/../resources"
57
S3_BUCKET="spec.ccfc.min"
@@ -13,13 +15,13 @@ ensure_firecracker() {
1315
TMP_FOLDER="/tmp/tmprelease"
1416
TMP_ARCHIVE="/tmp/release.tgz"
1517

16-
wget -q "https://github.com/firecracker-microvm/firecracker/releases/download/"${FC_VERSION}"/firecracker-"${FC_VERSION}"-"$TARGET".tgz" -O "$TMP_ARCHIVE"
18+
wget -q "https://github.com/firecracker-microvm/firecracker/releases/download/$FC_VERSION/firecracker-$FC_VERSION-$TARGET.tgz" -O "$TMP_ARCHIVE"
1719

1820
mkdir -p "$TMP_FOLDER"
1921
tar -zxf "$TMP_ARCHIVE" -C "$TMP_FOLDER"
2022

2123
# Get the firecracker binary
22-
cp `find "$TMP_FOLDER" -name "firecracker*$TARGET*"` "$file_path"
24+
cp "$(find "$TMP_FOLDER" -name "firecracker*$TARGET*")" "$file_path"
2325
chmod +x "$file_path"
2426

2527
echo "Saved firecracker at $file_path"
@@ -34,7 +36,7 @@ ensure_kernel() {
3436
file_path="$TEST_RES/vmlinux"
3537
kv="4.14"
3638
wget -q "https://s3.amazonaws.com/$S3_BUCKET/ci-artifacts/kernels/$TARGET/vmlinux-$kv.bin" -O "$file_path"
37-
echo "Saved kernel at "${file_path}"..."
39+
echo "Saved kernel at $file_path..."
3840
}
3941

4042
ensure_rootfs() {
@@ -43,7 +45,7 @@ ensure_rootfs() {
4345
wget -q "https://s3.amazonaws.com/$S3_BUCKET/img/alpine_demo/fsfiles/xenial.rootfs.ext4" -O "$file_path"
4446
wget -q "https://s3.amazonaws.com/$S3_BUCKET/img/alpine_demo/fsfiles/xenial.rootfs.id_rsa" -O "$key_path"
4547
chmod 400 "$key_path"
46-
echo "Saved rootfs and ssh key at "${file_path}" and "${key_path}"..."
48+
echo "Saved rootfs and ssh key at $file_path and $key_path..."
4749
}
4850

4951
mkdir -p "$TEST_RES"

scripts/one-time-setup.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
15
# Load kernel module
26
sudo modprobe kvm_intel
37

48
# Configure packet forwarding
5-
sudo sysctl -w net.ipv4.conf.all.forwarding=1
9+
sudo sysctl -wq net.ipv4.conf.all.forwarding=1
610

711
# Avoid "neighbour: arp_cache: neighbor table overflow!"
8-
sudo sysctl -w net.ipv4.neigh.default.gc_thresh1=1024
9-
sudo sysctl -w net.ipv4.neigh.default.gc_thresh2=2048
10-
sudo sysctl -w net.ipv4.neigh.default.gc_thresh3=4096
12+
sudo sysctl -wq net.ipv4.neigh.default.gc_thresh1=1024
13+
sudo sysctl -wq net.ipv4.neigh.default.gc_thresh2=2048
14+
sudo sysctl -wq net.ipv4.neigh.default.gc_thresh3=4096
1115

1216

1317
# Download relevant resources.

scripts/setup-network-taps.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
#!/bin/bash
22

3-
start="${1:-0}"
3+
set -euo pipefail
4+
45
upperlim="${2:-1}"
56
parallel="${3:-1}"
67

78
for ((i=0; i<parallel; i++)); do
89
s=$((i * upperlim / parallel))
910
e=$(((i+1) * upperlim / parallel))
1011
for ((j=s; j<e; j++)); do
11-
./setup-tap-with-id.sh $j
12+
./setup-tap-with-id.sh "$j"
1213
done &
1314
done
1415

scripts/setup-tap-with-id.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
#!/bin/bash -e
1+
#!/bin/bash
2+
3+
set -euo pipefail
24

35
SB_ID="${1:-0}" # Default to 0
46
TAP_DEV="fc-${SB_ID}-tap0"
57

68
# Setup TAP device that uses proxy ARP
7-
MASK_LONG="255.255.255.252"
89
MASK_SHORT="/30"
9-
FC_IP="$(printf '169.254.%s.%s' $(((4 * SB_ID + 1) / 256)) $(((4 * SB_ID + 1) % 256)))"
1010
TAP_IP="$(printf '169.254.%s.%s' $(((4 * SB_ID + 2) / 256)) $(((4 * SB_ID + 2) % 256)))"
11-
FC_MAC="$(printf '02:FC:00:00:%02X:%02X' $((SB_ID / 256)) $((SB_ID % 256)))"
11+
1212
ip link del "$TAP_DEV" 2> /dev/null || true
1313
ip tuntap add dev "$TAP_DEV" mode tap
14-
sysctl -w net.ipv4.conf.${TAP_DEV}.proxy_arp=1 > /dev/null
15-
sysctl -w net.ipv6.conf.${TAP_DEV}.disable_ipv6=1 > /dev/null
14+
sysctl -w net.ipv4.conf."$TAP_DEV".proxy_arp=1 > /dev/null
15+
sysctl -w net.ipv6.conf."$TAP_DEV".disable_ipv6=1 > /dev/null
1616
ip addr add "${TAP_IP}${MASK_SHORT}" dev "$TAP_DEV"
1717
ip link set dev "$TAP_DEV" up
1818

19-
iperf3 -B $TAP_IP -s > /dev/null 2>&1 &
19+
iperf3 -B "$TAP_IP" -s > /dev/null 2>&1 &
2020

start-firecracker.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
#!/bin/bash -e
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
25
SB_ID="${1:-0}" # Default to sb_id=0
36

47
FC_BINARY="$PWD/resources/firecracker"
@@ -34,7 +37,7 @@ logfile="$PWD/output/fc-sb${SB_ID}-log"
3437
#metricsfile="$PWD/output/fc-sb${SB_ID}-metrics"
3538
metricsfile="/dev/null"
3639

37-
touch $logfile
40+
touch "$logfile"
3841

3942
# Setup TAP device that uses proxy ARP
4043
MASK_LONG="255.255.255.252"
@@ -53,7 +56,7 @@ KERNEL_BOOT_ARGS="${KERNEL_BOOT_ARGS} ip=${FC_IP}::${TAP_IP}:${MASK_LONG}::eth0:
5356

5457
# Start Firecracker API server
5558
rm -f "$API_SOCKET"
56-
"${FC_BINARY}" --api-sock "$API_SOCKET" --id "${SB_ID}" --boot-timer >> $logfile &
59+
"${FC_BINARY}" --api-sock "$API_SOCKET" --id "${SB_ID}" --boot-timer >> "$logfile" &
5760

5861
sleep 0.015s
5962

0 commit comments

Comments
 (0)