aboutsummaryrefslogtreecommitdiffstats
path: root/bin/cp
diff options
context:
space:
mode:
authorChris Larson <chris_larson@mentor.com>2010-10-20 08:20:35 -0700
committerChris Larson <chris_larson@mentor.com>2010-10-21 20:29:24 -0700
commit788c62604ce3a0f99132fb1267236fa16fa1eac8 (patch)
treed1226b0f20721efc47a1d7178f2cdf5b8198d58e /bin/cp
parent4060ff0edc3e889bfb1ab54512fe468b79b8f810 (diff)
downloadopenembedded-788c62604ce3a0f99132fb1267236fa16fa1eac8.tar.gz
openembedded-788c62604ce3a0f99132fb1267236fa16fa1eac8.tar.bz2
openembedded-788c62604ce3a0f99132fb1267236fa16fa1eac8.zip
bin/{cp,sed}: Add shell script wrappers for portability
Signed-off-by: Chris Larson <chris_larson@mentor.com>
Diffstat (limited to 'bin/cp')
-rwxr-xr-xbin/cp62
1 files changed, 62 insertions, 0 deletions
diff --git a/bin/cp b/bin/cp
new file mode 100755
index 0000000000..81fdbe8d5c
--- /dev/null
+++ b/bin/cp
@@ -0,0 +1,62 @@
+#!/bin/sh
+#
+# - We do not allow -i due to the non-interactive nature of OE tasks
+# - We do not allow -r, as it has known problems, and is marked
+# obsolescent in the standard
+# - We allow -a as shorthand for -RpP
+# - Otherwise, we stick to what SuSv3 defines
+
+realbin() {
+ _script=`basename $0`
+ found=
+ for bin in `which -a $_script`; do
+ if ! cmp -s $bin $0; then
+ found=$bin
+ break
+ fi
+ done
+ if [ -n "$found" ]; then
+ echo "$found"
+ else
+ return 1
+ fi
+}
+
+quote(){
+ /usr/bin/sed -e "s,','\\\\'',g; 1s,^,',; \$s,\$,',;" << EOF
+$1
+EOF
+}
+
+save () {
+ case "$1" in
+ # when a string contains a "'" we have to escape it
+ *\'*)
+ saved="$saved `quote "$1"`"
+ ;;
+ # otherwise just quote the variable
+ *)
+ saved="$saved '$1'"
+ ;;
+ esac
+}
+
+saved=""
+while getopts fpaRHLP opt; do
+ case "$opt" in
+ a)
+ opt="RpP"
+ ;;
+ \?)
+ exit 1
+ ;;
+ esac
+ save "-$opt"
+done
+shift $(($OPTIND - 1))
+for arg; do
+ save "$arg"
+done
+
+eval set -- "$saved"
+exec `realbin` "$@"