Commit 974eb635 authored by hark's avatar hark
Browse files

initial

parents
This diff is collapsed.
This diff is collapsed.
#!/bin/bash
. /usr/local/bin/kernel_functions.sh
set -e
KEEP=1
#WORKDIR=/root/kernelbuilder
#KERNELDIR=/etc/xen/boot
#KERNELCONFIG=/root/kernel_config_4.18.11.txt
#KERNELVERSION=4.18.11
init
get_kernel
#stable_or_mainline_or_repo
download_and_unpack
build_kernel
#!/bin/bash
. /usr/local/bin/kernel_functions.sh
set -e
#KEEP=1
#WORKDIR=/root/kernelbuilder
#KERNELDIR=/etc/xen/boot
#KERNELCONFIG=/root/kernel_config_4.18.11.txt
#KERNELVERSION=4.18.11
##actual logic
init
get_kernel
if check_if_build
then
exit 0
else
exit 10
fi
function install_dependencies() {
echo "Installing dependencies..."
sudo apt -qq update
sudo apt -qq install curl git wget bison flex
## Apparently this does not satisfy all package requirements
#sudo apt -qq build-dep linux-image-generic
sudo apt -y -qq install build-essential fakeroot libncurses5-dev libssl-dev ccache libelf-dev dirmngr gcc-6-plugin-dev
gpg --recv 647F28654894E3BD457199BE38DBBDC86092693E
}
function init() {
echo "Initializing..."
#WORKDIR=/root/kernelbuilder
#KERNELDIR=/etc/xen/boot
#KERNELCONFIG=/root/kernel_config_4.18.11.txt
#KERNELVERSION=4.18.11
[[ -z "$KERNELDIR" ]] && { echo "KERNELDIR is empty" ; exit 1; }
[[ -z "$KERNELCONFIG" ]] && { echo "KERNELDIR is empty" ; exit 1; }
[[ -z "$KERNELVERSION" ]] && { echo "KERNELDIR is empty" ; exit 1; }
[[ -z "$WORKDIR" ]] && { echo "KERNELDIR is empty" ; exit 1; }
#kernel_config=$(ls /boot/config-* | grep generic | sort -Vr | head -n 1)
kernel_config=$KERNELCONFIG
kerneldir=$KERNELDIR
config_shasum=`sha1sum $kernel_config | cut -f 1 -d ' '`
echo "config sum is: $config_shasum"
current_dir=$(pwd)
# working_dir=$(mktemp -d)
working_dir=$WORKDIR
# mkdir -p $working_dir
cd "${working_dir}" || exit
##install_dependencies
}
function get_latest_version() {
stable_releases="https://mirrors.edge.kernel.org/pub/linux/kernel/v4.x/"
stable_version=$(curl -s "${stable_releases}" | grep -E -o 'linux-([0-9]{1,}\.)+[0-9]{1,}' | sort -Vr | head -n 1 | cut -d '-' -f 2)
stable_link="${stable_releases}linux-${stable_version}.tar.xz"
stable_siglink="${stable_releases}linux-${stable_version}.tar.sign"
stable_sigfile="linux-${stable_version}.tar.sign"
stable_file="linux-${stable_version}.tar.xz"
imagename="${stable_version}_$config_shasum.vmlinuz"
}
function get_specific_version() {
stable_releases="https://mirrors.edge.kernel.org/pub/linux/kernel/v4.x/"
# stable_version=$(curl -s "${stable_releases}" | grep -E -o 'linux-([0-9]{1,}\.)+[0-9]{1,}' | sort -Vr | head -n 1 | cut -d '-' -f 2)
stable_version="$1"
stable_link="${stable_releases}linux-${stable_version}.tar.xz"
stable_siglink="${stable_releases}linux-${stable_version}.tar.sign"
stable_sigfile="linux-${stable_version}.tar.sign"
stable_file="linux-${stable_version}.tar.xz"
imagename="${stable_version}_$config_shasum.vmlinuz"
}
get_kernel() {
if [ "$KERNELVERSION" == "latest" ]
then
get_latest_version
else
get_specific_version $KERNELVERSION
fi
}
function download_and_unpack() {
kernel_version="${stable_version}"
kernel_name="linux-${kernel_version}"
#ls -lhtr ${stable_file}
echo "file: ${stable_file}"
if [ ! -f ${stable_file} ]
then
echo "downloading tar"
wget "${stable_link}"
fi
if [ ! -f ${stable_sigfile} ]
then
echo "downloading sig"
wget "${stable_siglink}"
fi
if [ ! -f ${kernel_name}.tar ]
then
echo "unxzetting"
unxz ${stable_file}
fi
echo "checking sig"
gpg --verify ${stable_sigfile} ${kernel_name}.tar
if [ ! -d ${kernel_name} ]
then
echo "unpacking"
tar -xvf ${kernel_name}.tar
fi
#tar xvf "${kernel_name}.tar.xz"
cd "${kernel_name}" || exit
}
function build_kernel() {
kernel_localversion="-localversion"
cp "${kernel_config}" .config
yes '' | make oldconfig
make -j 4
#FIXME: make clean
cp arch/x86/boot/bzImage $kerneldir/$imagename
cd "${current_dir}" || exit
#FIXME: rm -rf "${working_dir}"
}
function check_if_build() {
if [ -f "$kerneldir/$imagename" ]
then
echo "kernel exists"
return 0
else
echo "kernel does not exist"
return 10
fi
}
#!/usr/bin/env bash
export WORKDIR=/root/kernelbuilder
export KERNELDIR=/etc/xen/boot
export KERNELCONFIG=/root/kernel_config_4.18.11.txt
export KERNELVERSION=4.18.11
./check_kernel.sh
./build_kernel.sh
define buildkernel::kernel (
String $kernel_version = 'latest',
String $kernel_workdir = '/root/kernelbuilder',
String $kernel_kerneldir = '/etc/xen/boot',
String $config_version = 'latest',
) {
require buildkernel::kernelprep
# scripts
file { "$kernel_workdir/config_$kernel_version.kconf":
ensure => present,
owner => root,
group => root,
mode => '0700',
source => "puppet:///modules/$module_name/kconfig/${kernel_version}_${config_version}.kconf",
}
Exec { "/usr/local/bin/build_kernel.sh":
require => [
File['/usr/local/bin/build_kernel.sh'],
File['/usr/local/bin/check_kernel.sh'],
File[$kernel_workdir],
File[$kernel_kerneldir],
],
# onlyif => "/usr/local/bin/check_kernel.sh",
environment => ["WORKDIR=${kernel_workdir}",
"KERNELVERSION=${kernel_version}",
"KERNELCONFIG=${kernel_workdir}/config_${kernel_version}.kconf",
"KERNELDIR=${kernel_kerneldir}"],
timeout => 0,
}
}
class buildkernel::kernelprep (
String $kernel_workdir = '/root/kernelbuilder',
String $kernel_kerneldir = '/etc/xen/boot',
String $signingkey = '647F28654894E3BD457199BE38DBBDC86092693E'
)
{
file { '/usr/local/bin/build_kernel.sh':
ensure => present,
owner => root,
group => root,
mode => '0700',
source => "puppet:///modules/$module_name/scripts/build_kernel.sh",
}
file { "/tmp/$signingkey.gpg":
ensure => present,
owner => root,
group => root,
mode => '0700',
source => "puppet:///modules/$module_name/$signingkey.gpg",
}
file { '/usr/local/bin/kernel_functions.sh':
ensure => present,
owner => root,
group => root,
mode => '0700',
source => "puppet:///modules/$module_name/scripts/kernel_functions.sh",
}
file { '/usr/local/bin/check_kernel.sh':
ensure => present,
owner => root,
group => root,
mode => '0700',
source => "puppet:///modules/$module_name/scripts/check_kernel.sh",
}
file { '/usr/local/bin/test_kernelscript.sh':
ensure => present,
owner => root,
group => root,
mode => '0700',
source => "puppet:///modules/$module_name/scripts/test_kernelscript.sh",
}
#dirs
file { "/etc/xen":
ensure => directory,
}
file { "$kernel_workdir":
ensure => directory,
}
file { "$kernel_kerneldir":
ensure => directory,
}
$packages = [
'build-essential',
'libncurses5-dev',
'libssl-dev',
'libelf-dev',
'dirmngr',
'curl',
'wget',
'git',
'bison',
'flex',
'gcc-6-plugin-dev',
'bc',
]
ensure_packages($packages)
/*
Exec { "/usr/bin/gpg --recv 647F28654894E3BD457199BE38DBBDC86092693E":
require => [
File['/usr/local/bin/build_kernel.sh'],
File['/usr/local/bin/check_kernel.sh'],
File[$kernel_workdir],
File[$kernel_kerneldir],
],
}
*/
Exec { "/usr/bin/gpg --import /tmp/$signingkey.gpg":
require => [
File["/tmp/$signingkey.gpg"],
File['/usr/local/bin/build_kernel.sh'],
File['/usr/local/bin/check_kernel.sh'],
File[$kernel_workdir],
File[$kernel_kerneldir],
],
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment