Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit a1ba7a8

Browse files
authored
Update scripts to pass Shellcheck lints (#11166)
2 parents 75ca0a6 + 0dffa9d commit a1ba7a8

20 files changed

+120
-104
lines changed

.ci/scripts/test_export_data_command.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Test for the export-data admin command against sqlite and postgres
44

55
set -xe
6-
cd `dirname $0`/../..
6+
cd "$(dirname "$0")/../.."
77

88
echo "--- Install dependencies"
99

.ci/scripts/test_synapse_port_db.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
set -xe
10-
cd `dirname $0`/../..
10+
cd "$(dirname "$0")/../.."
1111

1212
echo "--- Install dependencies"
1313

changelog.d/11166.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Update scripts to pass Shellcheck lints.

contrib/purge_api/purge_history.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ AUTH="Authorization: Bearer $TOKEN"
8484
###################################################################################################
8585
# finally start pruning the room:
8686
###################################################################################################
87-
POSTDATA='{"delete_local_events":"true"}' # this will really delete local events, so the messages in the room really disappear unless they are restored by remote federation
87+
# this will really delete local events, so the messages in the room really
88+
# disappear unless they are restored by remote federation. This is because
89+
# we pass {"delete_local_events":true} to the curl invocation below.
8890

8991
for ROOM in "${ROOMS_ARRAY[@]}"; do
9092
echo "########################################### $(date) ################# "
@@ -104,7 +106,7 @@ for ROOM in "${ROOMS_ARRAY[@]}"; do
104106
SLEEP=2
105107
set -x
106108
# call purge
107-
OUT=$(curl --header "$AUTH" -s -d $POSTDATA POST "$API_URL/admin/purge_history/$ROOM/$EVENT_ID")
109+
OUT=$(curl --header "$AUTH" -s -d '{"delete_local_events":true}' POST "$API_URL/admin/purge_history/$ROOM/$EVENT_ID")
108110
PURGE_ID=$(echo "$OUT" |grep purge_id|cut -d'"' -f4 )
109111
if [ "$PURGE_ID" == "" ]; then
110112
# probably the history purge is already in progress for $ROOM

debian/build_virtualenv

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export DH_VIRTUALENV_INSTALL_ROOT=/opt/venvs
1515
# python won't look in the right directory. At least this way, the error will
1616
# be a *bit* more obvious.
1717
#
18-
SNAKE=`readlink -e /usr/bin/python3`
18+
SNAKE=$(readlink -e /usr/bin/python3)
1919

2020
# try to set the CFLAGS so any compiled C extensions are compiled with the most
2121
# generic as possible x64 instructions, so that compiling it on a new Intel chip
@@ -24,7 +24,7 @@ SNAKE=`readlink -e /usr/bin/python3`
2424
# TODO: add similar things for non-amd64, or figure out a more generic way to
2525
# do this.
2626

27-
case `dpkg-architecture -q DEB_HOST_ARCH` in
27+
case $(dpkg-architecture -q DEB_HOST_ARCH) in
2828
amd64)
2929
export CFLAGS=-march=x86-64
3030
;;
@@ -56,8 +56,8 @@ case "$DEB_BUILD_OPTIONS" in
5656
*)
5757
# Copy tests to a temporary directory so that we can put them on the
5858
# PYTHONPATH without putting the uninstalled synapse on the pythonpath.
59-
tmpdir=`mktemp -d`
60-
trap "rm -r $tmpdir" EXIT
59+
tmpdir=$(mktemp -d)
60+
trap 'rm -r $tmpdir' EXIT
6161

6262
cp -r tests "$tmpdir"
6363

@@ -98,7 +98,7 @@ esac
9898
--output-file="${PACKAGE_BUILD_DIR}/etc/matrix-synapse/log.yaml"
9999

100100
# add a dependency on the right version of python to substvars.
101-
PYPKG=`basename $SNAKE`
101+
PYPKG=$(basename "$SNAKE")
102102
echo "synapse:pydepends=$PYPKG" >> debian/matrix-synapse-py3.substvars
103103

104104

debian/changelog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
matrix-synapse-py3 (1.47.0+nmu1) UNRELEASED; urgency=medium
2+
3+
* Update scripts to pass Shellcheck lints.
4+
5+
-- root <root@cae79a6e79d7> Fri, 22 Oct 2021 22:20:31 +0000
6+
17
matrix-synapse-py3 (1.46.0~rc1) stable; urgency=medium
28

39
* New synapse release 1.46.0~rc1.

