Skip to content

Commit

Permalink
Replace /bin/bash with /usr/bin/env bash
Browse files Browse the repository at this point in the history
Where 'bash -ue' is used, the replacement reads '/usr/bin/env -S bash -ue'
and requires coreutils 8.30 or newer (ubuntu:19.04 or newer)

Signed-off-by: Renato Alves <[email protected]>
  • Loading branch information
unode committed Sep 22, 2021
1 parent 7e7d525 commit 9e8eddb
Show file tree
Hide file tree
Showing 41 changed files with 86 additions and 81 deletions.
2 changes: 1 addition & 1 deletion compile.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
#!/usr/bin/env bash
./gradlew -q compile exportClasspath
6 changes: 3 additions & 3 deletions docker/entry.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
#
# Copyright 2013-2019, Centre for Genomic Regulation (CRG)
#
Expand Down Expand Up @@ -43,7 +43,7 @@ if [[ "$NXF_USRMAP" ]]; then
# create a `nextflow` user with the provided ID
# then change the docker socker ownership to `nextflow` user
addgroup docker
adduser -u $NXF_USRMAP -G docker -s /bin/bash -D nextflow
adduser -u $NXF_USRMAP -G docker -s "$(which bash)" -D nextflow
chown nextflow /var/run/docker.sock
# finally run the target command with `nextflow` user
su nextflow << EOF
Expand All @@ -54,4 +54,4 @@ EOF
# otherwise just execute the command
else
exec bash -c "$cli"
fi
fi
6 changes: 3 additions & 3 deletions docs/ignite.rst
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ Platform LSF launcher

The following example shows a launcher script for the `Platform LSF <https://en.wikipedia.org/wiki/Platform_LSF/>`_ resource manager::

#!/bin/bash
#!/usr/bin/env bash
#BSUB -oo output_%J.out
#BSUB -eo output_%J.err
#BSUB -J <job name>
Expand All @@ -175,7 +175,7 @@ Univa Grid Engine launcher

The following example shows a launcher script for the `Univa Grid Engine <https://en.wikipedia.org/wiki/Univa_Grid_Engine>`_ (aka SGE)::

#!/bin/bash
#!/usr/bin/env bash
#$ -cwd
#$ -j y
#$ -o <output file name>
Expand All @@ -195,7 +195,7 @@ Linux SLURM launcher

When using Linux SLURM you will need to use ``srun`` instead ``mpirun`` in your launcher script. For example::

#!/bin/bash
#!/usr/bin/env bash
#SBATCH --job-name=<job name>
#SBATCH --output=<log file %j>
#SBATCH --ntasks=5
Expand Down
2 changes: 1 addition & 1 deletion docs/process.rst
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ where the Nextflow script file is located (any other location can be provided by

The template script can contain any piece of code that can be executed by the underlying system. For example::

#!/bin/bash
#!/usr/bin/env bash
echo "process started at `date`"
echo $STR
:
Expand Down
2 changes: 1 addition & 1 deletion docs/sync-doc.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
TARGET=../../nextflow-website/assets
if egrep "^release = '.*edge|.*SNAPSHOT'$" -c conf.py >/dev/null; then
MODE=edge
Expand Down
2 changes: 1 addition & 1 deletion integration-tests.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
TEST_JDK=${TEST_JDK:=8}
X_BRANCH=${TRAVIS_BRANCH:-${CIRCLE_BRANCH:-'master'}}
X_PULL_REQUEST=${TRAVIS_PULL_REQUEST:-false}
Expand Down
2 changes: 1 addition & 1 deletion launch.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
#
# Copyright 2020-2021, Seqera Labs
# Copyright 2013-2019, Centre for Genomic Regulation (CRG)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class BashWrapperBuilder {
catch( Exception e ) {
log.warn "Invalid value for `NXF_DEBUG` variable: $str -- See http://www.nextflow.io/docs/latest/config.html#environment-variables"
}
BASH = Collections.unmodifiableList( level > 0 ? ['/bin/bash','-uex'] : ['/bin/bash','-ue'] )
BASH = Collections.unmodifiableList( level > 0 ? ['/usr/bin/env','bash','-uex'] : ['/usr/bin/env','bash','-ue'] )

}

