Completely remove sendmail

At times it was noted that sendmail on my Debian system was not getting completely removed.

Thing tried:

apt-get remove sendmail*

It worked at times, and didnt at others.

But I were to try:

netstat -tulpn | grep :25
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      27878/sendmail: MTA

I’d find it again.

To find where it came from, I did:

 ls -l /proc/27878/
total 0
-r-------- 1 root root 0 Mar  5 12:47 auxv
-r--r--r-- 1 root root 0 Mar  5 11:58 cmdline
-rw-r--r-- 1 root root 0 Mar  5 12:47 coredump_filter
-r--r--r-- 1 root root 0 Mar  5 12:47 cpusete
lrwxrwxrwx 1 root root 0 Mar  5 12:47 cwd -> (deleted) /var/spool/mqueue
-r-------- 1 root root 0 Mar  5 12:47 environ
lrwxrwxrwx 1 root root 0 Mar  5 11:58 exe -> (deleted) /usr/lib/sm.bin/sendmail

Note that it shows /usr/lib/sm.bin/sendmail

However there is no /usr/lib/sm.bin, but there sure is a /usr/lib/sendmail

So I deleted them, and restarted the apache2 server.

 service apache2 restart
[ ok ] Restarting web server: apache2 ... waiting .
[email protected]:~/imscp# netstat -tulpn | grep :25
[email protected]:~/imscp# netstat -tulpn | grep 'sendmail'

Another thing that worked once was doing this:

chmod ugo=rw /etc/init.d/sendmail

In other words, I prevented it from running. But in the earlier instance there was no entry for sendmail under init.d

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Recursive upload a directory to remote ftp location

lftp is required.

The command is:

nohup lftp -e 'mirror -R /var/www/virtual/htdocs/kernels /kernel/htdocs' -u username,password ftp2.mydomain.in

The nohup is added to prevent disconnections until the process is completed.

-R indicates reverse transfer (from local to remote)

 

Normal lftp syntax (Manual method):

lftp -u username,password ftp.mydomain.in

Now you can use various commands like:

ls – list directory

rm – delete files

rm -r recursive delete a directory

You may wish to set certain options in the lftp config file at ~/.lftp/rc:

set ftp:ssl-allow 0
set ssl:verify-certificate no
set ftp:list-options -a
debug 3

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Batch Remove spaces from filenames, and convert upper case to lowercase via bash

Use the following script:

#!/bin/bash

ls | while read -r FILE
do
    mv -v "$FILE" `echo $FILE | tr ' ' '_' | tr -d '[{}(),\!]' | tr -d "\'" | tr '[A-Z]' '[a-z]' | sed 's/_-_/_/g'`
done

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

ls unknown option -h

This happens in Android shell because the ls in Android is provided by the kernel, and is limited. You can solve it by deleting the system version, after installing busybox. The bysbox version is capable.


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

.bashrc file

My customized .bashrc file follows:

alias l='ls -lh --color'
alias la='ls -lah --color'
alias download='curl -c - -O'
#PS1='\[\e[0;32m\]\u\[\e[m\] \[\e[1;34m\]\w\[\e[m\] \[\e[1;32m\]\$\[\e[m\] \[\e[1;37m\]'

#Blue prompt
PS1='\[\e[1;34m\][\u@\h \W]\$\[\e[0m\]'

#Green prompt
#PS1='\[\e[1;32m\][\u@\h \W]\$\[\e[0m\] '
PATH=$PATH:~/bash-advanced-scripts:~/toolchains/linux-x86/bin:/home/droidzone/android/adb

#Path to SDK
PATH=$PATH:~/android/envt/SoftwareDevelopmentKit/sdk/tools:~/android/envt/SoftwareDevelopmentKit/sdk/platform-tools

#Path to javac and java
PATH=$PATH:~/android/java/jdk1.7.0_09/bin

#apktool
PATH=$PATH:~/android/Apktool

#Java envt
JAVA_HOME=~/android/java/jdk1.7.0_09
export GREP_OPTIONS="--color -i -n"

d=.dircolors
test -r $d && eval "$(dircolors $d)"

My root bashrc /root/.bashrc is:

alias l='ls -l --color'                                                                                                                
alias download='curl -c - -O'                                                                                                          
#PS1='\[\e[0;32m\]\u\[\e[m\] \[\e[1;34m\]\w\[\e[m\] \[\e[1;32m\]\$\[\e[m\] \[\e[1;37m\]'                                               
PS1='\[\e[1;31m\][\u@\h \W]\$\[\e[0m\]'                                                                                                
#'\[\e[1;32m\][\u@\h \W]\$\[\e[0m\] '                                                                                                  
PATH=$PATH:~/bash-advanced-scripts:~/toolchains/linux-x86/bin:/home/droidzone/android/adb                                              

#Path to SDK                                                                                                                           
PATH=$PATH:~/android/envt/SoftwareDevelopmentKit/sdk/tools:~/android/envt/SoftwareDevelopmentKit/sdk/platform-tools                    

#Path to javac and java                                                                                                                
PATH=$PATH:~/android/java/jdk1.7.0_09/bin                                                                                              

#apktool                                                                                                                               
PATH=$PATH:~/android/Apktool                                                                                                           

#Java envt                                                                                                                             
JAVA_HOME=~/android/java/jdk1.7.0_09

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.
A better shell existence – Changing ls colors

A better shell existence – Changing ls colors

I wasnt satisfied with the default blue color shades for ls, and was exploring ways to change them. I happened to come across the dircolor resources.

To get the default ouput, do this:

dircolors -p > ~/.dircolorsrc

Once this is done, you get a modifiable file with colors for everything. Edit it to your whim.

Then to make sure that the codes get loaded, add the following to your ~/.bashrc:

d=.dircolors
test -r $d && eval "$(dircolors $d)"

More info can be found by:

info coreutils 'dircolors invocation'

coloredls

 

I finally decided on the following colors:

color1

I am attaching my .dircolor file.

Download “Roms” – Downloaded 0 times –

I chose

Dir-Orange Underline

Symlinks-Cyan

Pictures-Pink

Executables-Blue

Color chart:

# Below are the color init strings for the basic file types. A color init
# string consists of one or more of the following numeric codes:
# Attribute codes:
# 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
# Text color codes:
# 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37-39=white
# 
# Background color codes:
# 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Note2 Kernel building tutorial [Dump] [Draft-Alpha 0.0.1]

First get the defconfig:

ls -l ./arch/arm/configs[/code] 

-t0_04_defconfig

So,

cp arch/arm/configs/t0_04_defconfig ./.config[/code] 

Once that's done, execute:

make oldconfig

Now a new .config file is written to kernel root

Now you can execute a make, only to find that it errors out soon. The reason is of course a "-Werror" parameter in the main Makefile, which you can see if you do a:

grep -i -n '-Werror' Makefile[/code] 

So, edit the file in emacs, and remove the -Werror

It didnt still build and gave an error of the compiler not supporting arm

So downloaded the latest NDK android-ndk-r8c

wget http://dl.google.com/android/ndk/android-ndk-r8c-linux-x86.tar.bz2

Added the toolchain to $PATH, chose the toolchain, and hey presto! The kernel compiled without any errors! 😀 😀


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Making BASH simpler – dir and tree

Ubuntu by default has an alias to point to ls.

I find it much better to use a customized tree command instead.

Contents of file ltree:

#!/bin/bash
argu=$*
#ls --color=always $argu | less -R
tree -C $argu | less -R[/code]

I add the following to ~/.bashrc

alias dir='ltree'[/code]

Now on executing dir, I get a beautiful colored hierarchy of directories and files.

Other useful aliases are:
l='ls -l'
la='ls -la' #Included by default in Ubuntu


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Finding files modified within x days

If I want to find all files (recursively) modified within n days, I do:

find . -ctime [n] -exec ls -l {} ;

find . -ctime 0 -exec ls -l {} ;[/code]

The above command finds files modified today


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Kernel compilation menu script

Latest version:

#!/bin/bash

function msg {
echo -e 'E[37;44m'"33[1m$welcome33[0m"
}

function pushmin {
echo "Last kernel pack with no mods:"
echo "$lastminpack"
echo
read -p "Push to SD card?" -n 1
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
adb push $lastminpack /sdcard/
fi
}

function backup_menuconfig {
echo
if [ -e $kstartpath/.config ]
then
date_str=`date '+%d%m%y_%H%M%S'`
nname="config_$mnameflag_$date_str.txt"
echo "Your menuconfig information resides in .config"
echo "It will be backed up as $nname"
echo "You can change the name to config_[yournametag]_$date_str"
echo
read -p "Change the name?" -n 1
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo
read -p "Enter new nametag:"
mnameflag=$REPLY
nname="config_"$mnameflag"_"$date_str".txt"
echo "New name will be $nname"
echo
read -p "Hit a key to continue.."
fi
echo
cp $kstartpath/.config $kstartpath/$nname
if [ -e $kstartpath/$nname ]
then
echo "Current menuconfig info successfully backed up as $kstartpath/$nname"
echo
else
echo "Warning! An error occured while trying to backup .config"
echo "Read Only filesystems/permissions error?"
echo
fi
else
echo
echo "No .config information found at $kstartpath"
echo "Are you in the kernel source root directory? "
echo "Rerun script from correct location...Aborting!"
echo
fi
read -p "Hit a key to continue.."
menu
}

function pushmax {
echo "Last kernel pack with mods: "
echo "$lastmaxpack"
echo
read -p "Push to SD card?" -n 1
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
adb push $lastmaxpack /sdcard/
fi

}

function openlast {
echo
if [ ! "$lastfolder" = "" ]
then
echo "Last output folder is $lastfolder"
echo
read -p "Open it in file manager?" -n 1
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
if [ -e /usr/bin/dolphin ]
then
echo "Opening output folder in Dolphon"
dolphin $lastfolder
elif [ -e /usr/bin/nautilus ]
then
echo "Opening output folder in Nautilus"
nautilus $lastfolder
elif [ -e /usr/local/bin/mc ]
then
echo "Opening output folder in Midnight Commander"
mc $lastfolder
else
echo "No compatible file managers found. Aborting.."
fi
fi
else
echo "There is no logged last output folder!"
echo "Compile a kernel/create flashable zips before choosing this option!!"
fi
echo
read -p "Hit a key to continue.."
menu
}

function pushzip {
echo
echo "Push last packed zips to sdcard"
echo "==============================="

if [ "$lastminpack" = "" ] && [ "$lastmaxpack" = "" ]
then
echo "Generate a zip pack before trying to push it!"
read -p "Hit a key to continue.."
menu
elif [ "$lastminpack" = "" ]
then
pushmax
elif [ "$lastmaxpack" = "" ]
then
pushmin
else
pushmin
pushmax
fi

#menu
}

function disp_kfiles {
echo
echo "Display compiled files in Kernel directory"
echo "=========================================="
echo "Current Kernel path is : $kstartpath"
cd $kstartpath
echo
echo "Locating zImage:"
echo
find . -name 'zImage' -exec echo '{}' ;
echo
echo "Locating Modules:"
echo
find . -name '*.ko' -exec echo '{}' ;
read -p "Hit a key to continue.."
menu
}

function lflashery {
clear

if [ ! -d $ksource/arch ]
then
echo "The kernel location could not be located. Please re-run script from within kernel source root."
echo "Script will now terminate!"
exit 1
fi

echo " =============================================="
welcome=" FLASHABLE ZIP MAKER 1.0 by Droidzone "
msg
#echo " FLASHABLE ZIP MAKER 1.0 by Droidzone"
echo " =============================================="
echo "Output dir is " $outdir/home/droidzone/kernel_flashable
echo "Anykernel source is at " $anykdir
echo "Kernel source is at " $ksource
echo " "
echo "Creating target directories"

if [ ! -d $outdir ]; then mkdir $outdir; fi
if [ ! -d $packagedir ]; then mkdir $packagedir; fi
if [ ! -d $tempdir ]; then mkdir $tempdir; fi
#Copying the new kernel files

if [ ls $outdir/*.zip > /dev/null 2>&1 ]
then
rm $outdir/*.zip
fi

if [ ls $tempdir/README > /dev/null 2>&1 ]
then
rm $tempdir/README
fi

echo "Working in temporary directory: $tempdir"
cp -a $anykdir/* $tempdir/

sync

echo "Cleaning up remnants..."
if [ -e $outdir/kernel/zImage ]; then rm $outdir/kernel/zImage; fi

if [ ls $outdir/system/lib/modules/* > /dev/null 2>&1 ]
then
rm $outdir/system/lib/modules/*
fi

if [ -d $ksource ]
then
if [ ! -e $ksource/arch/arm/boot/zImage ]
then
echo "Kernel source location: $ksource/arch/arm/boot/zImage"

echo "zImage was not located at kernel location. Please re-run script from within kernel source root."
echo "Script will now terminate!"
exit 1
else
echo "Copying zImage..."
cp $ksource/arch/arm/boot/zImage $outdir/kernel/
fi
else
echo "Kernel source folder: $ksource"

echo "Kernel source folder not found! Please re-run script from within kernel source root."
echo "Script will now terminate!"
exit 1
fi
cd $outdir
echo "At temp location: $(pwd)...About to cleanup!"
read -p "Hit a key to continue!"

#Precleaning temp folder
find . -name '*.ko' -exec rm '{}' ;
find . -name '*~' -exec rm '{}' ;
find . -name 'README*' -exec rm '{}' ;

echo
echo "Cleaned up the temp directory."
echo "Temp directory contains the following modules:"
find . -name '*.ko' -exec echo '{}' ;
read -p "Hit a key to continue!"

cd $ksource

#find . -name '*.ko' -exec cp '{}' $outdir/system/lib/modules/ ;
echo "Adding Network Driver..."
find . -name 'bcm4329.ko' -exec cp '{}' $outdir/system/lib/modules/ ;
if [ ! -e $outdir/system/lib/modules/bcm4329.ko ]
then
echo "WARNING! Wifi module was not compiled. Aborting.."
exit 1
fi

date_str=`date '+%d%m%y_%H%M%S'`
dirname="kernel_$nameflag_$date_str"
echo
echo "Current dir name is $dirname"
echo "You can change the name to kernel_[yourname]_$date_str"
echo
read -p "Change the name?" -n 1
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
read -p "Enter new name:"
#echo "Repy is " $REPLY
nameflag=$REPLY
dirname="kernel_"$nameflag"_"$date_str
echo "New name will be $dirname"
echo
read -p "Hit a key to continue.."
fi

pckdir="$packagedir/$dirname"
mkdir $pckdir

lastfolder=$pckdir
cd $outdir/
echo
zipnoname="kbase_"$nameflag"_"$date_str
zipaddnoname="kmods_"$nameflag"_"$date_str
zipname=$zipnoname".zip"
zipaddname=$zipaddnoname".zip"
echo "Creating $zipname from $(pwd)"
zip -r $zipnoname ./
mv $zipname $pckdir/
#echo $packagedir
welcome="Created flashable zip: $pckdir/$zipname"
msg

read -p "Push to sdcard(N/y)?" -n 1
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
lastminpack=$pckdir"/"$zipname
adb push $pckdir/$zipname /sdcard/
fi

read -p 'Make Package with Additional Modules (N/y)?' -n 1
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo
cd $ksource
echo "Kernel source is at $ksource"

#find . -name '*.ko' -exec cp '{}' $outdir/system/lib/modules/ ;
echo "Adding Additional Modules (if any)..."
echo
echo "Found the following modules:"
find . -name '*.ko' -exec echo '{}' ;
echo
read -p "Hit a key to continue!"
find . -name '*.ko' -exec cp '{}' $outdir/system/lib/modules/ ;
read -p "Copying over. Hit a key to continue!"
cd $outdir/

echo "Creating $zipaddname from $(pwd)"
zip -r $zipaddnoname ./
mv $zipaddname $pckdir/
###############################

welcome="Created a Full flashable package at $pckdir/$zipaddname"
msg
echo

read -p "Push to sdcard(N/y)?" -n 1
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
lastmaxpack=$pckdir"/"$zipname
adb push $pckdir/$zipaddname /sdcard/
fi
fi

read -p "Open Output folder in Dolphin (N/y)?" -n 1
echo
if [[ $REPLY =~ ^[Nn]$ ]]
then
menu
exit 0
else
dolphin $pckdir &
exit 0
fi
menu
exit 0
}

function menuconf {
cd $kstartpath
echo
echo "Entering Menuconfig..."
#Working on Kubuntu
#make ARCH=arm CC="arm-linux-gcc" LD="arm-linux-ld" AR="arm-linux-ar" RANLIB="arm-linux-ranlib" AS="arm-linux-as" -j10 -i all
if [ ! -e ./Makefile ]
then
echo "This script should be executed from within the root directory of kernel"
echo "Makefile could not be located in your current location. Aborting..."
exit 1
fi
make ARCH=arm CROSS_COMPILE=$toolchain menuconfig
menu
}

function defconf {
cd $kstartpath
echo
echo "Generating defconfig"
make ARCH=arm CROSS_COMPILE=$toolchain bravo_defconfig
echo "Entering Menuconfig..."
#Working on Kubuntu
#make ARCH=arm CC="arm-linux-gcc" LD="arm-linux-ld" AR="arm-linux-ar" RANLIB="arm-linux-ranlib" AS="arm-linux-as" -j10 -i all
if [ ! -e ./Makefile ]
then
echo "This script should be executed from within the root directory of kernel"
echo "Makefile could not be located in your current location. Aborting..."
exit 1
fi
make ARCH=arm CROSS_COMPILE=$toolchain menuconfig
menu
}

function cleanup {
echo
echo "Cleaning up.."
make ARCH=arm CROSS_COMPILE=$toolchain clean
read -p "Hit a key to continue.."
menu
}

function toolch {
echo
echo "Current toolchain prefix is:$toolchain"
echo "Note that script will not add paths for you. Do it manually!"
echo
read -p "Enter new toolchain (including the -):"
tempchain=$REPLY
echo
echo "New toolchain will be set as $tempchain"
read -p "Confirm (y/N)?" -n 1
if [[ $REPLY =~ ^[Yy]$ ]]
then
toolchain=$tempchain
echo
echo "New toolchain prefix is now :$toolchain"
else
echo
echo "Ok, Nothing will be modified!"
fi
read -p "Hit a key to continue.."
menu
}

function disp_path () {
echo
echo "Current PATH is :"
echo "$PATH"
echo
read -p "Hit a key to continue.."
menu
}

function comp () {
echo
echo "Compiling Kernel..."
if [ ! -e ./Makefile ]
then
echo "This script should be executed from within the root directory of kernel"
echo "Makefile could not be located in your current location. Aborting..."
exit 1
fi
make ARCH=arm CROSS_COMPILE=$toolchain -j$jobs
if [ ! -e arch/arm/boot/zImage ]
then
echo "ERROR: An error occured. Kernel was not compiled."
exit 1
else
echo "Making Modules..."
echo
make ARCH=arm CROSS_COMPILE="arm-bravo-" modules
echo -en "07"
fi
read -p "Hit a key to continue.."
menu
}

function menu () {
clear
echo
echo " ======================================================="
welcome=" Kernel Compilation Script by Droidzone 01-11-2011 "
msg
echo " ======================================================="
echo
echo " (D)efault config"
echo " (E)rase - Make Clean"
echo " (M)enuconfig"
echo " (C)ompile now"
echo " (F)lashable zip maker"
echo " (P)ush last zip to sdcard"
echo " (O)pen last output folder"
echo
echo " (Q)uit"
echo
echo " Advanced Compilation Options"
echo " ----------------------------"
echo " 1. Change Toolchain prefix (Current : $toolchain )"
echo " 2. Pick a Toolchain from menu"
echo " 3. Change Number of simultaneous jobs (Current : $jobs )"
echo " 4. Display Current path"
echo " 5. Display Kernel Files"
echo " 6. Backup Menuconfig/.config"
echo
read -p " Choose an option :" -n 1
if [[ $REPLY =~ ^[1]$ ]]
then
echo
toolch
elif [[ $REPLY =~ ^[2]$ ]]
then
echo
tcmenu
elif [[ $REPLY =~ ^[4]$ ]]
then
echo
disp_path
elif [[ $REPLY =~ ^[5]$ ]]
then
echo
disp_kfiles
elif [[ $REPLY =~ ^[6]$ ]]
then
echo
backup_menuconfig
elif [[ $REPLY =~ ^[Dd]$ ]]
then
echo
defconf
elif [[ $REPLY =~ ^[Ee]$ ]]
then
echo
cleanup
elif [[ $REPLY =~ ^[Mm]$ ]]
then
echo
menuconf
elif [[ $REPLY =~ ^[Cc]$ ]]
then
echo
comp
elif [[ $REPLY =~ ^[Ff]$ ]]
then
echo
lflashery
elif [[ $REPLY =~ ^[Pp]$ ]]
then
echo
pushzip
elif [[ $REPLY =~ ^[Oo]$ ]]
then
echo
openlast
elif [[ $REPLY =~ ^[Qq]$ ]]
then
echo
exit 0
else
menu
fi
}

function additional () {
ksource=$(pwd)
read -p "Configure Menuconfig?" -n 1
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
menuconf
fi

if [ ! -d $outdir ]; then mkdir $outdir; fi
if [ ! -d $packagedir ]; then mkdir $packagedir; fi
if [ ! -d $tempdir ]; then mkdir $tempdir; fi
#Copying the new kernel files>

if ls $outdir/*.zip > /dev/null 2>&1
then
rm $outdir/*.zip
fi

if ls $tempdir/README > /dev/null 2>&1
then
rm $tem
fi
read -p "Compile Kernel now?" -n 1
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
comp
fi

echo
echo "Kernel compilation is over.."
welcome="Generated the following files:"
msgMm
find . -name 'zImage' -exec echo '{}' ;
find . -name '*.ko' -exec echo '{}' ;
echo ""
read -p "Make Flashable zip now?" -n 1
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]
then
lflashery
fi
menu
exit 0
}

function tcmenu () {
echo
echo "Available Toolchains"
echo "===================="
echo "1. arm-bravo-"
echo "2. NDK Toolchain: arm-linux-androideabi-"
echo
echo "Currently selected toolchain: $toolchain"
echo
read -p "Pick your toolchain:" -n 1
echo
if [[ $REPLY =~ ^[1]$ ]]
then
toolchain="arm-bravo-"
elif [[ $REPLY =~ ^[2]$ ]]
then
toolchain="arm-linux-androideabi-"
else
echo "Invalid choice!"
fi
echo
echo "Currently set as toolchain :$toolchain"
echo
read -p "Hit a key to continue.."
menu
}

#Compiled toolchain:
#toolchain="arm-bravo-"

#NDK
toolchain="arm-linux-androideabi-"
jobs=50
kstartpath=$(pwd)
lastfolder=""
nameflag="zImage"
anykdir=/home/droidzone/flasher/AnyKernel
ksource=$kstartpath
outdir=~/kernel_flashable
packagedir=/home/droidzone/flasher/outdir
tempdir=~/kernel_flashablezImage
mnameflag=""

#Main menu
menu
exit 0
[/code]

Older version follows:

#!/bin/bash

function msg {
echo -e 'E[37;44m'"33[1m$welcome33[0m"
}

function pushmin {
echo "Last kernel pack with no mods:"
echo "$lastminpack"
echo
read -p "Push to SD card?" -n 1
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
adb push $lastminpack /sdcard/
fi
}

function pushmax {
echo "Last kernel pack with mods: "
echo "$lastmaxpack"
echo
read -p "Push to SD card?" -n 1
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
adb push $lastmaxpack /sdcard/
fi

}

function pushzip {
echo
echo "Push last packed zips to sdcard"
echo "==============================="

if [ "$lastminpack" = "" ] && [ "$lastmaxpack" = "" ]
then
echo "Generate a zip pack before trying to push it!"
read -p "Hit a key to continue.."
menu
elif [ "$lastminpack" = "" ]
then
pushmax
elif [ "$lastmaxpack" = "" ]
then
pushmin
else
pushmin
pushmax
fi

#menu
}

function lflashery {
nameflag=""
clear
anykdir=/home/droidzone/flasher/AnyKernel
if [ ! -d $(pwd)/arch ]
then
echo "The kernel location could not be located. Please re-run script from within kernel source root."
echo "Script will now terminate!"
exit 1
fi
ksource=$(pwd)
outdir=~/kernel_flashable
packagedir=/home/droidzone/flasher/outdir
tempdir=~/kernel_flashable

echo " =============================================="
welcome=" FLASHABLE ZIP MAKER 1.0 by Droidzone "
msg
#echo " FLASHABLE ZIP MAKER 1.0 by Droidzone"
echo " =============================================="
echo "Output dir is " $outdir/home/droidzone/kernel_flashable
echo "Anykernel source is at " $anykdir
echo "Kernel source is at " $ksource
echo " "
echo "Creating target directories"

if [ ! -d $outdir ]; then mkdir $outdir; fi
if [ ! -d $packagedir ]; then mkdir $packagedir; fi
if [ ! -d $tempdir ]; then mkdir $tempdir; fi
#Copying the new kernel files

if [ ls $outdir/*.zip > /dev/null 2>&1 ]
then
rm $outdir/*.zip
fi

if [ ls $tempdir/README > /dev/null 2>&1 ]
then
rm $tempdir/README
fi

echo "Working in temporary directory: $tempdir"
cp -a $anykdir/* $tempdir/

sync

echo "Cleaning up remnants..."
if [ -e $outdir/kernel/zImage ]; then rm $outdir/kernel/zImage; fi

if [ ls $outdir/system/lib/modules/* > /dev/null 2>&1 ]
then
rm $outdir/system/lib/modules/*
fi

if [ -d $ksource ]
then
if [ ! -e $ksource/arch/arm/boot/zImage ]
then
echo "Kernel source location: $ksource/arch/arm/boot/zImage"

echo "zImage was not located at kernel location. Please re-run script from within kernel source root."
echo "Script will now terminate!"
exit 1
else
echo "Copying zImage..."
cp $ksource/arch/arm/boot/zImage $outdir/kernel/
fi
else
echo "Kernel source folder: $ksource"

echo "Kernel source folder not found! Please re-run script from within kernel source root."
echo "Script will now terminate!"
exit 1
fi
find . -name '*~' -exec rm '{}' ;
find . -name 'README*' -exec rm '{}' ;
#Precleaning temp folder
find . -name '*.ko' -exec rm '{}' ;

cd $ksource

#find . -name '*.ko' -exec cp '{}' $outdir/system/lib/modules/ ;
echo "Adding Network Driver..."
find . -name 'bcm4329.ko' -exec cp '{}' $outdir/system/lib/modules/ ;
if [ ! -e $outdir/system/lib/modules/bcm4329.ko ]
then
echo "WARNING! Wifi module was not compiled. Aborting.."
exit 1
fi

date_str=`date '+%d%m%y_%H%M%S'`
dirname="kernel_$nameflag_$date_str"

echo "Current dir name is $dirname"
echo "You can change the name to kernel_[yourname]_$date_str"
echo
read -p "Change the name?" -n 1
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
read -p "Enter new name:"
#echo "Repy is " $REPLY
nameflag=$REPLY
dirname="kernel_"$nameflag"_"$date_str
echo "New name will be $dirname"
echo
read -p "Hit a key to continue.."
fi

pckdir="$packagedir/$dirname"
mkdir $pckdir

cd $outdir/
echo
zipnoname="kbase_"$nameflag"_"$date_str
zipaddnoname="kmods_"$nameflag"_"$date_str
zipname=$zipnoname".zip"
zipaddname=$zipaddnoname".zip"
echo "Creating $zipname from $(pwd)"
zip -r $zipnoname ./
mv $zipname $pckdir/
#echo $packagedir
welcome="Created flashable zip: $pckdir/$zipname"
msg

read -p "Push to sdcard(N/y)?" -n 1
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
lastminpack=$pckdir"/"$zipname
adb push $pckdir/$zipname /sdcard/
fi

read -p 'Make Package with Additional Modules (N/y)?' -n 1
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo
cd $ksource

#find . -name '*.ko' -exec cp '{}' $outdir/system/lib/modules/ ;
echo "Adding Additional Modules (if any)..."
find . -name '*.ko' -exec cp '{}' $outdir/system/lib/modules/ ;

cd $outdir/

echo "Creating $zipaddname from $(pwd)"
zip -r $zipaddnoname ./
mv $zipaddname $pckdir/
###############################

welcome="Created a Full flashable package at $pckdir/$zipaddname"
msg
echo

read -p "Push to sdcard(N/y)?" -n 1
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
lastmaxpack=$pckdir"/"$zipname
adb push $pckdir/$zipaddname /sdcard/
fi
fi

read -p "Open Output folder in Dolphin (N/y)?" -n 1
echo
if [[ $REPLY =~ ^[Nn]$ ]]
then
menu
exit 0
else
dolphin $pckdir &
exit 0
fi
menu
exit 0
}

function menuconf {
echo
echo "Entering Menuconfig..."
#Working on Kubuntu
#make ARCH=arm CC="arm-linux-gcc" LD="arm-linux-ld" AR="arm-linux-ar" RANLIB="arm-linux-ranlib" AS="arm-linux-as" -j10 -i all
if [ ! -e ./Makefile ]
then
echo "This script should be executed from within the root directory of kernel"
echo "Makefile could not be located in your current location. Aborting..."
exit 1
fi
make ARCH=arm CROSS_COMPILE=$toolchain menuconfig
menu
}

function defconf {
echo
echo "Generating defconfig"
make ARCH=arm CROSS_COMPILE=$toolchain bravo_defconfig
echo "Entering Menuconfig..."
#Working on Kubuntu
#make ARCH=arm CC="arm-linux-gcc" LD="arm-linux-ld" AR="arm-linux-ar" RANLIB="arm-linux-ranlib" AS="arm-linux-as" -j10 -i all
if [ ! -e ./Makefile ]
then
echo "This script should be executed from within the root directory of kernel"
echo "Makefile could not be located in your current location. Aborting..."
exit 1
fi
make ARCH=arm CROSS_COMPILE=$toolchain menuconfig
menu
}

function cleanup {
echo
echo "Cleaning up.."
make ARCH=arm CROSS_COMPILE=$toolchain clean
read -p "Hit a key to continue.."
menu
}

function comp () {
echo
echo "Compiling Kernel..."
if [ ! -e ./Makefile ]
then
echo "This script should be executed from within the root directory of kernel"
echo "Makefile could not be located in your current location. Aborting..."
exit 1
fi
make ARCH=arm CROSS_COMPILE=$toolchain -j$jobs
if [ ! -e arch/arm/boot/zImage ]
then
echo "ERROR: An error occured. Kernel was not compiled."
exit 1
else
echo "Making Modules..."
echo
make ARCH=arm CROSS_COMPILE="arm-bravo-" modules
echo -en "07"
fi
read -p "Hit a key to continue.."
menu
}

function menu () {
clear
echo
echo "======================================================="
welcome="Kernel Compilation Script by Droidzone 01-11-2011"
msg
echo "======================================================="
echo
echo " (D)efault config"
echo " (E)rase - Make Clean"
echo " (M)enuconfig"
echo " (C)ompile now"
echo " (F)lashable zip maker"
echo " (P)ush last zip to sdcard"
echo " (Q)uit"
echo
echo " Advanced Compilation Options"
echo " ----------------------------"
echo " Change Toolchain prefix (Current : $toolchain )"
echo " Change Number of simultaneous jobs (Current : $jobs )"
echo
read -p "Choose an option :" -n 1
if [[ $REPLY =~ ^[Dd]$ ]]
then
echo
defconf
elif [[ $REPLY =~ ^[Ee]$ ]]
then
echo
cleanup
elif [[ $REPLY =~ ^[Mm]$ ]]
then
echo
menuconf
elif [[ $REPLY =~ ^[Cc]$ ]]
then
echo
comp
elif [[ $REPLY =~ ^[Ff]$ ]]
then
echo
lflashery
elif [[ $REPLY =~ ^[Pp]$ ]]
then
echo
pushzip
elif [[ $REPLY =~ ^[Qq]$ ]]
then
echo
exit 0
else
menu
fi
}

function additional () {
ksource=$(pwd)
read -p "Configure Menuconfig?" -n 1
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
menuconf
fi

if [ ! -d $outdir ]; then mkdir $outdir; fi
if [ ! -d $packagedir ]; then mkdir $packagedir; fi
if [ ! -d $tempdir ]; then mkdir $tempdir; fi
#Copying the new kernel files>

if ls $outdir/*.zip > /dev/null 2>&1
then
rm $outdir/*.zip
fi

if ls $tempdir/README > /dev/null 2>&1
then
rm $tem
fi
read -p "Compile Kernel now?" -n 1
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
comp
fi

echo
echo "Kernel compilation is over.."
welcome="Generated the following files:"
msgMm
find . -name 'zImage' -exec echo '{}' ;
find . -name '*.ko' -exec echo '{}' ;
echo ""
read -p "Make Flashable zip now?" -n 1
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]
then
lflashery
fi
menu
exit 0
}

toolchain="arm-bravo-"
jobs=50
#Main menu
menu
exit 0
[/code]


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.