root/2009_cbc_hacking/nhs_installer/compile-debug

User picture

Author: Jeremy Rand

Revision: 1


File Size: 2.13 KB

(August 18, 2009 17:14 UTC) Almost 3 years ago

Code for the 2009 CBC Hacking GCER paper.

 
Show/hide line numbers
#!/bin/bash

DIR=/mnt/user/bin
PROG=$DIR/robot-debug

rm -rf $DIR
mkdir -p $DIR

if [ "$1" == "/mnt/usercode/robot.c" ]; then

CODEDIR="usb_stick_cached"
rm -rf /mnt/user/code/${CODEDIR%%/*} >/dev/null
mkdir -p /mnt/user/code/${CODEDIR%%/*} >/dev/null
echo "Compiling ${1} for debug" 
/mnt/user/nhs/gcc-usercode-debug "${1}" -o /mnt/user/code/${CODEDIR%%/*}/robot-debug 2>&1
if [ -e /mnt/user/code/${CODEDIR%%/*}/robot-debug ]; then
  echo "Compile for debug succeeded." 
else
  echo "Compiling ${1}pp for debug" 
  /mnt/user/nhs/g++-usercode-debug "${1}pp" -o /mnt/user/code/${CODEDIR%%/*}/robot-debug 2>&1
  if [ -e /mnt/user/code/${CODEDIR%%/*}/robot-debug ]; then
    echo "Compile for debug succeeded." 
  else
    echo "Compiling ${1}xx for debug" 
    /mnt/user/nhs/g++-usercode-debug "${1}xx" -o /mnt/user/code/${CODEDIR%%/*}/robot-debug 2>&1
    if [ -e /mnt/user/code/${CODEDIR%%/*}/robot-debug ]; then
      echo "Compile for debug succeeded." 
    else
      echo "Compile for debug failed." 
    fi
  fi
fi

else

case ${1} in
*/mnt/user/code/*) CODEDIR=${1#*/mnt/user/code/} ; echo "Checking directory ${CODEDIR%%/*} for binary" ;;
esac

if [ ! -e /mnt/user/code/${CODEDIR%%/*}/robot-debug ]; then
echo "Compiling ${1} for debug" 
/mnt/user/nhs/gcc-usercode-debug "${1}" -o /mnt/user/code/${CODEDIR%%/*}/robot-debug 2>&1
if [ -e /mnt/user/code/${CODEDIR%%/*}/robot-debug ]; then
  echo "Compile for debug succeeded." 
else
  echo "Compiling ${1}pp for debug" 
  /mnt/user/nhs/g++-usercode-debug "${1}pp" -o /mnt/user/code/${CODEDIR%%/*}/robot-debug 2>&1
  if [ -e /mnt/user/code/${CODEDIR%%/*}/robot-debug ]; then
    echo "Compile for debug succeeded." 
  else
    echo "Compiling ${1}xx for debug" 
    /mnt/user/nhs/g++-usercode-debug "${1}xx" -o /mnt/user/code/${CODEDIR%%/*}/robot-debug 2>&1
    if [ -e /mnt/user/code/${CODEDIR%%/*}/robot-debug ]; then
      echo "Compile for debug succeeded." 
    else
      echo "Compile for debug failed." 
    fi
  fi
fi
fi

fi

echo "Copying /mnt/user/code/${CODEDIR%%/*}/robot-debug to $PROG"
cp /mnt/user/code/${CODEDIR%%/*}/robot-debug $PROG
if [ -e $PROG ]; then
  echo "Copy succeeded." 
else
  echo "Copy failed." 
fi