Skip to content

Commit 3e04870

Browse files
authored
Merge pull request #3008 from element-hq/feature/bma/shellCheck
Shell check
2 parents 756905b + 89e0d94 commit 3e04870

File tree

8 files changed

+121
-108
lines changed

8 files changed

+121
-108
lines changed

.github/workflows/quality.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,19 @@ jobs:
187187
- name: Run Knit
188188
run: ./gradlew knitCheck $CI_GRADLE_ARG_PROPERTIES
189189

190+
# Note: to auto fix issues you can use the following command:
191+
# shellcheck -f diff <files> | git apply
192+
shellcheck:
193+
name: Check shell scripts
194+
runs-on: ubuntu-latest
195+
steps:
196+
- uses: actions/checkout@v4
197+
- name: Run shellcheck
198+
uses: ludeeus/[email protected]
199+
with:
200+
scandir: ./tools
201+
severity: warning
202+
190203
upload_reports:
191204
name: Project Check Suite
192205
runs-on: ubuntu-latest

tools/check/check_code_quality.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@ echo
4141
echo "Search for forbidden patterns in Kotlin source files..."
4242

4343
# list all Kotlin folders of the project.
44-
allKotlinDirs=`find . -type d |grep -v build |grep -v \.git |grep -v \.gradle |grep kotlin$`
44+
allKotlinDirs=$(find . -type d |grep -v build |grep -v \.git |grep -v \.gradle |grep kotlin$)
4545

46-
${searchForbiddenStringsScript} ./tools/check/forbidden_strings_in_code.txt $allKotlinDirs
46+
${searchForbiddenStringsScript} ./tools/check/forbidden_strings_in_code.txt "$allKotlinDirs"
4747

4848
resultForbiddenStringInCode=$?
4949

5050
echo
5151
echo "Search for forbidden patterns in XML resource files..."
5252

5353
# list all res folders of the project.
54-
allResDirs=`find . -type d |grep -v build |grep -v \.git |grep -v \.gradle |grep /res$`
54+
allResDirs=$(find . -type d |grep -v build |grep -v \.git |grep -v \.gradle |grep /res$)
5555

56-
${searchForbiddenStringsScript} ./tools/check/forbidden_strings_in_xml.txt $allResDirs
56+
${searchForbiddenStringsScript} ./tools/check/forbidden_strings_in_xml.txt "$allResDirs"
5757

5858
resultForbiddenStringInXml=$?
5959

tools/docs/generateModuleGraph.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#
1818

1919
## Dependency graph https://github.com/savvasdalkitsis/module-dependency-graph
20-
dotPath=`pwd`/docs/images/module_graph.dot
21-
pngPath=`pwd`/docs/images/module_graph.png
22-
./gradlew graphModules -PdotFilePath=${dotPath} -PgraphOutputFilePath=${pngPath} -PautoOpenGraph=false
23-
rm ${dotPath}
20+
dotPath=$(pwd)/docs/images/module_graph.dot
21+
pngPath=$(pwd)/docs/images/module_graph.png
22+
./gradlew graphModules -PdotFilePath="${dotPath}" -PgraphOutputFilePath="${pngPath}" -PautoOpenGraph=false
23+
rm "${dotPath}"

tools/localazy/downloadStrings.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ fi
5151

5252
set +e
5353
echo "Moving files from values-id to values-in..."
54-
find . -type d -name 'values-id' -execdir mv {}/translations.xml {}/../values-in/translations.xml 2> /dev/null \;
54+
find . -type d -name 'values-id' -execdir mv {}/translations.xml {}/../values-in/translations.xml \; 2> /dev/null
5555

5656
echo "Deleting all the folders values-id..."
57-
find . -type d -name 'values-id' -exec rm -rf {} 2> /dev/null \;
57+
find . -type d -name 'values-id' -exec rm -rf {} \; 2> /dev/null
5858
set -e
5959

6060
echo "Checking forbidden terms..."

tools/release/release.sh

Lines changed: 68 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ if [[ ! -d ${buildToolsPath} ]]; then
8383
fi
8484

