Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create fix-duplicates script #3981

Open
wants to merge 1 commit into
base: testing
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions woof-code/rootfs-skeleton/usr/bin/fix-duplicates
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/sh
#Search for duplicate files in a directory and replace by symlinks
#Written by mistfire based for Barry Kauler's mesa package fix

TARGET_PATH="$1"

if [ "$TARGET_PATH" == "" ]; then
echo "Enter path first"
exit 1
elif [ -d "$TARGET_PATH" ];then
PREFIX="$TARGET_PATH"
else
echo "Invalid path"
exit 1
fi

echo "Searching \"$PREFIX\"..."

DRVS0="$(find "$PREFIX" -type f -maxdepth 1 -print0 | xargs -0 md5sum | sort | uniq -Dw 32 | sed -e s'#^.*\ \/#\/#g' | sed -e 's#\ #_whitespace_#g' | xargs -i basename {})"

for aDRV in $DRVS0
do
xaDRV="$(echo "$aDRV" | sed -e 's#_whitespace_#\ #g')"
aDRV="$xaDRV"
[ -L "${PREFIX}/$aDRV" ] && continue
if [ -f "${PREFIX}/$aDRV" ]; then

for aaDRV in ${DRVS0}
do

paaDRV="$aaDRV"
xaaDRV="$(echo "$aaDRV" | sed -e 's#_whitespace_#\ #g')"
aaDRV="$xaaDRV"

[ "$aaDRV" == "" ] && continue
[ "$aaDRV" == "$aDRV" ] && continue
[ -L "${PREFIX}/$aaDRV" ] && continue
cmp -s "${PREFIX}/${aDRV}" "${PREFIX}/${aaDRV}"
if [ $? -eq 0 ];then
if [ ! -L "${PREFIX}/${aDRV}" ] && [ -f "${PREFIX}/${aDRV}" ]; then
echo "Symlinking ${PREFIX}/${aaDRV}..."
echo "Source: ${PREFIX}/${aDRV}"
echo ""
rm -f "${PREFIX}/${aaDRV}"
ln -sr "${PREFIX}/${aDRV}" "${PREFIX}/${aaDRV}"
fi
fi

done
fi

done