Add end-of-file checks to bash8
Add two end-of-file checks to bash8. Firstly, alert if heredoc hasn't
finished. Some heredocs were done like:
---
sudo bash -c "cat <<EOF > foo
...
EOF"
---
(A better way to do this is "cat <<EOF | sudo tee ..." as it retains
the usual heredoc layout in the code).
The trailing quote was throwing the matching in bash8 off and it kept
appending the next file as if it was still part of the heredoc. To
avoid this, we check if we're still in a heredoc when we start a new
file; if so raise an error and reset the heredoc status fresh. We
track the state of the previous file, line and lineno so we can give a
good error.
---
E012: heredoc did not end before EOF: 'cat <<EOF'
- lib/trove: L221
---
This includes fixes for the existing problem heredocs.
A similar EOF check is to ensure the previous file ended with a
newline.
---
E004: file did not end with a newline: '$MY_XTRACE'
- lib/neutron_plugins/embrane: L40
---
This requires only one fix
Change-Id: I5e547d87b3921fc7ce6588c28f074e5c9f489c1f
diff --git a/lib/nova_plugins/hypervisor-libvirt b/lib/nova_plugins/hypervisor-libvirt
index 415244f..a0552b4 100644
--- a/lib/nova_plugins/hypervisor-libvirt
+++ b/lib/nova_plugins/hypervisor-libvirt
@@ -58,40 +58,40 @@
if is_fedora || is_suse; then
if is_fedora && [[ $DISTRO =~ (rhel6) || "$os_RELEASE" -le "17" ]]; then
- sudo bash -c "cat <<EOF >/etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
+ cat <<EOF | sudo tee /etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
[libvirt Management Access]
Identity=unix-group:$LIBVIRT_GROUP
Action=org.libvirt.unix.manage
ResultAny=yes
ResultInactive=yes
ResultActive=yes
-EOF"
+EOF
elif is_suse && [[ $os_RELEASE = 12.2 || "$os_VENDOR" = "SUSE LINUX" ]]; then
# openSUSE < 12.3 or SLE
# Work around the fact that polkit-default-privs overrules pklas
# with 'unix-group:$group'.
- sudo bash -c "cat <<EOF >/etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
+ cat <<EOF | sudo tee /etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
[libvirt Management Access]
Identity=unix-user:$STACK_USER
Action=org.libvirt.unix.manage
ResultAny=yes
ResultInactive=yes
ResultActive=yes
-EOF"
+EOF
else
# Starting with fedora 18 and opensuse-12.3 enable stack-user to
# virsh -c qemu:///system by creating a policy-kit rule for
# stack-user using the new Javascript syntax
rules_dir=/etc/polkit-1/rules.d
sudo mkdir -p $rules_dir
- sudo bash -c "cat <<EOF > $rules_dir/50-libvirt-$STACK_USER.rules
+ cat <<EOF | sudo tee $rules_dir/50-libvirt-$STACK_USER.rules
polkit.addRule(function(action, subject) {
if (action.id == 'org.libvirt.unix.manage' &&
subject.user == '"$STACK_USER"') {
return polkit.Result.YES;
}
});
-EOF"
+EOF
unset rules_dir
fi
fi