#!/bin/bash -x
# patch libertas kernel module

os=`cat /etc/issue|gawk '/OLPC/ {print $3}'`
model=`cat /etc/issue|gawk '/OLPC/ {print $5}'`
if [ "$model" == "XO-1" ]; then
  if [ "$os" == "13.2.0" ]; then
    echo "Updating OS 13.2.0"
    cd /usr/lib/modules/3.3.8_xo1-20130329.1530.olpc.c0f817d/kernel/drivers/net/wireless/libertas
    cp -n libertas.ko libertas.ko.ORIG
    cp /media/binobjs/libertas.ko.dkms-13.2.0-13-xo-1 libertas.ko.fix
    cp -u libertas.ko.fix libertas.ko
  
  elif [ "$os" == "12.1.0" ]; then
    echo "Updating OS 12.1.0"
    cd /usr/lib/modules/3.3.8_xo1-20120705.1732.olpc.5d48a2f/kernel/drivers/net/wireless/libertas
    cp -n libertas.ko libertas.ko.ORIG
    cp /media/binobjs/libertas.ko.dkms-12.1.0-21-xo-1 libertas.ko.fix
    cp -u libertas.ko.fix libertas.ko
      
  else
    echo $os
    echo "is not a supported OS"  
  fi
else
    echo "This is only for an XO-1"    
fi

sync
echo ""
echo "           ********************************************"
echo "           *                                          *"
echo "           *  Make sure you read the messages         *"
echo "           *   to see if it worked                    *"
echo "           *                                          *"
echo "           ********************************************"
