#!/usr/bin/env bash # # take a given directory and replace all symlinks with their real # counterparts; replace a symlink to a file with the real file and # a symlink to a directory with the real one. # # SPDX-License-Identifier: MIT ROOT=$1 LINKS=$(find "${ROOT}" -type l -printf "%p\n") OLDIFS=$IFS IFS=$'\012' for link in ${LINKS}; do if [ -d "${link}" ]; then echo "dir: ${link}" mv "${link}" "${link}.sym" mkdir "${link}" cp -LcdpR "${link}.sym"/* "${link}/" elif [ -f "${link}" ]; then echo "file: ${link}" mv "${link}" "${link}.sym" cp -Lcp "${link}.sym" "${link}" else echo "unknown: ${link}" fi done IFS=${OLDIFS}