#!/bin/bash # relative to ./patch/ PATCHFILE="cx231xx-Add-support-for-OTG102-aka-EZGrabber2.patch" if [ "`pwd`" = "$HOME" ]; then echo "error: do not run this script in your home directory" >&2 exit 1 fi # set up directory structure mkdir -p rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS} tmp # target kernel version; this is used instead of `uname -r` # If this script is successful, the target version is saved to tmp/UNAME_R, # which is read by ./build and ./install UNAME_R_FILE="tmp/UNAME_R" UNAME_R="`rpm -q kernel --last | head -n1 | sed -e 's/^kernel-//g' -e 's/\s.*//g'`" # remove $UNAME_R_FILE for now so that ./build and ./install will fail rm -f "$UNAME_R_FILE" # set up rpmbuild rm -rf rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS} # keep SRPMS mkdir -p rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS} # check to see if the source for the latest installed kernel is available yumdownloader --urls --source kernel # run once so the user can see repo download progress PKGNAME="kernel-`egrep -o '^.*\.fc[0-9]+' <<< "$UNAME_R"`" URLBASENAME="$(basename "`yumdownloader --urls --source "$PKGNAME" | tail -n1`")" SRPMBASENAME="$(sed "s/\\.`uname -m`$//" <<< "$URLBASENAME")" if [ "$URLBASENAME" != "$SRPMBASENAME" ]; then echo "error: you do not have the latest kernel installed. Please fix that first." >&2 exit 1 fi # download kernel SRPM if necessary and prepare the source tree SRPM="rpmbuild/SRPMS/$SRPMBASENAME" TOPDIR="`pwd`/rpmbuild" if [ ! -e "$SRPM" ]; then # use a tmp directory first so that existing partial downloads will be ignored/overwritten yumdownloader --destdir=tmp --source "$PKGNAME" mv tmp/"$SRPMBASENAME" "$SRPM" fi sudo yum-builddep "$SRPM" rpm --define "_topdir $TOPDIR" -Uvh "$SRPM" cd rpmbuild/SPECS rpmbuild --define "_topdir $TOPDIR" -bp --target=`uname -m` kernel.spec cd ../BUILD/kernel-`egrep -o '^[0-9]+\.[0-9]+' <<< "$UNAME_R"`.`egrep -o 'fc[0-9]+' <<< "$UNAME_R"` cd linux-"$UNAME_R" # apply the patch and configure the kernel patch -p1 -F1 -s < ../../../../patch/"$PATCHFILE" R=$? if [ $R -ne 0 ]; then echo "error: problem applying patch" >&2 exit $R fi cp -a /boot/config-"$UNAME_R" .config cp -a /lib/modules/"$UNAME_R"/build/Module.symvers . sed -i.bak -r "s/^EXTRAVERSION ?= ?$/EXTRAVERSION = `grep -o -- '-.*$' <<< "$UNAME_R"`/" Makefile make oldconfig make scripts make prepare # write out the target version to $UNAME_R_FILE R=$? [ $R -eq 0 ] && echo -n "$UNAME_R" > ../../../../"$UNAME_R_FILE" || exit $R