#!/bin/sh

src="${1}"
dst="${2}"

if [ -z "${src}" -o -z "${dst}" ]
then
        echo "Usage: $(basename "${0}") <source> <dest>"
        echo "Clones the source directory tree into destination, hardlinking all files."
        echo "Useful for kernel build trees, when you wanna keep everything separate."
        exit 64
fi

if [ ! -d "${src}" ]
then
        echo "${src} doesn't appear to be a directory."
        exit 32
fi

if [ -e "${dst}" ]
then
        echo "${dst} already exists. Not overwriting."
        exit 16
fi

echo "Creating directory structure..."
mkdir -p "${dst}"
( cd "${src}" && find . -type d -print0 ) | ( cd "${dst}" && xargs -0 mkdir -p )

echo "Hardlinking files..."
( cd "${src}" && find . -type f -print ) | while read file; do ln "${src}/${file}" "${dst}/${file}"; done

echo "All done!"

PHP Warning

Warning: "preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead"

Warning: "preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead:"

Warning: "preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead"

Warning: "preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead"

Warning: "preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead"

Warning: "preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead"

Warning: "preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead"

Warning: "preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead"

Warning: "preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead:"