Skip to content

Commit 9516521

Browse files
Merge pull request #12570 from rabbitmq/mergify/bp/v4.0.x/pr-12550
Ensure init-slapd.sh passes `shellcheck` (backport #12550)
2 parents 94d705a + bf1aecd commit 9516521

File tree

1 file changed

+48
-19
lines changed
  • deps/rabbitmq_auth_backend_ldap/test/system_SUITE_data

1 file changed

+48
-19
lines changed

deps/rabbitmq_auth_backend_ldap/test/system_SUITE_data/init-slapd.sh

+48-19
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,45 @@
33

44
set -ex
55

6-
slapd_data_dir=$1
7-
tcp_port=$2
6+
readonly slapd_data_dir="$1"
7+
readonly tcp_port="$2"
88

9-
pidfile="$slapd_data_dir/slapd.pid"
10-
uri="ldap://localhost:$tcp_port"
9+
readonly pidfile="$slapd_data_dir/slapd.pid"
10+
readonly uri="ldap://localhost:$tcp_port"
1111

12-
binddn="cn=config"
13-
passwd=secret
12+
readonly binddn="cn=config"
13+
readonly passwd=secret
1414

1515
case "$(uname -s)" in
1616
Linux)
17-
slapd=/usr/sbin/slapd
18-
modulepath=/usr/lib/ldap
19-
schema_dir=/etc/ldap/schema
17+
if [ -x /usr/bin/slapd ]
18+
then
19+
readonly slapd=/usr/bin/slapd
20+
elif [ -x /usr/sbin/slapd ]
21+
then
22+
readonly slapd=/usr/sbin/slapd
23+
fi
24+
25+
if [ -d /usr/lib/openldap ]
26+
then
27+
readonly modulepath=/usr/lib/openldap
28+
elif [ -d /usr/lib/ldap ]
29+
then
30+
readonly modulepath=/usr/lib/ldap
31+
fi
32+
33+
if [ -d /etc/openldap/schema ]
34+
then
35+
readonly schema_dir=/etc/openldap/schema
36+
elif [ -d /etc/ldap/schema ]
37+
then
38+
readonly schema_dir=/etc/ldap/schema
39+
fi
2040
;;
2141
FreeBSD)
22-
slapd=/usr/local/libexec/slapd
23-
modulepath=/usr/local/libexec/openldap
24-
schema_dir=/usr/local/etc/openldap/schema
42+
readonly slapd=/usr/local/libexec/slapd
43+
readonly modulepath=/usr/local/libexec/openldap
44+
readonly schema_dir=/usr/local/etc/openldap/schema
2545
;;
2646
*)
2747
exit 1
@@ -35,7 +55,7 @@ esac
3555
rm -rf "$slapd_data_dir"
3656
mkdir -p "$slapd_data_dir"
3757

38-
conf_file=$slapd_data_dir/slapd.conf
58+
readonly conf_file="$slapd_data_dir/slapd.conf"
3959
cat <<EOF > "$conf_file"
4060
include $schema_dir/core.schema
4161
include $schema_dir/cosine.schema
@@ -52,7 +72,7 @@ EOF
5272

5373
cat "$conf_file"
5474

55-
conf_dir=$slapd_data_dir/slapd.d
75+
readonly conf_dir="$slapd_data_dir/slapd.d"
5676
mkdir -p "$conf_dir"
5777

5878
# Start slapd(8).
@@ -61,10 +81,12 @@ mkdir -p "$conf_dir"
6181
-F "$conf_dir" \
6282
-h "$uri"
6383

64-
auth="-x -D $binddn -w $passwd"
84+
readonly auth="-x -D $binddn -w $passwd"
6585

6686
# We wait for the server to start.
87+
# shellcheck disable=SC2034
6788
for seconds in 1 2 3 4 5 6 7 8 9 10; do
89+
# shellcheck disable=SC2086
6890
ldapsearch $auth -H "$uri" -LLL -b cn=config dn && break;
6991
sleep 1
7092
done
@@ -73,26 +95,33 @@ done
7395
# Load the example LDIFs for the testsuite.
7496
# --------------------------------------------------------------------
7597

76-
script_dir=$(cd "$(dirname "$0")" && pwd)
77-
example_ldif_dir="$script_dir/../../example"
78-
example_data_dir="$slapd_data_dir/example"
98+
tmp="$(cd "$(dirname "$0")" && pwd)"
99+
readonly script_dir="$tmp"
100+
readonly example_ldif_dir="$script_dir/../../example"
101+
readonly example_data_dir="$slapd_data_dir/example"
79102
mkdir -p "$example_data_dir"
80103

81104
# We update the hard-coded database directory with the one we computed
82105
# here, so the data is located inside the test directory.
106+
# shellcheck disable=SC2086
83107
sed -E -e "s,^olcDbDirectory:.*,olcDbDirectory: $example_data_dir," \
84108
< "$example_ldif_dir/global.ldif" | \
85109
ldapadd $auth -H "$uri"
86110

87111
# We remove the module path from the example LDIF as it was already
88112
# configured.
113+
# shellcheck disable=SC2086
89114
sed -E -e "s,^olcModulePath:.*,olcModulePath: $modulepath," \
90115
< "$example_ldif_dir/memberof_init.ldif" | \
91116
ldapadd $auth -H "$uri"
92117

118+
# shellcheck disable=SC2086
93119
ldapmodify $auth -H "$uri" -f "$example_ldif_dir/refint_1.ldif"
120+
121+
# shellcheck disable=SC2086
94122
ldapadd $auth -H "$uri" -f "$example_ldif_dir/refint_2.ldif"
95123

124+
# shellcheck disable=SC2086
96125
ldapsearch $auth -H "$uri" -LLL -b cn=config dn
97126

98-
echo SLAPD_PID=$(cat "$pidfile")
127+
echo SLAPD_PID="$(cat "$pidfile")"

0 commit comments

Comments
 (0)