bash-stuff/bash_aliases

143 lines
4.7 KiB
Bash

alias screen-off="xset dpms force off"
alias boot-sign-verify="sudo sign-boot && sudo verify-boot"
function kernel-build() {
echo "[+] Kernel Build Starting...";
cwd=$(pwd);
cd ~/kernel;
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);
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 debian/build/build-generic/certs/;
sudo chmod u=rw,g=rw,o=rw debian/build/build-generic/certs/signing_key.pem;
echo "[*] Building kernel...";
fakeroot debian/rules binary;
echo "[*] Build Complete!";
rm -f debian/build/build-generic/certs/signing_key.pem;
echo "[+] Extracting kernel package...";
cd ~/kernel;
mkdir -p deb-contents;
dpkg-deb -R $(ls linux-image-unsigned-* | head -1) deb-contents;
cd "$linuxdir";
echo "[*] Making kernel signed...";
pkgarch=$(dpkg-architecture -qDEB_HOST_ARCH);
pkgver=$(dpkg-parsechangelog --show-field Version);
cd ~/kernel/deb-contents;
pkgunom=$(head -1 DEBIAN/control | sed -e 's/Package: //');
find ./ -type f -exec sed -i -e 's/-unsigned//g' {} \;
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 update-mydebs;
cd "$cwd";
echo "Kernel Build Finished!";
}
function install-tar() {
if [ $# -gt 0 ]; then
if [ $# -eq 1 ]; then
fln=$(basename -- "$1");
flp=$1;
else
fln=$(basename -- "$2");
flp=$2;
fi
fln="${fln%%.*}";
echo "Installing: /opt/$fln";
sudo mkdir -p "/opt/$fln";
sudo tar -xvf "$flp" -C /opt/$fln;
if [ $# -gt 1 ]; then
sudo chown -R "$1" /opt/$fln;
fi
else
echo "Usage:";
echo "install-tar <archive> | <owner> <archive>";
fi
}
function install-tar-contents() {
if [ $# -gt 0 ]; then
if [ $# -eq 1 ]; then
flp=$1;
else
flp=$2;
fi
echo "Installing: /opt";
sudo tar -xvf "$flp" -C /opt;
if [ $# -gt 1 ]; then
sudo chown -R "$1" /opt;
fi
else
echo "Usage:";
echo "install-tar-contents <archive> | <owner> <archive>";
fi
}
function edit-dot-desktop() {
sudo nano "/usr/share/applications/$(basename -- "$1").desktop";
}
function edit-dot-desktop-local() {
nano ~"/.local/share/applications/$(basename -- "$1").desktop";
}
function tpm2-contents() {
sudo tpm2_selftest
sudo tpm2_gettestresult
sudo tpm2_getcap -l
sudo tmp2_pcrread
sudo tpm2_pcrread
}
alias list-xinput-devices="xinput list"
function disable-xinput-device() {
if [ -z $1 ]; then
echo "Provide a device name fragment.";
else
cdid=$(xinput list | grep "$1" | head -1 | grep -Po 'id=\K[^\t]*' | head -1);
echo "Disabling: $cdid";
xinput disable $cdid;
fi;
}
function enable-xinput-device() {
if [ -z $1 ]; then
echo "Provide a device name fragment.";
else
cdid=$(xinput list | grep "$1" | head -1 | grep -Po 'id=\K[^\t]*' | head -1);
echo "Enabling: $cdid";
xinput enable $cdid;
fi;
}