debian/matrix-synapse-py3.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
set -e
44

5+
# shellcheck disable=SC1091
56
. /usr/share/debconf/confmodule
67

78
# try to update the debconf db according to whatever is in the config files

debian/matrix-synapse-py3.postinst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/bin/sh -e
22

3+
# shellcheck disable=SC1091
34
. /usr/share/debconf/confmodule
45

56
CONFIGFILE_SERVERNAME="/etc/matrix-synapse/conf.d/server_name.yaml"

debian/test/provision.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ set -e
1010
apt-get update
1111
apt-get install -y lsb-release
1212

13-
deb=`ls /debs/matrix-synapse-py3_*+$(lsb_release -cs)*.deb | sort | tail -n1`
13+
deb=$(find /debs -name "matrix-synapse-py3_*+$(lsb_release -cs)*.deb" | sort | tail -n1)
1414

1515
debconf-set-selections <<EOF
1616
matrix-synapse matrix-synapse/report-stats boolean false
@@ -19,5 +19,6 @@ EOF
1919

2020
dpkg -i "$deb"
2121

22-
sed -i -e '/port: 8...$/{s/8448/18448/; s/8008/18008/}' -e '$aregistration_shared_secret: secret' /etc/matrix-synapse/homeserver.yaml
22+
sed -i -e 's/port: 8448$/port: 18448/; s/port: 8008$/port: 18008' /etc/matrix-synapse/homeserver.yaml
23+
echo 'registration_shared_secret: secret' >> /etc/matrix-synapse/homeserver.yaml
2324
systemctl restart matrix-synapse

demo/clean.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ DIR="$( cd "$( dirname "$0" )" && pwd )"
66

77
PID_FILE="$DIR/servers.pid"
88

9-
if [ -f $PID_FILE ]; then
9+
if [ -f "$PID_FILE" ]; then
1010
echo "servers.pid exists!"
1111
exit 1
1212
fi
1313

1414
for port in 8080 8081 8082; do
15-
rm -rf $DIR/$port
16-
rm -rf $DIR/media_store.$port
15+
rm -rf "${DIR:?}/$port"
16+
rm -rf "$DIR/media_store.$port"
1717
done
1818

19-
rm -rf $DIR/etc
19+
rm -rf "${DIR:?}/etc"

demo/start.sh

Lines changed: 79 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,22 @@ DIR="$( cd "$( dirname "$0" )" && pwd )"
44

55
CWD=$(pwd)
66

7-
cd "$DIR/.."
7+
cd "$DIR/.." || exit
88

99
mkdir -p demo/etc
1010

11-
export PYTHONPATH=$(readlink -f $(pwd))
11+
PYTHONPATH=$(readlink -f "$(pwd)")
12+
export PYTHONPATH
1213

1314

14-
echo $PYTHONPATH
15+
echo "$PYTHONPATH"
1516

1617
for port in 8080 8081 8082; do
1718
echo "Starting server on port $port... "
1819

1920
https_port=$((port + 400))
2021
mkdir -p demo/$port
21-
pushd demo/$port
22+
pushd demo/$port || exit
2223

2324
#rm $DIR/etc/$port.config
2425
python3 -m synapse.app.homeserver \
@@ -27,75 +28,78 @@ for port in 8080 8081 8082; do
2728
--config-path "$DIR/etc/$port.config" \
2829
--report-stats no
2930

30-
if ! grep -F "Customisation made by demo/start.sh" -q $DIR/etc/$port.config; then
31-
printf '\n\n# Customisation made by demo/start.sh\n' >> $DIR/etc/$port.config
32-
33-
echo "public_baseurl: http://localhost:$port/" >> $DIR/etc/$port.config
34-
35-
echo 'enable_registration: true' >> $DIR/etc/$port.config
36-
37-
# Warning, this heredoc depends on the interaction of tabs and spaces. Please don't
38-
# accidentaly bork me with your fancy settings.
39-
listeners=$(cat <<-PORTLISTENERS
40-
# Configure server to listen on both $https_port and $port
41-
# This overides some of the default settings above
42-
listeners:
43-
- port: $https_port
44-
type: http
45-
tls: true
46-
resources:
47-
- names: [client, federation]
48-
49-
- port: $port
50-
tls: false
51-
bind_addresses: ['::1', '127.0.0.1']
52-
type: http
53-
x_forwarded: true
54-
resources:
55-
- names: [client, federation]
56-
compress: false
57-
PORTLISTENERS
58-
)
59-
echo "${listeners}" >> $DIR/etc/$port.config
60-
61-
# Disable tls for the servers
62-
printf '\n\n# Disable tls on the servers.' >> $DIR/etc/$port.config
63-
echo '# DO NOT USE IN PRODUCTION' >> $DIR/etc/$port.config
64-
echo 'use_insecure_ssl_client_just_for_testing_do_not_use: true' >> $DIR/etc/$port.config
65-
echo 'federation_verify_certificates: false' >> $DIR/etc/$port.config
66-
67-
# Set tls paths
68-
echo "tls_certificate_path: \"$DIR/etc/localhost:$https_port.tls.crt\"" >> $DIR/etc/$port.config
69-
echo "tls_private_key_path: \"$DIR/etc/localhost:$https_port.tls.key\"" >> $DIR/etc/$port.config
70-
31+
if ! grep -F "Customisation made by demo/start.sh" -q "$DIR/etc/$port.config"; then
7132
# Generate tls keys
72-
openssl req -x509 -newkey rsa:4096 -keyout $DIR/etc/localhost\:$https_port.tls.key -out $DIR/etc/localhost\:$https_port.tls.crt -days 365 -nodes -subj "/O=matrix"
73-
74-
# Ignore keys from the trusted keys server
75-
echo '# Ignore keys from the trusted keys server' >> $DIR/etc/$port.config
76-
echo 'trusted_key_servers:' >> $DIR/etc/$port.config
77-
echo ' - server_name: "matrix.org"' >> $DIR/etc/$port.config
78-
echo ' accept_keys_insecurely: true' >> $DIR/etc/$port.config
79-
80-
# Reduce the blacklist
81-
blacklist=$(cat <<-BLACK
82-
# Set the blacklist so that it doesn't include 127.0.0.1, ::1
83-
federation_ip_range_blacklist:
84-
- '10.0.0.0/8'
85-
- '172.16.0.0/12'
86-
- '192.168.0.0/16'
87-
- '100.64.0.0/10'
88-
- '169.254.0.0/16'
89-
- 'fe80::/64'
90-
- 'fc00::/7'
91-
BLACK
92-
)
93-
echo "${blacklist}" >> $DIR/etc/$port.config
33+
openssl req -x509 -newkey rsa:4096 -keyout "$DIR/etc/localhost:$https_port.tls.key" -out "$DIR/etc/localhost:$https_port.tls.crt" -days 365 -nodes -subj "/O=matrix"
34+
35+
# Regenerate configuration
36+
{
37+
printf '\n\n# Customisation made by demo/start.sh\n'
38+
echo "public_baseurl: http://localhost:$port/"
39+
echo 'enable_registration: true'
40+
41+
# Warning, this heredoc depends on the interaction of tabs and spaces.
42+
# Please don't accidentaly bork me with your fancy settings.
43+
listeners=$(cat <<-PORTLISTENERS
44+
# Configure server to listen on both $https_port and $port
45+
# This overides some of the default settings above
46+
listeners:
47+
- port: $https_port
48+
type: http
49+
tls: true
50+
resources:
51+
- names: [client, federation]
52+
53+
- port: $port
54+
tls: false
55+
bind_addresses: ['::1', '127.0.0.1']
56+
type: http
57+
x_forwarded: true
58+
resources:
59+
- names: [client, federation]
60+
compress: false
61+
PORTLISTENERS
62+
)
63+
64+
echo "${listeners}"
65+
66+
# Disable tls for the servers
67+
printf '\n\n# Disable tls on the servers.'
68+
echo '# DO NOT USE IN PRODUCTION'
69+
echo 'use_insecure_ssl_client_just_for_testing_do_not_use: true'
70+
echo 'federation_verify_certificates: false'
71+
72+
# Set tls paths
73+
echo "tls_certificate_path: \"$DIR/etc/localhost:$https_port.tls.crt\""
74+
echo "tls_private_key_path: \"$DIR/etc/localhost:$https_port.tls.key\""
75+
76+
# Ignore keys from the trusted keys server
77+
echo '# Ignore keys from the trusted keys server'
78+
echo 'trusted_key_servers:'
79+
echo ' - server_name: "matrix.org"'
80+
echo ' accept_keys_insecurely: true'
81+
82+
# Reduce the blacklist
83+
blacklist=$(cat <<-BLACK
84+
# Set the blacklist so that it doesn't include 127.0.0.1, ::1
85+
federation_ip_range_blacklist:
86+
- '10.0.0.0/8'
87+
- '172.16.0.0/12'
88+
- '192.168.0.0/16'
89+
- '100.64.0.0/10'
90+
- '169.254.0.0/16'
91+
- 'fe80::/64'
92+
- 'fc00::/7'
93+
BLACK
94+
)
95+
96+
echo "${blacklist}"
97+
} >> "$DIR/etc/$port.config"
9498
fi
9599

