Skip to content

Commit 750c02d

Browse files
authored
CXX-2988 Use Bash and shebangs whenever able (#1179)
* Use `#!/usr/bin/env bash` in all scripts * Add executable permission to all shell scripts * Invoke executable scripts via shebang * Ensure generated uninstall script is always executable * Also respect shebang in EVG direct script invocations * Fix path to version.hpp in uninstall check tasks * Revert etc/generate-uninstall.sh to sh script * CXX-2809 Remove unused env vars in uninstall_check tasks
1 parent 74309fa commit 750c02d

File tree

20 files changed

+77
-62
lines changed

20 files changed

+77
-62
lines changed

.evergreen/build_example_projects.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
2+
23
set -o errexit
34
set -o pipefail
45

.evergreen/build_snapshot_rpm.sh

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/usr/bin/env bash
22

33
set -o errexit
44

.evergreen/compile.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
# Runs cmake and compiles the standard build targets (all, install, examples). Any arguments passed
44
# to this script will be forwarded on as flags passed to cmake.

.evergreen/connect.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
set -o errexit
44
set -o pipefail

.evergreen/debian_package_build.sh

100644100755
File mode changed.

.evergreen/find_cmake.sh

100644100755
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/bin/sh
1+
#!/usr/bin/env bash
2+
23
set -o errexit # Exit the script with error if any of the commands fail
34

45
find_cmake ()

.evergreen/uninstall_check.sh

100644100755
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/bin/sh
1+
#!/usr/bin/env bash
2+
23
set -o errexit # Exit the script with error if any of the commands fail
34

45
BUILD_DIR=$(pwd)/build

.mci.yml

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ functions:
6161
type: setup
6262
params:
6363
binary: bash
64-
args: [mongo-cxx-driver/.evergreen/abi-compliance-check-setup.sh]
64+
args: [-c, mongo-cxx-driver/.evergreen/abi-compliance-check-setup.sh]
6565
- command: subprocess.exec
6666
type: test
6767
params:
6868
binary: bash
69-
args: [mongo-cxx-driver/.evergreen/abi-compliance-check-test.sh]
69+
args: [-c, mongo-cxx-driver/.evergreen/abi-compliance-check-test.sh]
7070
- command: s3.put
7171
type: system
7272
params:
@@ -117,12 +117,12 @@ functions:
117117
type: setup
118118
params:
119119
binary: bash
120-
args: [mongo-cxx-driver/.evergreen/abidiff-setup.sh]
120+
args: [-c, mongo-cxx-driver/.evergreen/abidiff-setup.sh]
121121
- command: subprocess.exec
122122
type: test
123123
params:
124124
binary: bash
125-
args: [mongo-cxx-driver/.evergreen/abidiff-test.sh]
125+
args: [-c, mongo-cxx-driver/.evergreen/abidiff-test.sh]
126126
- command: s3.put
127127
type: system
128128
params:
@@ -151,7 +151,7 @@ functions:
151151
type: test
152152
params:
153153
binary: bash
154-
args: [mongo-cxx-driver/.evergreen/abi-prohibited-symbols-test.sh]
154+
args: [-c, mongo-cxx-driver/.evergreen/abi-prohibited-symbols-test.sh]
155155

156156
"setup":
157157
- command: shell.exec
@@ -193,7 +193,7 @@ functions:
193193
cd drivers-evergreen-tools
194194
export DRIVERS_TOOLS=$(pwd)
195195
196-
bash .evergreen/atlas_data_lake/pull-mongohouse-image.sh
196+
.evergreen/atlas_data_lake/pull-mongohouse-image.sh
197197
198198
"run_mongohouse":
199199
command: shell.exec
@@ -203,7 +203,7 @@ functions:
203203
cd drivers-evergreen-tools
204204
export DRIVERS_TOOLS=$(pwd)
205205
206-
bash .evergreen/atlas_data_lake/run-mongohouse-image.sh
206+
.evergreen/atlas_data_lake/run-mongohouse-image.sh
207207
208208
"test_mongohouse":
209209
command: shell.exec
@@ -338,7 +338,6 @@ functions:
338338
command: subprocess.exec
339339
params:
340340
binary: bash
341-
working_dir: "."
342341
args:
343342
- -c
344343
- |
@@ -583,7 +582,6 @@ functions:
583582
"upload mongo orchestration artifacts":
584583
- command: subprocess.exec
585584
params:
586-
working_dir: "."
587585
binary: bash
588586
args:
589587
- -c
@@ -659,9 +657,7 @@ functions:
659657
working_dir: "mongo-cxx-driver"
660658
add_expansions_to_env: true
661659
redirect_standard_error_to_output: true
662-
args:
663-
- -c
664-
- .evergreen/compile-scan-build.sh
660+
args: [-c, .evergreen/compile-scan-build.sh]
665661

666662
"upload scan artifacts":
667663
- command: subprocess.exec
@@ -711,9 +707,7 @@ functions:
711707
- ARTIFACTORY_PASSWORD
712708
- SILK_CLIENT_ID
713709
- SILK_CLIENT_SECRET
714-
args:
715-
- -c
716-
- .evergreen/check-augmented-sbom.sh
710+
args: [-c, .evergreen/check-augmented-sbom.sh]
717711

718712
"upload augmented sbom":
719713
- command: s3.put
@@ -991,39 +985,27 @@ tasks:
991985
- func: "setup"
992986
- func: "fetch_c_driver_source"
993987
- func: "compile"
994-
- command: expansions.update
995-
params:
996-
updates:
997-
- key: mongocxx_version_finder_sh
998-
value: $(sed -nE 's/^#define MONGOCXX_VERSION_STRING "([^"]+)".*/\1/p' build/src/mongocxx/config/version.hpp)
999988
- command: shell.exec
1000989
type: test
1001990
params:
1002991
shell: bash
1003992
working_dir: "mongo-cxx-driver"
1004993
script: |-
1005994
set -o errexit
1006-
export INSTALL_VERSION=${mongocxx_version_finder_sh}
1007-
sh ./.evergreen/uninstall_check.sh
995+
./.evergreen/uninstall_check.sh
1008996
1009997
- name: uninstall_check_windows
1010998
commands:
1011999
- func: "setup"
10121000
- func: "fetch_c_driver_source"
10131001
- func: "compile"
1014-
- command: expansions.update
1015-
params:
1016-
updates:
1017-
- key: mongocxx_version_finder_sh
1018-
value: $(sed -nE 's/^#define MONGOCXX_VERSION_STRING "([^"]+)".*/\1/p' build/src/mongocxx/config/version.hpp)
10191002
- command: shell.exec
10201003
type: test
10211004
params:
10221005
shell: bash
10231006
working_dir: "mongo-cxx-driver"
10241007
script: |-
10251008
set -o errexit
1026-
export INSTALL_VERSION=${mongocxx_version_finder_sh}
10271009
cmd.exe /c .\\.evergreen\\uninstall_check_windows.cmd
10281010
10291011
- name: build_example_with_add_subdirectory
@@ -1075,7 +1057,7 @@ tasks:
10751057
script: |-
10761058
set -o errexit
10771059
export IS_PATCH="${is_patch}"
1078-
sh .evergreen/debian_package_build.sh
1060+
.evergreen/debian_package_build.sh
10791061
- command: s3.put
10801062
params:
10811063
aws_key: ${aws_key}
@@ -1100,7 +1082,7 @@ tasks:
11001082
set -o errexit
11011083
export IS_PATCH="${is_patch}"
11021084
export DEB_BUILD_PROFILES="pkg.mongo-cxx-driver.mnmlstc"
1103-
sh .evergreen/debian_package_build.sh
1085+
.evergreen/debian_package_build.sh
11041086
- command: s3.put
11051087
params:
11061088
aws_key: ${aws_key}
@@ -1123,7 +1105,7 @@ tasks:
11231105
shell: bash
11241106
script: |-
11251107
set -o errexit
1126-
sh .evergreen/build_snapshot_rpm.sh
1108+
.evergreen/build_snapshot_rpm.sh
11271109
- command: s3.put
11281110
params:
11291111
aws_key: ${aws_key}
@@ -1287,7 +1269,7 @@ task_groups:
12871269
- command: subprocess.exec
12881270
params:
12891271
binary: bash
1290-
args: [mongo-cxx-driver/.evergreen/abi-stability-setup.sh]
1272+
args: [-c, mongo-cxx-driver/.evergreen/abi-stability-setup.sh]
12911273
include_expansions_in_env: [cxx_standard]
12921274
tasks: [".abi-stability"]
12931275
teardown_task_can_fail_task: true
@@ -1308,8 +1290,7 @@ task_groups:
13081290
add_expansions_to_env: true
13091291
env:
13101292
MONGODB_VERSION: '7.0'
1311-
args:
1312-
- ${DRIVERS_TOOLS}/.evergreen/atlas/setup-atlas-cluster.sh
1293+
args: [-c, "${DRIVERS_TOOLS}/.evergreen/atlas/setup-atlas-cluster.sh"]
13131294
- command: expansions.update
13141295
# Expected to set MONGODB_URI expansion.
13151296
params:
@@ -1320,8 +1301,7 @@ task_groups:
13201301
working_dir: mongo-cxx-driver
13211302
binary: bash
13221303
add_expansions_to_env: true
1323-
args:
1324-
- ${DRIVERS_TOOLS}/.evergreen/atlas/teardown-atlas-cluster.sh
1304+
args: [-c, "${DRIVERS_TOOLS}/.evergreen/atlas/teardown-atlas-cluster.sh"]
13251305
setup_group_can_fail_task: true
13261306
setup_group_timeout_secs: 1800
13271307
tasks:

etc/calc_release_version_selftest.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
2+
#
23
# calc_release_version_selftest.sh is used to test output of calc_release_version.py.
34
# run with:
45
# cd etc

etc/generate-uninstall.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ set prefix=%prefix:"=%
4646
echo.@echo off
4747
echo.
4848
echo.REM MongoDB C++ Driver uninstall program, generated with CMake
49-
echo.
49+
echo.REM
5050
echo.REM Copyright 2009-present MongoDB, Inc.
5151
echo.REM
5252
echo.REM Licensed under the Apache License, Version 2.0 (the "License");

etc/generate-uninstall.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/usr/bin/env sh
22

33
# Copyright 2009-present MongoDB, Inc.
44
#
@@ -60,9 +60,10 @@ if [ "${DESTDIR}" ]; then
6060
fi
6161

6262

63-
printf "#!/bin/sh\n"
63+
printf "#!/usr/bin/env bash\n"
64+
printf "#\n"
6465
printf "# MongoDB C++ Driver uninstall program, generated with CMake"
65-
printf "\n"
66+
printf "#\n"
6667
printf "# Copyright 2009-present MongoDB, Inc.\n"
6768
printf "#\n"
6869
printf "# Licensed under the Apache License, Version 2.0 (the \"License\");\n"

examples/projects/bsoncxx/cmake/shared/build.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
2+
23
set -o errexit
34
set -o pipefail
45

examples/projects/bsoncxx/cmake/static/build.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
2+
23
set -o errexit
34
set -o pipefail
45

examples/projects/bsoncxx/pkg-config/shared/build.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
2+
23
set -o errexit
34
set -o pipefail
45

examples/projects/bsoncxx/pkg-config/static/build.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
2+
23
set -o errexit
34
set -o pipefail
45

examples/projects/mongocxx/cmake/shared/build.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
2+
23
set -o errexit
34
set -o pipefail
45

examples/projects/mongocxx/cmake/static/build.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
2+
23
set -o errexit
34
set -o pipefail
45

examples/projects/mongocxx/pkg-config/shared/build.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
2+
23
set -o errexit
34
set -o pipefail
45

examples/projects/mongocxx/pkg-config/static/build.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
2+
23
set -o errexit
34
set -o pipefail
45

generate_uninstall/CMakeLists.txt

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ if (WIN32)
1919
"${CMAKE_INSTALL_PREFIX}"
2020
)
2121
install (CODE "
22-
string(REPLACE \";\" \"\\n\" MONGOCXX_INSTALL_MANIFEST_CONTENT
22+
string (REPLACE \";\" \"\\n\" MONGOCXX_INSTALL_MANIFEST_CONTENT
2323
\"\${CMAKE_INSTALL_MANIFEST_FILES}\")
24-
string(REPLACE \"/\" \"\\\\\" MONGOCXX_INSTALL_MANIFEST_CONTENT_WIN32
24+
string (REPLACE \"/\" \"\\\\\" MONGOCXX_INSTALL_MANIFEST_CONTENT_WIN32
2525
\"\${MONGOCXX_INSTALL_MANIFEST_CONTENT}\")
26-
file(WRITE \"mongocxx_install_manifest.txt\"
26+
file (WRITE \"mongocxx_install_manifest.txt\"
2727
\"\${MONGOCXX_INSTALL_MANIFEST_CONTENT_WIN32}\")
2828
execute_process (
2929
COMMAND
@@ -47,13 +47,13 @@ if (WIN32)
4747
install (FILES "${CMAKE_CURRENT_BINARY_DIR}/${UNINSTALL_PROG}" DESTINATION "${UNINSTALL_PROG_DIR}" PERMISSIONS ${UNINSTALL_PERMISSIONS})
4848

4949
add_custom_target (uninstall
50-
COMMAND call "${CMAKE_CURRENT_BINARY_DIR}/${UNINSTALL_PROG}"
50+
COMMAND "${CMAKE_CURRENT_BINARY_DIR}/${UNINSTALL_PROG}"
5151
)
5252
else ()
5353
install (CODE "
54-
string(REPLACE \";\" \"\\n\" MONGOCXX_INSTALL_MANIFEST_CONTENT
54+
string (REPLACE \";\" \"\\n\" MONGOCXX_INSTALL_MANIFEST_CONTENT
5555
\"\${CMAKE_INSTALL_MANIFEST_FILES}\")
56-
file(WRITE \"mongocxx_install_manifest.txt\"
56+
file (WRITE \"mongocxx_install_manifest.txt\"
5757
\"\${MONGOCXX_INSTALL_MANIFEST_CONTENT}\")
5858
execute_process (
5959
COMMAND
@@ -68,10 +68,32 @@ else ()
6868
OUTPUT_FILE
6969
\"${CMAKE_CURRENT_BINARY_DIR}/${UNINSTALL_PROG}\"
7070
)
71+
72+
# Ensure generated uninstall script has executable permissions.
73+
if (\"${CMAKE_VERSION}\" VERSION_GREATER_EQUAL \"3.19.0\")
74+
file (
75+
CHMOD \"${CMAKE_CURRENT_BINARY_DIR}/${UNINSTALL_PROG}\"
76+
PERMISSIONS
77+
OWNER_READ OWNER_WRITE OWNER_EXECUTE
78+
GROUP_READ GROUP_EXECUTE
79+
WORLD_READ WORLD_EXECUTE
80+
)
81+
else ()
82+
# Workaround lack of file(CHMOD).
83+
file (
84+
COPY \"${CMAKE_CURRENT_BINARY_DIR}/${UNINSTALL_PROG}\"
85+
DESTINATION \"${UNINSTALL_PROG}.d\"
86+
FILE_PERMISSIONS
87+
OWNER_READ OWNER_WRITE OWNER_EXECUTE
88+
GROUP_READ GROUP_EXECUTE
89+
WORLD_READ WORLD_EXECUTE
90+
)
91+
file (RENAME \"${UNINSTALL_PROG}.d/${UNINSTALL_PROG}\" \"${UNINSTALL_PROG}\")
92+
endif ()
7193
")
7294
install (FILES "${CMAKE_CURRENT_BINARY_DIR}/${UNINSTALL_PROG}" DESTINATION "${UNINSTALL_PROG_DIR}" PERMISSIONS ${UNINSTALL_PERMISSIONS})
7395

7496
add_custom_target (uninstall
75-
COMMAND sh "${CMAKE_CURRENT_BINARY_DIR}/${UNINSTALL_PROG}"
97+
COMMAND "${CMAKE_CURRENT_BINARY_DIR}/${UNINSTALL_PROG}"
7698
)
7799
endif ()

0 commit comments

Comments
 (0)