Expand Down Expand Up @@ -386,7 +386,7 @@ class BashWrapperBuilder {
final traceWrapper = isTraceRequired()
if( traceWrapper ) {
// executes the stub which in turn executes the target command
launcher = "/bin/bash ${fileStr(wrapperFile)} nxf_trace"
launcher = "/usr/bin/env bash ${fileStr(wrapperFile)} nxf_trace"
}
else {
launcher = "${interpreter} ${fileStr(scriptFile)}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ class K8sDriverLauncher {
new PodSpecBuilder()
.withPodName(runName)
.withImageName(podImage ?: k8sConfig.getNextflowImageName())
.withCommand(['/bin/bash', '-c', cmd])
.withCommand(['/usr/bin/env', 'bash', '-c', cmd])
.withLabels([ app: 'nextflow', runName: runName ])
.withNamespace(k8sClient.config.namespace)
.withServiceAccount(k8sClient.config.serviceAccount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class PodSpecBuilder {

PodSpecBuilder withCommand( cmd ) {
assert cmd instanceof List || cmd instanceof CharSequence, "Missing or invalid K8s command parameter: $cmd"
this.command = cmd instanceof List ? cmd : ['/bin/bash','-c', cmd.toString()]
this.command = cmd instanceof List ? cmd : ['/usr/bin/env','bash','-c', cmd.toString()]
return this
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ class TaskProcessor {
* <pre>
* {
* """
* #!/bin/bash
* #!/usr/bin/env bash
* do this ${x}
* do that ${y}
* :
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
su - !{userName} << 'EndOfScript'
(
set -e
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

su - !{userName} << 'EndOfScript'
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
#!/bin/bash
#!/usr/bin/env bash
{{header_script}}
# NEXTFLOW TASK: {{task_name}}
set -e
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class BashFunLibTest extends Specification {
given:
def scriptFile = Files.createTempFile("test", "sh")
def script = """
#!/bin/bash
#!/usr/bin/env bash
set -e
""".stripIndent() +
Expand Down Expand Up @@ -111,7 +111,7 @@ class BashFunLibTest extends Specification {
given:
def scriptFile = Files.createTempFile("test", "sh")
def script = """
#!/bin/bash
#!/usr/bin/env bash
set -e
""".stripIndent() +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class BashTemplateEngineTest extends Specification {
def engine = new BashTemplateEngine()
def template = '''\
## comment
#!/bin/bash
#!/usr/bin/env bash
# NEXTFLOW TASK: foo
line 1
## comment
Expand All @@ -42,7 +42,7 @@ class BashTemplateEngineTest extends Specification {

expect:
engine.render(template, [:]) == '''\
#!/bin/bash
#!/usr/bin/env bash
# NEXTFLOW TASK: foo
line 1
line 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class BashWrapperBuilderTest extends Specification {

folder.resolve('.command.sh').text ==
'''
#!/bin/bash -ue
#!/usr/bin/env -S bash -ue
echo Hello world!
''' .stripIndent().leftTrim()

Expand Down Expand Up @@ -132,7 +132,7 @@ class BashWrapperBuilderTest extends Specification {

folder.resolve('.command.sh').text ==
'''
#!/bin/bash -ue
#!/usr/bin/env -S bash -ue
echo Hello world!
'''.stripIndent().leftTrim()

Expand Down Expand Up @@ -475,21 +475,21 @@ class BashWrapperBuilderTest extends Specification {
when:
def binding = newBashWrapperBuilder(statsEnabled: false).makeBinding()
then:
binding.launch_cmd == '/bin/bash -ue /work/dir/.command.sh'
binding.launch_cmd == '/usr/bin/env bash -ue /work/dir/.command.sh'
binding.unstage_controls == null
binding.containsKey('unstage_controls')

when:
binding = newBashWrapperBuilder(statsEnabled: true).makeBinding()
then:
binding.launch_cmd == '/bin/bash /work/dir/.command.run nxf_trace'
binding.launch_cmd == '/usr/bin/env bash /work/dir/.command.run nxf_trace'
binding.unstage_controls == null
binding.containsKey('unstage_controls')

when:
binding = newBashWrapperBuilder(statsEnabled: true, scratch: true).makeBinding()
then:
binding.launch_cmd == '/bin/bash /work/dir/.command.run nxf_trace'
binding.launch_cmd == '/usr/bin/env bash /work/dir/.command.run nxf_trace'
binding.unstage_controls == '''\
cp .command.out /work/dir/.command.out || true
cp .command.err /work/dir/.command.err || true
Expand All @@ -503,13 +503,13 @@ class BashWrapperBuilderTest extends Specification {
when:
def binding = newBashWrapperBuilder().makeBinding()
then:
binding.launch_cmd == '/bin/bash -ue /work/dir/.command.sh'
binding.launch_cmd == '/usr/bin/env bash -ue /work/dir/.command.sh'
binding.trace_cmd == binding.launch_cmd

when:
binding = newBashWrapperBuilder(input: 'Ciao ciao').makeBinding()
then:
binding.launch_cmd == '/bin/bash -ue /work/dir/.command.sh < /work/dir/.command.in'
binding.launch_cmd == '/usr/bin/env bash -ue /work/dir/.command.sh < /work/dir/.command.in'
binding.trace_cmd == binding.launch_cmd

when:
Expand Down Expand Up @@ -851,6 +851,8 @@ class BashWrapperBuilderTest extends Specification {
builder.isBash('/usr/bin/bash')
builder.isBash('/bin/env bash')
builder.isBash('/bin/bash -eu')
builder.isBash('/usr/bin/env bash')
builder.isBash('/usr/bin/env bash -eu')
!builder.isBash('/bin/env perl')

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ class CondorExecutorTest extends Specification {
folder.resolve('.command.run').canExecute()

folder.resolve('.command.sh').text == '''
#!/bin/bash -ue
#!/usr/bin/env -S bash -ue
echo Hello world!
'''
.stripIndent()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# NEXTFLOW TASK: Hello 2
set -e
set -u
Expand Down Expand Up @@ -120,7 +120,7 @@ nxf_write_trace() {
nxf_trace_mac() {
local start_millis=$(nxf_date)

/bin/bash -ue {{folder}}/.command.sh
bash -ue {{folder}}/.command.sh

local end_millis=$(nxf_date)
local wall_time=$((end_millis-start_millis))
Expand All @@ -145,7 +145,7 @@ nxf_trace_linux() {
local start_millis=$(nxf_date)
trap 'kill $mem_proc' ERR

/bin/bash -ue {{folder}}/.command.sh &
bash -ue {{folder}}/.command.sh &
local task=$!

mem_fd=$(nxf_fd)
Expand Down Expand Up @@ -270,7 +270,7 @@ on_term() {
}

nxf_launch() {
/bin/bash {{folder}}/.command.run nxf_trace
bash {{folder}}/.command.run nxf_trace
}

nxf_stage() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
#BSUB -x 1
#BSUB -y 2
# NEXTFLOW TASK: Hello 1
Expand Down Expand Up @@ -85,7 +85,7 @@ on_term() {
}

nxf_launch() {
/bin/bash -ue {{folder}}/.command.sh
bash -ue {{folder}}/.command.sh
}

nxf_stage() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class K8sDriverLauncherTest extends Specification {
containers:[
[name:'foo-boo',
image:'the-image',
command:['/bin/bash', '-c', "source /etc/nextflow/init.sh; nextflow run foo"],
command:['/usr/bin/env'. 'bash', '-c', "source /etc/nextflow/init.sh; nextflow run foo"],
env:[
[name:'NXF_WORK', value:'/the/work/dir'],
[name:'NXF_ASSETS', value:'/the/project/dir'],
Expand Down Expand Up @@ -212,7 +212,7 @@ class K8sDriverLauncherTest extends Specification {
containers:[
[name:'foo-boo',
image:'foo/bar',
command:['/bin/bash', '-c', "source /etc/nextflow/init.sh; nextflow run foo"],
command:['/usr/bin/env', 'bash', '-c', "source /etc/nextflow/init.sh; nextflow run foo"],
env:[
[name:'NXF_WORK', value:'/the/work/dir'],
[name:'NXF_ASSETS', value:'/the/project/dir'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class K8sTaskHandlerTest extends Specification {
containers:[
[name:'nf-123',
image:'debian:latest',
command:['/bin/bash', '-ue','.command.run'],
command:['/usr/bin/env', 'bash', '-ue','.command.run'],
workingDir:'/some/work/dir']
]
]
Expand Down Expand Up @@ -116,7 +116,7 @@ class K8sTaskHandlerTest extends Specification {
containers:[
[name:'nf-foo',
image:'debian:latest',
command:['/bin/bash', '-ue','.command.run'],
command:['/usr/bin/env', 'bash', '-ue','.command.run'],
workingDir:'/some/work/dir',
resources:[ requests: [cpu:1], limits:[cpu:1] ],
env: [ [name:'NXF_OWNER', value:'501:502'] ]
Expand Down Expand Up @@ -148,7 +148,7 @@ class K8sTaskHandlerTest extends Specification {
containers:[
[name:'nf-abc',
image:'user/alpine:1.0',
command:['/bin/bash', '-ue', '.command.run'],
command:['/usr/bin/env', 'bash', '-ue', '.command.run'],
workingDir:'/some/work/dir',
resources:[ requests: [cpu:4, memory:'16384Mi'], limits:[cpu:4, memory:'16384Mi'] ]
]
Expand Down Expand Up @@ -195,7 +195,7 @@ class K8sTaskHandlerTest extends Specification {
containers:[
[name:'nf-123',
image:'debian:latest',
command:['/bin/bash', '-ue','.command.run'],
command:['/usr/bin/env', 'bash', '-ue','.command.run'],
workingDir:'/some/work/dir',
resources:[requests:[cpu:1], limits:[cpu:1]]
]
Expand Down Expand Up @@ -243,7 +243,7 @@ class K8sTaskHandlerTest extends Specification {
containers:[
[name:'nf-123',
image:'debian:latest',
command:['/bin/bash', '-ue','.command.run'],
command:['/usr/bin/env', 'bash', '-ue','.command.run'],
workingDir:'/some/work/dir',
env:[[name:'FOO', value:'bar']],
volumeMounts:[ [name:'vol-1', mountPath:'/etc'],
Expand Down Expand Up @@ -299,7 +299,7 @@ class K8sTaskHandlerTest extends Specification {
containers:[
[name: 'nf-123',
image: 'debian:latest',
command: ['/bin/bash', '-ue', '.command.run'],
command: ['/usr/bin/env', 'bash', '-ue', '.command.run'],
workingDir: '/some/work/dir',
volumeMounts: [
[name:'vol-1', mountPath:'/work'],
Expand Down Expand Up @@ -335,7 +335,7 @@ class K8sTaskHandlerTest extends Specification {
containers:[
[name: 'nf-123',
image: 'debian:latest',
command: ['/bin/bash', '-ue', '.command.run'],
command: ['/usr/bin/env', 'bash', '-ue', '.command.run'],
workingDir: '/some/work/dir',
volumeMounts: [
[name:'vol-3', mountPath:'/tmp'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class PodSpecBuilderTest extends Specification {
containers:[
[name:'foo',
image:'busybox',
command:['/bin/bash', '-c', 'echo hello'],
command:['/usr/bin/env', 'bash', '-c', 'echo hello'],
workingDir:'/some/work/dir',
env: [
[name:'ALPHA', value:'hello'],
Expand Down
Loading

0 comments on commit 9e8eddb

Please sign in to comment.