8585
# Check if git flow is enabled
86-
gitFlowDevelop=`git config gitflow.branch.develop`
86+
gitFlowDevelop=$(git config gitflow.branch.develop)
8787
if [[ ${gitFlowDevelop} != "" ]]
8888
then
8989
printf "Git flow is initialized\n"
@@ -105,23 +105,23 @@ git pull
105105
printf "\n================================================================================\n"
106106
# Guessing version to propose a default version
107107
versionsFile="./plugins/src/main/kotlin/Versions.kt"
108-
versionMajorCandidate=`grep "val versionMajor" ${versionsFile} | cut -d " " -f6`
109-
versionMinorCandidate=`grep "val versionMinor" ${versionsFile} | cut -d " " -f6`
110-
versionPatchCandidate=`grep "val versionPatch" ${versionsFile} | cut -d " " -f6`
108+
versionMajorCandidate=$(grep "val versionMajor" ${versionsFile} | cut -d " " -f6)
109+
versionMinorCandidate=$(grep "val versionMinor" ${versionsFile} | cut -d " " -f6)
110+
versionPatchCandidate=$(grep "val versionPatch" ${versionsFile} | cut -d " " -f6)
111111
versionCandidate="${versionMajorCandidate}.${versionMinorCandidate}.${versionPatchCandidate}"
112112

113113
read -p "Please enter the release version (example: ${versionCandidate}). Just press enter if ${versionCandidate} is correct. " version
114114
version=${version:-${versionCandidate}}
115115

116116
# extract major, minor and patch for future use
117-
versionMajor=`echo ${version} | cut -d "." -f1`
118-
versionMinor=`echo ${version} | cut -d "." -f2`
119-
versionPatch=`echo ${version} | cut -d "." -f3`
117+
versionMajor=$(echo "${version}" | cut -d "." -f1)
118+
versionMinor=$(echo "${version}" | cut -d "." -f2)
119+
versionPatch=$(echo "${version}" | cut -d "." -f3)
120120
nextPatchVersion=$((versionPatch + 1))
121121

122122
printf "\n================================================================================\n"
123123
printf "Starting the release ${version}\n"
124-
git flow release start ${version}
124+
git flow release start "${version}"
125125

126126
# Note: in case the release is already started and the script is started again, checkout the release branch again.
127127
ret=$?
@@ -154,15 +154,15 @@ git commit -a -m "Changelog for version ${version}"
154154

155155
printf "\n================================================================================\n"
156156
printf "Creating fastlane file...\n"
157-
printf -v versionMajor2Digits "%02d" ${versionMajor}
158-
printf -v versionMinor2Digits "%02d" ${versionMinor}
159-
printf -v versionPatch2Digits "%02d" ${versionPatch}
157+
printf -v versionMajor2Digits "%02d" "${versionMajor}"
158+
printf -v versionMinor2Digits "%02d" "${versionMinor}"
159+
printf -v versionPatch2Digits "%02d" "${versionPatch}"
160160
fastlaneFile="4${versionMajor2Digits}${versionMinor2Digits}${versionPatch2Digits}0.txt"
161161
fastlanePathFile="./fastlane/metadata/android/en-US/changelogs/${fastlaneFile}"
162-
printf "Main changes in this version: TODO.\nFull changelog: https://github.com/element-hq/element-x-android/releases" > ${fastlanePathFile}
162+
printf "Main changes in this version: TODO.\nFull changelog: https://github.com/element-hq/element-x-android/releases" > "${fastlanePathFile}"
163163

164164
read -p "I have created the file ${fastlanePathFile}, please edit it and press enter to continue. "
165-
git add ${fastlanePathFile}
165+
git add "${fastlanePathFile}"
166166
git commit -a -m "Adding fastlane file for version ${version}"
167167

168168
printf "\n================================================================================\n"
@@ -173,7 +173,7 @@ printf "\n======================================================================
173173
read -p "Done, push the branch 'main' and the new tag (yes/no) default to yes? " doPush
174174
doPush=${doPush:-yes}
175175

176-
if [ ${doPush} == "yes" ]; then
176+
if [ "${doPush}" == "yes" ]; then
177177
printf "Pushing branch 'main' and tag 'v${version}'...\n"
178178
git push origin main
179179
git push origin "v${version}"
@@ -202,7 +202,7 @@ printf "\n======================================================================
202202
read -p "Done, push the branch 'develop' (yes/no) default to yes? (A rebase may be necessary in case develop got new commits) " doPush
203203
doPush=${doPush:-yes}
204204

205-
if [ ${doPush} == "yes" ]; then
205+
if [ "${doPush}" == "yes" ]; then
206206
printf "Pushing branch 'develop'...\n"
207207
git push origin develop
208208
else
@@ -220,74 +220,74 @@ printf "\n======================================================================
220220
printf "Downloading the artifacts...\n"
221221

