Following is a script file called KLIST, version 1.10, which is a companion to the S.A.K.C. script and its purpose is to do the following:
- List all kernel source files in your default (~/Downloads) Folder.
- Allow you to select the kernel to compile, by entering a number from a list without knowing the exact name beforehand.
- Change to the default kernel compile folder (~/Kernel).
- Start S.A.K.C. with the name and path to the kernel source file you selected.
This latest version of KLIST validates user input as an integer, in the range of Kernel Source files found, exits if no files are found, ignores invalid entries and looks for a Q to quit if desired. More comments have been added to the script and the error messages expanded.
KLIST requires that you make the following three entries correct, shown below.
#
# Please Make Sure these names are correct - Do not include a "/" at the end...
#
# Where do your Keep Your Kernel Source Files?
kernel_folder=~/Downloads
# Where do you want to place your Compiled Kernels?
compile_folder=~/Kernel
# Where is SAKC located and what is it called (folder/name)
sakc_name=~/bin/sakc
The new text Display Looks like this:
KLIST - Kernel Source File Lister for S.A.K.C. - V 1.10
S.A.K.C. Location/Name: /home/james/bin/sakc
Kernel Compile Folder: /home/james/Kernel
Kernel Source Folder: /home/james/Downloads
- linux-2.6.35.10.tar.bz2
- linux-2.6.35.9.tar.bz2
- linux-2.6.36.2.tar.bz2
- linux-2.6.37-rc7.tar.bz2
- linux-2.6.37-rc8.tar.bz2
Enter the Kernel Source File Number to Compile (q=Quit):
For KLIST to work, You have already downloaded and made active the S.A.K.C. script file.
Copy and Paste the text of this script into a text editor and save it as the file klist in your home area bin folder (~/bin/klist).
#!/bin/bash
#: Title : klist - Kernel Source File Lister/Selector for S.A.K.C.
#: Date Created: Sun Dec 19 17:39:18 CST 2010
#: Last Edit : Thu Dec 30 19:44:00 CST 2010
#: Author : J. McDaniel
#: Version : 1.10
#: Description : list kernel source files for one to be selected for use with S.A.K.C.
#: Options : klist [kerenl_source_file.tar.bz2]
#
#
# Written for the openSUSE forums on Thursday December 30, 2010
#
TITLE="KLIST - Kernel Source File Lister for S.A.K.C. - V 1.10"
#
# Copy and Paste the text of this script into a text editor and save
# it as the file klist in your home area bin folder (~/bin/klist).
# This script must be marked executable to be used. Please run
# the following Terminal command: chmod +x ~/bin/klist
# To use klist, download the latest kernel source files from ...
# http://www.kernel.org/ into your download(s) folder.
# Open up a terminal session, change to your download(s) folder
# and run the command: klist
#
#
# Please Make Sure these names are correct - Do not include a "/" at the end...
#
# Where do your Keep Your Kernel Source Files?
kernel_folder=~/Downloads
# Where do you want to place your Compiled Kernels?
compile_folder=~/Kernel
# Where is SAKC located and what is it called (folder/name)
sakc_name=~/bin/sakc
#
# Common Text to Display When an Error is Detected
#
function error_message {
tput clear
echo "$TITLE"
echo
echo "$1"
echo
}
#
# Check to make sure klist was not started as Root
#
if $UID -eq 0 ] ; then
error_message "Please Do Not Run $0 as a Root User!"
exit 1
fi
#
# Make sure the sakc script file exists in the folder specified
#
if ! -e "$sakc_name" ] ; then
error_message "The S.A.K.C. Kernel Source File Compiler: $sakc_name, was not found!"
exit 1
fi
#
# Determine if the compile_folder exists
#
if -d "$compile_folder" ]] ; then
cd "$compile_folder"
else
error_message "The Kernel Compile Folder: $compile_folder, does not exist!"
echo "Please create or change this folder name and start $(basename $0) again."
echo
exit 1
fi
#
# Determine if a kernel file name was given at start
#
if $# -eq 0 ] ; then
#
# Determine if the kernel_folder (default is ~/Downloads) Exists
#
if -d "$kernel_folder" ]] ; then
menu=true
while $menu ; do
tput clear
echo "$TITLE"
echo
echo "S.A.K.C. Location/Name: $sakc_name"
echo
echo " Kernel Compile Folder: $compile_folder"
echo " Kernel Source Folder: $kernel_folder"
echo
counter=0
declare -a kernels
#
# Find and display all files that start with linux* and end with .tar.bz2
#
for i in "$kernel_folder"/linux*.tar.bz2 ; do
#
# Determine if the kernel source file exists
#
if -f $i ] ; then
let counter=counter+1
kernels$counter]=$i
echo " $counter) $(basename ${kernels$counter]})"
fi
done
#
# Determine if any Kernel Source Files were found
#
if $counter -eq 0 ]]; then
echo
echo "No Kernel Source Files were found in $kernel_folder!"
echo
exit 1
fi
#
# Main Program Prompt Displayed Here
#
echo
echo -n "Enter the Kernel Source File Number to Compile (q=Quit): "
read CHOICE
#
# Determine if input ($CHOICE) is an integer number and in range, look for Q to
# Quit. If menu is not set to false, the menu will just be redisplayed as you
# did not enter a valid menu option number for a kernel source file to compile.
#
if $CHOICE =~ ^[0-9]+$ ]] ; then
if $CHOICE -le $counter ]] && $CHOICE -gt 0 ]]; then
menu=false
fi
else
if $CHOICE == [Qq] ]] ; then
exit 0
fi
fi
done
$sakc_name ${kernels$CHOICE]}
else
#
# The Kernel Source File Folder (default=~/Downloads) was not found
#
error_message "The Kernel Source File Folder: $kernel_folder, does not exist!"
exit 1
fi
exit 0
else
#
# For this to be used, you suplied the full name/path to the kernel
# and just switched to your kernel compile folder
#
$sakc_name %1
fi
exit 0
# End Of Script
This script must be marked executable to be used. Please run the following Terminal command:
chmod +x ~/bin/klist
To use klist, download the latest kernel source files from ...
The Linux Kernel Archives
and save the source file into your downloads folder. Open up a terminal session and run the command:
klist
Again, you must already have the S.A.K.C. script file on your computer before you can use klist. If you have any comments, problems or requests, please let me know.
Thank You,