From eba93e2adb54659bce76e86ebd9f51523e15711c Mon Sep 17 00:00:00 2001 From: Juan RP Date: Tue, 28 Jan 2014 12:10:04 +0100 Subject: [PATCH] common: added a helpers directory with common shell helpers. --- common/helpers/README | 25 ++++++++++++++++ common/helpers/replace-interpreter.sh | 41 +++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 common/helpers/README create mode 100644 common/helpers/replace-interpreter.sh diff --git a/common/helpers/README b/common/helpers/README new file mode 100644 index 0000000000..ff5e3b865c --- /dev/null +++ b/common/helpers/README @@ -0,0 +1,25 @@ +SHELL HELPERS +============= + +This directory contains shell files that are read by xbps-src and can be used at any +phase when building source packages. Only files with the `.sh' extension will be read. + +A shell helper must provide its own function for use in the source packages. +The following examples illustrates a fake helper named `myhelper.sh' that provides +the `myhelper_func' function: + +myhelper.sh: +... +myhelper_func() { + ... +} +... + +You can then use this helper in a source package like this: + +srcpkgs/foo/template: +... +do_install() { + myhelper_func ... +} +... diff --git a/common/helpers/replace-interpreter.sh b/common/helpers/replace-interpreter.sh new file mode 100644 index 0000000000..1660ac6fa1 --- /dev/null +++ b/common/helpers/replace-interpreter.sh @@ -0,0 +1,41 @@ +# This helper replaces shebang paths pointing to the correct ones +# as used by xbps. Multiple languages are supported: +# +# - GNU Bash +# - Perl +# - Python +# + +bash_regexp=".*sh" +perl_regexp=".*perl[^[:space:]]*" +python_regexp=".*python[^[:space:]]*" + +replace_interpreter() { + local lang="$1" file="$2" trsb orsb + + [ -z $lang -o -z $file ] && return 1 + + case $lang in + bash) + orsb=$bash_regexp + trpath="/bin/bash" + ;; + perl) + orsb=$perl_regexp + trpath="/usr/bin/perl" + ;; + python) + orsb=$python_regexp + trpath="/usr/bin/python" + ;; + *) + ;; + esac + + if [ -f $file ]; then + sed -i -e "1s|^#![[:space:]]*${orsb}|#!${trpath}|" $file + msg_normal "Transformed $lang script: ${file##$wrksrc}.\n" + else + msg_warn "Ignoring unexistent $lang script: ${file##$wrksrc}.\n" + fi +}