# Add timeout on usplash startup script

if [ -e $DESTDIR/scripts/init-top/usplash -o -e /scripts/init-top/plymouth -o -e /scripts/init-top/00_splashy ]; then

  _echo "   * Applying usplash timeout patch"

cat << EOF > $DESTDIR/scripts/init-top/00_nosplash
#!/bin/sh

# new header not using prereqs
if [ "\$1" = "prereqs" ]; then
  echo ""
  exit 0
fi

. /scripts/functions
. /conf/tcos.conf
. /conf/tcos-run-functions

# kill usplash if cmdline have "nousplash" or "nosplash"
for x in \$(cat /proc/cmdline); do
        case \$x in
        nosplash)
		KILL_SPLASH=true
                ;;
        nousplash)
		KILL_SPLASH=true
                ;;
        esac
done

if [ "\$KILL_SPLASH" = "true" ] ; then
  echo -e "#!/bin/sh\nexit 0" > /scripts/init-top/framebuffer
  [ -e /scripts/init-top/usplash ] && echo -e "#!/bin/sh\nexit 0" > /scripts/init-top/usplash
  [ -e /scripts/init-top/plymouth ] && echo -e "#!/bin/sh\nexit 0" > /scripts/init-top/plymouth
  [ -e /scripts/init-top/00_splashy ] && echo -e "#!/bin/sh\nexit 0" > /scripts/init-top/00_splashy
fi


EOF
chmod +x $DESTDIR/scripts/init-top/00_nosplash

else 
  _verbose "(95usplash_timeout) Splash not found, timeout path not applied."
fi


# add fancy startup messages

cat << EOF >> $DESTDIR/scripts/functions

log_use_fancy_output () {
    TPUT=/bin/tput
    EXPR=/bin/expr
    if [ "x\$TERM" != "xdumb" ] && [ -x \$TPUT ] && [ -x \$EXPR ] && \$TPUT hpa 60 >/dev/null 2>&1 && \$TPUT setaf 1 >/dev/null 2>&1; then
        [ -z \$FANCYTTY ] && FANCYTTY=1 || true
    else
        FANCYTTY=0
    fi
    case "\$FANCYTTY" in
        1|Y|yes|true)   true;;
        *)              false;;
    esac
}

FANCYTTY=
[ -e /etc/lsb-base-logging.sh ] && . /etc/lsb-base-logging.sh || true

EOF

[ -e /etc/lsb-base-logging.sh ] && cpifexists /etc/lsb-base-logging.sh /etc
cpifexists /usr/bin/tput /bin
cpifexists /usr/bin/expr /bin

