Last active
June 7, 2022 00:23
-
-
Save h4tr3d/06f4c5fa701fb3083864eda92ba6e9fb to your computer and use it in GitHub Desktop.
AUR basic integrity check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /usr/share/libalpm/hooks/99-99-aur.hook | |
# /etc/pacman.d/hooks/99-99-aur.hook | |
[Trigger] | |
Operation = Upgrade | |
Type = Package | |
Target = * | |
[Action] | |
Description = "Check non-repo packages integrity" | |
When = PostTransaction | |
Exec = /usr/local/bin/aur-check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Ref to the /etc/makepkg.conf PACKAGER | |
PACKAGE_USER="Alexander Drozdov" | |
set -e | |
export LANG=C | |
packages=$(pacman -Qmq) | |
orphaned="" | |
declare -A broken | |
declare -A distro | |
aur_info_cower() { | |
cower -iq --timeout=30 -- $packages | grep '^Name' | awk '{print $3}' | |
} | |
aur_info_auracle() { | |
auracle info -F '{name}' -- $packages | |
} | |
aur_info_yay_pacaur() { | |
$1 -Siq --aur -- $packages | grep '^Name' | awk '{print $3}' | |
} | |
aur_info_yay() { | |
aur_info_yay_pacaur yay | |
} | |
aur_info_pacaur() { | |
aur_info_yay_pacaur pacaur | |
} | |
aur_info_detect_backend() { | |
set +e | |
which auracle > /dev/null 2>&1 && aur_info_backend="auracle" && return | |
which cower > /dev/null 2>&1 && aur_info_backend="cower" && return | |
which yay > /dev/null 2>&1 && aur_info_backend="yay" && return | |
which pacaur > /dev/null 2>&1 && aur_info_backend="pacaur" && return | |
set -e | |
} | |
check_orphaned() { | |
list1=$(mktemp -p /tmp -u XXXXXXXX) | |
list2=$(mktemp -p /tmp -u XXXXXXXX) | |
trap "rm -f $list1 $list2" RETURN QUIT | |
pacman -Qmq > $list1 | |
eval "aur_info_${aur_info_backend}" > $list2 | |
orphaned=$(diff -u $list1 $list2 | grep '^-' | grep -v '^---' | sed 's|^-||') | |
} | |
# detect tool to ask AUR package info | |
aur_info_detect_backend | |
# Check for orphaned packages | |
[ -n "$aur_info_backend" ] && check_orphaned | |
# Check integrity | |
for pkg in $packages | |
do | |
echo " => $pkg" | |
# Check that package previously maintained by Distro | |
dist_check=$(pacman -Qi $pkg | grep '^Packager' | grep -v "$PACKAGE_USER\|Unknown Packager") | |
if [ -n "$dist_check" ]; then | |
distro[$pkg]=1 | |
fi | |
# Basic check for package breaks, mostly call ldd for libs and binaries | |
files=$(pacman -Qlq $pkg) | |
for file in $files | |
do | |
# Check only executables and skip directories. | |
# Also, skip packages from /opt/ prefix, most of them is a | |
# binary distributed and need a LD_PRELOAD_PATH to be configured | |
# right | |
if [ -x "$file" -a "${file:0:5}" != "/opt/" ]; then | |
is_elf=$(file $file | grep ELF || true) | |
if [ -n "$is_elf" ]; then | |
# Apply check | |
tmp=$(mktemp /tmp/XXXXXXXXXXXXXXXXXX) | |
ldd "$file" > "$tmp" 2>&1 || true | |
is_broken=$(cat "$tmp" | grep '=> not found' || true) | |
if [ -n "$is_broken" ]; then | |
broken[$pkg]=1 | |
echo " $file:" | |
cat "$tmp" | grep '=> not found' | ts ' ' | |
fi | |
rm -f "$tmp" | |
fi | |
fi | |
done | |
done | |
if [ -n "$orphaned" ]; then | |
echo "Orphaned packages summary:" | |
for pkg in $orphaned | |
do | |
echo " $pkg" | |
done | |
fi | |
if [ ${#distro[@]} -gt 0 ]; then | |
echo "Previously maintained by the Distro summary:" | |
for pkg in ${!distro[*]} | |
do | |
echo " $pkg" | |
done | |
fi | |
if [ ${#broken[@]} -gt 0 ]; then | |
echo "Broken packages summary:" | |
for pkg in ${!broken[*]} | |
do | |
echo " $pkg" | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment