Blame project/pycopy.sh

636ff0
#!/bin/sh
636ff0
636ff0
# pyccopy:   a build-time utiltiy script
636ff0
# objective: copy one or more source python (.py) scripts
636ff0
#            to the destination directory specified via the
636ff0
#            environment variable PYCOPY_DSTDIR, replacing
636ff0
#            the original shebang line, should the script
636ff0
#            contain one, with a program interpreter based
636ff0
#            on the PYCOPY_PREFIX and PYCOPY_PYTHON
636ff0
#            environment variables.
636ff0
636ff0
if [ -z "$PYCOPY_PYTHON" ]; then
636ff0
	python='python'
636ff0
else
636ff0
	python="$PYCOPY_PYTHON"
636ff0
fi
636ff0
636ff0
if [ -z "$PYCOPY_PREFIX" ]; then
636ff0
	prefix='/usr'
636ff0
else
636ff0
	prefix="$PYCOPY_PREFIX"
636ff0
fi
636ff0
636ff0
if [ -z "$PYCOPY_DSTDIR" ]; then
636ff0
	dstdir='.'
636ff0
else
636ff0
	dstdir="$PYCOPY_DSTDIR"
636ff0
fi
636ff0
636ff0
for pysrc in $@; do
636ff0
	basename=$(basename "$pysrc");
636ff0
636ff0
	sed -e '1s@^#!.*@#!'" $prefix/bin/$python"'@g'   \
636ff0
		"$pysrc" > "$dstdir/$basename"          || exit 2
636ff0
636ff0
	if [ "$(head -n1 "$dstdir/$basename")" = "#! $prefix/bin/$python" ]; then
636ff0
		chmod +x "$dstdir/$basename"            || exit 2
636ff0
	fi
636ff0
done
636ff0
636ff0
exit 0