222222
python3 ./tools/github/download_all_github_artifacts.py \
223-
--token ${gitHubToken} \
224-
--runUrl ${runUrl} \
225-
--directory ${targetPath}
223+
--token "${gitHubToken}" \
224+
--runUrl "${runUrl}" \
225+
--directory "${targetPath}"
226226

227227
printf "\n================================================================================\n"
228228
printf "Unzipping the F-Droid artifact...\n"
229229

230230
fdroidTargetPath="${targetPath}/fdroid"
231-
unzip ${targetPath}/elementx-app-fdroid-apks-unsigned.zip -d ${fdroidTargetPath}
231+
unzip "${targetPath}"/elementx-app-fdroid-apks-unsigned.zip -d "${fdroidTargetPath}"
232232

233233
printf "\n================================================================================\n"
234234
printf "Signing the FDroid APKs...\n"
235235

236-
cp ${fdroidTargetPath}/app-fdroid-arm64-v8a-release.apk \
237-
${fdroidTargetPath}/app-fdroid-arm64-v8a-release-signed.apk
238-
${buildToolsPath}/apksigner sign \
236+
cp "${fdroidTargetPath}"/app-fdroid-arm64-v8a-release.apk \
237+
"${fdroidTargetPath}"/app-fdroid-arm64-v8a-release-signed.apk
238+
"${buildToolsPath}"/apksigner sign \
239239
-v \
240-
--ks ${keyStorePath} \
241-
--ks-pass pass:${keyStorePassword} \
240+
--ks "${keyStorePath}" \
241+
--ks-pass pass:"${keyStorePassword}" \
242242
--ks-key-alias elementx \
243-
--key-pass pass:${keyPassword} \
243+
--key-pass pass:"${keyPassword}" \
244244
--min-sdk-version ${minSdkVersion} \
245-
${fdroidTargetPath}/app-fdroid-arm64-v8a-release-signed.apk
245+
"${fdroidTargetPath}"/app-fdroid-arm64-v8a-release-signed.apk
246246

247-
cp ${fdroidTargetPath}/app-fdroid-armeabi-v7a-release.apk \
248-
${fdroidTargetPath}/app-fdroid-armeabi-v7a-release-signed.apk
249-
${buildToolsPath}/apksigner sign \
247+
cp "${fdroidTargetPath}"/app-fdroid-armeabi-v7a-release.apk \
248+
"${fdroidTargetPath}"/app-fdroid-armeabi-v7a-release-signed.apk
249+
"${buildToolsPath}"/apksigner sign \
250250
-v \
251-
--ks ${keyStorePath} \
252-
--ks-pass pass:${keyStorePassword} \
251+
--ks "${keyStorePath}" \
252+
--ks-pass pass:"${keyStorePassword}" \
253253
--ks-key-alias elementx \
254-
--key-pass pass:${keyPassword} \
254+
--key-pass pass:"${keyPassword}" \
255255
--min-sdk-version ${minSdkVersion} \
256-
${fdroidTargetPath}/app-fdroid-armeabi-v7a-release-signed.apk
256+
"${fdroidTargetPath}"/app-fdroid-armeabi-v7a-release-signed.apk
257257

258-
cp ${fdroidTargetPath}/app-fdroid-x86-release.apk \
259-
${fdroidTargetPath}/app-fdroid-x86-release-signed.apk
260-
${buildToolsPath}/apksigner sign \
258+
cp "${fdroidTargetPath}"/app-fdroid-x86-release.apk \
259+
"${fdroidTargetPath}"/app-fdroid-x86-release-signed.apk
260+
"${buildToolsPath}"/apksigner sign \
261261
-v \
262-
--ks ${keyStorePath} \
263-
--ks-pass pass:${keyStorePassword} \
262+
--ks "${keyStorePath}" \
263+
--ks-pass pass:"${keyStorePassword}" \
264264
--ks-key-alias elementx \
265-
--key-pass pass:${keyPassword} \
265+
--key-pass pass:"${keyPassword}" \
266266
--min-sdk-version ${minSdkVersion} \
267-
${fdroidTargetPath}/app-fdroid-x86-release-signed.apk
267+
"${fdroidTargetPath}"/app-fdroid-x86-release-signed.apk
268268

