mirror of
https://github.com/coreos/fedora-coreos-config.git
synced 2026-02-05 09:45:30 +01:00
*: ShellCheck fixes
This commit is contained in:
committed by
Luca Bruno
parent
c0aea3baa2
commit
eb3d40da8c
@@ -17,10 +17,13 @@ required_initrd_files=(
|
||||
)
|
||||
|
||||
tmpd=$(mktemp -d)
|
||||
trap "rm -r ${tmpd}" EXIT
|
||||
cleanup() {
|
||||
rm -r "${tmpd}"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
( cd "${tmpd}" && lsinitrd --unpack /boot/ostree/*/init* )
|
||||
|
||||
for file in ${required_initrd_files[@]}; do
|
||||
for file in "${required_initrd_files[@]}"; do
|
||||
if [ ! -e "${tmpd}/${file}" ]; then
|
||||
fatal "${file} was not found in initrd"
|
||||
fi
|
||||
|
||||
@@ -31,7 +31,15 @@ else
|
||||
# check for the UUID dropins
|
||||
[ -f /boot/grub2/bootuuid.cfg ]
|
||||
mount -o ro /dev/disk/by-label/EFI-SYSTEM /boot/efi
|
||||
[ -f /boot/efi/EFI/*/bootuuid.cfg ]
|
||||
found_bootuuid="false"
|
||||
for f in /boot/efi/EFI/*/bootuuid.cfg; do
|
||||
if [ -f "$f" ]; then
|
||||
found_bootuuid="true"
|
||||
fi
|
||||
done
|
||||
if [[ "${found_bootuuid}" == "false" ]]; then
|
||||
fatal "No /boot/efi/EFI/*/bootuuid.cfg found"
|
||||
fi
|
||||
umount /boot/efi
|
||||
fi
|
||||
|
||||
@@ -43,12 +51,12 @@ case "${AUTOPKGTEST_REBOOT_MARK:-}" in
|
||||
|
||||
rebooted)
|
||||
# check for expected default kargs
|
||||
grep root=UUID=$(cat /boot/.root_uuid) /proc/cmdline
|
||||
grep root=UUID="$(cat /boot/.root_uuid)" /proc/cmdline
|
||||
ok "found root karg"
|
||||
|
||||
bootsrc=$(findmnt -nvr /boot -o SOURCE)
|
||||
eval $(blkid -o export "${bootsrc}")
|
||||
grep boot=UUID=${UUID} /proc/cmdline
|
||||
grep boot=UUID="${UUID}" /proc/cmdline
|
||||
ok "found boot karg"
|
||||
|
||||
ok "second boot"
|
||||
|
||||
@@ -313,7 +313,7 @@ butane_dhcpvlanbond='
|
||||
|
||||
check_requirement() {
|
||||
req=$1
|
||||
if ! which $req &>/dev/null; then
|
||||
if ! which "$req" &>/dev/null; then
|
||||
echo "No $req. Can't continue" 1>&2
|
||||
return 1
|
||||
fi
|
||||
@@ -332,8 +332,8 @@ check_requirements() {
|
||||
virt-install
|
||||
virt-ls
|
||||
)
|
||||
for req in ${reqs[@]}; do
|
||||
check_requirement $req
|
||||
for req in "${reqs[@]}"; do
|
||||
check_requirement "$req"
|
||||
done
|
||||
}
|
||||
|
||||
@@ -343,11 +343,11 @@ start_vm() {
|
||||
local ignitionfile=$1; shift
|
||||
local kernel=$1; shift
|
||||
local initramfs=$1; shift
|
||||
local kernel_args=$@
|
||||
local kernel_args=$*
|
||||
virt-install --name $vmname --ram 3096 --vcpus 2 --graphics=none \
|
||||
--quiet --network bridge=virbr0 --network bridge=virbr0 \
|
||||
--disk size=20,backing_store=${disk} \
|
||||
--install kernel=${kernel},initrd=${initramfs},kernel_args_overwrite=yes,kernel_args="${kernel_args}" \
|
||||
--disk size=20,backing_store="${disk}" \
|
||||
--install kernel="${kernel}",initrd="${initramfs}",kernel_args_overwrite=yes,kernel_args="${kernel_args}" \
|
||||
--qemu-commandline="-fw_cfg name=opt/com.coreos/config,file=$ignitionfile"
|
||||
}
|
||||
|
||||
@@ -365,8 +365,8 @@ create_ignition_file() {
|
||||
local ignitionfile=$2
|
||||
# uncomment and use ign-converter instead if on rhcos less than 4.6
|
||||
#echo "$butaneconfig" | butane --strict | ign-converter -downtranslate -output $ignitionfile
|
||||
echo "$butaneconfig" | butane --strict --output $ignitionfile
|
||||
chcon --verbose unconfined_u:object_r:svirt_home_t:s0 $ignitionfile &>/dev/null
|
||||
echo "$butaneconfig" | butane --strict --output "$ignitionfile"
|
||||
chcon --verbose unconfined_u:object_r:svirt_home_t:s0 "$ignitionfile" &>/dev/null
|
||||
}
|
||||
|
||||
main() {
|
||||
@@ -396,7 +396,7 @@ main() {
|
||||
check_requirements
|
||||
|
||||
# Find out which partition is the boot partition
|
||||
partition=$(guestfish --ro -a $qcow <<EOF
|
||||
partition=$(guestfish --ro -a "$qcow" <<EOF
|
||||
run
|
||||
findfs-label boot
|
||||
exit
|
||||
@@ -404,17 +404,17 @@ EOF
|
||||
)
|
||||
|
||||
# Grab kernel/initramfs from the disk
|
||||
files=$(virt-ls -a $qcow -m $partition -R /ostree/)
|
||||
files=$(virt-ls -a "$qcow" -m "$partition" -R /ostree/)
|
||||
for f in $files; do
|
||||
if [[ "${f}" =~ hmac$ ]]; then
|
||||
# ignore .vmlinuz-5.5.9-200.fc31.x86_64.hmac
|
||||
true
|
||||
elif [[ "${f}" =~ img$ ]]; then
|
||||
# grab initramfs in the form initramfs-5.5.9-200.fc31.x86_64.img
|
||||
virt-cat -a $qcow -m $partition "/ostree/${f}" > $initramfs
|
||||
virt-cat -a "$qcow" -m "$partition" "/ostree/${f}" > "$initramfs"
|
||||
elif [[ "${f}" =~ '/vmlinuz' ]]; then
|
||||
# grab kernel in the form vmlinuz-5.5.9-200.fc31.x86_64
|
||||
virt-cat -a $qcow -m $partition "/ostree/${f}" > $kernel
|
||||
virt-cat -a "$qcow" -m "$partition" "/ostree/${f}" > "$kernel"
|
||||
fi
|
||||
done
|
||||
|
||||
@@ -435,7 +435,7 @@ EOF
|
||||
# Grab kernel arguments from the disk and use them
|
||||
# - strip `options ` from the front of the line
|
||||
# - strip `$ignition_firstboot`
|
||||
common_args=$(virt-cat -a $qcow -m $partition "/loader.1/entries/${bls_file}" | \
|
||||
common_args=$(virt-cat -a "$qcow" -m "$partition" "/loader.1/entries/${bls_file}" | \
|
||||
grep -P '^options' | \
|
||||
sed -e 's/options //' | \
|
||||
sed -e 's/$ignition_firstboot//')
|
||||
@@ -512,7 +512,7 @@ EOF
|
||||
)
|
||||
|
||||
create_ignition_file "$butane_none" $ignitionfile
|
||||
for net in ${loopitems[@]}; do
|
||||
for net in "${loopitems[@]}"; do
|
||||
var="initramfs_${net}"
|
||||
kernel_args=${!var}
|
||||
var="butane_initramfs_${net}"
|
||||
@@ -522,7 +522,7 @@ EOF
|
||||
destroy_vm
|
||||
done
|
||||
|
||||
for net in ${loopitems[@]}; do
|
||||
for net in "${loopitems[@]}"; do
|
||||
var="butane_${net}"
|
||||
butaneconfig=${!var}
|
||||
kernel_args=${common_args}
|
||||
@@ -539,5 +539,5 @@ EOF
|
||||
}
|
||||
|
||||
|
||||
main $@
|
||||
main "$@"
|
||||
|
||||
|
||||
@@ -238,7 +238,7 @@ butane_static_br0='
|
||||
|
||||
check_requirement() {
|
||||
req=$1
|
||||
if ! which $req &>/dev/null; then
|
||||
if ! which "$req" &>/dev/null; then
|
||||
echo "No $req. Can't continue" 1>&2
|
||||
return 1
|
||||
fi
|
||||
@@ -257,8 +257,8 @@ check_requirements() {
|
||||
virt-install
|
||||
virt-ls
|
||||
)
|
||||
for req in ${reqs[@]}; do
|
||||
check_requirement $req
|
||||
for req in "${reqs[@]}"; do
|
||||
check_requirement "$req"
|
||||
done
|
||||
}
|
||||
|
||||
@@ -268,11 +268,11 @@ start_vm() {
|
||||
local ignitionfile=$1; shift
|
||||
local kernel=$1; shift
|
||||
local initramfs=$1; shift
|
||||
local kernel_args=$@
|
||||
local kernel_args=$*
|
||||
virt-install --name $vmname --ram 3096 --vcpus 2 --graphics=none --noautoconsole \
|
||||
--quiet --network bridge=virbr0 --network bridge=virbr0 \
|
||||
--disk size=20,backing_store=${disk} \
|
||||
--install kernel=${kernel},initrd=${initramfs},kernel_args_overwrite=yes,kernel_args="${kernel_args}" \
|
||||
--disk size=20,backing_store="${disk}" \
|
||||
--install kernel="${kernel}",initrd="${initramfs}",kernel_args_overwrite=yes,kernel_args="${kernel_args}" \
|
||||
--qemu-commandline="-fw_cfg name=opt/com.coreos/config,file=$ignitionfile"
|
||||
}
|
||||
|
||||
@@ -290,7 +290,7 @@ check_vm() {
|
||||
ssh_config+=' -o StrictHostKeyChecking=no'
|
||||
ssh_config+=" -i $sshkeyfile"
|
||||
|
||||
if [ $dhcp == 'dhcp' ]; then
|
||||
if [ "$dhcp" == 'dhcp' ]; then
|
||||
macinfo=$(virsh dumpxml $vmname | grep 'mac address' | head -n 1)
|
||||
macregex='(..:..:..:..:..:..)'
|
||||
if ! [[ $macinfo =~ $macregex ]]; then
|
||||
@@ -379,7 +379,7 @@ check_vm() {
|
||||
# verify that the right number of NetworkManager keyfiles got created
|
||||
# use `echo -n | wc -l` so we can properly detect 0. Wasn't working
|
||||
# with `wc -l <<< $keyfiles`.
|
||||
if [ ${detectedkeyfiles} != ${numkeyfiles} ]; then
|
||||
if [ "${detectedkeyfiles}" != "${numkeyfiles}" ]; then
|
||||
rc=1
|
||||
echo "ERROR: Expected ${numkeyfiles} NM keyfiles, found ${detectedkeyfiles}" 1>&2
|
||||
fi
|
||||
@@ -390,28 +390,28 @@ check_vm() {
|
||||
else
|
||||
nameserverinfo="$resolvedotconf"
|
||||
fi
|
||||
if ! grep $nameserver &>/dev/null <<< "$nameserverinfo"; then
|
||||
if ! grep "$nameserver" &>/dev/null <<< "$nameserverinfo"; then
|
||||
rc=1
|
||||
echo "ERROR: Nameserver information was not what was expected" 1>&2
|
||||
fi
|
||||
|
||||
# verify that there are the right number of ipv4 devices "up"
|
||||
if [ $(jq length <<< $ipinfo) != "$((interfaces+1))" ]; then
|
||||
if [ "$(jq length <<< "$ipinfo")" != "$((interfaces+1))" ]; then
|
||||
rc=1
|
||||
echo "ERROR: More interfaces up than expected" 1>&2
|
||||
fi
|
||||
# verify that the first one in loopback
|
||||
if [ $(jq -r .[0].addr_info[0].dev <<< $ipinfo) != 'lo' ]; then
|
||||
if [ "$(jq -r .[0].addr_info[0].dev <<< "$ipinfo")" != 'lo' ]; then
|
||||
rc=1
|
||||
echo "ERROR: The first active interface is not 'lo'" 1>&2
|
||||
fi
|
||||
# verify that the second one is the expected device
|
||||
if [ $(jq -r .[1].addr_info[0].dev <<< $ipinfo) != "${dev}" ]; then
|
||||
if [ "$(jq -r .[1].addr_info[0].dev <<< "$ipinfo")" != "${dev}" ]; then
|
||||
rc=1
|
||||
echo "ERROR: The second active interface is not ${dev}" 1>&2
|
||||
fi
|
||||
# verify that the second one has the IP we assigned
|
||||
if [ $(jq -r .[1].addr_info[0].local <<< $ipinfo) != "${ip}" ]; then
|
||||
if [ "$(jq -r .[1].addr_info[0].local <<< "$ipinfo")" != "${ip}" ]; then
|
||||
rc=1
|
||||
echo "ERROR: The second active interface does not have expected ip" 1>&2
|
||||
fi
|
||||
@@ -420,8 +420,8 @@ check_vm() {
|
||||
echo "$hostnameinfo"
|
||||
echo "$nameserverinfo"
|
||||
echo "$keyfiles"
|
||||
jq -r .[].addr_info[].dev 1>&2 <<< $ipinfo
|
||||
jq -r .[].addr_info[].local 1>&2 <<< $ipinfo
|
||||
jq -r .[].addr_info[].dev 1>&2 <<< "$ipinfo"
|
||||
jq -r .[].addr_info[].local 1>&2 <<< "$ipinfo"
|
||||
true
|
||||
else
|
||||
echo "Check for ${hostname} + dns:${nameserver} + ${dev}/${ip} passed!"
|
||||
@@ -452,8 +452,8 @@ create_ignition_file() {
|
||||
local ignitionfile=$2
|
||||
# uncomment and use ign-converter instead if on rhcos less than 4.6
|
||||
#echo "$butaneconfig" | butane --strict | ign-converter -downtranslate -output $ignitionfile
|
||||
echo "$butaneconfig" | butane --strict --output $ignitionfile
|
||||
chcon --verbose unconfined_u:object_r:svirt_home_t:s0 $ignitionfile &>/dev/null
|
||||
echo "$butaneconfig" | butane --strict --output "$ignitionfile"
|
||||
chcon --verbose unconfined_u:object_r:svirt_home_t:s0 "$ignitionfile" &>/dev/null
|
||||
}
|
||||
|
||||
|
||||
@@ -477,12 +477,12 @@ main() {
|
||||
check_requirements
|
||||
|
||||
# generate an ssh key to use:
|
||||
rm -f $sshkeyfile $sshpubkeyfile
|
||||
ssh-keygen -N '' -C '' -f $sshkeyfile &>/dev/null
|
||||
sshpubkey=$(cat $sshpubkeyfile)
|
||||
rm -f "$sshkeyfile" "$sshpubkeyfile"
|
||||
ssh-keygen -N '' -C '' -f "$sshkeyfile" &>/dev/null
|
||||
sshpubkey="$(cat "$sshpubkeyfile")"
|
||||
|
||||
# Find out which partition is the boot partition
|
||||
partition=$(guestfish --ro -a $qcow <<EOF
|
||||
partition=$(guestfish --ro -a "$qcow" <<EOF
|
||||
run
|
||||
findfs-label boot
|
||||
exit
|
||||
@@ -490,17 +490,17 @@ EOF
|
||||
)
|
||||
|
||||
# Grab kernel/initramfs from the disk
|
||||
files=$(virt-ls -a $qcow -m $partition -R /ostree/)
|
||||
files=$(virt-ls -a "$qcow" -m "$partition" -R /ostree/)
|
||||
for f in $files; do
|
||||
if [[ "${f}" =~ hmac$ ]]; then
|
||||
# ignore .vmlinuz-5.5.9-200.fc31.x86_64.hmac
|
||||
true
|
||||
elif [[ "${f}" =~ img$ ]]; then
|
||||
# grab initramfs in the form initramfs-5.5.9-200.fc31.x86_64.img
|
||||
virt-cat -a $qcow -m $partition "/ostree/${f}" > $initramfs
|
||||
virt-cat -a "$qcow" -m "$partition" "/ostree/${f}" > "$initramfs"
|
||||
elif [[ "${f}" =~ '/vmlinuz' ]]; then
|
||||
# grab kernel in the form vmlinuz-5.5.9-200.fc31.x86_64
|
||||
virt-cat -a $qcow -m $partition "/ostree/${f}" > $kernel
|
||||
virt-cat -a "$qcow" -m "$partition" "/ostree/${f}" > "$kernel"
|
||||
fi
|
||||
done
|
||||
|
||||
@@ -530,7 +530,7 @@ EOF
|
||||
# Grab kernel arguments from the disk and use them
|
||||
# - strip `options ` from the front of the line
|
||||
# - strip `$ignition_firstboot`
|
||||
common_args=$(virt-cat -a $qcow -m $partition "/loader.1/entries/${bls_file}" | \
|
||||
common_args=$(virt-cat -a "$qcow" -m "$partition" "/loader.1/entries/${bls_file}" | \
|
||||
grep -P '^options' | \
|
||||
sed -e 's/options //' | \
|
||||
sed -e 's/$ignition_firstboot//')
|
||||
@@ -675,8 +675,8 @@ EOF
|
||||
static_br0
|
||||
)
|
||||
|
||||
for initramfsnet in ${initramfsloop[@]}; do
|
||||
for butanenet in ${butaneloop[@]}; do
|
||||
for initramfsnet in "${initramfsloop[@]}"; do
|
||||
for butanenet in "${butaneloop[@]}"; do
|
||||
method='none'; interfaces=1;
|
||||
nameserver=${nameserverstatic}
|
||||
numkeyfiles=3
|
||||
@@ -734,5 +734,5 @@ EOF
|
||||
}
|
||||
|
||||
|
||||
main $@
|
||||
main "$@"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user