#!/bin/sh

cd /tmp

# replace with your kernel version (at least 3.3.x)
SYMVERS=`find /usr/src/linux-* -name 'Module.symvers'|head`
KERNEL="linux-3.10.10"
MODPATH="drivers/net/ethernet/realtek"
MOD="r8169"

# system modules (destination)
MODULES="/lib/modules/`uname -r`/kernel/$MODPATH"

# tar xzf $KERNEL.tar.gz

cd $KERNEL || exit
cp -f $SYMVERS Module.symvers || exit
zcat /proc/config.gz > .config
make oldconfig && make prepare && make modules_prepare || exit
make M=$MODPATH || exit

exit
sudo modprobe -r $MOD
sudo mv -f $MODULES/$MOD.ko.gz $MODULES/$MOD.ko.gz_orig
sudo cp -v $MODPATH/$MOD.ko $MODULES/$MOD.ko
sudo gzip -9 $MODULES/$MOD.ko
sudo modprobe $MOD
