Skip to content

Commit

Permalink
Added new --is-new-kernel-available option.
Browse files Browse the repository at this point in the history
Version bumped accordingly to 1.0.5.
  • Loading branch information
sakaki- committed Sep 4, 2014
1 parent 9183bdd commit 7806216
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
35 changes: 31 additions & 4 deletions buildkernel
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ shopt -s nullglob
# ********************** variables *********************
PROGNAME="$(basename "${0}")"
CONFFILE="/etc/${PROGNAME}.conf"
VERSION="1.0.4"
VERSION="1.0.5"
DEFAULTEFIBOOTFILE="bootx64.efi"
EFIBOOTFILE="${DEFAULTEFIBOOTFILE}"
NEWVERSION="$(basename $(realpath "/usr/src/linux"))"
Expand Down Expand Up @@ -146,7 +146,7 @@ declare -i MOUNTEDONENTRY=0
declare -i ARG_ASK=0 ARG_CLEAN=0 ARG_COPYFROMSTAGING=0 ARG_HELP=0
declare -i ARG_STAGEONLY=0 ARG_UNMOUNTATEND=0 ARG_VERBOSE=0 ARG_VERSION=0
declare -i ARG_POSTCLEAR=0 ARG_MENUCONFIG=0 ARG_SNAPSHOTBACKUP=0
declare -i ARG_EASYSETUP=0
declare -i ARG_EASYSETUP=0 ARG_IS_NEW_KERNEL_AVAILABLE=0

# ***************** various functions ******************
cleanup_and_exit_with_code() {
Expand Down Expand Up @@ -1483,7 +1483,14 @@ kernel_build_pass_1() {
}
rebuild_external_modules_if_necessary() {
show "Creating any necessary external modules (e.g., VirtualBox)..."
emerge ${VERBOSITYFLAG} @module-rebuild
if ! emerge ${VERBOSITYFLAG} --noreplace @module-rebuild; then
if MAKEOPTS="${MAKEOPTS-} -j1" emerge --resume; then
warning "emerge @module-rebuild completed successfully, but only by restricting"
warning "build parallelism"
else
die "Failed to complete emerge @module-rebuild due to error"
fi
fi
}
create_initramfs_using_genkernel() {
show "Creating initramfs (uncompressed)..."
Expand Down Expand Up @@ -1748,6 +1755,10 @@ Options:
use this option after compiling a kernel with
--stage-only, to copy it to the EFI system partition
-h, --help show this help message and exit
-i, --is-new-kernel-available
return with code 0 if the currently-running kernel has
a different version from that built in the staging area
(at /boot), or 1 otherwise
-m, --menuconfig show kernel configuration GUI, even if non-interactive
-p, --postclear clear genkernel temporary files and caches after run
-s, --stage-only prepare kernel in /boot as usual, but do not copy
Expand Down Expand Up @@ -1795,12 +1806,25 @@ snapshot_kernel_on_efi_partition() {
backup_prior_config_if_present "${TIMESTAMP_PREFIX}"
finalize_efi_partition_and_unmount_if_desired
}
exit_zero_if_new_kernel_available() {
# simple test - is the currently running kernel the same as the one
# present in the staging area?
# exit with code 0 if it is not (i.e., a new kernel IS available), or 1
# if it is
if [[ "${CURRENTVERSION}" != "${NEWVERSION}" && \
(-s "${BOOTDIR}/${VMLINUZNAME}" || -s "${BOOTDIR}/${VMLINUZNAME}${SIGNEDSUFFIX}")]]; then
cleanup_and_exit_with_code 0
else
# up to date, or no new kernel available, so th
cleanup_and_exit_with_code 1
fi
}
process_command_line_options() {
local TEMP
declare -i RC
set +e
# error trapping off, as we want to handle errors
TEMP="$(getopt -o abcefhmpsuvV --long ask,snapshot-backup,clean,easy-setup,copy-from-staging,help,menuconfig,postclear,stage-only,verbose,unmount-at-end,version -n "${PROGNAME}" -- "${@}")"
TEMP="$(getopt -o abcefhimpsuvV --long ask,snapshot-backup,clean,easy-setup,copy-from-staging,help,is-new-kernel-available,menuconfig,postclear,stage-only,verbose,unmount-at-end,version -n "${PROGNAME}" -- "${@}")"
RC="${?}"
set -e
if ((RC!=0)); then
Expand All @@ -1817,6 +1841,7 @@ process_command_line_options() {
-e|--easy-setup) ARG_EASYSETUP=1 ; shift ;;
-f|--copy-from-staging) ARG_COPYFROMSTAGING=1 ; shift ;;
-h|--help) ARG_HELP=1 ; shift ;;
-i|--is-new-kernel-available) ARG_IS_NEW_KERNEL_AVAILABLE=1 ; shift ;;
-m|--menuconfig) ARG_MENUCONFIG=1 ; shift ;;
-p|--postclear) ARG_POSTCLEAR=1 ; shift ;;
-s|--stage-only) ARG_STAGEONLY=1 ; shift ;;
Expand Down Expand Up @@ -1854,6 +1879,8 @@ process_command_line_options() {
if ((ARG_SNAPSHOTBACKUP==1)); then
snapshot_kernel_on_efi_partition
cleanup_and_exit_with_code 0
elif ((ARG_IS_NEW_KERNEL_AVAILABLE==1)); then
exit_zero_if_new_kernel_available
fi
}

Expand Down
17 changes: 16 additions & 1 deletion buildkernel.8
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH BUILDKERNEL 8 "Version 1.0.4: August 2014"
.TH BUILDKERNEL 8 "Version 1.0.5: September 2014"
.SH NAME
buildkernel \- build secure boot kernel, save to EFI system partition
.SH SYNOPSIS
Expand Down Expand Up @@ -121,6 +121,14 @@ is specified, only copying.
.BR \-h ", " \-\-help
Displays a short help screen, and exits.
.TP
.BR \-i ", " \-\-is\-new\-kernel\-available
Returns an exit code of 0 if there is a kernel built in the staging area with
the same version as the kernel tree pointed to by \fI/usr/src/linux\fR,
\fBand\fR this is different to the version of the currently running kernel.
(Note, this does not check whether the kernel has been copied to the EFI
system partition.)
Returns an exit code of 1 otherwise.
.TP
.BR \-m ", " \-\-menuconfig
Specifies that the GUI-based kernel configuration step (\fBmake menuconfig\fR)
should be performed at the appropriate stage in the process
Expand Down Expand Up @@ -191,6 +199,13 @@ The exit status is 0 if the kernel build completed successfully, and 1 otherwise
\fBbuildkernel\fR currently executes the kernel build process as the root user.
It would be a little more hygienic to build as a non-priveleged user, and then
install as root.

Note also that if have installed a package that uses external modules (such as
VirtualBox), you will need to re-run \fBemerge @module-rebuild\fR once rebooted
under your new kernel (as this set takes its version from the
currently running kernel).
A post-reboot run of \fBgenup\fR(8) will achieve this.

.SH COPYRIGHT
.nf
Copyright \(co 2014 sakaki
Expand Down
2 changes: 1 addition & 1 deletion buildkernel.conf.5
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH BUILDKERNEL 5 "Version 1.0.4: August 2014"
.TH BUILDKERNEL 5 "Version 1.0.5: September 2014"
.SH NAME
buildkernel.conf \- a configuration file for \fBbuildkernel\fR(8)
.SH SYNOPSIS
Expand Down

0 comments on commit 7806216

Please sign in to comment.