Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sat 28 Feb 2015, 03:11
All times are UTC - 4
 Forum index » Advanced Topics » Cutting edge
kernel compiling in woof-ce
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 7 [97 Posts]   Goto page: 1, 2, 3, 4, 5, 6, 7 Next
Author Message
stemsee

Joined: 27 Jun 2013
Posts: 950
Location: Displaced

PostPosted: Thu 04 Dec 2014, 08:46    Post subject:  kernel compiling in woof-ce
Subject description: unattended mode
 

I have made a version of build.sh script from woof-ce which works unattended and builds both a 32bit-pae kernel and 64bit kernel automatically, I will also add 32bit-no-pae. I call it ubuild.sh ... still testing at the moment.
Back to top
View user's profile Send private message MSN Messenger 
stemsee

Joined: 27 Jun 2013
Posts: 950
Location: Displaced

PostPosted: Fri 05 Dec 2014, 18:11    Post subject:  

Needs Testers. Probably best to leave it running over night.
EDIT: 06/12/14

Last edited by stemsee on Sun 07 Dec 2014, 07:03; edited 1 time in total
Back to top
View user's profile Send private message MSN Messenger 
stemsee

Joined: 27 Jun 2013
Posts: 950
Location: Displaced

PostPosted: Sat 06 Dec 2014, 08:59    Post subject:  

Ok I have ironed aout a few more bugs, however in order for this to work over the long run it will be necessary to download up-to-date DOTconfig files which have been configured for new kernel features, otherwise the script will not be unattended, unless
Code:
make allyesconfig


Actually the config file is no -j6, until i test for single or dual core/thread cpu.

test
Code:
sh-4.3# cores=`cat /proc/cpuinfo | grep 'cpu cores' | cut -f3 -d ' ' | tr '\n' ' ' | cut -f1 -d ' '`
Back to top
View user's profile Send private message MSN Messenger 
stemsee

Joined: 27 Jun 2013
Posts: 950
Location: Displaced

PostPosted: Wed 21 Jan 2015, 15:05    Post subject:  

Here is the script so far. You can appreciate it takes hours to test it. So if anyone wants to work on this with me, welcome!

Code:
#!/bin/bash
# originally by Iguleder
# hacked to DEATH by 01micko
# re-hacked by stemsee to provide unattended version, which auto-builds
#32bit-pae then 64bit then 32bit-nopae kernels and modules consecutively.
# see /usr/share/doc/legal NO WARRANTY, NO responsibility accepted

CWD=`pwd`

#if [[  -e dist/packages/linux_kernel-* ]]; then
#rename packages packages32-pae dist/packages
#touch /tmp/32-pae
#mkdir -p dist/packages
#elif [[ ! -d dist/packages32-pae && ! -d dist/packages/linux_kernel-* ]]; then
#mkdir -p dist/packages
#elif [[ -d dist/packages32-pae && -d dist/packages/linux_kernel-* ]]; then
#rename packages packages64 dist/packages
#touch /tmp/64
#mkdir -p dist/packages
#elif [[  -d dist/packages32-pae &&  -d dist/packages64 && ! -e  dist/packages32-nopae ]]; then
#rename packages packages32-nopae dist/packages
#exit
#fi


if [[ -e /tmp/32-pae && -e /tmp/32-nopae && -e /tmp/64 ]]; then
echo "32bit-pae 64bit and 32bit-no-pae kernels built."
#rm /tmp/32-pae
#rm /tmp/64
#rm  /tmp/32-nopae
exit
fi


if [[ ! -e /tmp/32-pae && ! -d dist/packages32-pae ]]; then
. ./build32-pae.conf
elif [[ -e /tmp/32-pae && ! -e /tmp/64 && ! -d dist/packages64 ]]; then
. ./build64.conf
elif [[ -e /tmp/64  && ! -e /tmp/32-nopae && ! dist/packages32-nopae ]]; then
. ./build32-nopae.conf
elif [[ -e /tmp/32-pae &&  -d dist/packages32-pae && -e /tmp/64 &&  -d dist/packages64 && -e /tmp/32-nopae && -d dist/packages32-nopae ]]; then
exit
fi

if [ "$1" = "" ];then
   echo -en "\033[1;35m""WARNING" #purple?
   echo -en "\033[0m" #reset
   echo ": This will delete aufs, kernel folder but wont touch configs or dist."
   sleep 2
   echo "Please wait..."
   rm -rf ./{aufs*,linux*,kernel*,build.log*}
   echo "Cleaning complete"
fi
if [[ -d ./aufs* ]];then
   echo "This is not a clean kit."
   echo " CTRL+C to quit"
   read notcleango
fi