96100
# Check script parameters
97101
if [ $# -eq 1 ]; then
98-
if [ $1 = "--no-rate-limit" ]; then
102+
if [ "$1" = "--no-rate-limit" ]; then
99103

100104
# Disable any rate limiting
101105
ratelimiting=$(cat <<-RC
@@ -137,22 +141,22 @@ for port in 8080 8081 8082; do
137141
burst_count: 1000
138142
RC
139143
)
140-
echo "${ratelimiting}" >> $DIR/etc/$port.config
144+
echo "${ratelimiting}" >> "$DIR/etc/$port.config"
141145
fi
142146
fi
143147

144-
if ! grep -F "full_twisted_stacktraces" -q $DIR/etc/$port.config; then
145-
echo "full_twisted_stacktraces: true" >> $DIR/etc/$port.config
148+
if ! grep -F "full_twisted_stacktraces" -q "$DIR/etc/$port.config"; then
149+
echo "full_twisted_stacktraces: true" >> "$DIR/etc/$port.config"
146150
fi
147-
if ! grep -F "report_stats" -q $DIR/etc/$port.config ; then
148-
echo "report_stats: false" >> $DIR/etc/$port.config
151+
if ! grep -F "report_stats" -q "$DIR/etc/$port.config" ; then
152+
echo "report_stats: false" >> "$DIR/etc/$port.config"
149153
fi
150154

151155
python3 -m synapse.app.homeserver \
152156
--config-path "$DIR/etc/$port.config" \
153157
-D \
154158

155-
popd
159+
popd || exit
156160
done
157161

158-
cd "$CWD"
162+
cd "$CWD" || exit

demo/stop.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ for pid_file in $FILES; do
88
pid=$(cat "$pid_file")
99
if [[ $pid ]]; then
1010
echo "Killing $pid_file with $pid"
11-
kill $pid
11+
kill "$pid"
1212
fi
1313
done
1414

docker/build_debian.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
set -ex
66

77
# Get the codename from distro env
8-
DIST=`cut -d ':' -f2 <<< $distro`
8+
DIST=$(cut -d ':' -f2 <<< "${distro:?}")
99

1010
# we get a read-only copy of the source: make a writeable copy
1111
cp -aT /synapse/source /synapse/build
@@ -17,7 +17,7 @@ cd /synapse/build
1717
# Section to determine which "component" it should go into (see
1818
# https://manpages.debian.org/stretch/reprepro/reprepro.1.en.html#GUESSING)
1919

20-
DEB_VERSION=`dpkg-parsechangelog -SVersion`
20+
DEB_VERSION=$(dpkg-parsechangelog -SVersion)
2121
case $DEB_VERSION in
2222
*~rc*|*~a*|*~b*|*~c*)
2323
sed -ie '/^Section:/c\Section: prerelease' debian/control

scripts-dev/check-newsfragment

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ echo "--------------------------"
4242
echo
4343

4444
matched=0
45-
for f in `git diff --name-only FETCH_HEAD... -- changelog.d`; do
45+
for f in $(git diff --name-only FETCH_HEAD... -- changelog.d); do
4646
# check that any modified newsfiles on this branch end with a full stop.
47-
lastchar=`tr -d '\n' < $f | tail -c 1`
48-
if [ $lastchar != '.' -a $lastchar != '!' ]; then
47+
lastchar=$(tr -d '\n' < "$f" | tail -c 1)
48+
if [ "$lastchar" != '.' ] && [ "$lastchar" != '!' ]; then
4949
echo -e "\e[31mERROR: newsfragment $f does not end with a '.' or '!'\e[39m" >&2
5050
echo -e "$CONTRIBUTING_GUIDE_TEXT" >&2
5151
exit 1

scripts-dev/check_line_terminators.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# terminators are found, 0 otherwise.
2626

2727
# cd to the root of the repository
28-
cd `dirname $0`/..
28+
cd "$(dirname "$0")/.." || exit
2929

3030
# Find and print files with non-unix line terminators
3131
if find . -path './.git/*' -prune -o -type f -print0 | xargs -0 grep -I -l $'\r$'; then

0 commit comments

Comments
 (0)