269-
cp ${fdroidTargetPath}/app-fdroid-x86_64-release.apk \
270-
${fdroidTargetPath}/app-fdroid-x86_64-release-signed.apk
271-
${buildToolsPath}/apksigner sign \
269+
cp "${fdroidTargetPath}"/app-fdroid-x86_64-release.apk \
270+
"${fdroidTargetPath}"/app-fdroid-x86_64-release-signed.apk
271+
"${buildToolsPath}"/apksigner sign \
272272
-v \
273-
--ks ${keyStorePath} \
274-
--ks-pass pass:${keyStorePassword} \
273+
--ks "${keyStorePath}" \
274+
--ks-pass pass:"${keyStorePassword}" \
275275
--ks-key-alias elementx \
276-
--key-pass pass:${keyPassword} \
276+
--key-pass pass:"${keyPassword}" \
277277
--min-sdk-version ${minSdkVersion} \
278-
${fdroidTargetPath}/app-fdroid-x86_64-release-signed.apk
278+
"${fdroidTargetPath}"/app-fdroid-x86_64-release-signed.apk
279279

280280
printf "\n================================================================================\n"
281281
printf "Please check the information below:\n"
282282

283283
printf "File app-fdroid-arm64-v8a-release-signed.apk:\n"
284-
${buildToolsPath}/aapt dump badging ${fdroidTargetPath}/app-fdroid-arm64-v8a-release-signed.apk | grep package
284+
"${buildToolsPath}"/aapt dump badging "${fdroidTargetPath}"/app-fdroid-arm64-v8a-release-signed.apk | grep package
285285
printf "File app-fdroid-armeabi-v7a-release-signed.apk:\n"
286-
${buildToolsPath}/aapt dump badging ${fdroidTargetPath}/app-fdroid-armeabi-v7a-release-signed.apk | grep package
286+
"${buildToolsPath}"/aapt dump badging "${fdroidTargetPath}"/app-fdroid-armeabi-v7a-release-signed.apk | grep package
287287
printf "File app-fdroid-x86-release-signed.apk:\n"
288-
${buildToolsPath}/aapt dump badging ${fdroidTargetPath}/app-fdroid-x86-release-signed.apk | grep package
288+
"${buildToolsPath}"/aapt dump badging "${fdroidTargetPath}"/app-fdroid-x86-release-signed.apk | grep package
289289
printf "File app-fdroid-x86_64-release-signed.apk:\n"
290-
${buildToolsPath}/aapt dump badging ${fdroidTargetPath}/app-fdroid-x86_64-release-signed.apk | grep package
290+
"${buildToolsPath}"/aapt dump badging "${fdroidTargetPath}"/app-fdroid-x86_64-release-signed.apk | grep package
291291

292292
printf "\n"
293293
read -p "Does it look correct? Press enter when it's done."
@@ -299,32 +299,32 @@ printf "\n======================================================================
299299
printf "Unzipping the Gplay artifact...\n"
300300

301301
gplayTargetPath="${targetPath}/gplay"
302-
unzip ${targetPath}/elementx-app-gplay-bundle-unsigned.zip -d ${gplayTargetPath}
302+
unzip "${targetPath}"/elementx-app-gplay-bundle-unsigned.zip -d "${gplayTargetPath}"
303303

304304
unsignedBundlePath="${gplayTargetPath}/app-gplay-release.aab"
305305
signedBundlePath="${gplayTargetPath}/app-gplay-release-signed.aab"
306306

307307
printf "\n================================================================================\n"
308308
printf "Signing file ${unsignedBundlePath} with build-tools version ${buildToolsVersion} for min SDK version ${minSdkVersion}...\n"
309309

310-
cp ${unsignedBundlePath} ${signedBundlePath}
310+
cp "${unsignedBundlePath}" "${signedBundlePath}"
311311

312-
${buildToolsPath}/apksigner sign \
312+
"${buildToolsPath}"/apksigner sign \
313313
-v \
314-
--ks ${keyStorePath} \
315-
--ks-pass pass:${keyStorePassword} \
314+
--ks "${keyStorePath}" \
315+
--ks-pass pass:"${keyStorePassword}" \
316316
--ks-key-alias elementx \
317-
--key-pass pass:${keyPassword} \
317+
--key-pass pass:"${keyPassword}" \
318318
--min-sdk-version ${minSdkVersion} \
319-
${signedBundlePath}
319+
"${signedBundlePath}"
320320

