Add more libraries for kernel building + lock kernel build command to 1 invocation running at any time.

This commit is contained in:
Captain ALM 2024-08-21 14:50:54 +01:00
parent 40c32b1ad9
commit d304b49d52
Signed by: alfred
GPG Key ID: 4E4ADD02609997B1

View File

@ -13,7 +13,9 @@ alias screen-off="xset dpms force off"
alias boot-sign-verify="sudo sign-boot && sudo verify-boot"
function kernel-build-dep() {
echo "[+] Kernel Build Dependancy Installation...";
sudo apt install gawk git dh-make llvm libclang-dev libclang1 sbsigntool;
sudo apt install gawk git dh-make llvm libclang-dev sbsigntool linux-libc-dev libperl-dev libpython3-dev libunwind-dev liblzma-dev lzma-dev libzstd-dev libnuma-dev libelf-dev libcap-dev linux-libc-dev;
sudo apt install zlib1g-dev libclang1 zlib1g libbpf0 libzstd1 libnuma1 libelf1;
sudo apt install libpython3.10 libunwind8 liblzma5 libcap-ng0 libcap2;
sudo apt build-dep linux-image-unsigned-$(uname -r);
}
function kernel-build() {
@ -22,51 +24,60 @@ function kernel-build() {
mkdir -p ~/kernel;
cd ~/kernel;
doNotContinueKernelBuild=0;
if [ -f last-build-failed ]; then
echo "[*] Resuming last build; delete last-build-failed in the kernel directory before starting a kernel build to re-obtain sources.";
rm -f last-build-failed;
for _dir in *"linux"*; do
[ -d "${_dir}" ] && linuxdir="${_dir}" && break;
done;
cd "$linuxdir";
if [ -f kernel-build-occuring ]; then
echo "[-] Kernel Build Occuring Already!";
doNotContinueKernelBuild=1;
else
for _dir in *"linux"*; do
[ -d "${_dir}" ] && linuxdir="${_dir}" && break;
done;
echo "[-] Removing Sources...";
rm -rf "$linuxdir";
sudo rm -rf deb-contents;
rm -f *.gz;
rm -f *.dsc;
echo "[*] Archiving old packages...";
mkdir -p old-debs;
touch dummy.deb;
mv *.deb old-debs/;
echo "[+] Obtaining Sources...";
apt-get source linux-image-unsigned-$(uname -r);
if [ $? -eq 0 ]; then
touch kernel-build-occuring;
fi;
if [ $doNotContinueKernelBuild -eq 0 ]; then
if [ -f last-build-failed ]; then
echo "[*] Resuming last build; delete last-build-failed in the kernel directory before starting a kernel build to re-obtain sources.";
rm -f last-build-failed;
for _dir in *"linux"*; do
[ -d "${_dir}" ] && linuxdir="${_dir}" && break;
done;
cd "$linuxdir";
echo "[*] Patching source and configuration...";
sed -i "s/.*CONFIG_MODULE_SIG_FORCE.*/CONFIG_MODULE_SIG_FORCE policy<{'amd64': 'y', 'arm64': 'y', 'armhf': 'y', 'ppc64el': 'y', 's390x': 'y'}>/" debian.master/config/annotations;
git apply --verbose ~/Downloads/patches/hibernate/0001-Hibernate-Patch.patch;
echo "[*] Cleaning kernel build...";
chmod a+x debian/rules;
chmod a+x debian/scripts/*;
chmod a+x debian/scripts/misc/*;
fakeroot debian/rules clean;
mkdir -p debian/build/build-generic/certs;
sudo cp /cert/mok/signing_key.pem ../ -f;
sudo chmod u=rw,g=rw,o=rw ../signing_key.pem;
sudo cp /var/lib/shim-signed/mok/MOK.der ../signing_key.x509 -f;
sudo chmod u=rw,g=rw,o=rw ../signing_key.x509;
(((until [ -f debian/build/build-generic/certs/signing_key.pem ]; do sleep 0.1; done) && while lsof debian/build/build-generic/certs/signing_key.pem; do sleep 0.1; done) && mv -f ../signing_key.pem debian/build/build-generic/certs/signing_key.pem) &
(((until [ -f debian/build/build-generic/certs/signing_key.x509 ]; do sleep 0.1; done) && while lsof debian/build/build-generic/certs/signing_key.x509; do sleep 0.1; done) && mv -f ../signing_key.x509 debian/build/build-generic/certs/signing_key.x509) &
else
echo "[-] Failed to obtain sources!";
doNotContinueKernelBuild=1;
for _dir in *"linux"*; do
[ -d "${_dir}" ] && linuxdir="${_dir}" && break;
done;
echo "[-] Removing Sources...";
rm -rf "$linuxdir";
sudo rm -rf deb-contents;
rm -f *.gz;
rm -f *.dsc;
echo "[*] Archiving old packages...";
mkdir -p old-debs;
touch dummy.deb;
mv *.deb old-debs/;
echo "[+] Obtaining Sources...";
apt-get source linux-image-unsigned-$(uname -r);
if [ $? -eq 0 ]; then
for _dir in *"linux"*; do
[ -d "${_dir}" ] && linuxdir="${_dir}" && break;
done;
cd "$linuxdir";
echo "[*] Patching source and configuration...";
sed -i "s/.*CONFIG_MODULE_SIG_FORCE.*/CONFIG_MODULE_SIG_FORCE policy<{'amd64': 'y', 'arm64': 'y', 'armhf': 'y', 'ppc64el': 'y', 's390x': 'y'}>/" debian.master/config/annotations;
git apply --verbose ~/Downloads/patches/hibernate/0001-Hibernate-Patch.patch;
echo "[*] Cleaning kernel build...";
chmod a+x debian/rules;
chmod a+x debian/scripts/*;
chmod a+x debian/scripts/misc/*;
fakeroot debian/rules clean;
mkdir -p debian/build/build-generic/certs;
sudo cp /cert/mok/signing_key.pem ../ -f;
sudo chmod u=rw,g=rw,o=rw ../signing_key.pem;
sudo cp /var/lib/shim-signed/mok/MOK.der ../signing_key.x509 -f;
sudo chmod u=rw,g=rw,o=rw ../signing_key.x509;
(((until [ -f debian/build/build-generic/certs/signing_key.pem ]; do sleep 0.1; done) && while lsof debian/build/build-generic/certs/signing_key.pem; do sleep 0.1; done) && mv -f ../signing_key.pem debian/build/build-generic/certs/signing_key.pem) &
(((until [ -f debian/build/build-generic/certs/signing_key.x509 ]; do sleep 0.1; done) && while lsof debian/build/build-generic/certs/signing_key.x509; do sleep 0.1; done) && mv -f ../signing_key.x509 debian/build/build-generic/certs/signing_key.x509) &
else
echo "[-] Failed to obtain sources!";
doNotContinueKernelBuild=1;
rm -f kernel-build-occuring;
fi;
fi;
fi;
if [ $doNotContinueKernelBuild -eq 0 ]; then
@ -108,12 +119,14 @@ function kernel-build() {
sudo cp linux-modules* /usr/local/mydebs/;
sudo cp linux-lib-rust* /usr/local/mydebs/;
sudo update-mydebs;
rm -f kernel-build-occuring;
cd "$cwd";
echo "[+] Kernel Build Finished!";
else
echo "[*] Build Failed!";
cd ~/kernel;
touch last-build-failed;
rm -f kernel-build-occuring;
cd "$cwd";
fi;
fi;