#!/bin/sh

# Script that gets run if system integrity failure is detected
#
# Reuben Dowle

# set -x

YRES=`cat /sys/class/graphics/fb0/modes | cut -b 7-9`
STRIDE=`cat /sys/class/graphics/fb0/stride`

# clear the screen
dd if=/dev/zero of=/dev/fb0 bs=$STRIDE count=$YRES 2>/dev/null

# put a bitmap on the screen to tell the user they are screwed
BMPDX=512 # x-res * 2
BMPDY=65
BMPSTRIDE=16 # x-res * 2 / 32

/bin/busybox xzcat /lib/navico/systemfailure.bmp.xz | (
  LINE=0
  FBSEEK=$((($YRES+$BMPDY)/2*$STRIDE+($STRIDE-$BMPDX)/2-1))
  dd of=/dev/null bs=70 count=1 2>/dev/null # dump the bmp header. The header size seems to vary between bitmaps??
  while [ $LINE -lt $BMPDY ]; do
    dd of=/dev/fb0 bs=32 seek=$(($FBSEEK/32)) count=$BMPSTRIDE 2>/dev/null
    FBSEEK=$(($FBSEEK-$STRIDE))
    LINE=$(($LINE+1))
  done
)

# Wait forever
while true; do
  sleep 1
done

