Skip to content

Instantly share code, notes, and snippets.

@soul9
Created November 13, 2010 17:42
Show Gist options
  • Save soul9/675509 to your computer and use it in GitHub Desktop.
Save soul9/675509 to your computer and use it in GitHub Desktop.
script to check what files don't belong to any package on /. Depends on equery and qlist
#!/bin/bash
loginfo() {
echo $* >&2
}
lastcheck() {
lines=$(equery -q belongs $1 |wc -l)
if test $lines -eq 0; then
return 0
else
return 1
fi
}
excluded() {
for dir in $exclude; do
if [ $1 == $dir ]; then
return 0
fi
done
return 1
}
recwalk() {
loginfo "recwalk in $1"
cd $1
for file in *; do
if ! excluded $file; then
regexp="'$(pwd)/${file}'"
if ! grep -q "$(pwd)/${file}" $2; then
lastcheck "$(pwd)/${file}" && echo "$(pwd)/$file"
fi
if test -d "${file}"; then
if grep -q "$(pwd)/${file}" $2 || ! lastcheck "$(pwd)/${file}"; then
recwalk "$(pwd)/${file}" $2
fi
fi
fi
done
cd ..
}
#exclude some directories
exclude="/tmp /home /dev /proc /var/db /sys /boot /etc/config-archive /lib/modules /lib/firmware /mnt /media /lost+found /root"
loginfo "making tempfile"
tmpfile=$(mktemp)
loginfo "tempfile is $tmpfile"
loginfo "getting files list"
for pkg in $(qlist -IC); do
qlist -C "$pkg" >> $tmpfile
done
loginfo "done getting files list"
#start in /
loginfo "Starting in /"
for i in /*; do
if ! echo $exclude |grep -q $i; then
recwalk $i $tmpfile
fi
done
loginfo "done, removing temporary file"
rm $tmpfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment