0
0
mirror of https://github.com/termux-pacman/glibc-packages.git synced 2024-11-13 15:09:21 +00:00
glibc-packages/scripts-cgct/tools/replace_hard_with_symbolic
2024-06-27 15:30:43 +03:00

35 lines
679 B
Bash
Executable File

#!/usr/bin/env bash
# replacing hard links in a package with symbolic links
to_file() {
local a=$(echo $1 | sed 's|/||')
local b=(${2//// })
local points=""
for i in ${b[@]::${#b[@]}-1}; do
local c=$(echo $a | awk -F '/' '{printf $1}')
if [ "$c" != "$i" ]; then
points="../${points}"
continue
fi
a=$(echo $a | sed "s|$c/||")
done
echo "${points}${a}"
}
declare -A list
for i in $(find "$1" -type f -links +1); do
list[$(ls -i "$i" | awk '{printf $1}')]+="$i "
done
for i in ${!list[@]}; do
root_file=""
for j in ${list[$i]}; do
if [ -z "$root_file" ]; then
root_file="$j"
continue
fi
rm $j
ln -s $(to_file "$root_file" "$j") $j
done
done