sabayon-brokenlinks: Integrate automatic remove of broken links

This commit is contained in:
Daniele Rondina
2019-08-12 17:09:30 +02:00
parent 5972c0137f
commit 11977d3afd
+117 -108
View File
@@ -51,6 +51,8 @@ search_pkg() {
local -n libdir="$3"
local lib="$4"
# TODO: check if there is a more fast way instead of equery.
# Try to search for package
p=$(equery -N -q -C belongs $lib/$basename --early-out || true)
@@ -82,14 +84,14 @@ detect_libs_dir() {
local libs=""
if [ "${SAB_ARCH}" = "x86_64" ] ; then
if [ -d "/usr/lib32" ] ; then
libs="/usr/lib32"
libs="/usr/lib32 /lib32"
fi
if [ -d "/usr/lib64" ] ; then
libs="$libs /usr/lib64"
libs="$libs /usr/lib64 /lib64"
fi
else
if [ -d "/usr/lib" ] ; then
libs="/usr/lib"
libs="/usr/lib /lib"
fi
fi
if [ -z "$libs" ] ; then
@@ -106,6 +108,8 @@ examine_libs() {
local file=""
local broken_files=""
log 1 "The exam could be long sorry for the wait."
for lib in ${EXAMINED_LIBDIRS} ; do
broken_files=""
@@ -132,14 +136,6 @@ examine_file() {
local base=$(basename $1)
local is_present_equery=1
local is_present_qlist=1
which equery 2>&1 >/dev/null || {
is_present_equery=0
}
which qlist 2>&1 >/dev/null || {
is_present_qlist=0
}
local targetlink=$(readlink $f)
local link2remove=false
local link2fix=false
@@ -155,46 +151,93 @@ examine_file() {
#
#echo "BASE = $base"
if [ $is_present_equery = 1 ] ; then
search_pkg "$base" pkg newlibdir "$lib"
if [ -z "$pkg" ] ; then
MANUALLY_REMOVED_LINKS+=( "$f" )
return
else
search_pkg "$base" pkg newlibdir "$lib"
if [ -z "$pkg" ] ; then
MANUALLY_REMOVED_LINKS+=( "$f" )
return
else
if [ -n "$newlibdir" ] ; then
log 0 "Link $base available under $newlibdir. I remove it."
link2remove=true
fi
if [ -n "$newlibdir" ] ; then
log 0 "Link $base available under $newlibdir. I remove it."
link2remove=true
fi
if [ "$is_present_qlist" = 1 ] ; then
# Check new
res=$(qlist -IC $pkg 2>/dev/null | grep $f | wc -l)
if [ "$res" = 1 ] ; then
link2fix=true
fi
fi
if [ $link2remove = true ] ; then
BROKEN_LINKS2REMOVE+=( "$f" )
fi
log 0 "Link $f of the package $pkg"
fi
if [ "$is_present_qlist" = 1 ] ; then
# Check new
res=$(qlist -IC $pkg 2>/dev/null | grep $f | wc -l)
if [ "$res" = 1 ] ; then
link2fix=true
fi
fi
if [ $link2remove = true ] ; then
BROKEN_LINKS2REMOVE+=( "$f" )
fi
log 0 "Link $f of the package $pkg"
else
# Check if file has only one revision number (es. libudev.so.0)
res=$(perl -e "if ('$base' =~ /(.so[.][\d]+$)/) { print '1' }")
if [ -n "$res" ] ; then
if [ $is_present_equery = 1 ] ; then
search_pkg "$base" pkg newlibdir "$lib"
if [ -z "$pkg" ] ; then
# Try to search package with .so
base=$(echo "$base" | awk 'match($0, /.so/) { print substr($0, 0, RSTART+2) }')
search_pkg "$base" pkg newlibdir "$lib"
if [ -z "$pkg" ] ; then
# Try to search package with .so
base=$(echo "$base" | awk 'match($0, /.so/) { print substr($0, 0, RSTART+2) }')
log 0 "No package found for link $f."
MANUALLY_REMOVED_LINKS+=( "$f" )
return
fi
if [ -n "$newlibdir" ] ; then
log 0 "Link $base available under $newlibdir. I remove it."
link2remove=true
else
# POST: we have a broken link or old link
current_link=$(readlink $lib/$base)
log 0 "Link $f related to package $pkg (with an updated version $current_link). I remove it."
link2remove=true
fi
else
log 0 "Link $f of the package $pkg"
if [ -n "$newlibdir" ] ; then
log 0 "Link $base available under $newlibdir. I remove it."
link2remove=true
else
# Check new
res=$(qlist -IC $pkg 2>/dev/null | grep $f | wc -l)
if [ "$res" = 1 ] ; then
link2fix=true
fi
fi
fi
if [ $link2remove = true ] ; then
BROKEN_LINKS2REMOVE+=( "$f" )
fi
else
# Check if file has only one revision number (es. libudev.so.0.63)
res=$(perl -e "if ('$base' =~ /(.so[.][\d]+[.][\d]+$)/) { print '1' }")
if [ -n "$res" ] ; then
search_pkg "$base" pkg newlibdir "$lib"
if [ -z "$pkg" ] ; then
base=$(echo "$base" | awk 'match($0, /.so[.][0-9]+/) { print substr($0, 0, RSTART+RLENGTH-1) }')
search_pkg "$base" pkg newlibdir "$lib"
if [ -z "$pkg" ] ; then
log 0 "No package found for link $f."
@@ -206,7 +249,6 @@ examine_file() {
log 0 "Link $base available under $newlibdir. I remove it."
link2remove=true
else
# POST: we have a broken link or old link
current_link=$(readlink $lib/$base)
log 0 "Link $f related to package $pkg (with an updated version $current_link). I remove it."
@@ -223,72 +265,15 @@ examine_file() {
link2remove=true
else
if [ "$is_present_qlist" = 1 ] ; then
# Check new
res=$(qlist -IC $pkg 2>/dev/null | grep $f | wc -l)
if [ "$res" = 1 ] ; then
link2fix=true
fi
# Check new
res=$(qlist -IC $pkg 2>/dev/null | grep $f | wc -l)
if [ "$res" = 1 ] ; then
link2fix=true
fi
fi
fi
fi
if [ $link2remove = true ] ; then
BROKEN_LINKS2REMOVE+=( "$f" )
fi
else
# Check if file has only one revision number (es. libudev.so.0.63)
res=$(perl -e "if ('$base' =~ /(.so[.][\d]+[.][\d]+$)/) { print '1' }")
if [ -n "$res" ] ; then
if [ $is_present_equery = 1 ] ; then
search_pkg "$base" pkg newlibdir "$lib"
if [ -z "$pkg" ] ; then
base=$(echo "$base" | awk 'match($0, /.so[.][0-9]+/) { print substr($0, 0, RSTART+RLENGTH-1) }')
search_pkg "$base" pkg newlibdir "$lib"
if [ -z "$pkg" ] ; then
log 0 "No package found for link $f."
MANUALLY_REMOVED_LINKS+=( "$f" )
return
fi
if [ -n "$newlibdir" ] ; then
log 0 "Link $base available under $newlibdir. I remove it."
link2remove=true
else
current_link=$(readlink $lib/$base)
log 0 "Link $f related to package $pkg (with an updated version $current_link). I remove it."
link2remove=true
fi
else
log 0 "Link $f of the package $pkg"
if [ -n "$newlibdir" ] ; then
log 0 "Link $base available under $newlibdir. I remove it."
link2remove=true
else
if [ "$is_present_qlist" = 1 ] ; then
# Check new
res=$(qlist -IC $pkg 2>/dev/null | grep $f | wc -l)
if [ "$res" = 1 ] ; then
link2fix=true
fi
fi
fi
fi
fi # $is_present_equery
else
echo "Link $f not supported".
@@ -301,10 +286,20 @@ examine_file() {
fi
}
rm_broken_links() {
for l in ${BROKEN_LINKS2REMOVE[@]} ; do
if [ "$DRY_RUN" = 0 ]; then
rm -vf ${l}
else
echo "rm -vf ${l}"
fi
done
}
print_links2remove() {
echo $MANUALLY_REMOVED_LINKS
for l in ${MANUALLY_REMOVED_LINKS[@]} ; do
echo "rm -vf ${l}"
done
}
main() {
@@ -319,13 +314,27 @@ main() {
exit 1
fi
which equery 2>&1 >/dev/null || {
echo "equery tool is needed. Please install app-portage/gentoolkit."
exit 1
}
which qlist 2>&1 >/dev/null || {
echo "qlist tool is needed. Please install app-portage/portage-utils."
exit 1
}
examine_libs
echo "=======+++++++++++++++++======="
echo $BROKEN_LINKS2REMOVE
echo "=======+++++++++++++++++======="
log 1 "Remove Broken Links!"
rm_broken_links
print_links2remove
if [ ${#MANUALLY_REMOVED_LINKS[@]} -gt 0 ] ; then
log 1 "Hereinafter, links to manually remove:"
print_links2remove
fi
echo "All Done."
}