- #!/bin/bash
- ###########################
- ## Instructions by Eric ##
- ###########################
- ##### ATTRIBUTES ################################
- CURRENT_KERNEL=NOT_SET_YET
- NEW_KERNEL=NOT_SET_YET
- ##### METHODS ################################
- setEnv() {
- MAINDIR=/root/sysadmin/kernel
- LOG=$MAINDIR/kernel_build.log
- }
- log() {
- # print a log message to stdout
- echo `date` " -- $1" | tee -a $LOG
- }
- getCurrentVersion() {
- # determine the current kernel version by parsing what /usr/src/linux is linked to
- log " called getCurrentVersion() (STUB)..."
- CURRENT_KERNEL=2.6.17-gentoo-r4
- }
- getNewestVersion() {
- # determine the newest kernel version by parsing all directory names in /usr/src
- log " called getNewestVersion() (STUB)..."
- NEW_KERNEL=2.6.17-gentoo-r7
- }
- ##### MAIN ###################################
- log "Starting..."
- setEnv
- # ensure we're ready to do this
- getCurrentVersion
- getNewestVersion
- if [ "${CURRENT_KERNEL}" == NOT_SET_YET ]
- then
- log "FAILURE: CURRENT_KERNET is not set ( ${CURRENT_KERNEL} )"
- exit 666
- fi
- if [ "${NEW_KERNEL}" == NOT_SET_YET ]
- then
- log "FAILURE: NEW_KERNET is not set ( ${NEW_KERNEL} )"
- exit 666
- fi
- if [ "${NEW_KERNEL}" == "${CURRENT_KERNEL}" ]
- then
- log "FAILURE: NEW_KERNEL $NEW_KERNEL matches CURRENT_KERNEL $CURRENT_KERNEL"
- exit 1
- fi
- # ensure we have most recent updates of linux source
- log " emerge gentoo-sources..."
- #emerge gentoo-sources
- # link to newest source
- log " relink /usr/src/linux..."
- cd /usr/src
- rm linux
- ln -s /usr/src/linux-${NEW_KERNEL} /usr/src/linux
- cd /usr/src/linux
- # The above line will change to whatever version is present in /usr/src
- # do NOT pull in your existing kernel config to use here UNLESS...
- # per Gentoo handbook, it's only safe to use old config when changing gentoo-r?? releases (i.e. r4 to r5), and NOT larger releases (i.e. 2.6.11 to 2.6.12)
- log " copy existing config..."
- cp /usr/src/linux-$CURRENT_KERNEL/.config /usr/src/linux-$NEW_KERNEL/
- # run MenuConfig to review/set kernel parameters
- log " launch menuconfig..."
- make menuconfig
- # Now enable/disable anything that you have decided that you want or no longer need
- # do the compilation, kernel copy to /boot, and the module installation
- log " build and install the new kernel..."
- make && make install && make modules_install
- # here are the manual steps accomplished by "make install"
- # cp System.map /boot/System.map-linux-2.6.10-gentoo-r7
- # cp .config /boot/config-linux-2.6.10-gentoo-r7
- # cp arch/i386/boot/bzImage /boot/kernel-linux-2.6.10-gentoo-r7
- log " now add new entry /boot/grub/grub.conf pointing to the new kernel. "
- log " do NOT remove the entry for your old kernel until you are sure that this one works correctly."
- GRUB=/boot/grub/grub.conf
- mount /boot
- echo " " >> $GRUB
- echo "title Gentoo Linux ($NEW_KERNEL) - TESTING" >> $GRUB
- echo "root (hd0,0)" >> $GRUB
- echo "kernel /vmlinuz-$NEW_KERNEL root=/dev/hda3 udev" >> $GRUB
- echo " " >> $GRUB
- log " Now, ( is reboot necessary???) re-emerge any additional modules that you may have for this new kernel, i.e. wireless, video, etc."
- ACCEPT_KEYWORDS="~x86" module-rebuild rebuild
- log "Finished."