void-packages

Void Source Packages
git clone git://ezup.dev/void-packages.git
Log | Files | Refs | README | LICENSE

replace-interpreter.sh (776B)


      1# This helper replaces shebang paths pointing to the correct ones
      2# as used by xbps. Multiple languages are supported:
      3#
      4#	- GNU Bash
      5#	- Perl
      6#	- Python
      7#
      8
      9bash_regexp=".*sh"
     10perl_regexp=".*perl[^[:space:]]*"
     11python_regexp=".*python[^[:space:]]*"
     12
     13replace_interpreter() {
     14	local lang="$1" file="$2" trsb orsb
     15
     16	[ -z $lang -o -z $file ] && return 1
     17
     18	case $lang in
     19	bash)
     20		orsb=$bash_regexp
     21		trpath="/bin/bash"
     22		;;
     23	perl)
     24		orsb=$perl_regexp
     25		trpath="/usr/bin/perl"
     26		;;
     27	python)
     28		orsb=$python_regexp
     29		trpath="/usr/bin/python"
     30		;;
     31	*)
     32		;;
     33	esac
     34
     35	if [ -f $file ]; then
     36		sed -i -e "1s|^#![[:space:]]*${orsb}|#!${trpath}|" $file
     37		msg_normal "Transformed $lang script: ${file##$wrksrc}.\n"
     38	else
     39		msg_warn "Ignoring unexistent $lang script: ${file##$wrksrc}.\n"
     40	fi
     41}