A collection of system hardening and generally-useful scripts for Linux systems. Targets Artix, works on any distro. Some inits require disabling the included boot parameter hardening, otherwise they won't boot (systemd)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

150 lines
4.1 KiB

#!/bin/bash
# MisPac is a simple shell script to replicate a subset of `pacman`'s functionalities, except building packages from source using Arch's ABS
# The name codes from the game Ms. Pacman
if [[ "$UID" != 0 ]]; then
sudo "$0" "$@"
exit
fi
wd="/tmp/abs/"
mkdir -p "$wd"
chown -R abs_build_user "$wd"
sessiondir="$wd/session-$(cat /dev/urandom | head -c64 | md5sum | cut -d' ' -f1 | head -c8)"
mkdir -p "$sessiondir"
chown -R abs_build_user "$sessiondir"
cd "$sessiondir"
if [[ "$1" == "-S" ]]; then
x=2
success=true
while [[ "$x" -le "$#" ]]; do
pkg="${!x}"
echo "Downloading $pkg..."
pkgdir="$sessiondir/$x"
mkdir -p "$pkgdir"
chown -R abs_build_user "$pkgdir"
cd "$pkgdir"
sudo -u abs_build_user proxychains asp update "$pkg"
sudo -u abs_build_user proxychains asp export "$pkg"
x="$(("$x"+1))"
for srcdir in */; do
cd "$pkgdir"
cd "$srcdir"
echo "Installing $pkg/$srcdir..."
sudo -u abs_build_user proxychains updpkgsums
sudo -u abs_build_user proxychains makepkg -o
sudo -u abs_build_user proxychains makepkg -e
# pkgver="$(grep -F pkgver= PKGBUILD | cut -d= -f2 | tr -d \' | tr -d \")"
# pkgrel="$(grep -F pkgrel= PKGBUILD | cut -d= -f2 | tr -d \' | tr -d \")"
# arch="$(grep -F arch= PKGBUILD | cut -d'(' -f2 | cut -d')' -f1 | tr -d \' | tr -d \")"
source PKGBUILD
arch=x86_64
# echo *.zst
if pacman -U "$pkg-$pkgver-$pkgrel-$arch.pkg.tar.zst" --noconfirm; then
# if true; then
echo "$pkg" >> /parsec/etc/abs/pkgs-installed
python /parsec/bin/psec-remove-dups.py /parsec/etc/abs/pkgs-installed
if [[ "$(grep -F "IgnorePkg = $pkg # PSEC ABS" /etc/pacman.conf)" == "" ]]; then
echo "IgnorePkg = $pkg # PSEC ABS" >> /etc/pacman.conf
fi
cp "$pkg-$pkgver-$pkgrel-$arch.pkg.tar.zst" /parsec/abs/pkgs/
else
success=false
fi
echo "Done installing $pkg"
# echo "Cleaning up build files..."
done
done
echo "All operations finished."
if [[ "$success" == "true" ]]; then
# wipe -rf "$sessiondir"
rm -rf "$sessiondir"
fi
exit
fi
if [[ "$1" == "-Su" ]]; then
echo "Updating packages..."
while read pkg; do
echo "- $pkg"
while read line; do
if [[ "$line" == "$pkg" ]]; then
echo "$line == $pkg"
"$0" --update "$pkg" # -S / --update
fi
done < <(pacman -Qu | cut -d' ' -f1)
x="$(("$x"+1))"
done < /parsec/etc/abs/pkgs-installed
# "$0" -S $(cat /parsec/etc/abs/pkgs-installed)
echo "Completed all updates."
rm -rf "$sessiondir"
exit
fi
if [[ "$1" == "--update" ]]; then
for pkg in "${@:2}"; do
echo "Updating (with dependency management): $pkg"
# exit
sudo -u abs_build_user proxychains asp update "$pkg"
sudo -u abs_build_user proxychains asp export "$pkg"
cd "$pkg"
source PKGBUILD
for dep in "${makedepends[@]}"; do
while read line; do
if [[ "$line" == "$dep" ]]; then
while read pkgtoupdate; do
"$0" --update "$pkgtoupdate" ""
done < <(pacman -Qu | cut -d' ' -f1)
fi
done < /parsec/etc/abs/pkgs-installed
done
while read line; do
if [[ "$line" == "$pkg" ]]; then
"$0" -S "$pkg"
fi
done < <(pacman -Qu | cut -d' ' -f1)
done
rm -rf "$sessiondir"
exit
fi
if [[ "$1" == "--info" ]]; then
# Lists all info needed to build and install a given package
for pkg in "${@:2}"; do
# echo "$pkg"
cd "$sessiondir"
echo "- $pkg"
sudo -u abs_build_user proxychains asp update "$pkg"
sudo -u abs_build_user proxychains asp export "$pkg"
cd "$pkg"
source PKGBUILD
for dep in "${depends[@]}"; do
echo "$pkg (depends) $dep"
done
for dep in "${makedepends[@]}"; do
echo "$pkg (makedepends) $dep"
done
for key in "${validpgpkeys[@]}"; do
echo "$pkg (pgp) $key"
done
done
rm -rf "$sessiondir"
exit
fi
if [[ "$1" == "-Sk" ]]; then
for pkg in "${@:2}"; do
echo "$pkg"
cd "$sessiondir"
echo "- $pkg"
sudo -u abs_build_user proxychains asp update "$pkg"
sudo -u abs_build_user proxychains asp export "$pkg"
cd "$pkg"
source PKGBUILD
for key in "${validpgpkeys[@]}"; do
echo "$pkg (pgp) $key"
sudo -u abs_build_user proxychains /parsec/bin/psec-gpg --recv-key "$key"
done
done
rm -rf "$sessiondir"
exit
fi
rm -rf "$sessiondir"