#!/bin/sh -x

wget -q http://www.kernel.org/pub/linux/kernel/v3.x/linux-3.2.tar.xz
tar xpJf linux-3.2.tar.xz

wget http://www.kernel.org/pub/linux/kernel/v3.x/patch-3.2.30.xz
wget ftp://plamo.linet.gr.jp/pub/Plamo-test/kernelsrc_patches/UNICON/vd_unicon-kernel-20120107-3.2.patch
wget http://vdlinux.sourceforge.jp/dists/UNICON/vd_unicon-kernel-fonts-20040205.patch.bz2
wget ftp://plamo.linet.gr.jp/pub/Plamo-test/kernelsrc_patches/misc/2.6.31-export-init_mm.patch
git clone git://aufs.git.sourceforge.net/gitroot/aufs/aufs3-standalone.git
( cd aufs3-standalone ; git checkout origin/aufs3.2 ; git reset --hard 267cb11 )
wget ftp://plamo.linet.gr.jp/pub/Plamo-test/kernelsrc_patches/mcp/3.2-panic_beep.patch
wget ftp://plamo.linet.gr.jp/pub/Plamo-test/kernelsrc_patches/mcp/3.2-morse_code_panics.patch
git clone git://github.com/NigelCunningham/tuxonice-kernel.git
( cd tuxonice-kernel ; git checkout origin/tuxonice-3.2 ; git reset --hard 06a2f2b
  git diff ef00e58 | bzip2 > ../current-tuxonice-for-3.2.30.patch.bz2 )

cd linux-3.2
unxz -c ../patch-3.2.30.xz | patch -Np1 -i -
patch -Np1 -i ../vd_unicon-kernel-20120107-3.2.patch
bunzip2 -c ../vd_unicon-kernel-fonts-20040205.patch.bz2 | patch -Np1 -i -
patch -Np1 -i ../2.6.31-export-init_mm.patch
patch -Np1 -i ../aufs3-standalone/aufs3-kbuild.patch
patch -Np1 -i ../aufs3-standalone/aufs3-base.patch
patch -Np1 -i ../aufs3-standalone/aufs3-proc_map.patch
patch -Np1 -i ../aufs3-standalone/aufs3-standalone.patch
cp -av ../aufs3-standalone/Documentation .
cp -av ../aufs3-standalone/fs .
cp -pv ../aufs3-standalone/include/linux/aufs_type.h include/linux
patch -Np1 -i ../3.2-panic_beep.patch
patch -Np1 -i ../3.2-morse_code_panics.patch
bunzip2 -c ../current-tuxonice-for-3.2.30.patch.bz2 | patch -Np1 -i -
find . -name "*.orig" -ls -exec rm {} \;
