#!/bin/bash PROGNAME=`basename $0` # ============================= Functions ============================ ############################## Debugging Functions ###################### function BUGPAUSE { echo " " echo "-----------------------------------------------------------" echo " MANUAL BUG CHECK!" echo " Is the program doing what you expect? Please " echo " review preceeding output for correctness. Thank you." echo "-----------------------------------------------------------" echo " " echo "Args so far:" echo "ARG1: $ARG1 " echo "ARG2: $ARG2 " echo "ARG3: $ARG3 " echo "ARG4: $ARG4 " echo " " ask "Continue? [Y/n]" y if [ $? -ne 0 ]; then { exit 100 } fi } #### #### # # Error Handler. # #### #### function ERROR { clear echo "----------------" echo "| ABEND: Code $1 |" echo "-------------------------------------------------------------------------" echo " Bummer! An error occurred!" echo " Don't you just hate it when..." echo "${2}?" echo "==========================" echo " Maybe this will help...." echo "==========================" SYNTAX exit $1 } #### #### # # - SYNTAX -------- Bet you cannot guess what this does. # #### #### function SYNTAX { MORE "Do you wish to view the Syntax for `VERSION`" y echo "SYNTAX: Program $PROGNAME" echo " " MORE "Do you wish to continue?" y echo "NOTES: " echo " " MORE "Do you wish to continue?" y echo "NOTES:" echo " " echo "**** End of help. Don't you wish there was more? ****" echo "Strike a key to exit help." read DUMMY return } #### #### # # MORE # #### #### function MORE() { ask "$1 [y/n]" $2 if [ $? -eq 0 ]; then return else exit 0 fi } #### #### # # - CHECKCMD --------- Locates the system cammands used by this script.------- # This makes sure the commands we need exist. If a command is missing, # this function will cause the script to abort. # #### #### function CHECKCMD { # Check for required *NIX executable commands. echo "---->In CHECKCMD...." for i in id seq echo hostname touch gcc make cp mv rm rsync mount smbmount ask; do which $i; if [ $? -ne 0 ]; then ERROR 1 "the command $i is missing from the system" fi; done } #### #### # # CHECK_HOST ----Aborts the program if the hostname keyfile is missing. # #### #### function CHECK_HOST() { AUTHORIZED_BACKUP_HOST=`cat /root/bin/snapback_hostkey` if [ $AUTHORIZED_BACKUP_HOST = `hostname` ]; then { echo "Host $AUTHORIZED_BACKUP_HOST validated." } else { ERROR 20 "When you try to run Snapback on an unauthorized backup host" } fi } #### #### # # - R_U_ROOT ----- Aborts the program if the person running it is not root. # #### #### function R_U_ROOT { ID=`id -u` if [ $ID -ne 0 ]; then { echo "$PROGNAME is a potentially dangerous program." echo "Therefore it is only to be run by the root user." echo "You appear to be running it as `id -nu`." echo "Please try again as root or have the system administrator run" echo "$PROGNAME for you." ERROR 10 "you forget to log in as root first" } fi } #### #### # # - GETARGS ----------- Converts command-line args to appropriate parameters. Otherwise, # it prompts for the necessary arguments. # #### #### function GETARGS { echo "IN GETARGS...." if [ -z $1 ]; then { echo "So what directory should we Do The Deed in?" read ARG1 if [ -z $ARG1 ]; then ERROR 30 "you forget to specify the compilation directory" fi } else { ARG1=$1 } fi echo $ARG1 | grep 'usr/src' if [ $? -eq 0 ]; then { ask "Compiling in /usr/src may be a no-no. Shall I continue anyway[y/N]?" n if [ $? -ne 0 ]; then ERROR 31 'you decide not to try to compile in /usr/src--a major no-no' else echo "Continuing in /usr/src..." fi } fi if [ -z $2 ]; then { echo "Please specify an option for parallel-compiling. This may speed up compilation on multiprocessor machines." read ARG2 if [ -z $ARG2 ]; then { echo "We are defaulting to j=2" ARG2=2 } fi } else ARG2=$2 fi } #### #### # # Reports the version for this program. # #### #### function VERSION { echo "$PROGNAME Version 04232k4-a-parallel, NEWSCRIPT Version 11132k3-a" } #======================================= No more functions. ========== ############################################################################# ################################# #################################### ################################# MAIN #################################### ################################# #################################### ############################################################################# case "$1" in v|V|-v|-V|--version|--VERSION|--Version|-version|-Version|-VERSION--ver|--Ver|--VER|-ver|-Ver|-VER) VERSION exit 0 ;; h|H|-h|-H|--help|--HELP|--Help|HELP|help|Help|-help|-HELP|-Help) SYNTAX exit 0 ;; esac #CHECK_HOST R_U_ROOT VERSION CHECKCMD GETARGS $1 $2 echo "IN MAIN-------->>>>>>>" cd $ARG1 # Check to make sure that the current directory contains a valid kernel source tree. if [ -f ./arch/i386/defconfig ]; then { echo "We appear to be in the correct directory." echo "Proceeding." } else ERROR 90 "when `pwd` does not contain a valid kernel source tree" fi # Do housekeeping. make mrproper make clean # Apply any patches (bz2 only. We don't do gzipped ones yet.) ask "Wanna patch the source tree? [y/N]" n if [ $? -eq 0 ]; then { PATCH_AGAIN=0 # Should loop repeatedly, giving user chance to apply multiple patches, # prompting to run again after each patch. Does not check for success of patch. while [ $PATCH_AGAIN -eq 0 ]; do { echo "Here is a listing of the available patches in this directory." echo "Note: We only look for .bz2 files in the kernel source-tree root that" echo "have \"patch\" in their names." echo "Please select a patch by entering its full name at the prompt." echo "===================================" ls | grep patch | grep bz2 echo "===================================" read DUMMY if [ -f $DUMMY ]; then { echo "Applying patch $DUMMY" bzcat $DUMMY | patch -p1 } else echo "$DUMMY is either mispelled or does not exist." fi ask "Wanna do another patch? [y/N]" n if [ $? -ne 0 ]; then PATCH_AGAIN=1 fi } done } fi ask "Make menuconfig? [Y/n]" y if [ $? -eq 0 ]; then make -j $ARG2 menuconfig fi for i in dep clean bzImage modules; do { clear echo "=============================================" echo "| Now doing this: ---> make $i <---" echo "=============================================" make -j $ARG2 $i if [ $? -ne 0 ]; then { ERR=$? clear ERROR $ERR "compilation messes up in $i" } fi } done ask "Install the new kernel and modules [y/N]" n if [ $? -eq 0 ]; then { KERNEL_RELEASE=`uname -r` echo "I have identified the CURRENTLY RUNNING kernel release as $KERNEL_RELEASE." ask "Are we compiling a new kernel based on $KERNEL_RELEASE?" if [ $? -eq 0 ]; then { echo "===============================================" echo "If you are patching/altering this kernel, we need to move the current modules" echo "out of the way so they don't get overwritten." echo "Remember:" echo "If something goes wrong, you can always move them back to the original" echo "directory." ask "Shall I continue? [Y/n]?" y if [ $? -eq 0 ]; then { mv /lib/modules/$KERNEL_RELEASE /lib/modules/${KERNEL_RELEASE}_OLD if [ $? -ne 0 ]; then ERROR 92 "we cannot move the original kernel modules" fi } fi } fi echo "I understand that the new kernel you have compiled " echo "is NOT a $KERNEL_RELEASE kernel." echo "This means that we don't need to worry about moving old modules." echo "But we need a directory to place the new modules in." echo "I really don't have any way of telling what the new kernel release" echo "since it could be named almost anything." echo "Examine previous output to see what the kernel release name is." echo "If you have applied patches, it may well be named for the last patch" echo "that you applied. Thus, if you applied a patch called" echo "patch-2.4.25-om-20040314.bz2, then the modules should probably live" echo "in /lib/modules/2.4.25-om." echo " " echo "Please tell me what directory to put the modules into:" read MOD_DIR echo "I will now make a directory for the modules at /lib/modules/$MOD_DIR." mkdir -p /lib/modules/$MOD_DIR if [ $? -eq 0 ]; then echo "Directory created." else ERROR 93 "we cannot make /lib/modules/$MOD_DIR" fi echo "Now attempting to install the new kernel...." make -j $ARG2 install if [ $? -ne 0 ]; then error 94 "we cannot get the kernel installed" fi echo "Now attempting to install the modules...." make -j $ARG2 modules_install if [ $? -ne 0 ]; then error 95 "we cannot get (all) the modules installed" fi } else echo "Kernel not installed. Install it with \"make modules install.\"" fi vi /etc/lilo.conf ask "Update the LILO configuration? [y/N]" n if [ $? -eq 0 ]; then lilo echo "--->>>Check preceding output for success of lilo update.<<<---" fi echo "End run-------------->>>>>>`basename $0`<<<<<<<".