Sample Header Ad - 728x90

ShellCheck warning of individual redirects

-2 votes
1 answer
108 views
I am using here document to create a startup script, when I checked my code on it gives me a warning which it can be ignored. But I am wondering if there is a better way to write a code and avoid that warning if possible.
cat > /usr/local/etc/rc.d/"${name}"
#!/bin/sh
. /etc/rc.subr
cpu="${cpu}"
ram="${ram}"
tap="${tap}"
name="${name}"
EOF
  sed -n '3,16p' ./bhyve >>  /usr/local/etc/rc.d/"${name}"
  cat > /usr/local/etc/rc.d/"${name}"
start_cmd=${name}_start
stop_cmd=${name}_stop
restart_cmd=${name}_restart
delete_cmd=${name}_delete
${name}_start() {
EOF
  cat > /usr/local/etc/rc.d/"${name}"
  while true; do
    bhyve -Hw -c "${cpu}" -m "${ram}"G \
      -s 0,hostbridge \
      -s 1,virtio-net,"${tap}" \
      -s 2,virtio-blk,/dev/zvol/zroot/VMs/"${name}"/disk0 \
      -s 29,fbuf,tcp=0.0.0.0:"${vnc}",w=1024,h=768 \
      -s 30,xhci,tablet \
      -s 31,lpc \
      -l bootrom,/zroot/VMs/efi.fd \
      "${name}" || break;
  done > /dev/null 2>&1 &
}
EOF
  cat > /usr/local/etc/rc.d/"${name}"
${name}_stop() {
EOF
  cat > /usr/local/etc/rc.d/"${name}"
  bhyvectl --vm="${name}" --force-poweroff
}
EOF
  cat > /usr/local/etc/rc.d/"${name}"
${name}_restart() {
EOF
cat > /usr/local/etc/rc.d/"${name}"
  bhyvectl --vm="${name}" --force-reset
}
EOF
  cat > /usr/local/etc/rc.d/"${name}"
${name}_delete() {
EOF
  cat > /usr/local/etc/rc.d/"${name}"
  bhyvectl --vm="${name}" --destroy
  sleep 5
  ifconfig "${tap}" destroy
  sysrc cloned_interfaces-="${tap}"
EOF
  cat > /usr/local/etc/rc.d/"${name}"
  sed -i '' 's/ addm ${tap}//g' /etc/rc.conf
  sed -i '' 's/service ${name} start || sleep 5//g' /usr/local/etc/rc.d/bhyve
  sed -i '' '/^$/d' /usr/local/etc/rc.d/bhyve
EOF
  cat > /usr/local/etc/rc.d/"${name}"
  zfs destroy -r zroot/VMs/"${name}"
  rm /usr/local/etc/rc.d/"${name}"
}

load_rc_config "${name}"
run_rc_command "$1"
EOF
  # Add the VM to /usr/local/etc/rc.d/bhyve for autostart
  sed -i '' -e "9s/^/service ${name} start || sleep 5\n/g"  /usr/local/etc/rc.d/bhyve
Asked by Amr (61 rep)
Dec 27, 2020, 11:45 PM
Last activity: Dec 28, 2020, 01:18 PM