summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2018-12-16 19:09:22 -0500
committermidipix <writeonce@midipix.org>2018-12-18 20:38:41 -0500
commit636ff0c1fdbce370c40dea52360beb001c813cd7 (patch)
tree545c07bbddac6ceae83a0e46ba8df9b336b59094
parentca0fc2f788d341fbed9056ac4f34ddd09ef61c3d (diff)
downloadsbpython3-636ff0c1fdbce370c40dea52360beb001c813cd7.tar.bz2
sbpython3-636ff0c1fdbce370c40dea52360beb001c813cd7.tar.xz
project: imported pycopy.sh from sbpython2.
-rwxr-xr-xproject/pycopy.sh41
1 files changed, 41 insertions, 0 deletions
diff --git a/project/pycopy.sh b/project/pycopy.sh
new file mode 100755
index 0000000..2a55b7a
--- /dev/null
+++ b/project/pycopy.sh
@@ -0,0 +1,41 @@
+#!/bin/sh
+
+# pyccopy: a build-time utiltiy script
+# objective: copy one or more source python (.py) scripts
+# to the destination directory specified via the
+# environment variable PYCOPY_DSTDIR, replacing
+# the original shebang line, should the script
+# contain one, with a program interpreter based
+# on the PYCOPY_PREFIX and PYCOPY_PYTHON
+# environment variables.
+
+if [ -z "$PYCOPY_PYTHON" ]; then
+ python='python'
+else
+ python="$PYCOPY_PYTHON"
+fi
+
+if [ -z "$PYCOPY_PREFIX" ]; then
+ prefix='/usr'
+else
+ prefix="$PYCOPY_PREFIX"
+fi
+
+if [ -z "$PYCOPY_DSTDIR" ]; then
+ dstdir='.'
+else
+ dstdir="$PYCOPY_DSTDIR"
+fi
+
+for pysrc in $@; do
+ basename=$(basename "$pysrc");
+
+ sed -e '1s@^#!.*@#!'" $prefix/bin/$python"'@g' \
+ "$pysrc" > "$dstdir/$basename" || exit 2
+
+ if [ "$(head -n1 "$dstdir/$basename")" = "#! $prefix/bin/$python" ]; then
+ chmod +x "$dstdir/$basename" || exit 2
+ fi
+done
+
+exit 0