build.sh 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. #!/bin/sh
  2. # originally by Iguleder
  3. # hacked to DEATH by 01micko
  4. # see /usr/share/doc/legal NO WARRANTY, NO resposibility accepted
  5. # read config
  6. [ -f ./build.conf ] && . ./build.conf
  7. package_name_suffix=$package_name_suffix
  8. custom_suffix=$custom_suffix
  9. kernel_version=$kernel_version
  10. kernel_mirror=$kernel_mirror
  11. # depcheck
  12. echo "Dependency check..."
  13. if git --version &>/dev/null
  14. then echo -e "\033[1;34m""git is installed" #green
  15. else echo -e "\033[1;31m""git is not installed""\033[0m" && exit #red
  16. fi
  17. if gcc --version &>/dev/null
  18. then echo -e "\033[1;34m""gcc is installed"
  19. else
  20. echo -e "\033[1;31m""gcc is not installed""\033[0m" && exit
  21. fi
  22. MKSQ="$(which mksquashfs)"
  23. if [ "$MKSQ" ]
  24. then
  25. echo -e "\033[1;34m""mksquashfs is installed"
  26. else #yellow
  27. echo -e "\033[1;30m""mksquashfs is not installed but you can continue"
  28. fi
  29. echo -e "\033[0m" #reset to original
  30. # .configs
  31. [ -f /tmp/kernel_configs ] && rm -f /tmp/kernel_configs
  32. CONFIGS=$(ls ./configs_extra)
  33. # list
  34. echo "Choose a number of the config you want to try"
  35. NUM=1
  36. for C in $CONFIGS
  37. do echo "${NUM}. $C" >> /tmp/kernel_configs
  38. NUM=$(($NUM + 1))
  39. done
  40. echo "z. Custom DOTconfig" >> /tmp/kernel_configs
  41. echo "d. Default DOTconfig" >> /tmp/kernel_configs
  42. cat /tmp/kernel_configs
  43. echo -n "Enter choice: "
  44. read Chosen
  45. if [ ! $Chosen ];then
  46. echo -e "\033[1;31m""ERROR: you didn't choose, start again!""\033[0m" \
  47. && exit
  48. else
  49. Choice=$(grep ^$Chosen /tmp/kernel_configs|cut -d ' ' -f2)
  50. [ ! $Choice ] && \
  51. echo -e "\033[1;31m""ERROR: your choice is not sane ..quiting""\033[0m" \
  52. && exit
  53. echo -e "You chose $Choice. If this is ok hit ENTER, \
  54. \nif not hit CTRL|C to quit"
  55. read oknow
  56. if [[ "$Choice" = "Default" || "$Choice" = "Custom" ]];then
  57. echo $Choice
  58. else
  59. cp -af configs_extra/$Choice DOTconfig
  60. fi
  61. fi
  62. [ ! -f DOTconfig ] && echo -e \
  63. "\033[1;31m""ERROR: No DOTconfig found ..quiting""\033[0m" \
  64. && exit
  65. # the aufs major version
  66. aufs_version=${kernel_version%.*.*} #
  67. # fail-safe switch in case someone clicks the script in ROX (real story! not
  68. # fun at all!!!!) :p
  69. read -p "Press ENTER to begin" dummy
  70. # get the major version (2.6.32 in the case of 2.6.32.40)
  71. kernel_major_version=$kernel_version #blah, hack for 3.x
  72. # get the kernel branch (32 in the case of 2.6.32.40; needed to download Aufs)
  73. kernel_branch=`echo $kernel_major_version | cut -f 2 -d .` #3.x kernels
  74. # get the minor version (40 in the case of 2.6.32.40)
  75. #case $kernel_version in
  76. #*.*.*.*) kernel_minor_version=`echo $kernel_version | cut -f 4 -d .` ;;
  77. #esac
  78. # old 2 series info
  79. # the package name suffix (-40 in the case of 2.6.32.40); Woof assumes the
  80. # package version is identical to the kernel version and uses paths that
  81. # contain the package version, so use $kernel_major version as the version and
  82. # "-$kernel_minor_version" as the suffix
  83. #case "$kernel_minor_version" in
  84. #*) package_name_suffix="-$kernel_minor_version";;
  85. #esac
  86. # create directories for the results
  87. [ ! -d dist/sources/vanilla ] && mkdir -p dist/sources/{patches,vanilla}
  88. # get today's date
  89. today=`date +%d%m%y`
  90. # delete the previous log
  91. [ -f build.log ] && rm -f build.log
  92. [ -f build.log.tar.bz2 ] && mv -f build.log.${today}.tar.bz2
  93. # download the kernel
  94. if [ ! -f dist/sources/vanilla/linux-$kernel_version.tar.bz2 ]; then
  95. echo "Downloading the kernel sources"
  96. wget -P dist/sources/vanilla $kernel_mirror/linux-$kernel_version.tar.bz2 > build.log 2>&1
  97. if [ $? -ne 0 ]; then
  98. echo "Error: failed to download the kernel sources."
  99. exit 1
  100. fi
  101. fi
  102. # download Aufs
  103. if [ ! -f dist/sources/vanilla/aufs$aufs_version-$kernel_branch-git$today.tar.bz2 ]; then
  104. echo "Downloading the Aufs sources"
  105. #git clone http://git.c3sl.ufpr.br/pub/scm/aufs/aufs2-standalone.git aufs$aufs_version-$kernel_branch-git$today >> build.log 2>&1
  106. git clone git://aufs.git.sourceforge.net/gitroot/aufs/aufs3-standalone.git aufs$aufs_version-$kernel_branch-git$today >> build.log 2>&1
  107. if [ $? -ne 0 ]; then
  108. echo "Error: failed to download the Aufs sources."
  109. exit 1
  110. fi
  111. cd aufs$aufs_version-$kernel_branch-git$today
  112. git checkout origin/aufs$aufs_version.$kernel_branch >> ../build.log 2>&1
  113. if [ $? -ne 0 ]; then
  114. echo "Error: failed to download the Aufs sources."
  115. exit 1
  116. fi
  117. rm -rf .git
  118. cd ..
  119. echo "Creating the Aufs sources tarball"
  120. tar -c aufs$aufs_version-$kernel_branch-git$today | bzip2 -9 > dist/sources/vanilla/aufs$aufs_version-$kernel_branch-git$today.tar.bz2
  121. else
  122. echo "Extracting the Aufs sources"
  123. tar xf dist/sources/vanilla/aufs$aufs_version-$kernel_branch-git$today.tar.bz2 >> build.log 2>&1
  124. if [ $? -ne 0 ]; then
  125. echo "Error: failed to extract the Aufs sources."
  126. exit 1
  127. fi
  128. fi
  129. # patch Aufs
  130. echo "Patching the Aufs sources"
  131. patch -d aufs$aufs_version-$kernel_branch-git$today -p1 < aufs-allow-sfs.patch >> build.log 2>&1
  132. if [ $? -ne 0 ]; then
  133. echo "Error: failed to patch the Aufs sources."
  134. exit 1
  135. fi
  136. cp aufs-allow-sfs.patch dist/sources/patches
  137. ##download unionfs
  138. #if [ ! -f dist/sources/vanilla/unionfs-2.5.11_for_${kernel_version}.diff.gz ]; then
  139. #echo "downloading unionfs patches"
  140. #wget -P dist/sources/vanilla http://download.filesystems.org/unionfs/unionfs-2.x-latest/unionfs-2.5.11_for_${kernel_version}.diff.gz >> build.log 2>&1
  141. #if [ $? -ne 0 ]; then
  142. #echo "Error: failed to download the unionfs patch."
  143. #exit 1
  144. #fi
  145. #gunzip dist/sources/vanilla/unionfs-2.5.11_for_${kernel_version}.diff.gz
  146. #if [ $? -ne 0 ]; then
  147. #echo "Error: failed to extract the unionfs patch."
  148. #exit 1
  149. #fi
  150. #mv dist/sources/vanilla/unionfs-2.5.11_for_${kernel_version}.diff patches/unionfs-2.5.11_for_${kernel_version}.patch
  151. #fi
  152. #read #remove!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  153. # extract the kernel
  154. echo "Extracting the kernel sources"
  155. tar xf dist/sources/vanilla/linux-$kernel_version.tar.bz2 >> build.log 2>&1
  156. if [ $? -ne 0 ]; then
  157. echo "Error: failed to extract the kernel sources."
  158. exit 1
  159. fi
  160. cd linux-$kernel_version
  161. echo "Adding Aufs to the kernel sources"
  162. for i in kbuild base standalone; do
  163. patch -p1 < ../aufs$aufs_version-$kernel_branch-git$today/aufs$aufs_version-$i.patch >> ../build.log 2>&1
  164. if [ $? -ne 0 ]; then
  165. echo "Error: failed to add Aufs to the kernel sources."
  166. exit 1
  167. fi
  168. done
  169. cp -r ../aufs$aufs_version-$kernel_branch-git$today/{fs,Documentation} .
  170. cp ../aufs$aufs_version-$kernel_branch-git$today/include/linux/aufs_type.h include/linux
  171. [ -d ../aufs$aufs_version-$kernel_branch-git$today/include/uapi ] && \
  172. cp -r ../aufs$aufs_version-$kernel_branch-git$today/include/uapi/linux/aufs_type.h include/uapi/linux
  173. #cat ../aufs$aufs_version-1-git$today/include/linux/Kbuild >> include/Kbuild
  174. ################################################################################
  175. echo "Resetting the minor version number"
  176. cp Makefile Makefile-orig
  177. sed -i "s/^EXTRAVERSION =/EXTRAVERSION = $custom_suffix/" Makefile
  178. diff -up Makefile-orig Makefile > ../dist/sources/patches/extra-version.patch
  179. rm Makefile-orig
  180. echo "Reducing the number of consoles"
  181. cp kernel/printk.c kernel/printk.c-orig
  182. sed -i s/'#define MAX_CMDLINECONSOLES 8'/'#define MAX_CMDLINECONSOLES 5'/ kernel/printk.c
  183. diff -up kernel/printk.c-orig kernel/printk.c > ../dist/sources/patches/less-consoles.patch
  184. echo "Reducing the verbosity level"
  185. cp -f kernel/printk.c kernel/printk.c-orig
  186. 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.c
  187. diff -up kernel/printk.c-orig kernel/printk.c > ../dist/sources/patches/lower-verbosity.patch
  188. for patch in ../patches/*; do
  189. echo "Applying $patch"
  190. patch -p1 < $patch >> ../build.log 2>&1
  191. if [ $? -ne 0 ]; then
  192. echo "Error: failed to apply $patch on the kernel sources."
  193. exit 1
  194. fi
  195. cp $patch ../dist/sources/patches
  196. done
  197. echo "Cleaning the kernel sources"
  198. make clean
  199. make mrproper
  200. find . -name '*.orig' -delete
  201. find . -name '*.rej' -delete
  202. find . -name '*~' -delete
  203. cp ../DOTconfig .config
  204. #echo "exiting for config" #uncomment this to change .config #nah, pause routine
  205. #exit #uncomment this to change .config
  206. #pause to configure
  207. echo -en "You now should configure your kernel. The supplied .config\nis \
  208. already configured but you may want to make changes, plus the date \
  209. \nshould be updated. You can choose to run \"make menuconfig\" for \
  210. \nan ncurses based gui (recommended if you don't change stuff or\
  211. \nfor advanced users) or run \"make gconfig\" for a gtk based gui \
  212. \nor if you have qt installed \"make xconfig\" is nice.\
  213. \nHit a number or s to skip\
  214. \n1. make menuconfig\
  215. \n2. make gconfig\
  216. \n3. make xconfig \n"
  217. echo
  218. read kernelconfig
  219. case $kernelconfig in
  220. 1)make menuconfig ;;
  221. 2)make gconfig ;;
  222. 3)make xconfig
  223. [ "$?" -ne "0" ] && echo "woops.. no qt? exiting" && exit ;;
  224. s)echo "skipping" ;;
  225. esac
  226. echo
  227. echo "Ok, kernel is configured. hit ENTER to contine, CTRL+C to quit"
  228. read goon
  229. [ ! -d ../dist/packages ] && mkdir ../dist/packages
  230. echo "Creating the kernel headers package"
  231. make headers_check >> ../build.log 2>&1
  232. make INSTALL_HDR_PATH=kernel_headers-$kernel_major_version-$package_name_suffix/usr headers_install >> ../build.log 2>&1
  233. find kernel_headers-$kernel_major_version-$package_name_suffix/usr/include \( -name .install -o -name ..install.cmd \) -delete
  234. mv kernel_headers-$kernel_major_version-$package_name_suffix ../dist/packages
  235. echo "Compiling the kernel"
  236. make bzImage modules >> ../build.log 2>&1
  237. if [[ ! -f arch/x86/boot/bzImage || ! -f System.map ]]; then
  238. echo "Error: failed to compile the kernel sources."
  239. exit 1
  240. fi
  241. cp .config ../dist/sources/DOTconfig-$kernel_version-$today
  242. echo "Creating the kernel package"
  243. make INSTALL_MOD_PATH=linux_kernel-$kernel_major_version-$package_name_suffix modules_install >> ../build.log 2>&1
  244. rm -f linux_kernel-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix/{build,source}
  245. #(cd linux_kernel-$kernel_major_version-$package_name_suffix/lib/modules/; ln -s ${kernel_major_version}$custom_suffix $kernel_major_version)
  246. mkdir linux_kernel-$kernel_major_version-$package_name_suffix/boot
  247. mkdir -p linux_kernel-$kernel_major_version-$package_name_suffix/etc/modules
  248. cp .config linux_kernel-$kernel_major_version-$package_name_suffix/etc/modules/DOTconfig-$kernel_version-$today
  249. cp arch/x86/boot/bzImage linux_kernel-$kernel_major_version-$package_name_suffix/boot/vmlinuz
  250. cp System.map linux_kernel-$kernel_major_version-$package_name_suffix/boot
  251. cp linux_kernel-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix/{modules.builtin,modules.order} \
  252. linux_kernel-$kernel_major_version-$package_name_suffix/etc/modules/
  253. rm linux_kernel-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix/modules*
  254. mv linux_kernel-$kernel_major_version-$package_name_suffix ../dist/packages
  255. echo "Cleaning the kernel sources"
  256. make clean >> ../build.log 2>&1
  257. make prepare >> ../build.log 2>&1
  258. cd ..
  259. echo "Creating a kernel sources SFS"
  260. mkdir -p kernel_sources-$kernel_major_version-$package_name_suffix/usr/src
  261. mv linux-$kernel_version kernel_sources-$kernel_major_version-$package_name_suffix/usr/src/linux
  262. mkdir -p kernel_sources-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix
  263. ln -s /usr/src/linux kernel_sources-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix/build
  264. 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
  265. ln -s /usr/src/linux kernel_sources-$kernel_major_version-$package_name_suffix/lib/modules/${kernel_major_version}$custom_suffix/source
  266. mksquashfs kernel_sources-$kernel_major_version-$package_name_suffix dist/sources/kernel_sources-$kernel_major_version-$package_name_suffix.sfs
  267. # build aufs-utils userspace modules
  268. echo "Now to build the aufs-utils for userspace"
  269. git clone git://aufs.git.sourceforge.net/gitroot/aufs/aufs-util.git aufs-util
  270. [ $? -ne 0 ] && echo "Failed to get aufs-util from git, do it manually. Kernel is compiled OK :)" && exit
  271. cd aufs-util
  272. git checkout origin/aufs3.0
  273. [ $? -ne 0 ] && echo "Failed to get aufs-util from git, do it manually. Kernel is compiled OK :)" && exit
  274. LinuxSrc=../dist/packages/kernel_headers*
  275. CPPFLAGS="-I $LinuxSrc/usr/include"
  276. make
  277. [ $? -ne 0 ] && echo "Failed to compile aufs-util, do it manually. Kernel is compiled OK :)" && exit
  278. make DESTDIR=../dist/packages/aufs-util-$kernel_version install
  279. make clean
  280. echo "aufs-util-$kernel_version is in dist"
  281. cd ..
  282. echo "Compressing the log"
  283. bzip2 -9 build.log
  284. cp build.log.bz2 dist/sources
  285. echo "Done!"
  286. aplay /usr/share/sounds/2barks.au