Fix kernel build functionality + add features to detect failures and react.
This commit is contained in:
parent
47e122a3a4
commit
40c32b1ad9
164
bash_aliases
164
bash_aliases
@ -21,74 +21,102 @@ function kernel-build() {
|
|||||||
cwd=$(pwd);
|
cwd=$(pwd);
|
||||||
mkdir -p ~/kernel;
|
mkdir -p ~/kernel;
|
||||||
cd ~/kernel;
|
cd ~/kernel;
|
||||||
for _dir in *"linux"*; do
|
doNotContinueKernelBuild=0;
|
||||||
[ -d "${_dir}" ] && linuxdir="${_dir}" && break;
|
if [ -f last-build-failed ]; then
|
||||||
done;
|
echo "[*] Resuming last build; delete last-build-failed in the kernel directory before starting a kernel build to re-obtain sources.";
|
||||||
echo "[-] Removing Sources...";
|
rm -f last-build-failed;
|
||||||
rm -rf "$linuxdir";
|
for _dir in *"linux"*; do
|
||||||
sudo rm -rf deb-contents;
|
[ -d "${_dir}" ] && linuxdir="${_dir}" && break;
|
||||||
rm -f *.gz;
|
done;
|
||||||
rm -f *.dsc;
|
cd "$linuxdir";
|
||||||
echo "[*] Archiving old packages...";
|
else
|
||||||
mkdir -p old-debs;
|
for _dir in *"linux"*; do
|
||||||
touch dummy.deb;
|
[ -d "${_dir}" ] && linuxdir="${_dir}" && break;
|
||||||
mv *.deb old-debs/;
|
done;
|
||||||
echo "[+] Obtaining Sources...";
|
echo "[-] Removing Sources...";
|
||||||
apt-get source linux-image-unsigned-$(uname -r);
|
rm -rf "$linuxdir";
|
||||||
for _dir in *"linux"*; do
|
sudo rm -rf deb-contents;
|
||||||
[ -d "${_dir}" ] && linuxdir="${_dir}" && break;
|
rm -f *.gz;
|
||||||
done;
|
rm -f *.dsc;
|
||||||
cd "$linuxdir";
|
echo "[*] Archiving old packages...";
|
||||||
echo "[*] Patching source and configuration...";
|
mkdir -p old-debs;
|
||||||
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;
|
touch dummy.deb;
|
||||||
git apply --verbose ~/Downloads/patches/hibernate/0001-Hibernate-Patch.patch;
|
mv *.deb old-debs/;
|
||||||
echo "[*] Cleaning kernel build...";
|
echo "[+] Obtaining Sources...";
|
||||||
chmod a+x debian/rules;
|
apt-get source linux-image-unsigned-$(uname -r);
|
||||||
chmod a+x debian/scripts/*;
|
if [ $? -eq 0 ]; then
|
||||||
chmod a+x debian/scripts/misc/*;
|
for _dir in *"linux"*; do
|
||||||
fakeroot debian/rules clean;
|
[ -d "${_dir}" ] && linuxdir="${_dir}" && break;
|
||||||
mkdir -p debian/build/build-generic/certs;
|
done;
|
||||||
sudo cp /cert/mok/signing_key.pem ../;
|
cd "$linuxdir";
|
||||||
sudo chmod u=rw,g=rw,o=rw ../signing_key.pem;
|
echo "[*] Patching source and configuration...";
|
||||||
(((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) &
|
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;
|
||||||
echo "[*] Building kernel...";
|
git apply --verbose ~/Downloads/patches/hibernate/0001-Hibernate-Patch.patch;
|
||||||
fakeroot debian/rules binary;
|
echo "[*] Cleaning kernel build...";
|
||||||
echo "[*] Build Complete!";
|
chmod a+x debian/rules;
|
||||||
rm -f debian/build/build-generic/certs/signing_key.pem;
|
chmod a+x debian/scripts/*;
|
||||||
rm -f ../signing_key.pem;
|
chmod a+x debian/scripts/misc/*;
|
||||||
echo "[+] Extracting kernel package...";
|
fakeroot debian/rules clean;
|
||||||
cd ~/kernel;
|
mkdir -p debian/build/build-generic/certs;
|
||||||
mkdir -p deb-contents;
|
sudo cp /cert/mok/signing_key.pem ../ -f;
|
||||||
dpkg-deb -R $(ls linux-image-unsigned-* | head -1) deb-contents;
|
sudo chmod u=rw,g=rw,o=rw ../signing_key.pem;
|
||||||
cd "$linuxdir";
|
sudo cp /var/lib/shim-signed/mok/MOK.der ../signing_key.x509 -f;
|
||||||
echo "[*] Making kernel signed...";
|
sudo chmod u=rw,g=rw,o=rw ../signing_key.x509;
|
||||||
pkgarch=$(dpkg-architecture -qDEB_HOST_ARCH);
|
(((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) &
|
||||||
pkgver=$(dpkg-parsechangelog --show-field Version);
|
(((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) &
|
||||||
cd ~/kernel/deb-contents;
|
else
|
||||||
pkgunom=$(head -1 DEBIAN/control | sed -e 's/Package: //');
|
echo "[-] Failed to obtain sources!";
|
||||||
find ./ -type f -exec sed -i -e 's/-unsigned//g' {} \;
|
doNotContinueKernelBuild=1;
|
||||||
find ./ -type f -exec sed -i -e 's/ unsigned//g' {} \;
|
fi;
|
||||||
pkgnom=$(head -1 DEBIAN/control | sed -e 's/Package: //');
|
fi;
|
||||||
sudo mv usr/share/doc/$pkgunom usr/share/doc/$pkgnom;
|
if [ $doNotContinueKernelBuild -eq 0 ]; then
|
||||||
tlinuz=$(ls boot/vmlinuz-* | head -1);
|
echo "[*] Building kernel...";
|
||||||
sudo sbsign --key /cert/BMOK.priv --cert /cert/BMOK.pem $tlinuz --output $tlinuz;
|
fakeroot debian/rules binary;
|
||||||
sed -i "s/.*Conflicts: .*/Conflicts: $pkgunom/" DEBIAN/control;
|
if [ $? -eq 0 ]; then
|
||||||
pkgisz=$(du -ks * | grep -v DEBIAN | cut -f1 | xargs | sed -e 's/\ /+/g' | bc);
|
echo "[*] Build Complete!";
|
||||||
find ./ -path '*/DEBIAN' -prune -o -type f -exec md5sum {} \; | awk '{ print $1 " " substr($2, 10) }' > DEBIAN/md5sums;
|
rm -f debian/build/build-generic/certs/signing_key.pem;
|
||||||
sed -i "s/.*Installed-Size: .*/Installed-Size: $pkgisz/" DEBIAN/control;
|
rm -f ../signing_key.pem;
|
||||||
echo "[+] Packing signed kernel...";
|
rm -f ../signing_key.x509;
|
||||||
cd ~/kernel;
|
echo "[+] Extracting kernel package...";
|
||||||
dpkg-deb -b deb-contents ${pkgnom}_${pkgver}_${pkgarch}.deb;
|
cd ~/kernel;
|
||||||
sudo rm -rf deb-contents;
|
mkdir -p deb-contents;
|
||||||
echo "[+] Deploying Packages Locally...";
|
dpkg-deb -R $(ls linux-image-unsigned-* | head -1) deb-contents;
|
||||||
sudo cp ${pkgnom}_${pkgver}_${pkgarch}.deb /usr/local/mydebs/;
|
cd "$linuxdir";
|
||||||
sudo cp linux-headers-* /usr/local/mydebs/;
|
echo "[*] Making kernel signed...";
|
||||||
sudo cp linux-libc-dev* /usr/local/mydebs/;
|
pkgarch=$(dpkg-architecture -qDEB_HOST_ARCH);
|
||||||
sudo cp linux-modules* /usr/local/mydebs/;
|
pkgver=$(dpkg-parsechangelog --show-field Version);
|
||||||
sudo cp linux-lib-rust* /usr/local/mydebs/;
|
cd ~/kernel/deb-contents;
|
||||||
sudo update-mydebs;
|
pkgunom=$(head -1 DEBIAN/control | sed -e 's/Package: //');
|
||||||
cd "$cwd";
|
find ./ -type f -exec sed -i -e 's/-unsigned//g' {} \;
|
||||||
echo "Kernel Build Finished!";
|
find ./ -type f -exec sed -i -e 's/ unsigned//g' {} \;
|
||||||
|
pkgnom=$(head -1 DEBIAN/control | sed -e 's/Package: //');
|
||||||
|
sudo mv usr/share/doc/$pkgunom usr/share/doc/$pkgnom;
|
||||||
|
tlinuz=$(ls boot/vmlinuz-* | head -1);
|
||||||
|
sudo sbsign --key /cert/BMOK.priv --cert /cert/BMOK.pem $tlinuz --output $tlinuz;
|
||||||
|
sed -i "s/.*Conflicts: .*/Conflicts: $pkgunom/" DEBIAN/control;
|
||||||
|
pkgisz=$(du -ks * | grep -v DEBIAN | cut -f1 | xargs | sed -e 's/\ /+/g' | bc);
|
||||||
|
find ./ -path '*/DEBIAN' -prune -o -type f -exec md5sum {} \; | awk '{ print $1 " " substr($2, 10) }' > DEBIAN/md5sums;
|
||||||
|
sed -i "s/.*Installed-Size: .*/Installed-Size: $pkgisz/" DEBIAN/control;
|
||||||
|
echo "[+] Packing signed kernel...";
|
||||||
|
cd ~/kernel;
|
||||||
|
dpkg-deb -b deb-contents ${pkgnom}_${pkgver}_${pkgarch}.deb;
|
||||||
|
sudo rm -rf deb-contents;
|
||||||
|
echo "[+] Deploying Packages Locally...";
|
||||||
|
sudo cp ${pkgnom}_${pkgver}_${pkgarch}.deb /usr/local/mydebs/;
|
||||||
|
sudo cp linux-headers-* /usr/local/mydebs/;
|
||||||
|
sudo cp linux-libc-dev* /usr/local/mydebs/;
|
||||||
|
sudo cp linux-modules* /usr/local/mydebs/;
|
||||||
|
sudo cp linux-lib-rust* /usr/local/mydebs/;
|
||||||
|
sudo update-mydebs;
|
||||||
|
cd "$cwd";
|
||||||
|
echo "[+] Kernel Build Finished!";
|
||||||
|
else
|
||||||
|
echo "[*] Build Failed!";
|
||||||
|
cd ~/kernel;
|
||||||
|
touch last-build-failed;
|
||||||
|
cd "$cwd";
|
||||||
|
fi;
|
||||||
|
fi;
|
||||||
}
|
}
|
||||||
function install-tar() {
|
function install-tar() {
|
||||||
if [ $# -gt 0 ]; then
|
if [ $# -gt 0 ]; then
|
||||||
|
Loading…
Reference in New Issue
Block a user