321321
printf "\n================================================================================\n"
322322
printf "Please check the information below:\n"
323323

324324
printf "Version code: "
325-
bundletool dump manifest --bundle=${signedBundlePath} --xpath=/manifest/@android:versionCode
325+
bundletool dump manifest --bundle="${signedBundlePath}" --xpath=/manifest/@android:versionCode
326326
printf "Version name: "
327-
bundletool dump manifest --bundle=${signedBundlePath} --xpath=/manifest/@android:versionName
327+
bundletool dump manifest --bundle="${signedBundlePath}" --xpath=/manifest/@android:versionName
328328

329329
printf "\n"
330330
read -p "Does it look correct? Press enter to continue. "
@@ -336,17 +336,17 @@ printf "\n======================================================================
336336
read -p "Do you want to build the APKs from the app bundle? You need to do this step if you want to install the application to your device. (yes/no) default to yes " doBuildApks
337337
doBuildApks=${doBuildApks:-yes}
338338

339-
if [ ${doBuildApks} == "yes" ]; then
339+
if [ "${doBuildApks}" == "yes" ]; then
340340
printf "Building apks...\n"
341-
bundletool build-apks --bundle=${signedBundlePath} --output=${gplayTargetPath}/elementx.apks \
341+
bundletool build-apks --bundle="${signedBundlePath}" --output="${gplayTargetPath}"/elementx.apks \
342342
--ks=./app/signature/debug.keystore --ks-pass=pass:android --ks-key-alias=androiddebugkey --key-pass=pass:android \
343343
--overwrite
344344

345345
read -p "Do you want to install the application to your device? Make sure there is one (and only one!) connected device first. (yes/no) default to yes " doDeploy
346346
doDeploy=${doDeploy:-yes}
347-
if [ ${doDeploy} == "yes" ]; then
347+
if [ "${doDeploy}" == "yes" ]; then
348348
printf "Installing apk for your device...\n"
349-
bundletool install-apks --apks=${gplayTargetPath}/elementx.apks
349+
bundletool install-apks --apks="${gplayTargetPath}"/elementx.apks
350350
read -p "Please run the application on your phone to check that the upgrade went well. Press enter to continue. "
351351
else
352352
printf "APK will not be deployed!\n"
@@ -373,7 +373,7 @@ printf "\n======================================================================
373373
body="%3C%21--%20Copy%20paste%20the%20section%20of%20the%20file%20CHANGES.md%20for%20this%20release%20here%20--%3E"
374374
githubCreateReleaseLink="https://github.com/element-hq/element-x-android/releases/new?tag=v${version}&title=Element%20X%20Android%20v${version}&body=${body}"
375375
printf "Creating the release on gitHub.\n"
376-
printf -- "Open this link: %s\n" ${githubCreateReleaseLink}
376+
printf -- "Open this link: %s\n" "${githubCreateReleaseLink}"
377377
printf "Then\n"
378378
printf " - copy paste the section of the file CHANGES.md for this release.\n"
379379
printf " - click on the 'Generate releases notes' button.\n"
@@ -392,12 +392,12 @@ if [[ -z "${elementBotToken}" ]]; then
392392
else
393393
read -p "Send this message to the room (yes/no) default to yes? " doSend
394394
doSend=${doSend:-yes}
395-
if [ ${doSend} == "yes" ]; then
395+
if [ "${doSend}" == "yes" ]; then
396396
printf "Sending message...\n"
397-
transactionId=`openssl rand -hex 16`
397+
transactionId=$(openssl rand -hex 16)
398398
# Element Android internal
399399
matrixRoomId="!LiSLXinTDCsepePiYW:matrix.org"
400-
curl -X PUT --data $"{\"msgtype\":\"m.text\",\"body\":\"${message}\"}" -H "Authorization: Bearer ${elementBotToken}" https://matrix-client.matrix.org/_matrix/client/r0/rooms/${matrixRoomId}/send/m.room.message/\$local.${transactionId}
400+
curl -X PUT --data "{\"msgtype\":\"m.text\",\"body\":\"${message}\"}" -H "Authorization: Bearer ${elementBotToken}" https://matrix-client.matrix.org/_matrix/client/r0/rooms/${matrixRoomId}/send/m.room.message/\$local."${transactionId}"
401401
else
402402
printf "Message not sent, please send it manually!\n"
403403
fi

0 commit comments

Comments
 (0)