Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Linux build script for Puppy Linux

By: a guest on Jun 4th, 2011  |  syntax: Bash  |  size: 8.96 KB  |  views: 283  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/sh
  2.  
  3. ##########################################
  4. #       Linux build script for Puppy Linux   #
  5. ##########################################
  6.  
  7. # the Linux version to build
  8. LINUX_VERSION="2.6.32.41"
  9.  
  10. # the file name of the Linux sources tarball
  11. LINUX_SOURCES_TARBALL="linux-2.6.32.41.tar.bz2"
  12.  
  13. # the Linux download mirror
  14. LINUX_MIRROR="http://www.il.kernel.org/pub/linux/kernel/v2.6/longterm/v2.6.32"
  15.  
  16. # the Linux image and modules package name
  17. LINUX_PACKAGE_NAME="linux_kernel"
  18.  
  19. # the Linux API headers package name
  20. LINUX_HEADERS_PACKAGE_NAME="kernel_headers"
  21.  
  22. # the Linux sources package name
  23. LINUX_SOURCES_PACKAGE_NAME="kernel_sources"
  24.  
  25. # the Aufs version to use
  26. AUFS_VERSION="2.1"
  27.  
  28. # get the Linux major version number
  29. LINUX_MAJOR_VERSION=`echo $LINUX_VERSION | cut -f 1-3 -d .`
  30.  
  31. # get the Linux release number
  32. LINUX_RELEASE_NUMBER=`echo $LINUX_VERSION | cut -f 3 -d .`
  33.  
  34. # get the Linux minor version number
  35. LINUX_MINOR_VERSION=`echo $LINUX_VERSION | cut -f 4 -d .`
  36.  
  37. # the package name suffix
  38. PACKAGE_NAME_SUFFIX="${LINUX_MINOR_VERSION}-lts-libre-bfs"
  39.  
  40. # the Linux-libre scripts to use
  41. LINUX_LIBRE_SCRIPTS="deblob-${LINUX_MAJOR_VERSION} deblob-check"
  42.  
  43. # the Linux-libre mirror to download the scripts from
  44. LINUX_LIBRE_MIRROR="http://www.fsfla.org/svn/fsfla/software/linux-libre/scripts"
  45.  
  46. # get the build date
  47. BUILD_DATE=`date +%d%m%Y`
  48.  
  49. # the absolute log file path                                                                   
  50. LOG_PATH=`pwd`/build.log
  51.  
  52. # delete old logs
  53. [ -f "$LOG_PATH" ] && rm -f "$LOG_PATH"
  54.  
  55. # create directories for the output
  56. mkdir -p dist/sources/{patches,vanilla}
  57.  
  58. # download the Linux sources tarball
  59. if [ ! -f dist/sources/vanilla/$LINUX_SOURCES_TARBALL ]; then
  60.         echo "Downloading the Linux sources tarball"
  61.         wget -P dist/sources/vanilla $LINUX_MIRROR/$LINUX_SOURCES_TARBALL > "$LOG_PATH" 2>&1
  62.         if [ $? -ne 0 ]
  63.         then
  64.                 echo "Error: failed to download the Linux sources tarball."
  65.                 exit 1
  66.         fi
  67. fi
  68.  
  69. # check whether the Linux-libre scripts are missing
  70. download=0
  71. for script in $LINUX_LIBRE_SCRIPTS
  72. do
  73.         if [ ! -f dist/sources/vanilla/$script ]
  74.         then
  75.                 download=1
  76.                 break
  77.         fi
  78. done
  79.  
  80. # if at least one script is missing, download it
  81. if [ $download -eq 1 ]
  82. then
  83.         echo "Downloading the Linux-libre deblob scripts"
  84.         for script in $LINUX_LIBRE_SCRIPTS
  85.         do
  86.                 if [ ! -f dist/sources/vanilla/$script ]
  87.                 then
  88.                         wget -P dist/sources/vanilla $LINUX_LIBRE_MIRROR/$script >> build.log 2>&1
  89.                         if [ $? -ne 0 ]
  90.                         then
  91.                                 [ -f dist/sources/vanilla/$script ] && rm -f dist/sources/vanilla/$script
  92.                                 echo "Error: failed to download the $script script."
  93.                                 exit 1
  94.                         fi
  95.                 fi
  96.         done   
  97. fi
  98.  
  99. # get the full Aufs package name
  100. AUFS_FULL_PACKAGE_NAME=aufs${AUFS_VERSION}-${LINUX_RELEASE_NUMBER}-git${BUILD_DATE}
  101.  
  102. # download the Aufs sources through git
  103. if [ ! -f dist/sources/vanilla/aufs$AUFS_VERSION-$LINUX_RELEASE_NUMBER-git$BUILD_DATE.tar.bz2 ]
  104. then
  105.         echo "Downloading the Aufs sources through git"
  106.         git clone http://git.c3sl.ufpr.br/pub/scm/aufs/aufs2-standalone.git $AUFS_FULL_PACKAGE_NAME>> "$LOG_PATH" 2>&1
  107.         if [ $? -ne 0 ]
  108.         then
  109.                 echo "Error: failed to download the Aufs sources through git."
  110.                 exit 1
  111.         fi
  112.         cd aufs$AUFS_VERSION-$LINUX_RELEASE_NUMBER-git$BUILD_DATE
  113.         git checkout origin/aufs$AUFS_VERSION-$LINUX_RELEASE_NUMBER >> "$LOG_PATH" 2>&1
  114.         if [ $? -ne 0 ]
  115.         then
  116.                 echo "Error: failed to download the Aufs sources through git."
  117.                 exit 1
  118.         fi
  119.         rm -rf .git
  120.         cd ..
  121.         echo "Creating the Aufs sources tarball"
  122.         tar -c $AUFS_FULL_PACKAGE_NAME| bzip2 -9 > dist/sources/vanilla/aufs$AUFS_VERSION-$LINUX_RELEASE_NUMBER-git$BUILD_DATE.tar.bz2
  123. else
  124.         echo "Extracting the Aufs sources tarball"
  125.         tar xf dist/sources/vanilla/aufs$AUFS_VERSION-$LINUX_RELEASE_NUMBER-git$BUILD_DATE.tar.bz2 >> "$LOG_PATH" 2>&1
  126.         if [ $? -ne 0 ]
  127.         then
  128.                 echo "Error: failed to extract the Aufs sources tarball."
  129.                 exit 1
  130.         fi
  131. fi
  132.  
  133. # patch Aufs
  134. echo "Patching the Aufs sources"
  135. patch -d $AUFS_FULL_PACKAGE_NAME -p1 < aufs-allow-sfs.patch >> "$LOG_PATH" 2>&1
  136. if [ $? -ne 0 ]
  137. then
  138.         echo "Error: failed to patch the Aufs sources."
  139.         exit 1
  140. fi
  141. cp aufs-allow-sfs.patch dist/sources/patches
  142.  
  143. # extract the Linux sources tarball
  144. echo "Extracting the Linux sources tarball"
  145. tar xf dist/sources/vanilla/$LINUX_SOURCES_TARBALL >> "$LOG_PATH" 2>&1
  146. if [ $? -ne 0 ]
  147. then
  148.         echo "Error: failed to extract the Linux sources tarball."
  149.         exit 1
  150. fi
  151.  
  152. echo "Deblobing the Linux sources"
  153. echo "  creating a clean copy of the sources"
  154. cp -r linux-$LINUX_VERSION linux-$LINUX_VERSION-orig
  155. for script in $LINUX_LIBRE_SCRIPTS
  156. do
  157.         chmod +x dist/sources/vanilla/$script
  158. done
  159.  
  160. echo "  deblobing"
  161. cd linux-$LINUX_VERSION
  162. ../dist/sources/vanilla/deblob-$LINUX_MAJOR_VERSION > "$LOG_PATH" 2>&1
  163. if [ $? -ne 0 ]
  164. then
  165.         echo "Error: failed to deblob the Linux sources."
  166.         exit 1
  167. fi
  168.  
  169. echo "  creating a patch"
  170. cd ..
  171. diff -rupN linux-$LINUX_VERSION-orig linux-$LINUX_VERSION > dist/sources/patches/deblob.patch
  172. rm -rf linux-%LINUX_VERSION-orig
  173.  
  174. mkdir dist/packages
  175.  
  176. cd linux-$LINUX_VERSION
  177.  
  178. echo "Cleaning the Linux sources"
  179. make clean >> "$LOG_PATH" 2>&1
  180. make mrproper >> "$LOG_PATH" 2>&1
  181.  
  182. echo "Creating the Linux headers package"
  183. make headers_check >> "$LOG_PATH" 2>&1
  184. LINUX_HEADERS_FULL_PACKAGE_NAME=${LINUX_HEADERS_PACKAGE_NAME}-${LINUX_MAJOR_VERSION}-${PACKAGE_NAME_SUFFIX}
  185. make INSTALL_HDR_PATH=$LINUX_HEADERS_FULL_PACKAGE_NAME headers_install >> "$LOG_PATH" 2>&1
  186. find $LINUX_HEADERS_FULL_PACKAGE_NAME/include \( -name .install -o -name ..install.cmd \) -delete
  187. mv $LINUX_HEADERS_FULL_PACKAGE_NAME ../dist/packages
  188.  
  189. # patch the Linux sources with the Aufs patches and add the file system code itself
  190. echo "Adding Aufs to the Linux sources"
  191. for i in kbuild base standalone; do
  192.         patch -p1 < ../aufs$AUFS_VERSION-$LINUX_RELEASE_NUMBER-git$BUILD_DATE/aufs2-$i.patch >> "$LOG_PATH" 2>&1
  193.         if [ $? -ne 0 ]
  194.         then
  195.                 echo "Error: failed to add Aufs to the Linux sources."
  196.                 exit 1
  197.         fi
  198. done
  199. cp -r ../aufs$AUFS_VERSION-$LINUX_RELEASE_NUMBER-git$BUILD_DATE/{fs,Documentation} .
  200. cp -r ../aufs$AUFS_VERSION-$LINUX_RELEASE_NUMBER-git$BUILD_DATE/include/linux/aufs_type.h include/linux
  201. cat ../aufs$AUFS_VERSION-$LINUX_RELEASE_NUMBER-git$BUILD_DATE/include/linux/Kbuild >> include/linux/Kbuild
  202.  
  203. echo "Resetting the minor version number"
  204. cp Makefile Makefile-orig
  205. sed -i s/'^EXTRAVERSION = .*$'/'EXTRAVERSION = '/ Makefile
  206. diff -up Makefile-orig Makefile > ../dist/sources/patches/extra-version.patch
  207. rm Makefile-orig
  208.  
  209. echo "Reducing the number of consoles"
  210. cp kernel/printk.c kernel/printk.c-orig
  211. sed -i s/'#define MAX_CMDLINECONSOLES 8'/'#define MAX_CMDLINECONSOLES 5'/ kernel/printk.c
  212. diff -up kernel/printk.c-orig kernel/printk.c > ../dist/sources/patches/less-consoles.patch
  213.  
  214. echo "Reducing the verbosity level"
  215. cp -f kernel/printk.c kernel/printk.c-orig
  216. 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
  217. diff -up kernel/printk.c-orig kernel/printk.c > ../dist/sources/patches/lower-verbosity.patch
  218.  
  219. for patch in ../patches/*
  220. do
  221.         echo "Applying $patch"
  222.         patch -p1 < $patch >> "$LOG_PATH" 2>&1
  223.         if [ $? -ne 0 ]
  224.         then
  225.                 echo "Error: failed to apply $patch on the Linux sources."
  226.                 exit 1
  227.         fi
  228.         cp $patch ../dist/sources/patches
  229. done
  230.  
  231. find . -name '*.orig' -delete
  232. find . -name '*.rej' -delete
  233. find . -name '*~' -delete
  234.  
  235. echo "Building Linux"
  236. cp ../DOTconfig .config
  237. make bzImage modules >> "$LOG_PATH" 2>&1
  238. if [[ ! -f arch/x86/boot/bzImage || ! -f System.map ]]; then
  239.         echo "Error: failed to build Linux."
  240.         exit 1
  241. fi
  242. cp .config ../dist/sources/DOTconfig-$LINUX_VERSION-$BUILD_DATE
  243.  
  244. echo "Creating the kernel package"
  245. LINUX_FULL_PACKAGE_NAME=${LINUX_PACKAGE_NAME}-${LINUX_RELEASE_NUMBER}-${PACKAGE_NAME_SUFFIX}
  246. make INSTALL_MOD_PATH=$LINUX_FULL_PACKAGE_NAME modules_install
  247. rm $LINUX_FULL_PACKAGE_NAME/lib/modules/$LINUX_MAJOR_VERSION/{build,source}
  248. ln -s $LINUX_MAJOR_VERSION $LINUX_FULL_PACKAGE_NAME/lib/modules/$kernel_version
  249. mkdir $LINUX_FULL_PACKAGE_NAME/boot
  250. cp `find arch -name bzImage -type f` $LINUX_FULL_PACKAGE_NAME/boot/vmlinuz
  251. cp System.map $LINUX_FULL_PACKAGE_NAME/boot
  252. mv $LINUX_FULL_PACKAGE_NAME ../dist/packages
  253.  
  254. echo "Cleaning the kernel sources"
  255. make clean >> "$LOG_PATH" 2>&1
  256. make prepare >> "$LOG_PATH" 2>&1
  257.  
  258. cd ..
  259.  
  260. echo "Creating a kernel sources SFS"
  261. LINUX_SOURCES_FULL_PACKAGE_NAME=${LINUX_SOURCES_PACKAGE_NAME}-${LINUX_RELEASE_NUMBER}-${PACKAGE_NAME_SUFFIX}
  262. mkdir -p $LINUX_SOURCES_FULL_PACKAGE_NAME/usr/src
  263. mv linux-$kernel_version $LINUX_SOURCES_FULL_PACKAGE_NAME/usr/src/linux
  264. mkdir -p $LINUX_SOURCES_FULL_PACKAGE_NAME/lib/modules/$LINUX_MAJOR_VERSION
  265. ln -s /usr/src/linux $LINUX_SOURCES_FULL_PACKAGE_NAME/lib/modules/$LINUX_MAJOR_VERSION/build
  266. ln -s /usr/src/linux $LINUX_SOURCES_FULL_PACKAGE_NAME/lib/modules/$LINUX_MAJOR_VERSION/source
  267. mksquashfs $LINUX_SOURCES_FULL_PACKAGE_NAME dist/sources/$LINUX_SOURCES_FULL_PACKAGE_NAME.sfs
  268.  
  269. echo "Compressing the log"
  270. bzip2 -9 build.log
  271. cp build.log.bz2 dist/sources
  272.  
  273. echo "Done!"
  274. aplay /usr/share/sounds/2barks.au