aboutsummaryrefslogtreecommitdiff
path: root/scripts/cp_s
blob: 515905c5afd6bd671751c4a0fc0fc90f609a1bae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/sh
# Emulate cp -s for systems without coreutils

if test -z "$1" || test -z "$2" ; then
	echo "usage: ${0} srcdir destdir" >&2
	exit 1
fi

# Portability notes:
# - Avoid set -e given its ambiguous interaction with subshells.
# - Not all shells update $PWD as required by POSIX.
#   Use the pwd builtin instead.
# - Command substitution strips all trailing newlines.
#   Preserve trailing newlines by appending a safety character and then
#   removing it with parameter substitution, along with the newline
#   appended by pwd itself.

mkdir -p "$2" &&
destdir=`cd "$2" && pwd && echo x` &&
destdir=${destdir%??} &&

cd "$1" &&
srcdir=`pwd && echo x` &&
srcdir=${srcdir%??} &&
find . -type d -exec mkdir -p "${destdir}/{}" \; &&
find . -type f -exec ln -sf "${srcdir}/{}" "${destdir}/{}" \;