#!/bin/sh
echo "Enabling the serial console..."
if [ -f /etc/default/grub ]; then
  #683124/#769406 requires the cmdline patch, and #444026 is for GRUB_TERMINAL:
  sed -i -e '/^GRUB_CMDLINE_LINUX=/s/"$/ console=tty0 console=ttyS0,115200n8&/' \
        -e '/^GRUB_CMDLINE_LINUX=/s/=" /="/' \
        -e '/^GRUB_TERMINAL=/s/serial/"& console"/' \
        /etc/default/grub
  update-grub
fi
if [ -f /etc/inittab ]; then
  sed -i '/ttyS0/s/^#//;/ttyS0/s/9600 vt100/115200 linux/' /etc/inittab
else
  echo "Not setting up a TTY on the serial port, presumably systemd will..."
fi