#!/bin/sh #set -e # initramfs-tools header PREREQ="" prereqs() { echo "${PREREQ}" } case "${1}" in prereqs) prereqs exit 0 ;; esac # live-initramfs header DESCRIPTION="Setting up serial console for inittab ..." echo "$DESCRIPTION" # live-initramfs script # Arrange for shells on virtual consoles, rather than login prompts for x in $(cat /proc/cmdline); do case $x in live-getty) export LIVE_GETTY=1 ;; console=*) export DEFCONSOLE=$(sed -e 's%.*console=%console=%' /proc/cmdline | \ cut -d " " -f 1 ) ;; autoinstall=*) AUTOINSTALL=$(sed -e 's%.*autoinstall=%%' /proc/cmdline | \ cut -d " " -f 1 ) ;; targetdisk=*) TARGET_DISK=$(sed -e 's%.*targetdisk=%%' /proc/cmdline | \ cut -d " " -f 1 ) ;; recovery) RECOVERY=1 ;; esac done if [ ! -z "${RECOVERY}" ] ; then INSTALL=1; fi if [ ! -z "${NETBOOT}" ] ; then INSTALL=1; fi echo "DEFCONSOLE=${DEFCONSOLE}" echo "LIVE_GETTY=${LIVE_GETTY}" echo "AUTOINSTALL=${AUTOINSTALL}" echo "TARGET_DISK=${TARGET_DISK}" echo "INSTALL=${INSTALL}" ## only change inittab serial setting if netboot is defined. if [ ! -z "${DEFCONSOLE}" ] && [ ! -z "${INSTALL}" ]; then if echo "${DEFCONSOLE}" | grep -qs ttyS; then # AUTOMATIC SERIAL CONSOLE # PORT=$(echo "${DEFCONSOLE}" | \ sed -e 's%^console=ttyS%%' -e 's%,.*%%') SPEED=$(echo "${DEFCONSOLE}" | \ sed -e 's%^console=ttyS[0-9]\+,%%' \ -e's%\([0-9]\+\).*%\1%') cmd1="/^T0:/ s/${PORT} 9600/${PORT} ${SPEED}/" echo "Setting Serial Port to ttyS${PORT} ${SPEED}" sed -i -e "${cmd1}" /root/etc/inittab fi fi if [ ! -z "${AUTOINSTALL}" ] ; then echo "V0:23:once:/usr/local/sbin/autoinstall.sh ${AUTOINSTALL} ${TARGET_DISK}" >> /root/etc/inittab sed -i -e "s/^T0/#T0/" /root/etc/inittab fi