From 687f61effcd6e37da42a65d64de0937c8cb12c2c Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Sat, 10 Sep 2016 21:30:23 +0200 Subject: sollte erst mal gehen ... mal sehen --- .gitignore | 1 + Makefile | 7 +- makekernel.8.in | 0 makekernel.conf | 19 ------ makekernel.conf.in | 21 ++++++ makekernel.in | 195 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 221 insertions(+), 22 deletions(-) create mode 100644 makekernel.8.in delete mode 100644 makekernel.conf create mode 100644 makekernel.conf.in create mode 100644 makekernel.in diff --git a/.gitignore b/.gitignore index 9ebea17..2025a2e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.ori makekernel +makekernel.conf makekernel.8 diff --git a/Makefile b/Makefile index b939797..0fc6937 100644 --- a/Makefile +++ b/Makefile @@ -23,13 +23,14 @@ DESTDIR = ETCDIR = /etc BINDIR = /usr/bin MANDIR = /usr/share/man +SRCDIR = /usr/src VERSION = 0.0 -all: makekernel makekernel.8 +all: makekernel makekernel.conf makekernel.8 %: %.in - sed "s/#VERSION#/$(VERSION)/; s@#BINDIR#@$(BINDIR)@; s@#ETCDIR#@$(ETCDIR)@" $< > $@ + sed "s@#VERSION#@$(VERSION)@g; s@#BINDIR#@$(BINDIR)@g; s@#ETCDIR#@$(ETCDIR)@g; s@#SRCDIR#@$(SRCDIR)@g" $< > $@ .PHONY: install dist clean @@ -39,7 +40,7 @@ install: all install -D -m0644 makekernel.conf $(DESTDIR)$(ETCDIR)/makekernel.conf clean: - rm -f makekernel makekernel.8 + rm -f makekernel makekernel.conf makekernel.8 dist: clean git status --porcelain 2> /dev/null | grep -q "\S" && (git add .; git commit -m"neue Version: $(VERSION)") || true diff --git a/makekernel.8.in b/makekernel.8.in new file mode 100644 index 0000000..e69de29 diff --git a/makekernel.conf b/makekernel.conf deleted file mode 100644 index 32fe109..0000000 --- a/makekernel.conf +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -before_install_hook() { - mount -o remount,rw /boot -} - -after_install_hook() { - summen="$(sha512sum /boot/grub/grub.cfg /boot/vmlinuz-*)" - original=$(mount | grep '^[^ ]* on /boot' | awk '{print $1;}') - kopie=$(mdadm --detail /dev/disk/by-uuid/080c93f3-0c76-4821-b72f-3d1b7d807a70 | tail -n2 | sed 's/2$/1/' | grep -v "${original}" | sed 's/.* //') - echo "${summen}" - echo "${original}" - echo "${kopie}" - umount /boot || exit 1 - dd if="${original}" of="${kopie}" bs=1M || (sync; mount /boot; exit 1) || exit 1 - sync || exit 1 - mount "${kopie}" /boot -o ro || exit 1 - echo -ne "${summen}" | sha512sum -c || exit 1 -} diff --git a/makekernel.conf.in b/makekernel.conf.in new file mode 100644 index 0000000..a5053c0 --- /dev/null +++ b/makekernel.conf.in @@ -0,0 +1,21 @@ +#!/bin/bash + +kernelDir=#SRCDIR#/kernel + +before_install_hook() { + mount -o remount,rw /boot +} + +after_install_hook() { + summen="$(sha512sum /boot/grub/grub.cfg /boot/vmlinuz-*)" + original=$(mount | grep '^[^ ]* on /boot' | awk '{print $1;}') + kopie=$(mdadm --detail /dev/disk/by-uuid/080c93f3-0c76-4821-b72f-3d1b7d807a70 | tail -n2 | sed 's/2$/1/' | grep -v "${original}" | sed 's/.* //') + echo "${summen}" + echo "${original}" + echo "${kopie}" + umount /boot || exit 1 + dd if="${original}" of="${kopie}" bs=1M || (sync; mount /boot; exit 1) || exit 1 + sync || exit 1 + mount "${kopie}" /boot -o ro || exit 1 + echo -ne "${summen}" | sha512sum -c || exit 1 +} diff --git a/makekernel.in b/makekernel.in new file mode 100644 index 0000000..d508dac --- /dev/null +++ b/makekernel.in @@ -0,0 +1,195 @@ +#!/bin/bash + +set -e + +usage () { + >&2 echo 'makekernel version #VERSION#' + >&2 echo 'usage:' + >&2 echo ' makekernel [ -a | --allowDownload ] [ -c $version | --compileVersion=$version ]:' + >&2 echo ' download and compile kernel' + >&2 echo ' -a | --allowDownload:' + >&2 echo ' allow to download complete source instead of patch if necessary' + >&2 echo ' -c | --compileVersion $version:' + >&2 echo ' download and compile version $version instead of most current stable' + >&2 echo ' makekernel ( -s | --showVersion ):' + >&2 echo ' show version of most current stable kernel' + exit 1 +} + +dlExVer () { + wget -nd "$1.xz" + wget -nd "$1.sig" + xz -d "$2.xz" + if ! gpg --verify $2{.sign,} + then + >&2 echo 'ERROR: Wrong signature! Closing.' + exit 1 + fi + rm "$2.sign" +} + +. #ETCDIR#/makekernel.conf + +if [ "$(whoami)" == "root" ] +then + >&2 echo 'ERROR: Do not call as root! Closing.' + exit 1 +fi + +eval set -- "$( + getopt -o ac:s \ + --long allowDownload \ + --long compileVersion: \ + --long showVersion \ + -n "$(basename "$0")" \ + -- "$@" || echo usage +)" + +allowDownload=false +forceVersion=false +showVersion=false + +while true +do + case "$1" in + -a|--allowDownload) + ${allowDownload} && usage + ${showVersion} && usage + allowDownload=true + ;; + -c|--compileVersion) + ${forceVersion} && usage + ${showVersion} && usage + curVer="$2" + forceVersion=true + shift + ;; + -s|--showVersion) + ${allowDownload} && usage + ${forceVersion} && usage + ${showVersion} && usage + showVersion=true + ;; + --) + shift + break + ;; + *) + >&2 echo "ERROR: Option \"$1\" unknown in the end! Closing." + usage + esac + shift +done + +[ $# -ne 0 ] && usage + +if ${showVersion} +then + mainVersion="$( + curl 'https://cdn.kernel.org/pub/linux/kernel/' 2> /dev/null | \ + tr '>/' '\n' | \ + grep '^v.*$' | \ + sort -V | \ + tail -n1 + )" + curl "https://cdn.kernel.org/pub/linux/kernel/${mainVersion}/" 2> /dev/null | \ + tr '<>' '\n\n' | \ + grep '^linux-.*\.tar\.xz$' | \ + sed 's/^linux-\(.*\)\.tar\.xz$/\1/' | \ + sort -V | \ + tail -n1 + exit 0 +fi + +[ -z "${curVer}" ] && curVer="$("$0" -s)" +mainVer="$( + echo "${curVer}" | \ + sed 's|^\([0-9]\+\.[0-9]\+\)\(\..*\)\?$|\1|' +)" +if [ "${curVer}" == "${mainVer}" ] +then + minPreVer='#invalid#' + mainPreVer="${curVer%.*}.$[${curVer##*.}-1]" +else + minPreVer="${mainVer}.$[${curVer##*.}-1]" + mainPreVer='#invalid#' +fi + +# possible updates with patches from old sources are: +# - "recompile" old source +# - "minor" incremental (e.g. 4.7.2 -> 4.7.3) +# - make a "stablePatch" (e.g. 4.7 -> 4.7.3) +# - "major" incremental (e.g. 4.6 -> 4.7) +# alternative (if allowed): +# - download complete source + +if [ -d "${kernelDir}/linux-${curVer}" ] +then + updateType='recompile' + patchSrc='' + dlSrc='' +elif [ -d "${kernelDir}/linux-${minPreVer}" ] +then + updateType='minor' + srcDir="linux-${minPreVer}" + patch="patch-${minPreVer}-${curVer##*.}" + patchSrc="https://cdn.kernel.org/pub/linux/kernel/v${curVer%%.*}.x/incr/${patch}" + dlSrc='' +elif [ -d "${kernelDir}/linux-${mainVer}" ] +then + updateType='stablePatch' + srcDir="linux-${mainVer}" + patch="patch-${curVer}" + patchSrc="https://cdn.kernel.org/pub/linux/kernel/v${curVer%%.*}.x/${patch}" + dlSrc='' +elif [ -d "${kernelDir}/linux-${mainPreVer}" ] +then + updateType='major' + srcDir="linux-${mainPreVer}" + patch="patch-${curVer}" + patchSrc="https://cdn.kernel.org/pub/linux/kernel/v${curVer%%.*}.x/${patch}" + dlSrc='' +elif ${allowDownload} +then + updateType='download' + patchSrc='' + dlSrc="https://cdn.kernel.org/pub/linux/kernel/v${curVer%%.*}.x/linux-${curVer}.tar" +else + >&2 echo 'No patch method available and download of complete source not allowed! Closing.' + usage +fi + +cd "${kernelDir}" +echo "update type: ${updateType}" + +if [ -n "${patchSrc}" ] +then + dlExVer "${patchSrc}" "${patch}" + cp -r "${srcDir}" "linux-${curVer}" + cd "linux-${curVer}" + patch -p1 -i "../${patch}" + rm "../${patch}" +elif [ -n "${dlSrc}" ] +then + dlExVer "${dlSrc}" "linux-${curVer}.tar" + tar -xf "linux-${curVer}.tar" + rm "linux-${curVer}.tar" +fi + +cd "linux-${curVer}" +[ ! -r .config ] && zcat /proc/config.gz > .config + +make oldconfig +make +grep -q '^# CONFIG_MODULES is not set$' .config || make modules_install + +echo 'becoming root ...' + +su -c ' \ + before_install_hook && \ + make install && \ + grub-mkconfig -o /boot/grub/grub.cfg && \ + after_install_hook \ +' + +echo 'Success.' -- cgit v1.2.3-70-g09d2