2020-04-30 09:24:25 +00:00
|
|
|
function symlink_contents_to_dir() {
|
|
|
|
local target="$2"
|
2020-05-08 09:43:40 +00:00
|
|
|
mkdir -p "$target"
|
|
|
|
if [[ -f "$1" ]]; then
|
2021-01-31 15:43:03 +00:00
|
|
|
symlink_to_dir "$1" "$target"
|
|
|
|
elif [[ -L "$1" && ! -d "$1" ]]; then
|
2020-05-08 09:43:40 +00:00
|
|
|
local actual=$(readlink "$1")
|
2021-01-31 15:43:03 +00:00
|
|
|
symlink_contents_to_dir "$actual" "$target"
|
2020-05-08 09:43:40 +00:00
|
|
|
elif [[ -d "$1" ]]; then
|
2021-01-31 15:43:03 +00:00
|
|
|
SAVEIFS=$IFS
|
|
|
|
IFS=$'
|
|
|
|
'
|
|
|
|
local children=($(find "$1" -maxdepth 1 -mindepth 1))
|
|
|
|
IFS=$SAVEIFS
|
|
|
|
for child in "${children[@]}"; do
|
|
|
|
symlink_to_dir "$child" "$target"
|
2020-04-30 09:24:25 +00:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
function symlink_to_dir() {
|
|
|
|
local target="$2"
|
2020-05-08 09:43:40 +00:00
|
|
|
mkdir -p "$target"
|
|
|
|
if [[ -f "$1" ]]; then
|
|
|
|
ln -s -f "$1" "$target"
|
2021-01-31 15:43:03 +00:00
|
|
|
elif [[ -L "$1" && ! -d "$1" ]]; then
|
|
|
|
cp "$1" "$2"
|
2020-05-08 09:43:40 +00:00
|
|
|
elif [[ -d "$1" ]]; then
|
2021-01-31 15:43:03 +00:00
|
|
|
SAVEIFS=$IFS
|
|
|
|
IFS=$'
|
|
|
|
'
|
|
|
|
local children=($(find "$1" -maxdepth 1 -mindepth 1))
|
|
|
|
IFS=$SAVEIFS
|
2020-05-08 09:43:40 +00:00
|
|
|
local dirname=$(basename "$1")
|
|
|
|
mkdir -p "$target/$dirname"
|
2021-01-31 15:43:03 +00:00
|
|
|
for child in "${children[@]}"; do
|
|
|
|
symlink_to_dir "$child" "$target/$dirname"
|
2020-05-08 09:43:40 +00:00
|
|
|
done
|
2020-04-30 09:24:25 +00:00
|
|
|
else
|
|
|
|
echo "Can not copy $1"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
symlink_contents_to_dir $SOURCE_DIR $TARGET_DIR
|