FW_URL=${FW_URL:-http://distro.ibiblio.org/puppylinux/firmware}
package_name_suffix=$package_name_suffix
custom_suffix=$custom_suffix
kernel_version=$kernel_version
kernel_mirror=$kernel_mirror

# depcheck
echo "Dependency check..."
if git --version &>/dev/null
   then echo -e "\033[1;32m""git is installed" #green
else echo -e "\033[1;31m""git is not installed""\033[0m" && exit #red
fi
if gcc --version &>/dev/null
   then echo -e "\033[1;32m""gcc is installed"
else
   echo -e "\033[1;31m""gcc is not installed""\033[0m" && exit
fi
MKSQ="$(which mksquashfs)"
if [ "$MKSQ" ]
   then
   echo -e "\033[1;32m""mksquashfs is installed"
else #yellow
   echo -e "\033[1;30m""mksquashfs is not installed but you can continue"
fi
echo -e "\033[0m" #reset to original

# .configs
[ -f /tmp/kernel_configs ] && rm -f /tmp/kernel_configs

CONFIGS=$(ls ./configs_extra)

# list
echo "Choose a number of the config you want to try"
NUM=1
for C in $CONFIGS
  do echo "${NUM}. $C" >> /tmp/kernel_configs
  NUM=$(($NUM + 1))
  done
echo "z. Custom DOTconfig" >> /tmp/kernel_configs
echo "d. Default DOTconfig" >> /tmp/kernel_configs 
cat /tmp/kernel_configs
echo "Enter choice"
sleep 4

   if [[ ! -e /tmp/32 && ! -e /tmp/64 ]]; then
   Chosen=3
   elif [[ -e /tmp/32-pae && ! -e /tmp/64 ]]; then
   Chosen=1
   elif [[ -e /tmp/32 && -e /tmp/64 ]]; then
   Chosen=2
   fi

Choice=$(grep "^$Chosen\." /tmp/kernel_configs|cut -d ' ' -f2)
rm -r DOTconfig
cp -af configs_extra/$Choice DOTconfig
 

# the aufs major version
aufs_version=${kernel_version%%.*}
# get the major version (2.6.32 in the case of 2.6.32.40)
kernel_major_version=$kernel_version #blah, hack for 3.x
# get the kernel branch (32 in the case of 2.6.32.40; needed to download Aufs)
kernel_branch=`echo $kernel_major_version | cut -f 2 -d .` #3.x kernels

# create directories for the results
[ ! -d dist/sources/vanilla ] && mkdir -p dist/sources/{patches,vanilla}

# get today's date
today=`date +%d%m%y`

# delete the previous log
[ -f build.log ] && rm -f build.log
[ -f build.log.tar.bz2 ] && mv -f build.log.tar.bz2

downkern () {

if [ ! -e dist/sources/vanilla/linux-$kernel_version.tar.xz ]; then
# download the kernel
echo ${kernel_version##*-}|grep -q "rc"
[ "$?" -eq 0 ] && testing=testing||testing=
   if [[ ! -f dist/sources/vanilla/linux-$kernel_version.tar.xz ]]; then
   echo "Downloading the kernel sources"
   wget -P dist/sources/vanilla $kernel_mirror/$testing/linux-$kernel_version.tar.xz --no-check-certificate > build.log 2>&1
      if [[ $? -ne 0 ]]; then
         echo "Error: failed to download the kernel sources."
         exit 1
      fi
   fi
fi
if [ -e dist/sources/vanilla/linux-$kernel_version.tar.xz ]; then
echo "Kernel Sources already there!"
fi
}
downkern

downaufs () {
   # download Aufs
if [ ! -f dist/sources/vanilla/aufs$aufs_version-$kernel_branch-git$today.tar.bz2 ]; then
      echo "Downloading the Aufs sources"
      git clone git://aufs.git.sourceforge.net/gitroot/aufs/aufs3-standalone.git aufs$aufs_version-$kernel_branch-git$today >> build.log 2>&1

      if [[ $? -ne 0 ]]; then
         echo "Error: failed to download the Aufs sources."
         exit 1
      fi
      cd aufs$aufs_version-$kernel_branch-git$today
      if [[ "$aufsv" ]];then #new far for new kernels
      git checkout origin/aufs$aufsv >> ../build.log 2>&1
      else
      git checkout origin/aufs$aufs_version.$kernel_branch >> ../build.log 2>&1
      fi
      if [[ $? -ne 0 ]]; then
      echo "Error: failed to download the Aufs sources."
      exit 1
      fi
   rm -rf .git
   cd ..
   echo "Creating the Aufs sources tarball"
   tar -c aufs$aufs_version-$kernel_branch-git$today | bzip2 -9 > dist/sources/vanilla/aufs$aufs_version-$kernel_branch-git$today.tar.bz2

elif  [ -f dist/sources/vanilla/aufs$aufs_version-$kernel_branch-git$today.tar.bz2 ]; then
   echo "Extracting the Aufs sources"
   tar xf dist/sources/vanilla/aufs$aufs_version-$kernel_branch-git$today.tar.bz2 >> build.log 2>&1
   if [[ $? -ne 0 ]]; then
      echo "Error: failed to extract the Aufs sources."
      exit 1
   fi
fi
}
downaufs

patchaufs () {
   # patch Aufs
if [ -f aufs-allow-sfs.patch ];then #removed for K3.9 experiment
   echo "Patching the Aufs sources"
   patch -d aufs$aufs_version-$kernel_branch-git$today -p1 < aufs-allow-sfs.patch >> build.log 2>&1
   if [[ $? -ne 0 ]]; then
      echo "Error: failed to patch the Aufs sources."
      exit 1
   fi
   cp aufs-allow-sfs.patch dist/sources/patches
fi
if [ -f aufs-kconfig.patch ];then #special for K3.9
   echo "Patching the Aufs sources"
   patch -d aufs$aufs_version-$kernel_branch-git$today -p1 < aufs-kconfig.patch >> build.log 2>&1
   if [[ $? -ne 0 ]]; then
      echo "Error: failed to patch the Aufs sources for kconfig."
      exit 1
   fi
   cp aufs-kconfig.patch dist/sources/patches
fi
}
patchaufs

extractkern () {
   # extract the kernel
echo "Extracting the kernel sources"
tar xf dist/sources/vanilla/linux-$kernel_version.tar.* >> build.log 2>&1
if [[ $? -ne 0 ]]; then
   echo "Error: failed to extract the kernel sources."
   exit 1
   extractkern
else
echo "extracted"
fi
}
extractkern

cd linux-$kernel_version

aufspatch () {
   echo "Adding Aufs to the kernel sources"
for i in kbuild base standalone mmap; do
   patch -N -p1 < ../aufs$aufs_version-$kernel_branch-git$today/aufs$aufs_version-$i.patch >> ../build.log 2>&1
   if [[ $? -ne 0 ]]; then
      echo "WARNING: failed to add some Aufs patches to the kernel sources."
      echo "Check it manually and either CRTL+C to bail or hit enter to go on"
      sleep 4
   fi
done
}
aufspatch

cp -r ../aufs$aufs_version-$kernel_branch-git$today/{fs,Documentation} .
cp ../aufs$aufs_version-$kernel_branch-git$today/include/linux/aufs_type.h include/linux 2>/dev/null
cp ../aufs$aufs_version-$kernel_branch-git$today/include/uapi/linux/aufs_type.h include/linux 2>/dev/null
[ -d ../aufs$aufs_version-$kernel_branch-git$today/include/uapi ] && \
cp -r ../aufs$aufs_version-$kernel_branch-git$today/include/uapi/linux/aufs_type.h include/uapi/linux

echo "Resetting the minor version number"
cp Makefile Makefile-orig
sed -i "s/^EXTRAVERSION =/EXTRAVERSION = $custom_suffix/" Makefile
diff -up Makefile-orig Makefile > ../dist/sources/patches/extra-version.patch
rm Makefile-orig

#echo "Reducing the number of consoles"
#if [ "$kernel_branch" -ge 12 ]; then
 #if [[ "${kernel_version%%.*}" -ge 3 -a "$kernel_branch" -ge 16 ]]; then
    cp kernel/printk/printk.c kernel/printk/printk.c.orig
    sed -i s/'#define MAX_CMDLINECONSOLES 8'/'#define MAX_CMDLINECONSOLES 5'/ kernel/printk/printk.c
    diff -up kernel/printk/printk.c.orig kernel/printk/printk.c > ../dist/sources/patches/less-consoles.patch
   
    echo "Reducing the verbosity level"
    cp -f include/linux/printk.h include/linux/printk.h.orig
    sed -i s/'#define CONSOLE_LOGLEVEL_DEFAULT 7 \/\* anything MORE serious than KERN_DEBUG \*\/'/'#define CONSOLE_LOGLEVEL_DEFAULT 3 \/\* anything MORE serious than KERN_ERR \*\/'/ include/linux/printk.h
    diff -up include/linux/printk.h.orig include/linux/printk.h > ../dist/sources/patches/lower-verbosity.patch
 #else
    #cp kernel/printk/printk.c kernel/printk/printk.c.orig
    #sed -i s/'#define MAX_CMDLINECONSOLES 8'/'#define MAX_CMDLINECONSOLES 5'/ kernel/printk/printk.c
    #diff -up kernel/printk/printk.c.orig kernel/printk/printk.c > ../dist/sources/patches/less-consoles.patch
   
    #echo "Reducing the verbosity level"
    #cp -f kernel/printk/printk.c kernel/printk/printk.c.orig
    #sed -i s/'#define DEFAULT_CONSOLE_LOGLEVEL 7 \/\* anything MORE serious than KERN_DEBUG \*\/'/'#define DEFAULT_CONSOLE_LOGLEVEL 3 \/\* anything MORE serious than KERN_ERR \*\/'/ kernel/printk/printk.c
    #diff -up kernel/printk/printk.c.orig kernel/printk/printk.c > ../dist/sources/patches/lower-verbosity.patch
  #fi
#else
 #cp kernel/printk.c kernel/printk.c.orig
 #sed -i s/'#define MAX_CMDLINECONSOLES 8'/'#define MAX_CMDLINECONSOLES 5'/ kernel/printk.c
 #diff -up kernel/printk.c.orig kernel/printk.c > ../dist/sources/patches/less-consoles.patch

 #echo "Reducing the verbosity level"
 #cp -f kernel/printk.c kernel/printk.c.orig
 #sed -i s/'#define DEFAULT_CONSOLE_LOGLEVEL 7 \/\* anything MORE serious than KERN_DEBUG \*\/'/'#define DEFAULT_CONSOLE_LOGLEVEL 3 \/\* Puppy linux hack \*\/'/ kernel/printk.c
 #diff -up kernel/printk.c.orig kernel/printk.c > ../dist/sources/patches/lower-verbosity.patch
#fi

patches () {
for patch in ../patches/*; do
   echo "Applying $patch"
   patch -p1 < $patch >> ../build.log 2>&1
   if [[ $? -ne 0 ]]; then
      echo "Error: failed to apply $patch on the kernel sources."
      exit 1
   fi
   cp $patch ../dist/sources/patches
done
}
patches

cleaningsrc () {
echo "Cleaning the kernel sources"
make clean
make mrproper
find . -name '*.orig' -delete
find . -name '*.rej' -delete
find . -name '*~' -delete
cp ../DOTconfig .config
}
cleaningsrc

#pause to configure
configure () {
echo "You now should configure your kernel. The supplied .config is
already configured but you may want to make changes, plus the date
should be updated. You can choose to run \"make menuconfig\" for
an ncurses based gui (recommended if you don't change stuff or
for advanced users)

1. make olddefconfig
s) skip"
echo
sleep 4
kernelconfig=1
case $kernelconfig in
1) make olddefconfig;;
s)echo "skipping";;
esac
echo
echo "Ok, kernel is configured. CTRL+C to quit"
sleep 4

[ ! -d ../dist/packages ] && mkdir -p ../dist/packages
}
configure
krnheads () {
   echo "Creating the kernel headers package"
make headers_check >> ../build.log 2>&1
make INSTALL_HDR_PATH=kernel_headers-$kernel_major_version-$package_name_suffix/usr headers_install >> ../build.log 2>&1
find kernel_headers-$kernel_major_version-$package_name_suffix/usr/include \( -name .install -o -name ..install.cmd \) -delete
mv kernel_headers-$kernel_major_version-$package_name_suffix ../dist/packages
}
krnheads

krncompile () {
echo "Compiling the kernel"
cores=`cat /proc/cpuinfo | grep 'cpu cores' | cut -f3 -d ' ' | tr '\n' ' ' | cut -f1 -d ' '`
if [[ $cores -ge 2 ]]; then
make -d -j6
else
make -d
fi
if [[ ! -f arch/x86/boot/bzImage || ! -f System.map ]]; then
   echo "Error: failed to compile the kernel sources."
   exit 1
fi
cp .config ../dist/sources/DOTconfig-$kernel_version-
}

krncompile
echo "Creating the kernel package"
make INSTALL_MOD_PATH=linux_kernel-$kernel_major_version-$package_name_suffix modules_install >> ../build.log 2>&1
rm -f linux_kernel-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix/{build,source}
mkdir -p linux_kernel-$kernel_major_version-$package_name_suffix/boot
mkdir -p linux_kernel-$kernel_major_version-$package_name_suffix/etc/modules
cp .config linux_kernel-$kernel_major_version-$package_name_suffix/etc/modules/DOTconfig-$kernel_version-
cp arch/x86/boot/bzImage linux_kernel-$kernel_major_version-$package_name_suffix/boot/vmlinuz
BZIMAGE=`find . -type f -name bzImage`
cp System.map linux_kernel-$kernel_major_version-$package_name_suffix/boot/
cp linux_kernel-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix/{modules.builtin,modules.order} \
 linux_kernel-$kernel_major_version-$package_name_suffix/etc/modules/
 mkdir -p ../dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/{lib,etc/modules}
[ "$FD" = "1" ] || \
mv linux_kernel-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix/modules* ../dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/lib/
mv linux_kernel-$kernel_major_version-$package_name_suffix ../dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/etc/modules/

if [ "$FD" = "1" ];then #make fatdog kernel module package
   mv ../dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/boot/vmlinuz ../dist/packages/vmlinuz-$kernel_major_version-$package_name_suffix/vmlinuz-${kernel-major-version}$custom_suffix
   [ -f ../dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/boot/bzImage ] &&
rm -f ../dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/boot/bzImage
   echo "Huge kernel $kernel_major_version-$package_name_suffix is ready in dist"
fi

echo "Cleaning the kernel sources"
make clean >> ../build.log 2>&1
make prepare >> ../build.log 2>&1

cd ..

echo "Creating a kernel sources SFS"
mkdir -p kernel_sources-$kernel_major_version-$package_name_suffix/usr/src
mv linux-$kernel_version kernel_sources-$kernel_major_version-$package_name_suffix/usr/src/linux
mkdir -p kernel_sources-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix
ln -s /usr/src/linux kernel_sources-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix/build
[ ! -f kernel_sources-${kernel_major_version}-$package_name_suffix/usr/src/linux/include/linux/version.h ] && \
ln -s /usr/src/linux/include/generated/uapi/linux/version.h kernel_sources-${kernel_major_version}-$package_name_suffix/usr/src/linux/include/linux/version.h
ln -s /usr/src/linux kernel_sources-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix/source
mksquashfs kernel_sources-$kernel_major_version-$package_name_suffix dist/sources/kernel_sources-$kernel_major_version-$package_name_suffix.sfs $COMP

# build aufs-utils userspace modules
echo "Now to build the aufs-utils for userspace"
if [ ! -f dist/sources/vanilla/aufs-util${today}.tar.bz2 ];then
   git clone git://aufs.git.sourceforge.net/gitroot/aufs/aufs-util.git aufs-util >> build.log 2>&1
   [[ $? -ne 0 ]] && echo "Failed to get aufs-util from git, do it manually. Kernel is compiled OK :)" && exit
   
   cd aufs-util
   
   git branch -a | grep 'aufs3' |grep -v 'rcN' | cut -d '.' -f2 > /tmp/aufs-util-version #we go for stable only
   while read line
     do
       if [[ "$kernel_branch" = "$line" ]];then branch=$line
       else
         while [[ "$kernel_branch" -gt "$line" ]]
           do branch=$line
           echo $branch && break
           done
       fi
     done < /tmp/aufs-util-version
   git checkout origin/aufs3.${branch} >> ../build.log 2>&1
   
   [[ $? -ne 0 ]] && echo "Failed to get aufs-util from git, do it manually. Kernel is compiled OK :)" && exit
   echo "Patching aufs-util sources"
   cp Makefile Makefile.orig
   sed -i 's/-static //' Makefile
   diff -ru Makefile.orig Makefile > ../dist/sources/patches/aufs-util-dynamic.patch
   rm *.orig
   else
   echo "Extracting the Aufs-util sources"
   tar xf dist/sources/vanilla/aufs-util$today.tar.bz2 >> ../build.log 2>&1
   if [[ $? -ne 0 ]]; then
      echo "Error: failed to extract the aufs-util sources."
      exit 1
   fi   
   cd aufs-util   
   patch -p1 < ../dist/sources/patches/aufs-util-dynamic.patch >> ../build.log 2>&1
   [[ "$?" -ne 0 ]] && echo "Failed to patch the aufs-util sources, do it manually. Kernel is compiled ok"
fi
arch=`uname -m`
CONFIG=`find $CWD/dist/sources -type f -name 'DOTconfig*'`
grep -q 'CONFIG_AUFS_FHSM=y' $CONFIG
[[ "$?" -eq 0 ]] && export MAKE=make || export MAKE="make BuildFHSM=no"
LinuxSrc=`find $CWD -type d -name 'kernel_headers*'`
export CPPFLAGS="-I $LinuxSrc/usr/include"
$MAKE >> ../build.log 2>&1
[[ $? -ne 0 ]] && echo "Failed to compile aufs-util, do it manually. Kernel is compiled OK :)"
make DESTDIR=$CWD/dist/packages/aufs-util-$kernel_version-$arch install >> ../build.log 2>&1 #maybe needs absolute path
make clean >> ../build.log 2>&1
if [[ "$arch" = "x86_64" ]];then
 mv $CWD/dist/packages/aufs-util-$kernel_version-$arch/usr/lib \
$CWD/dist/packages/aufs-util-$kernel_version-$arch/usr/lib64
fi
echo "aufs-util-$kernel_version is in dist"
cd ..
if [[ "$FD" = "1" ]];then #shift aufs-utils to kernel-modules.sfs
   echo "Installing aufs-utils into kernel package"
   cp -a dist/packages/aufs-util-$kernel_version-$arch/* \
   dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix
   cp -r /lib/firmware dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/lib/
   mksquashfs dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix dist/packages/kernel-modules.sfs-$kernel_major_version-$package_name_suffix $COMP
   [[ "$?" = 0 ]] && echo "Huge compatible kernel packages are ready to package./" || exit 1
   echo "Packaging huge-$kernel_major_version-$package_name_suffix kernel"
   cd dist/packages/
   tar -cjvf huge-$kernel_major_version-${package_name_suffix}.tar.bz2 \
   vmlinuz-$kernel_major_version-$package_name_suffix kernel-modules.sfs-$kernel_major_version-$package_name_suffix
   [[ "$?" = 0 ]] && echo "huge-$kernel_major_version-${package_name_suffix}.tar.bz2 is in dist/packages" || exit 1
   md5sum huge-$kernel_major_version-${package_name_suffix}.tar.bz2 > huge-$kernel_major_version-${package_name_suffix}.tar.bz2.md5.txt
   echo
   cd $CWD
   
fi

tar -c aufs-util | bzip2 -9 > dist/sources/vanilla/aufs-util$today-$-$arch.tar.bz2

echo "Compressing the log"
bzip2 -9 build.log
cp build.log.bz2 dist/sources

echo "Done!"
if [[ -e /tmp/32-nopae ]]; then
exit
elif [[ -e /tmp/64 ]]; then
touch /tmp/32-nopae
elif [[ -e /tmp/32-pae && ! -e /tmp/64 ]]; then
touch /tmp/64
elif [[ ! -e /tmp/32-pae ]]; then
touch /tmp/32-pae
fi

[ -f /usr/share/sounds/2barks.au ] && aplay /usr/share/sounds/2barks.au

if [[ -e /tmp/32-pae && ! -e /tmp/64 ]]; then
rename packages packages32-pae dist/packages
mkdir dist/packages
if [[ -e /tmp/32-pae &&  -e /tmp/64 ]]; then
rename packages packages64 dist/packages
mkdir dist/packages
if [[ -e /tmp/32-nopae &&  -e /tmp/64 ]]; then
rename packages packages32-nopae dist/packages
exit
fi
cd $CWD
./ubuild.sh
exit
stemskernelkit(1).zip
Description  added patches dir ...
zip

 Download 
Filename  stemskernelkit(1).zip 
Filesize  113.07 KB 
Downloaded  44 Time(s) 

Last edited by stemsee on Wed 21 Jan 2015, 19:39; edited 3 times in total
Back to top
View user's profile Send private message MSN Messenger 
l0wt3ch

Joined: 23 Apr 2014
Posts: 82

PostPosted: Wed 21 Jan 2015, 19:19    Post subject:  

Here is the output when I tried it, without me pressing any keys after selecting a config:

Code:
# ./ubuild.sh
WARNING: This will delete aufs, kernel folder but wont touch configs or dist.
Please wait...
Cleaning complete
Dependency check...
git is installed
gcc is installed
mksquashfs is installed

Choose a number of the config you want to try
1. DOTconfig-3.14.25-64
2. DOTconfig-3.14.25-pae
3. DOTconfig-3.17.4-64
4. DOTconfig-3.17.4-nopae
5. DOTconfig-3.17.4-pae
z. Custom DOTconfig
d. Default DOTconfig
Enter choice
rm: cannot remove ‘DOTconfig’: No such file or directory
Downloading the kernel sources
2
Kernel Sources already there!
Downloading the Aufs sources
Creating the Aufs sources tarball
Extracting the kernel sources
extracted
Adding Aufs to the kernel sources
WARNING: failed to add some Aufs patches to the kernel sources.
Check it manually and either CRTL+C to bail or hit enter to go on
Resetting the minor version number
Reducing the verbosity level
Applying ../patches/*
./ubuild.sh: line 292: ../patches/*: No such file or directory
Error: failed to apply ../patches/* on the kernel sources.
# 2
bash: 2: command not found
Back to top
View user's profile Send private message 
stemsee

Joined: 27 Jun 2013
Posts: 950
Location: Displaced

PostPosted: Wed 21 Jan 2015, 19:35    Post subject:  

added the patches dir. Should be unattended, ie don't select anything, until the logic is improved to allow user input as well.
Back to top
View user's profile Send private message MSN Messenger 
l0wt3ch

Joined: 23 Apr 2014
Posts: 82

PostPosted: Wed 21 Jan 2015, 21:15    Post subject:  

Looks like it worked... Very Happy

Attached the build.log file.
build.log.bz2
Description 
bz2

 Download 
Filename  build.log.bz2 
Filesize  28.27 KB 
Downloaded  34 Time(s) 
Back to top
View user's profile Send private message 
stemsee

Joined: 27 Jun 2013
Posts: 950
Location: Displaced

PostPosted: Thu 22 Jan 2015, 06:21    Post subject:  

I scanned the build log..... but I think it built only one kernel, not three. Also when I did it packages do not end up in the assigned locations. Although they are all in the sources. The script (original) gets messy, and I cannot follow it clearly. 'exit' needs to be removed from the end of the script. Not sure how to make the script call itself, maybe I will just make it into a function and call the function 3 times!
Back to top
View user's profile Send private message MSN Messenger 
stemsee

Joined: 27 Jun 2013
Posts: 950
Location: Displaced

PostPosted: Thu 22 Jan 2015, 14:59    Post subject:  

The function idea didn't work! Guess I will have to copy the script appended to itself twice more.
Back to top
View user's profile Send private message MSN Messenger 
stemsee

Joined: 27 Jun 2013
Posts: 950
Location: Displaced

PostPosted: Thu 22 Jan 2015, 17:44    Post subject:  

reworked base script. Not tested ... who wants to be first.
Builds 64 bit first then pae then non-pae

Known issues: Everything gets compiled but squashed with sources.

Code:
#!/bin/bash
# originally by Iguleder
# hacked to DEATH by 01micko
# re-hacked by stemsee to provide unattended version, which auto-builds
#32bit-pae then 64bit then 32bit-nopae kernels and modules consecutively.
# see /usr/share/doc/legal NO WARRANTY, NO responsibility accepted
CWD=`pwd`

if [[ ! -e /tmp/64 && ! -d dist/packages64 ]]; then
. ./build64.conf
fi

if [ "$1" = "" ];then
   echo -en "\033[1;35m""WARNING" #purple?
   echo -en "\033[0m" #reset
   echo ": This will delete aufs, kernel folder but wont touch configs or dist."
   sleep 2
   echo "Please wait..."
   rm -rf ./{aufs*,linux*,kernel*,build.log*}
   echo "Cleaning complete"
fi
if [[ -d ./aufs* ]];then
   echo "This is not a clean kit."
   echo " CTRL+C to quit"
   read notcleango
fi

FW_URL=${FW_URL:-http://distro.ibiblio.org/puppylinux/firmware}
package_name_suffix=$package_name_suffix
custom_suffix=$custom_suffix
kernel_version=$kernel_version
kernel_mirror=$kernel_mirror

# depcheck
echo "Dependency check..."
if git --version &>/dev/null
   then echo -e "\033[1;32m""git is installed" #green
else echo -e "\033[1;31m""git is not installed""\033[0m" && exit #red
fi
if gcc --version &>/dev/null
   then echo -e "\033[1;32m""gcc is installed"
else
   echo -e "\033[1;31m""gcc is not installed""\033[0m" && exit
fi
MKSQ="$(which mksquashfs)"
if [ "$MKSQ" ]
   then
   echo -e "\033[1;32m""mksquashfs is installed"
else #yellow
   echo -e "\033[1;30m""mksquashfs is not installed but you can continue"
fi
echo -e "\033[0m" #reset to original

# .configs
[ -f /tmp/kernel_configs ] && rm -f /tmp/kernel_configs

CONFIGS=$(ls ./configs_extra)

# list
echo "configs"
NUM=1
for C in $CONFIGS
  do echo "${NUM}. $C" >> /tmp/kernel_configs
  NUM=$(($NUM + 1))
  done
echo "z. Custom DOTconfig" >> /tmp/kernel_configs
echo "d. Default DOTconfig" >> /tmp/kernel_configs 
figs=`cat /tmp/kernel_configs`
echo "$figs"
sleep 2

   Chosen=1

echo "$Chosen"
sleep 1
Choice=$(grep "^$Chosen\." /tmp/kernel_configs | cut -d ' ' -f2)
echo "$Choice"
sleep 1
rm -r DOTconfig
cp -af configs_extra/$Choice DOTconfig
 

# the aufs major version
aufs_version=${kernel_version%%.*}
# get the major version (2.6.32 in the case of 2.6.32.40)
kernel_major_version=$kernel_version #blah, hack for 3.x
# get the kernel branch (32 in the case of 2.6.32.40; needed to download Aufs)
kernel_branch=`echo $kernel_major_version | cut -f 2 -d .` #3.x kernels

# create directories for the results
[ ! -d dist/sources/vanilla ] && mkdir -p dist/sources/{patches,vanilla}

# get today's date
today=`date +%d%m%y`

# delete the previous log
[ -f build.log ] && rm -f build.log
[ -f build.log.tar.bz2 ] && mv -f build.log.tar.bz2

downkern () {

if [ ! -e dist/sources/vanilla/linux-$kernel_version.tar.xz ]; then
# download the kernel
echo ${kernel_version##*-}|grep -q "rc"
[ "$?" -eq 0 ] && testing=testing||testing=
   if [[ ! -f dist/sources/vanilla/linux-$kernel_version.tar.xz ]]; then
   echo "Downloading the kernel sources"
   wget -P dist/sources/vanilla $kernel_mirror/$testing/linux-$kernel_version.tar.xz --no-check-certificate > build.log 2>&1
      if [[ $? -ne 0 ]]; then
         echo "Error: failed to download the kernel sources."
         exit 1
      fi
   fi
fi
if [ -e dist/sources/vanilla/linux-$kernel_version.tar.xz ]; then
echo "Kernel Sources already there!"
fi
}
downkern

downaufs () {
   # download Aufs

      git clone git://git.code.sf.net/p/aufs/aufs3-standalone aufs$aufs_version-18-git$today >> build.log 2>&1

      if [[ $? -ne 0 ]]; then
         echo "Error: failed to download the Aufs sources."
         exit 1
      fi
      cd aufs$aufs_version-$kernel_branch-git$today
      if [[ "$aufsv" ]];then #new far for new kernels
      git checkout origin/aufs$aufsv >> ../build.log 2>&1
      else
      git checkout origin/aufs$aufs_version.$kernel_branch >> ../build.log 2>&1
      fi
      if [[ $? -ne 0 ]]; then
      echo "Error: failed to download the Aufs sources."
      exit 1
      fi
   rm -rf .git
   cd ..
   echo "Creating the Aufs sources tarball"
   tar -c aufs$aufs_version-$kernel_branch-git$today | bzip2 -9 > dist/sources/vanilla/aufs$aufs_version-$kernel_branch-git$today.tar.bz2

   echo "Extracting the Aufs sources"
   tar xf dist/sources/vanilla/aufs$aufs_version-$kernel_branch-git$today.tar.bz2
   if [[ $? -ne 0 ]]; then
      echo "Error: failed to extract the Aufs sources."
      exit 1
      fi
}
downaufs

patchaufs () {
   # patch Aufs
if [ -f aufs-allow-sfs.patch ];then #removed for K3.9 experiment
   echo "Patching the Aufs sources"
   patch -d aufs$aufs_version-$kernel_branch-git$today -p1 < aufs-allow-sfs.patch >> build.log 2>&1
   if [[ $? -ne 0 ]]; then
      echo "Error: failed to patch the Aufs sources."
      exit 1
   fi
   cp aufs-allow-sfs.patch dist/sources/patches
fi
if [ -f aufs-kconfig.patch ];then #special for K3.9
   echo "Patching the Aufs sources"
   patch -d aufs$aufs_version-$kernel_branch-git$today -p1 < aufs-kconfig.patch >> build.log 2>&1
   if [[ $? -ne 0 ]]; then
      echo "Error: failed to patch the Aufs sources for kconfig."
      exit 1
   fi
   cp aufs-kconfig.patch dist/sources/patches
fi
}
patchaufs

extractkern () {
   # extract the kernel
echo "Extracting the kernel sources"
tar xf dist/sources/vanilla/linux-$kernel_version.tar.* >> build.log 2>&1
if [[ $? -ne 0 ]]; then
   echo "Error: failed to extract the kernel sources."
   exit 1
   extractkern
else
echo "extracted"
fi
}
extractkern

cd linux-$kernel_version

aufspatch () {
   echo "Adding Aufs to the kernel sources"
for i in kbuild base standalone mmap; do
   patch -N -p1 < ../aufs$aufs_version-$kernel_branch-git$today/aufs$aufs_version-$i.patch >> ../build.log 2>&1
   if [[ $? -ne 0 ]]; then
      echo "WARNING: failed to add some Aufs patches to the kernel sources."
      echo "Check it manually and either CRTL+C to bail or hit enter to go on"
      sleep 4
   fi
done
}
aufspatch

cp -r ../aufs$aufs_version-$kernel_branch-git$today/{fs,Documentation} .
cp ../aufs$aufs_version-$kernel_branch-git$today/include/linux/aufs_type.h include/linux 2>/dev/null
cp ../aufs$aufs_version-$kernel_branch-git$today/include/uapi/linux/aufs_type.h include/linux 2>/dev/null
[ -d ../aufs$aufs_version-$kernel_branch-git$today/include/uapi ] && \
cp -r ../aufs$aufs_version-$kernel_branch-git$today/include/uapi/linux/aufs_type.h include/uapi/linux

echo "Resetting the minor version number"
cp Makefile Makefile-orig
sed -i "s/^EXTRAVERSION =/EXTRAVERSION = $custom_suffix/" Makefile
diff -up Makefile-orig Makefile > ../dist/sources/patches/extra-version.patch
rm Makefile-orig

#echo "Reducing the number of consoles"
#if [ "$kernel_branch" -ge 12 ]; then
 #if [[ "${kernel_version%%.*}" -ge 3 -a "$kernel_branch" -ge 16 ]]; then
    cp kernel/printk/printk.c kernel/printk/printk.c.orig
    sed -i s/'#define MAX_CMDLINECONSOLES 8'/'#define MAX_CMDLINECONSOLES 5'/ kernel/printk/printk.c
    diff -up kernel/printk/printk.c.orig kernel/printk/printk.c > ../dist/sources/patches/less-consoles.patch
   
    echo "Reducing the verbosity level"
    cp -f include/linux/printk.h include/linux/printk.h.orig
    sed -i s/'#define CONSOLE_LOGLEVEL_DEFAULT 7 \/\* anything MORE serious than KERN_DEBUG \*\/'/'#define CONSOLE_LOGLEVEL_DEFAULT 3 \/\* anything MORE serious than KERN_ERR \*\/'/ include/linux/printk.h
    diff -up include/linux/printk.h.orig include/linux/printk.h > ../dist/sources/patches/lower-verbosity.patch
 #else
    #cp kernel/printk/printk.c kernel/printk/printk.c.orig
    #sed -i s/'#define MAX_CMDLINECONSOLES 8'/'#define MAX_CMDLINECONSOLES 5'/ kernel/printk/printk.c
    #diff -up kernel/printk/printk.c.orig kernel/printk/printk.c > ../dist/sources/patches/less-consoles.patch
   
    #echo "Reducing the verbosity level"
    #cp -f kernel/printk/printk.c kernel/printk/printk.c.orig
    #sed -i s/'#define DEFAULT_CONSOLE_LOGLEVEL 7 \/\* anything MORE serious than KERN_DEBUG \*\/'/'#define DEFAULT_CONSOLE_LOGLEVEL 3 \/\* anything MORE serious than KERN_ERR \*\/'/ kernel/printk/printk.c
    #diff -up kernel/printk/printk.c.orig kernel/printk/printk.c > ../dist/sources/patches/lower-verbosity.patch
  #fi
#else
 #cp kernel/printk.c kernel/printk.c.orig
 #sed -i s/'#define MAX_CMDLINECONSOLES 8'/'#define MAX_CMDLINECONSOLES 5'/ kernel/printk.c
 #diff -up kernel/printk.c.orig kernel/printk.c > ../dist/sources/patches/less-consoles.patch

 #echo "Reducing the verbosity level"
 #cp -f kernel/printk.c kernel/printk.c.orig
 #sed -i s/'#define DEFAULT_CONSOLE_LOGLEVEL 7 \/\* anything MORE serious than KERN_DEBUG \*\/'/'#define DEFAULT_CONSOLE_LOGLEVEL 3 \/\* Puppy linux hack \*\/'/ kernel/printk.c
 #diff -up kernel/printk.c.orig kernel/printk.c > ../dist/sources/patches/lower-verbosity.patch
#fi

patches () {
for patch in ../patches/*; do
   echo "Applying $patch"
   patch -p1 < $patch >> ../build.log 2>&1
   if [[ $? -ne 0 ]]; then
      echo "Error: failed to apply $patch on the kernel sources."
      exit 1
   fi
   cp $patch ../dist/sources/patches

done
}
patches

cleaningsrc () {
echo "Cleaning the kernel sources"
make clean
make mrproper
find . -name '*.orig' -delete
find . -name '*.rej' -delete
find . -name '*~' -delete

}
cleaningsrc

#pause to configure
configure () {
echo "You now should configure your kernel. The supplied .config is
already configured but you may want to make changes, plus the date
should be updated. You can choose to run \"make menuconfig\" for
an ncurses based gui (recommended if you don't change stuff or
for advanced users)

1. make oldconfig
s) skip"
echo
sleep 4
kernelconfig=1
case $kernelconfig in
1) make olddefconfig;;
s)echo "skipping";;
esac
echo
echo "Ok, kernel is configured. CTRL+C to quit"
sleep 4
cp -f ../DOTconfig .config.old
cp -f ../DOTconfig .config

[ ! -d ../dist/packages ] && mkdir -p ../dist/packages
}
configure
krnheads () {
   echo "Creating the kernel headers package"
make headers_check >> ../build.log 2>&1
make INSTALL_HDR_PATH=kernel_headers-$kernel_major_version-$package_name_suffix/usr headers_install >> ../build.log 2>&1
find kernel_headers-$kernel_major_version-$package_name_suffix/usr/include \( -name .install -o -name ..install.cmd \) -delete
mv kernel_headers-$kernel_major_version-$package_name_suffix ../dist/packages
}
krnheads

krncompile () {
echo "Compiling the kernel"
cores=`cat /proc/cpuinfo | grep 'cpu cores' | cut -f3 -d ' ' | tr '\n' ' ' | cut -f1 -d ' '`
if [[ $cores -ge 2 ]]; then
make -d -j6
else
make -d
fi
if [[ ! -f arch/x86/boot/bzImage || ! -f System.map ]]; then
   echo "Error: failed to compile the kernel sources."
   exit 1
fi
cp .config ../dist/sources/DOTconfig-$kernel_version-
}

krncompile
echo "Creating the kernel package"
make INSTALL_MOD_PATH=linux_kernel-$kernel_major_version-$package_name_suffix modules_install >> ../build.log 2>&1
rm -f linux_kernel-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix/{build,source}
mkdir -p linux_kernel-$kernel_major_version-$package_name_suffix/boot
mkdir -p linux_kernel-$kernel_major_version-$package_name_suffix/etc/modules
cp .config linux_kernel-$kernel_major_version-$package_name_suffix/etc/modules/DOTconfig-$kernel_version-
cp arch/x86/boot/bzImage linux_kernel-$kernel_major_version-$package_name_suffix/boot/vmlinuz
BZIMAGE=`find . -type f -name bzImage`
cp System.map linux_kernel-$kernel_major_version-$package_name_suffix/boot/
cp linux_kernel-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix/{modules.builtin,modules.order} \
 linux_kernel-$kernel_major_version-$package_name_suffix/etc/modules/
 mkdir -p ../dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/{lib,etc/modules}
[ "$FD" = "1" ] || \
mv linux_kernel-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix/modules* ../dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/lib/
mv linux_kernel-$kernel_major_version-$package_name_suffix ../dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/etc/modules/

if [ "$FD" = "1" ];then #make fatdog kernel module package
   mv ../dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/boot/vmlinuz ../dist/packages/vmlinuz-$kernel_major_version-$package_name_suffix/vmlinuz-${kernel-major-version}$custom_suffix
   [ -f ../dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/boot/bzImage ] &&
rm -f ../dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/boot/bzImage
   echo "Huge kernel $kernel_major_version-$package_name_suffix is ready in dist"
fi

echo "Cleaning the kernel sources"
make clean >> ../build.log 2>&1
make prepare >> ../build.log 2>&1

cd ..

echo "Creating a kernel sources SFS"
mkdir -p kernel_sources-$kernel_major_version-$package_name_suffix/usr/src
mv linux-$kernel_version kernel_sources-$kernel_major_version-$package_name_suffix/usr/src/linux
mkdir -p kernel_sources-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix
ln -s /usr/src/linux kernel_sources-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix/build
[ ! -f kernel_sources-${kernel_major_version}-$package_name_suffix/usr/src/linux/include/linux/version.h ] && \
ln -s /usr/src/linux/include/generated/uapi/linux/version.h kernel_sources-${kernel_major_version}-$package_name_suffix/usr/src/linux/include/linux/version.h
ln -s /usr/src/linux kernel_sources-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix/source
mksquashfs kernel_sources-$kernel_major_version-$package_name_suffix dist/sources/kernel_sources-$kernel_major_version-$package_name_suffix.sfs $COMP

# build aufs-utils userspace modules
echo "Now to build the aufs-utils for userspace"
if [ ! -f dist/sources/vanilla/aufs-util${today}.tar.bz2 ];then
   git clone git://aufs.git.sourceforge.net/gitroot/aufs/aufs-util.git aufs-util >> build.log 2>&1
   [[ $? -ne 0 ]] && echo "Failed to get aufs-util from git, do it manually. Kernel is compiled OK :)" && exit
   
   cd aufs-util
   
   git branch -a | grep 'aufs3' |grep -v 'rcN' | cut -d '.' -f2 > /tmp/aufs-util-version #we go for stable only
   while read line
     do
       if [[ "$kernel_branch" = "$line" ]];then branch=$line
       else
         while [[ "$kernel_branch" -gt "$line" ]]
           do branch=$line
           echo $branch && break
           done
       fi
     done < /tmp/aufs-util-version
   git checkout origin/aufs3.${branch} >> ../build.log 2>&1
   
   [[ $? -ne 0 ]] && echo "Failed to get aufs-util from git, do it manually. Kernel is compiled OK :)" && exit
   echo "Patching aufs-util sources"
   cp Makefile Makefile.orig
   sed -i 's/-static //' Makefile
   diff -ru Makefile.orig Makefile > ../dist/sources/patches/aufs-util-dynamic.patch
   rm *.orig
   else
   echo "Extracting the Aufs-util sources"
   tar xf dist/sources/vanilla/aufs-util$today.tar.bz2 >> ../build.log 2>&1
   if [[ $? -ne 0 ]]; then
      echo "Error: failed to extract the aufs-util sources."
      exit 1
   fi   
   cd aufs-util   
   patch -p1 < ../dist/sources/patches/aufs-util-dynamic.patch >> ../build.log 2>&1
   [[ "$?" -ne 0 ]] && echo "Failed to patch the aufs-util sources, do it manually. Kernel is compiled ok"
fi
arch=`uname -m`
CONFIG=`find $CWD/dist/sources -type f -name 'DOTconfig*'`
grep -q 'CONFIG_AUFS_FHSM=y' $CONFIG
[[ "$?" -eq 0 ]] && export MAKE=make || export MAKE="make BuildFHSM=no"
LinuxSrc=`find $CWD -type d -name 'kernel_headers*'`
export CPPFLAGS="-I $LinuxSrc/usr/include"
$MAKE >> ../build.log 2>&1
[[ $? -ne 0 ]] && echo "Failed to compile aufs-util, do it manually. Kernel is compiled OK :)"
make DESTDIR=$CWD/dist/packages/aufs-util-$kernel_version-$arch install >> ../build.log 2>&1 #maybe needs absolute path
make clean >> ../build.log 2>&1
if [[ "$arch" = "x86_64" ]];then
 mv $CWD/dist/packages/aufs-util-$kernel_version-$arch/usr/lib \
$CWD/dist/packages/aufs-util-$kernel_version-$arch/usr/lib64
fi
echo "aufs-util-$kernel_version is in dist"
cd ..
if [[ "$FD" = "1" ]];then #shift aufs-utils to kernel-modules.sfs
   echo "Installing aufs-utils into kernel package"
   cp -a dist/packages/aufs-util-$kernel_version-$arch/* \
   dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix
   cp -r /lib/firmware dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/lib/
   mksquashfs dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix dist/packages/kernel-modules.sfs-$kernel_major_version-$package_name_suffix $COMP
   [[ "$?" = 0 ]] && echo "Huge compatible kernel packages are ready to package./" || exit 1
   echo "Packaging huge-$kernel_major_version-$package_name_suffix kernel"
   cd dist/packages/
   tar -cjvf huge-$kernel_major_version-${package_name_suffix}.tar.bz2 \
   vmlinuz-$kernel_major_version-$package_name_suffix kernel-modules.sfs-$kernel_major_version-$package_name_suffix
   [[ "$?" = 0 ]] && echo "huge-$kernel_major_version-${package_name_suffix}.tar.bz2 is in dist/packages" || exit 1
   md5sum huge-$kernel_major_version-${package_name_suffix}.tar.bz2 > huge-$kernel_major_version-${package_name_suffix}.tar.bz2.md5.txt
   echo
   cd $CWD
fi

tar -c aufs-util | bzip2 -9 > dist/sources/vanilla/aufs-util$today-$-$arch.tar.bz2

echo "Compressing the log"
bzip2 -9 build.log
cp build.log.bz2 dist/sources

echo "Done!"

if [[ ! -e /tmp/64 ]]; then
touch /tmp/64
fi

[ -f /usr/share/sounds/2barks.au ] && aplay /usr/share/sounds/2barks.au
if [[ -e /tmp/64 ]]; then
rename packages packages64 dist/packages
mkdir dist/packages
fi

#SECOND RUN


if [[ ! -e /tmp/32-pae && ! -d dist/packages32-pae ]]; then
. ./build32-pae.conf
fi

if [ "$1" = "" ];then
   echo -en "\033[1;35m""WARNING" #purple?
   echo -en "\033[0m" #reset
   echo ": This will delete aufs, kernel folder but wont touch configs or dist."
   sleep 2
   echo "Please wait..."
   rm -rf ./{aufs*,linux*,kernel*,build.log*}
   echo "Cleaning complete"
fi
if [[ -d ./aufs* ]];then
   echo "This is not a clean kit."
   echo " CTRL+C to quit"
   read notcleango
fi

FW_URL=${FW_URL:-http://distro.ibiblio.org/puppylinux/firmware}
package_name_suffix=$package_name_suffix
custom_suffix=$custom_suffix
kernel_version=$kernel_version
kernel_mirror=$kernel_mirror

# .configs
[ -f /tmp/kernel_configs ] && rm -f /tmp/kernel_configs

CONFIGS=$(ls ./configs_extra)

# list
echo "configs"
NUM=1
for C in $CONFIGS
  do echo "${NUM}. $C" >> /tmp/kernel_configs
  NUM=$(($NUM + 1))
  done
echo "z. Custom DOTconfig" >> /tmp/kernel_configs
echo "d. Default DOTconfig" >> /tmp/kernel_configs 
figs=`cat /tmp/kernel_configs`
echo "$figs"
sleep 2

   if [[ -e /tmp/64 ]]; then
   Chosen=3
   fi
echo "$Chosen"
sleep 1
Choice=$(grep "^$Chosen\." /tmp/kernel_configs | cut -d ' ' -f2)
echo "$Choice"
sleep 1
rm -r DOTconfig
cp -af configs_extra/$Choice DOTconfig
 
   echo "Extracting the Aufs sources"
   tar xf dist/sources/vanilla/aufs$aufs_version-$kernel_branch-git$today.tar.bz2
   if [[ $? -ne 0 ]]; then
      echo "Error: failed to extract the Aufs sources."
      exit 1
      fi
patchaufs () {
   # patch Aufs
if [ -f aufs-allow-sfs.patch ];then #removed for K3.9 experiment
   echo "Patching the Aufs sources"
   patch -d aufs$aufs_version-$kernel_branch-git$today -p1 < aufs-allow-sfs.patch >> build.log 2>&1
   if [[ $? -ne 0 ]]; then
      echo "Error: failed to patch the Aufs sources."
      exit 1
   fi
   cp aufs-allow-sfs.patch dist/sources/patches
fi
if [ -f aufs-kconfig.patch ];then #special for K3.9
   echo "Patching the Aufs sources"
   patch -d aufs$aufs_version-$kernel_branch-git$today -p1 < aufs-kconfig.patch >> build.log 2>&1
   if [[ $? -ne 0 ]]; then
      echo "Error: failed to patch the Aufs sources for kconfig."
      exit 1
   fi
   cp aufs-kconfig.patch dist/sources/patches
fi
}
patchaufs

extractkern () {
   # extract the kernel
echo "Extracting the kernel sources"
tar xf dist/sources/vanilla/linux-$kernel_version.tar.* >> build.log 2>&1
if [[ $? -ne 0 ]]; then
   echo "Error: failed to extract the kernel sources."
   exit 1
   extractkern
else
echo "extracted"
fi
}
extractkern

cd linux-$kernel_version

aufspatch () {
   echo "Adding Aufs to the kernel sources"
for i in kbuild base standalone mmap; do
   patch -N -p1 < ../aufs$aufs_version-$kernel_branch-git$today/aufs$aufs_version-$i.patch >> ../build.log 2>&1
   if [[ $? -ne 0 ]]; then
      echo "WARNING: failed to add some Aufs patches to the kernel sources."
      echo "Check it manually and either CRTL+C to bail or hit enter to go on"
      sleep 4
   fi
done
}
aufspatch

cp -r ../aufs$aufs_version-$kernel_branch-git$today/{fs,Documentation} .
cp ../aufs$aufs_version-$kernel_branch-git$today/include/linux/aufs_type.h include/linux 2>/dev/null
cp ../aufs$aufs_version-$kernel_branch-git$today/include/uapi/linux/aufs_type.h include/linux 2>/dev/null
[ -d ../aufs$aufs_version-$kernel_branch-git$today/include/uapi ] && \
cp -r ../aufs$aufs_version-$kernel_branch-git$today/include/uapi/linux/aufs_type.h include/uapi/linux

echo "Resetting the minor version number"
cp Makefile Makefile-orig
sed -i "s/^EXTRAVERSION =/EXTRAVERSION = $custom_suffix/" Makefile
diff -up Makefile-orig Makefile > ../dist/sources/patches/extra-version.patch
rm Makefile-orig

#echo "Reducing the number of consoles"
#if [ "$kernel_branch" -ge 12 ]; then
 #if [[ "${kernel_version%%.*}" -ge 3 -a "$kernel_branch" -ge 16 ]]; then
    cp kernel/printk/printk.c kernel/printk/printk.c.orig
    sed -i s/'#define MAX_CMDLINECONSOLES 8'/'#define MAX_CMDLINECONSOLES 5'/ kernel/printk/printk.c
    diff -up kernel/printk/printk.c.orig kernel/printk/printk.c > ../dist/sources/patches/less-consoles.patch
   
    echo "Reducing the verbosity level"
    cp -f include/linux/printk.h include/linux/printk.h.orig
    sed -i s/'#define CONSOLE_LOGLEVEL_DEFAULT 7 \/\* anything MORE serious than KERN_DEBUG \*\/'/'#define CONSOLE_LOGLEVEL_DEFAULT 3 \/\* anything MORE serious than KERN_ERR \*\/'/ include/linux/printk.h
    diff -up include/linux/printk.h.orig include/linux/printk.h > ../dist/sources/patches/lower-verbosity.patch


patches () {
for patch in ../patches/*; do
   echo "Applying $patch"
   patch -p1 < $patch >> ../build.log 2>&1
   if [[ $? -ne 0 ]]; then
      echo "Error: failed to apply $patch on the kernel sources."
      exit 1
   fi
   cp $patch ../dist/sources/patches

done
}
patches

cleaningsrc () {
echo "Cleaning the kernel sources"
make clean
make mrproper
find . -name '*.orig' -delete
find . -name '*.rej' -delete
find . -name '*~' -delete

}
cleaningsrc

#pause to configure
configure () {
echo "You now should configure your kernel. The supplied .config is
already configured but you may want to make changes, plus the date
should be updated. You can choose to run \"make menuconfig\" for
an ncurses based gui (recommended if you don't change stuff or
for advanced users)

1. make olddefconfig
s) skip"
echo
sleep 4
kernelconfig=1
case $kernelconfig in
1) make olddefconfig;;
s)echo "skipping";;
esac
echo
echo "Ok, kernel is configured. CTRL+C to quit"
sleep 4
cp -f ../DOTconfig .config.old
cp -f ../DOTconfig .config

[ ! -d ../dist/packages ] && mkdir -p ../dist/packages
}
configure
krnheads () {
   echo "Creating the kernel headers package"
make headers_check >> ../build.log 2>&1
make INSTALL_HDR_PATH=kernel_headers-$kernel_major_version-$package_name_suffix/usr headers_install >> ../build.log 2>&1
find kernel_headers-$kernel_major_version-$package_name_suffix/usr/include \( -name .install -o -name ..install.cmd \) -delete
mv kernel_headers-$kernel_major_version-$package_name_suffix ../dist/packages
}
krnheads

krncompile () {
echo "Compiling the kernel"
cores=`cat /proc/cpuinfo | grep 'cpu cores' | cut -f3 -d ' ' | tr '\n' ' ' | cut -f1 -d ' '`
if [[ $cores -ge 2 ]]; then
make -d -j6
else
make -d
fi
if [[ ! -f arch/x86/boot/bzImage || ! -f System.map ]]; then
   echo "Error: failed to compile the kernel sources."
   exit 1
fi
cp .config ../dist/sources/DOTconfig-$kernel_version-
}

krncompile
echo "Creating the kernel package"
make INSTALL_MOD_PATH=linux_kernel-$kernel_major_version-$package_name_suffix modules_install >> ../build.log 2>&1
rm -f linux_kernel-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix/{build,source}
mkdir -p linux_kernel-$kernel_major_version-$package_name_suffix/boot
mkdir -p linux_kernel-$kernel_major_version-$package_name_suffix/etc/modules
cp .config linux_kernel-$kernel_major_version-$package_name_suffix/etc/modules/DOTconfig-$kernel_version-
cp arch/x86/boot/bzImage linux_kernel-$kernel_major_version-$package_name_suffix/boot/vmlinuz
BZIMAGE=`find . -type f -name bzImage`
cp System.map linux_kernel-$kernel_major_version-$package_name_suffix/boot/
cp linux_kernel-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix/{modules.builtin,modules.order} \
 linux_kernel-$kernel_major_version-$package_name_suffix/etc/modules/
 mkdir -p ../dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/{lib,etc/modules}
[ "$FD" = "1" ] || \
mv linux_kernel-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix/modules* ../dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/lib/
mv linux_kernel-$kernel_major_version-$package_name_suffix ../dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/etc/modules/

if [ "$FD" = "1" ];then #make fatdog kernel module package
   mv ../dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/boot/vmlinuz ../dist/packages/vmlinuz-$kernel_major_version-$package_name_suffix/vmlinuz-${kernel-major-version}$custom_suffix
   [ -f ../dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/boot/bzImage ] &&
rm -f ../dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/boot/bzImage
   echo "Huge kernel $kernel_major_version-$package_name_suffix is ready in dist"
fi

echo "Cleaning the kernel sources"
make clean >> ../build.log 2>&1
make prepare >> ../build.log 2>&1

cd ..

echo "Creating a kernel sources SFS"
mkdir -p kernel_sources-$kernel_major_version-$package_name_suffix/usr/src
mv linux-$kernel_version kernel_sources-$kernel_major_version-$package_name_suffix/usr/src/linux
mkdir -p kernel_sources-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix
ln -s /usr/src/linux kernel_sources-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix/build
[ ! -f kernel_sources-${kernel_major_version}-$package_name_suffix/usr/src/linux/include/linux/version.h ] && \
ln -s /usr/src/linux/include/generated/uapi/linux/version.h kernel_sources-${kernel_major_version}-$package_name_suffix/usr/src/linux/include/linux/version.h
ln -s /usr/src/linux kernel_sources-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix/source
mksquashfs kernel_sources-$kernel_major_version-$package_name_suffix dist/sources/kernel_sources-$kernel_major_version-$package_name_suffix.sfs $COMP

# build aufs-utils userspace modules
echo "Now to build the aufs-utils for userspace"
if [ ! -f dist/sources/vanilla/aufs-util${today}.tar.bz2 ];then
   git clone git://aufs.git.sourceforge.net/gitroot/aufs/aufs-util.git aufs-util >> build.log 2>&1
   [[ $? -ne 0 ]] && echo "Failed to get aufs-util from git, do it manually. Kernel is compiled OK :)" && exit
   
   cd aufs-util
   
   git branch -a | grep 'aufs3' |grep -v 'rcN' | cut -d '.' -f2 > /tmp/aufs-util-version #we go for stable only
   while read line
     do
       if [[ "$kernel_branch" = "$line" ]];then branch=$line
       else
         while [[ "$kernel_branch" -gt "$line" ]]
           do branch=$line
           echo $branch && break
           done
       fi
     done < /tmp/aufs-util-version
   git checkout origin/aufs3.${branch} >> ../build.log 2>&1
   
   [[ $? -ne 0 ]] && echo "Failed to get aufs-util from git, do it manually. Kernel is compiled OK :)" && exit
   echo "Patching aufs-util sources"
   cp Makefile Makefile.orig
   sed -i 's/-static //' Makefile
   diff -ru Makefile.orig Makefile > ../dist/sources/patches/aufs-util-dynamic.patch
   rm *.orig
   else
   echo "Extracting the Aufs-util sources"
   tar xf dist/sources/vanilla/aufs-util$today.tar.bz2 >> ../build.log 2>&1
   if [[ $? -ne 0 ]]; then
      echo "Error: failed to extract the aufs-util sources."
      exit 1
   fi   
   cd aufs-util   
   patch -p1 < ../dist/sources/patches/aufs-util-dynamic.patch >> ../build.log 2>&1
   [[ "$?" -ne 0 ]] && echo "Failed to patch the aufs-util sources, do it manually. Kernel is compiled ok"
fi
arch=`uname -m`
CONFIG=`find $CWD/dist/sources -type f -name 'DOTconfig*'`
grep -q 'CONFIG_AUFS_FHSM=y' $CONFIG
[[ "$?" -eq 0 ]] && export MAKE=make || export MAKE="make BuildFHSM=no"
LinuxSrc=`find $CWD -type d -name 'kernel_headers*'`
export CPPFLAGS="-I $LinuxSrc/usr/include"
$MAKE >> ../build.log 2>&1
[[ $? -ne 0 ]] && echo "Failed to compile aufs-util, do it manually. Kernel is compiled OK :)"
make DESTDIR=$CWD/dist/packages/aufs-util-$kernel_version-$arch install >> ../build.log 2>&1 #maybe needs absolute path
make clean >> ../build.log 2>&1
if [[ "$arch" = "x86_64" ]];then
 mv $CWD/dist/packages/aufs-util-$kernel_version-$arch/usr/lib \
$CWD/dist/packages/aufs-util-$kernel_version-$arch/usr/lib64
fi
echo "aufs-util-$kernel_version is in dist"
cd ..
if [[ "$FD" = "1" ]];then #shift aufs-utils to kernel-modules.sfs
   echo "Installing aufs-utils into kernel package"
   cp -a dist/packages/aufs-util-$kernel_version-$arch/* \
   dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix
   cp -r /lib/firmware dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/lib/
   mksquashfs dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix dist/packages/kernel-modules.sfs-$kernel_major_version-$package_name_suffix $COMP
   [[ "$?" = 0 ]] && echo "Huge compatible kernel packages are ready to package./" || exit 1
   echo "Packaging huge-$kernel_major_version-$package_name_suffix kernel"
   cd dist/packages/
   tar -cjvf huge-$kernel_major_version-${package_name_suffix}.tar.bz2 \
   vmlinuz-$kernel_major_version-$package_name_suffix kernel-modules.sfs-$kernel_major_version-$package_name_suffix
   [[ "$?" = 0 ]] && echo "huge-$kernel_major_version-${package_name_suffix}.tar.bz2 is in dist/packages" || exit 1
   md5sum huge-$kernel_major_version-${package_name_suffix}.tar.bz2 > huge-$kernel_major_version-${package_name_suffix}.tar.bz2.md5.txt
   echo
   cd $CWD
fi

tar -c aufs-util | bzip2 -9 > dist/sources/vanilla/aufs-util$today-$-$arch.tar.bz2

echo "Compressing the log"
bzip2 -9 build.log
cp build.log.bz2 dist/sources

echo "Done!"

if [[ -e /tmp/64 ]]; then
touch /tmp/32-pae
fi

[ -f /usr/share/sounds/2barks.au ] && aplay /usr/share/sounds/2barks.au
if [[ -e /tmp/32-pae && -e /tmp/64 ]]; then
rename packages packages32-pae dist/packages
mkdir dist/packages
fi


#THIRD RUN

if [[ -e /tmp/64  && -e /tmp/32-nopae && ! dist/packages32-nopae ]]; then
. ./build32-nopae.conf
fi

if [ "$1" = "" ];then
   echo -en "\033[1;35m""WARNING" #purple?
   echo -en "\033[0m" #reset
   echo ": This will delete aufs, kernel folder but wont touch configs or dist."
   sleep 2
   echo "Please wait..."
   rm -rf ./{aufs*,linux*,kernel*,build.log*}
   echo "Cleaning complete"
fi
if [[ -d ./aufs* ]];then
   echo "This is not a clean kit."
   echo " CTRL+C to quit"
   read notcleango
fi

FW_URL=${FW_URL:-http://distro.ibiblio.org/puppylinux/firmware}
package_name_suffix=$package_name_suffix
custom_suffix=$custom_suffix
kernel_version=$kernel_version
kernel_mirror=$kernel_mirror


# .configs
[ -f /tmp/kernel_configs ] && rm -f /tmp/kernel_configs

CONFIGS=$(ls ./configs_extra)

# list
echo "configs"
NUM=1
for C in $CONFIGS
  do echo "${NUM}. $C" >> /tmp/kernel_configs
  NUM=$(($NUM + 1))
  done
echo "z. Custom DOTconfig" >> /tmp/kernel_configs
echo "d. Default DOTconfig" >> /tmp/kernel_configs 
figs=`cat /tmp/kernel_configs`
echo "$figs"
sleep 2

   if [[ -e /tmp/32-pae && -e /tmp/64 ]]; then
   Chosen=2
   fi
echo "$Chosen"
sleep 1
Choice=$(grep "^$Chosen\." /tmp/kernel_configs | cut -d ' ' -f2)
echo "$Choice"
sleep 1
rm -r DOTconfig
cp -af configs_extra/$Choice DOTconfig

# create directories for the results
[ ! -d dist/sources/vanilla ] && mkdir -p dist/sources/{patches,vanilla}

# delete the previous log
[ -f build.log ] && rm -f build.log
[ -f build.log.tar.bz2 ] && mv -f build.log.tar.bz2

   echo "Extracting the Aufs sources"
   tar xf dist/sources/vanilla/aufs$aufs_version-$kernel_branch-git$today.tar.bz2
   if [[ $? -ne 0 ]]; then
      echo "Error: failed to extract the Aufs sources."
      exit 1
      fi

patchaufs () {
   # patch Aufs
if [ -f aufs-allow-sfs.patch ];then #removed for K3.9 experiment
   echo "Patching the Aufs sources"
   patch -d aufs$aufs_version-$kernel_branch-git$today -p1 < aufs-allow-sfs.patch >> build.log 2>&1
   if [[ $? -ne 0 ]]; then
      echo "Error: failed to patch the Aufs sources."
      exit 1
   fi
   cp aufs-allow-sfs.patch dist/sources/patches
fi
if [ -f aufs-kconfig.patch ];then #special for K3.9
   echo "Patching the Aufs sources"
   patch -d aufs$aufs_version-$kernel_branch-git$today -p1 < aufs-kconfig.patch >> build.log 2>&1
   if [[ $? -ne 0 ]]; then
      echo "Error: failed to patch the Aufs sources for kconfig."
      exit 1
   fi
   cp aufs-kconfig.patch dist/sources/patches
fi
}
patchaufs

extractkern () {
   # extract the kernel
echo "Extracting the kernel sources"
tar xf dist/sources/vanilla/linux-$kernel_version.tar.* >> build.log 2>&1
if [[ $? -ne 0 ]]; then
   echo "Error: failed to extract the kernel sources."
   exit 1
   extractkern
else
echo "extracted"
fi
}
extractkern

cd linux-$kernel_version

aufspatch () {
   echo "Adding Aufs to the kernel sources"
for i in kbuild base standalone mmap; do
   patch -N -p1 < ../aufs$aufs_version-$kernel_branch-git$today/aufs$aufs_version-$i.patch >> ../build.log 2>&1
   if [[ $? -ne 0 ]]; then
      echo "WARNING: failed to add some Aufs patches to the kernel sources."
      echo "Check it manually and either CRTL+C to bail or hit enter to go on"
      sleep 4
   fi
done
}
aufspatch

cp -r ../aufs$aufs_version-$kernel_branch-git$today/{fs,Documentation} .
cp ../aufs$aufs_version-$kernel_branch-git$today/include/linux/aufs_type.h include/linux 2>/dev/null
cp ../aufs$aufs_version-$kernel_branch-git$today/include/uapi/linux/aufs_type.h include/linux 2>/dev/null
[ -d ../aufs$aufs_version-$kernel_branch-git$today/include/uapi ] && \
cp -r ../aufs$aufs_version-$kernel_branch-git$today/include/uapi/linux/aufs_type.h include/uapi/linux

echo "Resetting the minor version number"
cp Makefile Makefile-orig
sed -i "s/^EXTRAVERSION =/EXTRAVERSION = $custom_suffix/" Makefile
diff -up Makefile-orig Makefile > ../dist/sources/patches/extra-version.patch
rm Makefile-orig

    cp kernel/printk/printk.c kernel/printk/printk.c.orig
    sed -i s/'#define MAX_CMDLINECONSOLES 8'/'#define MAX_CMDLINECONSOLES 5'/ kernel/printk/printk.c
    diff -up kernel/printk/printk.c.orig kernel/printk/printk.c > ../dist/sources/patches/less-consoles.patch
   
    echo "Reducing the verbosity level"
    cp -f include/linux/printk.h include/linux/printk.h.orig
    sed -i s/'#define CONSOLE_LOGLEVEL_DEFAULT 7 \/\* anything MORE serious than KERN_DEBUG \*\/'/'#define CONSOLE_LOGLEVEL_DEFAULT 3 \/\* anything MORE serious than KERN_ERR \*\/'/ include/linux/printk.h
    diff -up include/linux/printk.h.orig include/linux/printk.h > ../dist/sources/patches/lower-verbosity.patch

patches () {
for patch in ../patches/*; do
   echo "Applying $patch"
   patch -p1 < $patch >> ../build.log 2>&1
   if [[ $? -ne 0 ]]; then
      echo "Error: failed to apply $patch on the kernel sources."
      exit 1
   fi
   cp $patch ../dist/sources/patches

done
}
patches

cleaningsrc () {
echo "Cleaning the kernel sources"
make clean
make mrproper
find . -name '*.orig' -delete
find . -name '*.rej' -delete
find . -name '*~' -delete

}
cleaningsrc

#pause to configure
configure () {
echo "You now should configure your kernel. The supplied .config is
already configured but you may want to make changes, plus the date
should be updated. You can choose to run \"make menuconfig\" for
an ncurses based gui (recommended if you don't change stuff or
for advanced users)

1. make olddefconfig
s) skip"
echo
sleep 2
kernelconfig=1
case $kernelconfig in
1) make olddefconfig;;
s)echo "skipping";;
esac
echo
echo "Ok, kernel is configured. CTRL+C to quit"
sleep 2
cp -f ../DOTconfig .config.old
cp -f ../DOTconfig .config

[ ! -d ../dist/packages ] && mkdir -p ../dist/packages
}
configure
krnheads () {
   echo "Creating the kernel headers package"
make headers_check >> ../build.log 2>&1
make INSTALL_HDR_PATH=kernel_headers-$kernel_major_version-$package_name_suffix/usr headers_install >> ../build.log 2>&1
find kernel_headers-$kernel_major_version-$package_name_suffix/usr/include \( -name .install -o -name ..install.cmd \) -delete
mv kernel_headers-$kernel_major_version-$package_name_suffix ../dist/packages
}
krnheads

krncompile () {
echo "Compiling the kernel"
cores=`cat /proc/cpuinfo | grep 'cpu cores' | cut -f3 -d ' ' | tr '\n' ' ' | cut -f1 -d ' '`
if [[ $cores -ge 2 ]]; then
make -d -j6
else
make -d
fi
if [[ ! -f arch/x86/boot/bzImage || ! -f System.map ]]; then
   echo "Error: failed to compile the kernel sources."
   exit 1
fi
cp .config ../dist/sources/DOTconfig-$kernel_version-
}

krncompile
echo "Creating the kernel package"
make INSTALL_MOD_PATH=linux_kernel-$kernel_major_version-$package_name_suffix modules_install >> ../build.log 2>&1
rm -f linux_kernel-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix/{build,source}
mkdir -p linux_kernel-$kernel_major_version-$package_name_suffix/boot
mkdir -p linux_kernel-$kernel_major_version-$package_name_suffix/etc/modules
cp .config linux_kernel-$kernel_major_version-$package_name_suffix/etc/modules/DOTconfig-$kernel_version-
cp arch/x86/boot/bzImage linux_kernel-$kernel_major_version-$package_name_suffix/boot/vmlinuz
BZIMAGE=`find . -type f -name bzImage`
cp System.map linux_kernel-$kernel_major_version-$package_name_suffix/boot/
cp linux_kernel-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix/{modules.builtin,modules.order} \
 linux_kernel-$kernel_major_version-$package_name_suffix/etc/modules/
 mkdir -p ../dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/{lib,etc/modules}
[ "$FD" = "1" ] || \
mv linux_kernel-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix/modules* ../dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/lib/
mv linux_kernel-$kernel_major_version-$package_name_suffix ../dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/etc/modules/

if [ "$FD" = "1" ];then #make fatdog kernel module package
   mv ../dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/boot/vmlinuz ../dist/packages/vmlinuz-$kernel_major_version-$package_name_suffix/vmlinuz-${kernel-major-version}$custom_suffix
   [ -f ../dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/boot/bzImage ] &&
rm -f ../dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/boot/bzImage
   echo "Huge kernel $kernel_major_version-$package_name_suffix is ready in dist"
fi

echo "Cleaning the kernel sources"
make clean >> ../build.log 2>&1
make prepare >> ../build.log 2>&1

cd ..

echo "Creating a kernel sources SFS"
mkdir -p kernel_sources-$kernel_major_version-$package_name_suffix/usr/src
mv linux-$kernel_version kernel_sources-$kernel_major_version-$package_name_suffix/usr/src/linux
mkdir -p kernel_sources-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix
ln -s /usr/src/linux kernel_sources-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix/build
[ ! -f kernel_sources-${kernel_major_version}-$package_name_suffix/usr/src/linux/include/linux/version.h ] && \
ln -s /usr/src/linux/include/generated/uapi/linux/version.h kernel_sources-${kernel_major_version}-$package_name_suffix/usr/src/linux/include/linux/version.h
ln -s /usr/src/linux kernel_sources-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix/source
mksquashfs kernel_sources-$kernel_major_version-$package_name_suffix dist/sources/kernel_sources-$kernel_major_version-$package_name_suffix.sfs $COMP

# build aufs-utils userspace modules
echo "Now to build the aufs-utils for userspace"
if [ ! -f dist/sources/vanilla/aufs-util${today}.tar.bz2 ];then
   git clone git://aufs.git.sourceforge.net/gitroot/aufs/aufs-util.git aufs-util >> build.log 2>&1
   [[ $? -ne 0 ]] && echo "Failed to get aufs-util from git, do it manually. Kernel is compiled OK :)" && exit
   
   cd aufs-util
   
   git branch -a | grep 'aufs3' |grep -v 'rcN' | cut -d '.' -f2 > /tmp/aufs-util-version #we go for stable only
   while read line
     do
       if [[ "$kernel_branch" = "$line" ]];then branch=$line
       else
         while [[ "$kernel_branch" -gt "$line" ]]
           do branch=$line
           echo $branch && break
           done
       fi
     done < /tmp/aufs-util-version
   git checkout origin/aufs3.${branch} >> ../build.log 2>&1
   
   [[ $? -ne 0 ]] && echo "Failed to get aufs-util from git, do it manually. Kernel is compiled OK :)" && exit
   echo "Patching aufs-util sources"
   cp Makefile Makefile.orig
   sed -i 's/-static //' Makefile
   diff -ru Makefile.orig Makefile > ../dist/sources/patches/aufs-util-dynamic.patch
   rm *.orig
   else
   echo "Extracting the Aufs-util sources"
   tar xf dist/sources/vanilla/aufs-util$today.tar.bz2 >> ../build.log 2>&1
   if [[ $? -ne 0 ]]; then
      echo "Error: failed to extract the aufs-util sources."
      exit 1
   fi   
   cd aufs-util   
   patch -p1 < ../dist/sources/patches/aufs-util-dynamic.patch >> ../build.log 2>&1
   [[ "$?" -ne 0 ]] && echo "Failed to patch the aufs-util sources, do it manually. Kernel is compiled ok"
fi
arch=`uname -m`
CONFIG=`find $CWD/dist/sources -type f -name 'DOTconfig*'`
grep -q 'CONFIG_AUFS_FHSM=y' $CONFIG
[[ "$?" -eq 0 ]] && export MAKE=make || export MAKE="make BuildFHSM=no"
LinuxSrc=`find $CWD -type d -name 'kernel_headers*'`
export CPPFLAGS="-I $LinuxSrc/usr/include"
$MAKE >> ../build.log 2>&1
[[ $? -ne 0 ]] && echo "Failed to compile aufs-util, do it manually. Kernel is compiled OK :)"
make DESTDIR=$CWD/dist/packages/aufs-util-$kernel_version-$arch install >> ../build.log 2>&1 #maybe needs absolute path
make clean >> ../build.log 2>&1
if [[ "$arch" = "x86_64" ]];then
 mv $CWD/dist/packages/aufs-util-$kernel_version-$arch/usr/lib \
$CWD/dist/packages/aufs-util-$kernel_version-$arch/usr/lib64
fi
echo "aufs-util-$kernel_version is in dist"
cd ..
if [[ "$FD" = "1" ]];then #shift aufs-utils to kernel-modules.sfs
   echo "Installing aufs-utils into kernel package"
   cp -a dist/packages/aufs-util-$kernel_version-$arch/* \
   dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix
   cp -r /lib/firmware dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/lib/
   mksquashfs dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix dist/packages/kernel-modules.sfs-$kernel_major_version-$package_name_suffix $COMP
   [[ "$?" = 0 ]] && echo "Huge compatible kernel packages are ready to package./" || exit 1
   echo "Packaging huge-$kernel_major_version-$package_name_suffix kernel"
   cd dist/packages/
   tar -cjvf huge-$kernel_major_version-${package_name_suffix}.tar.bz2 \
   vmlinuz-$kernel_major_version-$package_name_suffix kernel-modules.sfs-$kernel_major_version-$package_name_suffix
   [[ "$?" = 0 ]] && echo "huge-$kernel_major_version-${package_name_suffix}.tar.bz2 is in dist/packages" || exit 1
   md5sum huge-$kernel_major_version-${package_name_suffix}.tar.bz2 > huge-$kernel_major_version-${package_name_suffix}.tar.bz2.md5.txt
   echo
   cd $CWD
fi

tar -c aufs-util | bzip2 -9 > dist/sources/vanilla/aufs-util$today-$-$arch.tar.bz2

echo "Compressing the log"
bzip2 -9 build.log
cp build.log.bz2 dist/sources

echo "Done!"

if [[ -e /tmp/32-pae && -e /tmp/64 ]]; then
touch /tmp/32-nopae
fi

[ -f /usr/share/sounds/2barks.au ] && aplay /usr/share/sounds/2barks.au

if [[ -e /tmp/32-nopae &&  -e /tmp/64 ]]; then
rename packages packages32-nopae dist/packages
fi

exit

###the end###
Back to top
View user's profile Send private message MSN Messenger 
stemsee

Joined: 27 Jun 2013
Posts: 950
Location: Displaced

PostPosted: Fri 23 Jan 2015, 10:03    Post subject:  

I just ran this script and got three kernels compiled. However the packages were copied to $kernel_version/etc/$kernel_version/* but everything is there, so should be easy to sort out the last few bugs.

EDIT: ALso need to update .config scripts so as not to get any prompts during compilation. I thought 'make olddefconfig' would sort that out but maybe I didn't copy the apropriate DOTconfig to .config.old first!
Back to top
View user's profile Send private message MSN Messenger 
stemsee

Joined: 27 Jun 2013
Posts: 950
Location: Displaced

PostPosted: Fri 23 Jan 2015, 16:48    Post subject:  

Here is kernel-3.18.3-pae . i am posting from it now!! Compiled 2nd in the script.

https://drive.google.com/folderview?id=0B4GhZVmB2RkwOW5jNnNRM2NOaDA&usp=sharing
Back to top
View user's profile Send private message MSN Messenger 
stemsee

Joined: 27 Jun 2013
Posts: 950
Location: Displaced

PostPosted: Sat 24 Jan 2015, 07:56    Post subject:  

Updated the script (needs testing), removed duplicate sources mksquashfs, left only one after final kernel is compiled, remove duplicate patching etc. Changed path errors (hopefully).
Code:
#!/bin/bash
# originally by Iguleder
# hacked to DEATH by 01micko
# re-hacked by stemsee to provide unattended version, which auto-builds
# 64bit, 32bit-pae then 32bit-nopae kernels and modules consecutively.
# And renames /dist/packages to packages64, packages32-pae and packages32-nopae
# see /usr/share/doc/legal NO WARRANTY, NO responsibility accepted
CWD=`pwd`

if [[ ! -e /tmp/64 && ! -d dist/packages64 ]]; then
. ./build64.conf
fi

if [ "$1" = "" ];then
   echo -en "\033[1;35m""WARNING" #purple?
   echo -en "\033[0m" #reset
   echo ": This will delete aufs, kernel folder but wont touch configs or dist."
   sleep 2
   echo "Please wait..."
   rm -rf ./{aufs*,linux*,kernel*,build.log*}
   echo "Cleaning complete"
fi
if [[ -d ./aufs* ]];then
   echo "This is not a clean kit."
   echo " CTRL+C to quit"
   read notcleango
fi

FW_URL=${FW_URL:-http://distro.ibiblio.org/puppylinux/firmware}
package_name_suffix=$package_name_suffix
custom_suffix=$custom_suffix
kernel_version=$kernel_version
kernel_mirror=$kernel_mirror

# depcheck
echo "Dependency check..."
if git --version &>/dev/null
   then echo -e "\033[1;32m""git is installed" #green
else echo -e "\033[1;31m""git is not installed""\033[0m" && exit #red
fi
if gcc --version &>/dev/null
   then echo -e "\033[1;32m""gcc is installed"
else
   echo -e "\033[1;31m""gcc is not installed""\033[0m" && exit
fi
MKSQ="$(which mksquashfs)"
if [ "$MKSQ" ]
   then
   echo -e "\033[1;32m""mksquashfs is installed"
else #yellow
   echo -e "\033[1;30m""mksquashfs is not installed but you can continue"
fi
echo -e "\033[0m" #reset to original

# .configs
[ -f /tmp/kernel_configs ] && rm -f /tmp/kernel_configs

CONFIGS=$(ls ./configs_extra)

# list
echo "configs"
NUM=1
for C in $CONFIGS
  do echo "${NUM}. $C" >> /tmp/kernel_configs
  NUM=$(($NUM + 1))
  done
echo "z. Custom DOTconfig" >> /tmp/kernel_configs
echo "d. Default DOTconfig" >> /tmp/kernel_configs 
figs=`cat /tmp/kernel_configs`
echo "$figs"
sleep 2

   Chosen=1

echo "$Chosen"
sleep 1
Choice=$(grep "^$Chosen\." /tmp/kernel_configs | cut -d ' ' -f2)
echo "$Choice"
sleep 1
rm -r DOTconfig
cp -af configs_extra/$Choice DOTconfig
 

# the aufs major version
aufs_version=${kernel_version%%.*}
# get the major version (2.6.32 in the case of 2.6.32.40)
kernel_major_version=$kernel_version #blah, hack for 3.x
# get the kernel branch (32 in the case of 2.6.32.40; needed to download Aufs)
kernel_branch=`echo $kernel_major_version | cut -f 2 -d .` #3.x kernels

# create directories for the results
[ ! -d dist/sources/vanilla ] && mkdir -p dist/sources/{patches,vanilla}

# get today's date
today=`date +%d%m%y`

# delete the previous log
[ -f build.log ] && rm -f build.log
[ -f build.log.tar.bz2 ] && mv -f build.log.tar.bz2

downkern () {

if [ ! -e dist/sources/vanilla/linux-$kernel_version.tar.xz ]; then
# download the kernel
echo ${kernel_version##*-}|grep -q "rc"
[ "$?" -eq 0 ] && testing=testing||testing=
   if [[ ! -f dist/sources/vanilla/linux-$kernel_version.tar.xz ]]; then
   echo "Downloading the kernel sources"
   wget -P dist/sources/vanilla $kernel_mirror/$testing/linux-$kernel_version.tar.xz --no-check-certificate > build.log 2>&1
      if [[ $? -ne 0 ]]; then
         echo "Error: failed to download the kernel sources."
         exit 1
      fi
   fi
fi
if [ -e dist/sources/vanilla/linux-$kernel_version.tar.xz ]; then
echo "Kernel Sources already there!"
fi
}
downkern

downaufs () {
   # download Aufs

      git clone git://git.code.sf.net/p/aufs/aufs3-standalone aufs$aufs_version-18-git$today >> build.log 2>&1

      if [[ $? -ne 0 ]]; then
         echo "Error: failed to download the Aufs sources."
         exit 1
      fi
      cd aufs$aufs_version-$kernel_branch-git$today
      if [[ "$aufsv" ]];then #new far for new kernels
      git checkout origin/aufs$aufsv >> ../build.log 2>&1
      else
      git checkout origin/aufs$aufs_version.$kernel_branch >> ../build.log 2>&1
      fi
      if [[ $? -ne 0 ]]; then
      echo "Error: failed to download the Aufs sources."
      exit 1
      fi
   rm -rf .git
   cd ..
   echo "Creating the Aufs sources tarball"
   tar -c aufs$aufs_version-$kernel_branch-git$today | bzip2 -9 > dist/sources/vanilla/aufs$aufs_version-$kernel_branch-git$today.tar.bz2

   echo "Extracting the Aufs sources"
   tar xf dist/sources/vanilla/aufs$aufs_version-$kernel_branch-git$today.tar.bz2
   if [[ $? -ne 0 ]]; then
      echo "Error: failed to extract the Aufs sources."
      exit 1
      fi
}
downaufs

patchaufs () {
   # patch Aufs
if [ -f aufs-allow-sfs.patch ];then #removed for K3.9 experiment
   echo "Patching the Aufs sources"
   patch -d aufs$aufs_version-$kernel_branch-git$today -p1 < aufs-allow-sfs.patch >> build.log 2>&1
   if [[ $? -ne 0 ]]; then
      echo "Error: failed to patch the Aufs sources."
      exit 1
   fi
   cp aufs-allow-sfs.patch dist/sources/patches
fi
if [ -f aufs-kconfig.patch ];then #special for K3.9
   echo "Patching the Aufs sources"
   patch -d aufs$aufs_version-$kernel_branch-git$today -p1 < aufs-kconfig.patch >> build.log 2>&1
   if [[ $? -ne 0 ]]; then
      echo "Error: failed to patch the Aufs sources for kconfig."
      exit 1
   fi
   cp aufs-kconfig.patch dist/sources/patches
fi
}
patchaufs

extractkern () {
   # extract the kernel
echo "Extracting the kernel sources"
tar xf dist/sources/vanilla/linux-$kernel_version.tar.* >> build.log 2>&1
if [[ $? -ne 0 ]]; then
   echo "Error: failed to extract the kernel sources."
   exit 1
   extractkern
else
echo "extracted"
fi
}
extractkern

cd linux-$kernel_version

aufspatch () {
   echo "Adding Aufs to the kernel sources"
for i in kbuild base standalone mmap; do
   patch -N -p1 < ../aufs$aufs_version-$kernel_branch-git$today/aufs$aufs_version-$i.patch >> ../build.log 2>&1
   if [[ $? -ne 0 ]]; then
      echo "WARNING: failed to add some Aufs patches to the kernel sources."
      echo "Check it manually and either CRTL+C to bail or hit enter to go on"
      sleep 4
   fi
done
}
aufspatch

cp -r ../aufs$aufs_version-$kernel_branch-git$today/{fs,Documentation} .
cp ../aufs$aufs_version-$kernel_branch-git$today/include/linux/aufs_type.h include/linux 2>/dev/null
cp ../aufs$aufs_version-$kernel_branch-git$today/include/uapi/linux/aufs_type.h include/linux 2>/dev/null
[ -d ../aufs$aufs_version-$kernel_branch-git$today/include/uapi ] && \
cp -r ../aufs$aufs_version-$kernel_branch-git$today/include/uapi/linux/aufs_type.h include/uapi/linux

echo "Resetting the minor version number"
cp Makefile Makefile-orig
sed -i "s/^EXTRAVERSION =/EXTRAVERSION = $custom_suffix/" Makefile
diff -up Makefile-orig Makefile > ../dist/sources/patches/extra-version.patch
rm Makefile-orig

#echo "Reducing the number of consoles"
#if [ "$kernel_branch" -ge 12 ]; then
 #if [[ "${kernel_version%%.*}" -ge 3 -a "$kernel_branch" -ge 16 ]]; then
    cp kernel/printk/printk.c kernel/printk/printk.c.orig
    sed -i s/'#define MAX_CMDLINECONSOLES 8'/'#define MAX_CMDLINECONSOLES 5'/ kernel/printk/printk.c
    diff -up kernel/printk/printk.c.orig kernel/printk/printk.c > ../dist/sources/patches/less-consoles.patch
   
    echo "Reducing the verbosity level"
    cp -f include/linux/printk.h include/linux/printk.h.orig
    sed -i s/'#define CONSOLE_LOGLEVEL_DEFAULT 7 \/\* anything MORE serious than KERN_DEBUG \*\/'/'#define CONSOLE_LOGLEVEL_DEFAULT 3 \/\* anything MORE serious than KERN_ERR \*\/'/ include/linux/printk.h
    diff -up include/linux/printk.h.orig include/linux/printk.h > ../dist/sources/patches/lower-verbosity.patch
 #else
    #cp kernel/printk/printk.c kernel/printk/printk.c.orig
    #sed -i s/'#define MAX_CMDLINECONSOLES 8'/'#define MAX_CMDLINECONSOLES 5'/ kernel/printk/printk.c
    #diff -up kernel/printk/printk.c.orig kernel/printk/printk.c > ../dist/sources/patches/less-consoles.patch
   
    #echo "Reducing the verbosity level"
    #cp -f kernel/printk/printk.c kernel/printk/printk.c.orig
    #sed -i s/'#define DEFAULT_CONSOLE_LOGLEVEL 7 \/\* anything MORE serious than KERN_DEBUG \*\/'/'#define DEFAULT_CONSOLE_LOGLEVEL 3 \/\* anything MORE serious than KERN_ERR \*\/'/ kernel/printk/printk.c
    #diff -up kernel/printk/printk.c.orig kernel/printk/printk.c > ../dist/sources/patches/lower-verbosity.patch
  #fi
#else
 #cp kernel/printk.c kernel/printk.c.orig
 #sed -i s/'#define MAX_CMDLINECONSOLES 8'/'#define MAX_CMDLINECONSOLES 5'/ kernel/printk.c
 #diff -up kernel/printk.c.orig kernel/printk.c > ../dist/sources/patches/less-consoles.patch

 #echo "Reducing the verbosity level"
 #cp -f kernel/printk.c kernel/printk.c.orig
 #sed -i s/'#define DEFAULT_CONSOLE_LOGLEVEL 7 \/\* anything MORE serious than KERN_DEBUG \*\/'/'#define DEFAULT_CONSOLE_LOGLEVEL 3 \/\* Puppy linux hack \*\/'/ kernel/printk.c
 #diff -up kernel/printk.c.orig kernel/printk.c > ../dist/sources/patches/lower-verbosity.patch
#fi

patches () {
for patch in ../patches/*; do
   echo "Applying $patch"
   patch -p1 < $patch >> ../build.log 2>&1
   if [[ $? -ne 0 ]]; then
      echo "Error: failed to apply $patch on the kernel sources."
      exit 1
   fi
   cp $patch ../dist/sources/patches

done
}
patches

cleaningsrc () {
echo "Cleaning the kernel sources"
make clean
make mrproper
find . -name '*.orig' -delete
find . -name '*.rej' -delete
find . -name '*~' -delete

}
cleaningsrc

#pause to configure
configure () {
echo "You now should configure your kernel. The supplied .config is
already configured but you may want to make changes, plus the date
should be updated. You can choose to run \"make menuconfig\" for
an ncurses based gui (recommended if you don't change stuff or
for advanced users)

1. make oldconfig
s) skip"
echo
sleep 4
kernelconfig=1
case $kernelconfig in
1) make olddefconfig;;
s)echo "skipping";;
esac
echo
echo "Ok, kernel is configured. CTRL+C to quit"
sleep 4
cp -f ../DOTconfig .config.old
cp -f ../DOTconfig .config

[ ! -d ../dist/packages ] && mkdir -p ../dist/packages
}
configure
krnheads () {
   echo "Creating the kernel headers package"
make headers_check >> ../build.log 2>&1
make INSTALL_HDR_PATH=kernel_headers-$kernel_major_version-$package_name_suffix/usr headers_install >> ../build.log 2>&1
find kernel_headers-$kernel_major_version-$package_name_suffix/usr/include \( -name .install -o -name ..install.cmd \) -delete
mv kernel_headers-$kernel_major_version-$package_name_suffix ../dist/packages
}
krnheads

krncompile () {
echo "Compiling the kernel"
cores=`cat /proc/cpuinfo | grep 'cpu cores' | cut -f3 -d ' ' | tr '\n' ' ' | cut -f1 -d ' '`
if [[ $cores -ge 2 ]]; then
make -d -j6
else
make -d
fi
if [[ ! -f arch/x86/boot/bzImage || ! -f System.map ]]; then
   echo "Error: failed to compile the kernel sources."
   exit 1
fi
cp .config ../dist/sources/DOTconfig-$kernel_version-
}

krncompile
echo "Creating the kernel package"
make INSTALL_MOD_PATH=linux_kernel-$kernel_major_version-$package_name_suffix modules_install >> ../build.log 2>&1
rm -f linux_kernel-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix/{build,source}
mkdir -p linux_kernel-$kernel_major_version-$package_name_suffix/boot
mkdir -p linux_kernel-$kernel_major_version-$package_name_suffix/etc/modules
cp .config linux_kernel-$kernel_major_version-$package_name_suffix/etc/modules/DOTconfig-$kernel_version-
cp arch/x86/boot/bzImage linux_kernel-$kernel_major_version-$package_name_suffix/boot/vmlinuz
BZIMAGE=`find . -type f -name bzImage`
cp System.map linux_kernel-$kernel_major_version-$package_name_suffix/boot/
cp linux_kernel-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix/{modules.builtin,modules.order} \
 linux_kernel-$kernel_major_version-$package_name_suffix/etc/modules/
mv linux_kernel-$kernel_major_version-$package_name_suffix ../dist/packages/
if [ "$FD" = "1" ];then #make fatdog kernel module package
   mv ../dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/boot/vmlinuz ../dist/packages/vmlinuz-$kernel_major_version-$package_name_suffix/vmlinuz-${kernel-major-version}$custom_suffix
   [ -f ../dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/boot/bzImage ] &&
rm -f ../dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/boot/bzImage
   echo "Huge kernel $kernel_major_version-$package_name_suffix is ready in dist"
fi

echo "Cleaning the kernel sources"
make clean >> ../build.log 2>&1
make prepare >> ../build.log 2>&1

cd ..

#echo "Creating a kernel sources SFS"
#mkdir -p kernel_sources-$kernel_major_version-$package_name_suffix/usr/src
#mv linux-$kernel_version kernel_sources-$kernel_major_version-$package_name_suffix/usr/src/linux
#mkdir -p kernel_sources-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix
#ln -s /usr/src/linux kernel_sources-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix/build
#[ ! -f kernel_sources-${kernel_major_version}-$package_name_suffix/usr/src/linux/include/linux/version.h ] && \
#ln -s /usr/src/linux/include/generated/uapi/linux/version.h kernel_sources-${kernel_major_version}-$package_name_suffix/usr/src/linux/include/linux/version.h
#ln -s /usr/src/linux kernel_sources-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix/source
#mksquashfs kernel_sources-$kernel_major_version-$package_name_suffix dist/sources/kernel_sources-$kernel_major_version-$package_name_suffix.sfs $COMP

# build aufs-utils userspace modules
echo "Now to build the aufs-utils for userspace"
if [ ! -f dist/sources/vanilla/aufs-util${today}.tar.bz2 ];then
   git clone git://aufs.git.sourceforge.net/gitroot/aufs/aufs-util.git aufs-util >> build.log 2>&1
   [[ $? -ne 0 ]] && echo "Failed to get aufs-util from git, do it manually. Kernel is compiled OK :)" && exit
   
   cd aufs-util
   
   git branch -a | grep 'aufs3' |grep -v 'rcN' | cut -d '.' -f2 > /tmp/aufs-util-version #we go for stable only
   while read line
     do
       if [[ "$kernel_branch" = "$line" ]];then branch=$line
       else
         while [[ "$kernel_branch" -gt "$line" ]]
           do branch=$line
           echo $branch && break
           done
       fi
     done < /tmp/aufs-util-version
   git checkout origin/aufs3.${branch} >> ../build.log 2>&1
   
   [[ $? -ne 0 ]] && echo "Failed to get aufs-util from git, do it manually. Kernel is compiled OK :)" && exit
   echo "Patching aufs-util sources"
   cp Makefile Makefile.orig
   sed -i 's/-static //' Makefile
   diff -ru Makefile.orig Makefile > ../dist/sources/patches/aufs-util-dynamic.patch
   rm *.orig
   else
   echo "Extracting the Aufs-util sources"
   tar xf dist/sources/vanilla/aufs-util$today.tar.bz2 >> ../build.log 2>&1
   if [[ $? -ne 0 ]]; then
      echo "Error: failed to extract the aufs-util sources."
      exit 1
   fi   
   cd aufs-util   
   patch -p1 < ../dist/sources/patches/aufs-util-dynamic.patch >> ../build.log 2>&1
   [[ "$?" -ne 0 ]] && echo "Failed to patch the aufs-util sources, do it manually. Kernel is compiled ok"
fi
arch=`uname -m`
CONFIG=`find $CWD/dist/sources -type f -name 'DOTconfig*'`
grep -q 'CONFIG_AUFS_FHSM=y' $CONFIG
[[ "$?" -eq 0 ]] && export MAKE=make || export MAKE="make BuildFHSM=no"
LinuxSrc=`find $CWD -type d -name 'kernel_headers*'`
export CPPFLAGS="-I $LinuxSrc/usr/include"
$MAKE >> ../build.log 2>&1
[[ $? -ne 0 ]] && echo "Failed to compile aufs-util, do it manually. Kernel is compiled OK :)"
make DESTDIR=$CWD/dist/packages/aufs-util-$kernel_version-$arch install >> ../build.log 2>&1 #maybe needs absolute path
make clean >> ../build.log 2>&1
if [[ "$arch" = "x86_64" ]];then
 mv $CWD/dist/packages/aufs-util-$kernel_version-$arch/usr/lib \
$CWD/dist/packages/aufs-util-$kernel_version-$arch/usr/lib64
fi
echo "aufs-util-$kernel_version is in dist"
cd ..
if [[ "$FD" = "1" ]];then #shift aufs-utils to kernel-modules.sfs
   echo "Installing aufs-utils into kernel package"
   cp -a dist/packages/aufs-util-$kernel_version-$arch/* \
   dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix
   cp -r /lib/firmware dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/lib/
   mksquashfs dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix dist/packages/kernel-modules.sfs-$kernel_major_version-$package_name_suffix $COMP
   [[ "$?" = 0 ]] && echo "Huge compatible kernel packages are ready to package./" || exit 1
   echo "Packaging huge-$kernel_major_version-$package_name_suffix kernel"
   cd dist/packages/
   tar -cjvf huge-$kernel_major_version-${package_name_suffix}.tar.bz2 \
   vmlinuz-$kernel_major_version-$package_name_suffix kernel-modules.sfs-$kernel_major_version-$package_name_suffix
   [[ "$?" = 0 ]] && echo "huge-$kernel_major_version-${package_name_suffix}.tar.bz2 is in dist/packages" || exit 1
   md5sum huge-$kernel_major_version-${package_name_suffix}.tar.bz2 > huge-$kernel_major_version-${package_name_suffix}.tar.bz2.md5.txt
   echo
   cd $CWD
fi

tar -c aufs-util | bzip2 -9 > dist/sources/vanilla/aufs-util$today-$-$arch.tar.bz2

echo "Compressing the log"
bzip2 -9 build.log
cp build.log.bz2 dist/sources

echo "Done!"

if [[ ! -e /tmp/64 ]]; then
touch /tmp/64
fi

[ -f /usr/share/sounds/2barks.au ] && aplay /usr/share/sounds/2barks.au
if [[ -e /tmp/64 ]]; then
rename packages packages64 dist/packages
mkdir dist/packages
fi

#SECOND RUN


if [[ ! -e /tmp/32-pae && ! -d dist/packages32-pae ]]; then
. ./build32-pae.conf
fi

if [ "$1" = "" ];then
   echo -en "\033[1;35m""WARNING" #purple?
   echo -en "\033[0m" #reset
   echo ": This will delete aufs, kernel folder but wont touch configs or dist."
   sleep 2
   echo "Please wait..."
   rm -rf ./{aufs*,build.log*}
   echo "Cleaning complete"
fi
if [[ -d ./aufs* ]];then
   echo "This is not a clean kit."
   echo " CTRL+C to quit"
   read notcleango
fi

FW_URL=${FW_URL:-http://distro.ibiblio.org/puppylinux/firmware}
package_name_suffix=$package_name_suffix
custom_suffix=$custom_suffix
kernel_version=$kernel_version
kernel_mirror=$kernel_mirror

# .configs
[ -f /tmp/kernel_configs ] && rm -f /tmp/kernel_configs

CONFIGS=$(ls ./configs_extra)

# list
echo "configs"
NUM=1
for C in $CONFIGS
  do echo "${NUM}. $C" >> /tmp/kernel_configs
  NUM=$(($NUM + 1))
  done
echo "z. Custom DOTconfig" >> /tmp/kernel_configs
echo "d. Default DOTconfig" >> /tmp/kernel_configs 
figs=`cat /tmp/kernel_configs`
echo "$figs"
sleep 2

   if [[ -e /tmp/64 ]]; then
   Chosen=3
   fi
echo "$Chosen"
sleep 1
Choice=$(grep "^$Chosen\." /tmp/kernel_configs | cut -d ' ' -f2)
echo "$Choice"
sleep 1
rm -r DOTconfig
cp -af configs_extra/$Choice DOTconfig
 
   echo "Extracting the Aufs sources"
   tar xf dist/sources/vanilla/aufs$aufs_version-$kernel_branch-git$today.tar.bz2
   if [[ $? -ne 0 ]]; then
      echo "Error: failed to extract the Aufs sources."
      exit 1
      fi
patchaufs () {
   # patch Aufs
if [ -f aufs-allow-sfs.patch ];then #removed for K3.9 experiment
   echo "Patching the Aufs sources"
   patch -d aufs$aufs_version-$kernel_branch-git$today -p1 < aufs-allow-sfs.patch >> build.log 2>&1
   if [[ $? -ne 0 ]]; then
      echo "Error: failed to patch the Aufs sources."
      exit 1
   fi
   cp aufs-allow-sfs.patch dist/sources/patches
fi
if [ -f aufs-kconfig.patch ];then #special for K3.9
   echo "Patching the Aufs sources"
   patch -d aufs$aufs_version-$kernel_branch-git$today -p1 < aufs-kconfig.patch >> build.log 2>&1
   if [[ $? -ne 0 ]]; then
      echo "Error: failed to patch the Aufs sources for kconfig."
      exit 1
   fi
   cp aufs-kconfig.patch dist/sources/patches
fi
}
patchaufs

cd linux-$kernel_version

#pause to configure
configure () {
echo "You now should configure your kernel. The supplied .config is
already configured but you may want to make changes, plus the date
should be updated. You can choose to run \"make menuconfig\" for
an ncurses based gui (recommended if you don't change stuff or
for advanced users)

1. make olddefconfig
s) skip"
echo
sleep 2
kernelconfig=1
case $kernelconfig in
1) make olddefconfig;;
s)echo "skipping";;
esac
echo
echo "Ok, kernel is configured. CTRL+C to quit"
sleep 2
cp -f ../DOTconfig .config.old
cp -f ../DOTconfig .config

[ ! -d ../dist/packages ] && mkdir -p ../dist/packages
}
configure
krnheads () {
   echo "Creating the kernel headers package"
make headers_check >> ../build.log 2>&1
make INSTALL_HDR_PATH=kernel_headers-$kernel_major_version-$package_name_suffix/usr headers_install >> ../build.log 2>&1
find kernel_headers-$kernel_major_version-$package_name_suffix/usr/include \( -name .install -o -name ..install.cmd \) -delete
mv kernel_headers-$kernel_major_version-$package_name_suffix ../dist/packages
}
krnheads

krncompile () {
echo "Compiling the kernel"
cores=`cat /proc/cpuinfo | grep 'cpu cores' | cut -f3 -d ' ' | tr '\n' ' ' | cut -f1 -d ' '`
if [[ $cores -ge 2 ]]; then
make -d -j6
else
make -d
fi
if [[ ! -f arch/x86/boot/bzImage || ! -f System.map ]]; then
   echo "Error: failed to compile the kernel sources."
   exit 1
fi
cp .config ../dist/sources/DOTconfig-$kernel_version-
}


krncompile
echo "Creating the kernel package"
make INSTALL_MOD_PATH=linux_kernel-$kernel_major_version-$package_name_suffix modules_install >> ../build.log 2>&1
rm -f linux_kernel-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix/{build,source}
mkdir -p linux_kernel-$kernel_major_version-$package_name_suffix/boot
mkdir -p linux_kernel-$kernel_major_version-$package_name_suffix/etc/modules
cp .config linux_kernel-$kernel_major_version-$package_name_suffix/etc/modules/DOTconfig-$kernel_version-
cp arch/x86/boot/bzImage linux_kernel-$kernel_major_version-$package_name_suffix/boot/vmlinuz
BZIMAGE=`find . -type f -name bzImage`
cp System.map linux_kernel-$kernel_major_version-$package_name_suffix/boot/
cp linux_kernel-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix/{modules.builtin,modules.order} \
 linux_kernel-$kernel_major_version-$package_name_suffix/etc/modules/
mv linux_kernel-$kernel_major_version-$package_name_suffix ../dist/packages/
if [ "$FD" = "1" ];then #make fatdog kernel module package
   mv ../dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/boot/vmlinuz ../dist/packages/vmlinuz-$kernel_major_version-$package_name_suffix/vmlinuz-${kernel-major-version}$custom_suffix
   [ -f ../dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/boot/bzImage ] &&
rm -f ../dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/boot/bzImage
   echo "Huge kernel $kernel_major_version-$package_name_suffix is ready in dist"
fi
echo "Cleaning the kernel sources"
make clean >> ../build.log 2>&1
make prepare >> ../build.log 2>&1

cd ..

# build aufs-utils userspace modules
echo "Now to build the aufs-utils for userspace"
if [ ! -f dist/sources/vanilla/aufs-util${today}.tar.bz2 ];then
   git clone git://aufs.git.sourceforge.net/gitroot/aufs/aufs-util.git aufs-util >> build.log 2>&1
   [[ $? -ne 0 ]] && echo "Failed to get aufs-util from git, do it manually. Kernel is compiled OK :)" && exit
   
   cd aufs-util
   
   git branch -a | grep 'aufs3' |grep -v 'rcN' | cut -d '.' -f2 > /tmp/aufs-util-version #we go for stable only
   while read line
     do
       if [[ "$kernel_branch" = "$line" ]];then branch=$line
       else
         while [[ "$kernel_branch" -gt "$line" ]]
           do branch=$line
           echo $branch && break
           done
       fi
     done < /tmp/aufs-util-version
   git checkout origin/aufs3.${branch} >> ../build.log 2>&1
   
   [[ $? -ne 0 ]] && echo "Failed to get aufs-util from git, do it manually. Kernel is compiled OK :)" && exit
   echo "Patching aufs-util sources"
   cp Makefile Makefile.orig
   sed -i 's/-static //' Makefile
   diff -ru Makefile.orig Makefile > ../dist/sources/patches/aufs-util-dynamic.patch
   rm *.orig
   else
   echo "Extracting the Aufs-util sources"
   tar xf dist/sources/vanilla/aufs-util$today.tar.bz2 >> ../build.log 2>&1
   if [[ $? -ne 0 ]]; then
      echo "Error: failed to extract the aufs-util sources."
      exit 1
   fi   
   cd aufs-util   
   patch -p1 < ../dist/sources/patches/aufs-util-dynamic.patch >> ../build.log 2>&1
   [[ "$?" -ne 0 ]] && echo "Failed to patch the aufs-util sources, do it manually. Kernel is compiled ok"
fi
arch=`uname -m`
CONFIG=`find $CWD/dist/sources -type f -name 'DOTconfig*'`
grep -q 'CONFIG_AUFS_FHSM=y' $CONFIG
[[ "$?" -eq 0 ]] && export MAKE=make || export MAKE="make BuildFHSM=no"
LinuxSrc=`find $CWD -type d -name 'kernel_headers*'`
export CPPFLAGS="-I $LinuxSrc/usr/include"
$MAKE >> ../build.log 2>&1
[[ $? -ne 0 ]] && echo "Failed to compile aufs-util, do it manually. Kernel is compiled OK :)"
make DESTDIR=$CWD/dist/packages/aufs-util-$kernel_version-$arch install >> ../build.log 2>&1 #maybe needs absolute path
make clean >> ../build.log 2>&1
if [[ "$arch" = "x86_64" ]];then
 mv $CWD/dist/packages/aufs-util-$kernel_version-$arch/usr/lib \
$CWD/dist/packages/aufs-util-$kernel_version-$arch/usr/lib64
fi
echo "aufs-util-$kernel_version is in dist"
cd ..
if [[ "$FD" = "1" ]];then #shift aufs-utils to kernel-modules.sfs
   echo "Installing aufs-utils into kernel package"
   cp -a dist/packages/aufs-util-$kernel_version-$arch/* \
   dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix
   cp -r /lib/firmware dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/lib/
   mksquashfs dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix dist/packages/kernel-modules.sfs-$kernel_major_version-$package_name_suffix $COMP
   [[ "$?" = 0 ]] && echo "Huge compatible kernel packages are ready to package./" || exit 1
   echo "Packaging huge-$kernel_major_version-$package_name_suffix kernel"
   cd dist/packages/
   tar -cjvf huge-$kernel_major_version-${package_name_suffix}.tar.bz2 \
   vmlinuz-$kernel_major_version-$package_name_suffix kernel-modules.sfs-$kernel_major_version-$package_name_suffix
   [[ "$?" = 0 ]] && echo "huge-$kernel_major_version-${package_name_suffix}.tar.bz2 is in dist/packages" || exit 1
   md5sum huge-$kernel_major_version-${package_name_suffix}.tar.bz2 > huge-$kernel_major_version-${package_name_suffix}.tar.bz2.md5.txt
   echo
   cd $CWD
fi

tar -c aufs-util | bzip2 -9 > dist/sources/vanilla/aufs-util$today-$-$arch.tar.bz2

echo "Compressing the log"
bzip2 -9 build.log
cp build.log.bz2 dist/sources

echo "Done!"

if [[ -e /tmp/64 ]]; then
touch /tmp/32-pae
fi

[ -f /usr/share/sounds/2barks.au ] && aplay /usr/share/sounds/2barks.au
if [[ -e /tmp/32-pae && -e /tmp/64 ]]; then
rename packages packages32-pae dist/packages
mkdir dist/packages
fi


#THIRD RUN

if [[ -e /tmp/64  && -e /tmp/32-nopae && ! dist/packages32-nopae ]]; then
. ./build32-nopae.conf
fi

if [ "$1" = "" ];then
   echo -en "\033[1;35m""WARNING" #purple?
   echo -en "\033[0m" #reset
   echo ": This will delete aufs, kernel folder but wont touch configs or dist."
   sleep 2
   echo "Please wait..."
   rm -rf ./{aufs*,build.log*}
   echo "Cleaning complete"
fi
if [[ -d ./aufs* ]];then
   echo "This is not a clean kit."
   echo " CTRL+C to quit"
   read notcleango
fi

FW_URL=${FW_URL:-http://distro.ibiblio.org/puppylinux/firmware}
package_name_suffix=$package_name_suffix
custom_suffix=$custom_suffix
kernel_version=$kernel_version
kernel_mirror=$kernel_mirror


# .configs
[ -f /tmp/kernel_configs ] && rm -f /tmp/kernel_configs

CONFIGS=$(ls ./configs_extra)

# list
echo "configs"
NUM=1
for C in $CONFIGS
  do echo "${NUM}. $C" >> /tmp/kernel_configs
  NUM=$(($NUM + 1))
  done
echo "z. Custom DOTconfig" >> /tmp/kernel_configs
echo "d. Default DOTconfig" >> /tmp/kernel_configs 
figs=`cat /tmp/kernel_configs`
echo "$figs"
sleep 2

   if [[ -e /tmp/32-pae && -e /tmp/64 ]]; then
   Chosen=2
   fi
echo "$Chosen"
sleep 1
Choice=$(grep "^$Chosen\." /tmp/kernel_configs | cut -d ' ' -f2)
echo "$Choice"
sleep 1
rm -r DOTconfig
cp -af configs_extra/$Choice DOTconfig

# create directories for the results
[ ! -d dist/sources/vanilla ] && mkdir -p dist/sources/{patches,vanilla}

# delete the previous log
[ -f build.log ] && rm -f build.log
[ -f build.log.tar.bz2 ] && mv -f build.log.tar.bz2

   echo "Extracting the Aufs sources"
   tar xf dist/sources/vanilla/aufs$aufs_version-$kernel_branch-git$today.tar.bz2
   if [[ $? -ne 0 ]]; then
      echo "Error: failed to extract the Aufs sources."
      exit 1
      fi

patchaufs () {
   # patch Aufs
if [ -f aufs-allow-sfs.patch ];then #removed for K3.9 experiment
   echo "Patching the Aufs sources"
   patch -d aufs$aufs_version-$kernel_branch-git$today -p1 < aufs-allow-sfs.patch >> build.log 2>&1
   if [[ $? -ne 0 ]]; then
      echo "Error: failed to patch the Aufs sources."
      exit 1
   fi
   cp aufs-allow-sfs.patch dist/sources/patches
fi
if [ -f aufs-kconfig.patch ];then #special for K3.9
   echo "Patching the Aufs sources"
   patch -d aufs$aufs_version-$kernel_branch-git$today -p1 < aufs-kconfig.patch >> build.log 2>&1
   if [[ $? -ne 0 ]]; then
      echo "Error: failed to patch the Aufs sources for kconfig."
      exit 1
   fi
   cp aufs-kconfig.patch dist/sources/patches
fi
}
patchaufs

cd linux-$kernel_version


#pause to configure
configure () {
echo "You now should configure your kernel. The supplied .config is
already configured but you may want to make changes, plus the date
should be updated. You can choose to run \"make menuconfig\" for
an ncurses based gui (recommended if you don't change stuff or
for advanced users)

1. make olddefconfig
s) skip"
echo
sleep 2
kernelconfig=1
case $kernelconfig in
1) make olddefconfig;;
s)echo "skipping";;
esac
echo
echo "Ok, kernel is configured. CTRL+C to quit"
sleep 2
cp -f ../DOTconfig .config.old
cp -f ../DOTconfig .config

[ ! -d ../dist/packages ] && mkdir -p ../dist/packages
}
configure
krnheads () {
   echo "Creating the kernel headers package"
make headers_check >> ../build.log 2>&1
make INSTALL_HDR_PATH=kernel_headers-$kernel_major_version-$package_name_suffix/usr headers_install >> ../build.log 2>&1
find kernel_headers-$kernel_major_version-$package_name_suffix/usr/include \( -name .install -o -name ..install.cmd \) -delete
mv kernel_headers-$kernel_major_version-$package_name_suffix ../dist/packages
}
krnheads

krncompile () {
echo "Compiling the kernel"
cores=`cat /proc/cpuinfo | grep 'cpu cores' | cut -f3 -d ' ' | tr '\n' ' ' | cut -f1 -d ' '`
if [[ $cores -ge 2 ]]; then
make -d -j6
else
make -d
fi
if [[ ! -f arch/x86/boot/bzImage || ! -f System.map ]]; then
   echo "Error: failed to compile the kernel sources."
   exit 1
fi
cp .config ../dist/sources/DOTconfig-$kernel_version-
}

krncompile
echo "Creating the kernel package"
make INSTALL_MOD_PATH=linux_kernel-$kernel_major_version-$package_name_suffix modules_install >> ../build.log 2>&1
rm -f linux_kernel-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix/{build,source}
mkdir -p linux_kernel-$kernel_major_version-$package_name_suffix/boot
mkdir -p linux_kernel-$kernel_major_version-$package_name_suffix/etc/modules
cp .config linux_kernel-$kernel_major_version-$package_name_suffix/etc/modules/DOTconfig-$kernel_version-
cp arch/x86/boot/bzImage linux_kernel-$kernel_major_version-$package_name_suffix/boot/vmlinuz
BZIMAGE=`find . -type f -name bzImage`
cp System.map linux_kernel-$kernel_major_version-$package_name_suffix/boot/
cp linux_kernel-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix/{modules.builtin,modules.order} \
 linux_kernel-$kernel_major_version-$package_name_suffix/etc/modules/
mv linux_kernel-$kernel_major_version-$package_name_suffix ../dist/packages/
if [ "$FD" = "1" ];then #make fatdog kernel module package
   mv ../dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/boot/vmlinuz ../dist/packages/vmlinuz-$kernel_major_version-$package_name_suffix/vmlinuz-${kernel-major-version}$custom_suffix
   [ -f ../dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/boot/bzImage ] &&
rm -f ../dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/boot/bzImage
   echo "Huge kernel $kernel_major_version-$package_name_suffix is ready in dist"
fi
echo "Cleaning the kernel sources"
make clean >> ../build.log 2>&1
make prepare >> ../build.log 2>&1

cd ..

echo "Creating a kernel sources SFS"
mkdir -p kernel_sources-$kernel_major_version-$package_name_suffix/usr/src
mv linux-$kernel_version kernel_sources-$kernel_major_version-$package_name_suffix/usr/src/linux
mkdir -p kernel_sources-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix
ln -s /usr/src/linux kernel_sources-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix/build
[ ! -f kernel_sources-${kernel_major_version}-$package_name_suffix/usr/src/linux/include/linux/version.h ] && \
ln -s /usr/src/linux/include/generated/uapi/linux/version.h kernel_sources-${kernel_major_version}-$package_name_suffix/usr/src/linux/include/linux/version.h
ln -s /usr/src/linux kernel_sources-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix/source
mksquashfs kernel_sources-$kernel_major_version-$package_name_suffix dist/sources/kernel_sources-$kernel_major_version-$package_name_suffix.sfs $COMP

# build aufs-utils userspace modules
echo "Now to build the aufs-utils for userspace"
if [ ! -f dist/sources/vanilla/aufs-util${today}.tar.bz2 ];then
   git clone git://aufs.git.sourceforge.net/gitroot/aufs/aufs-util.git aufs-util >> build.log 2>&1
   [[ $? -ne 0 ]] && echo "Failed to get aufs-util from git, do it manually. Kernel is compiled OK :)" && exit
   
   cd aufs-util
   
   git branch -a | grep 'aufs3' |grep -v 'rcN' | cut -d '.' -f2 > /tmp/aufs-util-version #we go for stable only
   while read line
     do
       if [[ "$kernel_branch" = "$line" ]];then branch=$line
       else
         while [[ "$kernel_branch" -gt "$line" ]]
           do branch=$line
           echo $branch && break
           done
       fi
     done < /tmp/aufs-util-version
   git checkout origin/aufs3.${branch} >> ../build.log 2>&1
   
   [[ $? -ne 0 ]] && echo "Failed to get aufs-util from git, do it manually. Kernel is compiled OK :)" && exit
   echo "Patching aufs-util sources"
   cp Makefile Makefile.orig
   sed -i 's/-static //' Makefile
   diff -ru Makefile.orig Makefile > ../dist/sources/patches/aufs-util-dynamic.patch
   rm *.orig
   else
   echo "Extracting the Aufs-util sources"
   tar xf dist/sources/vanilla/aufs-util$today.tar.bz2 >> ../build.log 2>&1
   if [[ $? -ne 0 ]]; then
      echo "Error: failed to extract the aufs-util sources."
      exit 1
   fi   
   cd aufs-util   
   patch -p1 < ../dist/sources/patches/aufs-util-dynamic.patch >> ../build.log 2>&1
   [[ "$?" -ne 0 ]] && echo "Failed to patch the aufs-util sources, do it manually. Kernel is compiled ok"
fi
arch=`uname -m`
CONFIG=`find $CWD/dist/sources -type f -name 'DOTconfig*'`
grep -q 'CONFIG_AUFS_FHSM=y' $CONFIG
[[ "$?" -eq 0 ]] && export MAKE=make || export MAKE="make BuildFHSM=no"
LinuxSrc=`find $CWD -type d -name 'kernel_headers*'`
export CPPFLAGS="-I $LinuxSrc/usr/include"
$MAKE >> ../build.log 2>&1
[[ $? -ne 0 ]] && echo "Failed to compile aufs-util, do it manually. Kernel is compiled OK :)"
make DESTDIR=$CWD/dist/packages/aufs-util-$kernel_version-$arch install >> ../build.log 2>&1 #maybe needs absolute path
make clean >> ../build.log 2>&1
if [[ "$arch" = "x86_64" ]];then
 mv $CWD/dist/packages/aufs-util-$kernel_version-$arch/usr/lib \
$CWD/dist/packages/aufs-util-$kernel_version-$arch/usr/lib64
fi
echo "aufs-util-$kernel_version is in dist"
cd ..
if [[ "$FD" = "1" ]];then #shift aufs-utils to kernel-modules.sfs
   echo "Installing aufs-utils into kernel package"
   cp -a dist/packages/aufs-util-$kernel_version-$arch/* \
   dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix
   cp -r /lib/firmware dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix/lib/
   mksquashfs dist/packages/linux_kernel-$kernel_major_version-$package_name_suffix dist/packages/kernel-modules.sfs-$kernel_major_version-$package_name_suffix $COMP
   [[ "$?" = 0 ]] && echo "Huge compatible kernel packages are ready to package./" || exit 1
   echo "Packaging huge-$kernel_major_version-$package_name_suffix kernel"
   cd dist/packages/
   tar -cjvf huge-$kernel_major_version-${package_name_suffix}.tar.bz2 \
   vmlinuz-$kernel_major_version-$package_name_suffix kernel-modules.sfs-$kernel_major_version-$package_name_suffix
   [[ "$?" = 0 ]] && echo "huge-$kernel_major_version-${package_name_suffix}.tar.bz2 is in dist/packages" || exit 1
   md5sum huge-$kernel_major_version-${package_name_suffix}.tar.bz2 > huge-$kernel_major_version-${package_name_suffix}.tar.bz2.md5.txt
   echo
   cd $CWD
fi

tar -c aufs-util | bzip2 -9 > dist/sources/vanilla/aufs-util$today-$-$arch.tar.bz2

echo "Compressing the log"
bzip2 -9 build.log
cp build.log.bz2 dist/sources

echo "Done!"

if [[ -e /tmp/32-pae && -e /tmp/64 ]]; then
touch /tmp/32-nopae
fi

[ -f /usr/share/sounds/2barks.au ] && aplay /usr/share/sounds/2barks.au

if [[ -e /tmp/32-nopae &&  -e /tmp/64 ]]; then
rename packages packages32-nopae dist/packages
fi

exit

###the end###
Back to top
View user's profile Send private message MSN Messenger 
amigo

Joined: 02 Apr 2007
Posts: 2329

PostPosted: Sat 24 Jan 2015, 09:17    Post subject:  

That's pretty long there -I should have showed you how to make the script re-run itself, with:
exec $0 (options)
Back to top
View user's profile Send private message 
stemsee

Joined: 27 Jun 2013
Posts: 950
Location: Displaced

PostPosted: Sat 24 Jan 2015, 14:54    Post subject:  

That would have been useful, but actually the script is more versatile stretched out! Did you try it?
Back to top
View user's profile Send private message MSN Messenger 
Display posts from previous:   Sort by:   
Page 1 of 7 [97 Posts]   Goto page: 1, 2, 3, 4, 5, 6, 7 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Advanced Topics » Cutting edge
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.4626s ][ Queries: 12 (0.0046s) ][ GZIP on ]