Skip to content

Commit 0615b7b

Browse files
committed
shellscripts: improve code for shellcheck
Signed-off-by: Patrizio Bekerle <[email protected]>
1 parent 80cd1fb commit 0615b7b

34 files changed

+372
-336
lines changed

build-systems/aur/build-for-aur.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ BRANCH=main
2121
#BRANCH=release
2222

2323
PROJECT_PATH="/tmp/QOwnNotes-aur-$$"
24-
CUR_DIR=$(pwd)
2524

2625
# use temporary checksum variable file
2726
_QQwnNotesCheckSumVarFile="/tmp/QOwnNotes.checksum.vars"
@@ -31,36 +30,37 @@ if [[ ! -f ${_QQwnNotesCheckSumVarFile} ]]; then
3130
exit 1
3231
fi
3332

34-
source ${_QQwnNotesCheckSumVarFile}
33+
# shellcheck source=/dev/null
34+
source "${_QQwnNotesCheckSumVarFile}"
3535

3636
# check checksum variable from build-systems/github/build-github-src.sh
37-
if [ -z ${QOWNNOTES_ARCHIVE_SHA256} ]; then
37+
if [ -z "${QOWNNOTES_ARCHIVE_SHA256}" ]; then
3838
echo "QOWNNOTES_ARCHIVE_SHA256 was not set!"
3939
exit 1
4040
fi
4141

4242
echo "Started the AUR packaging process, using latest '$BRANCH' git tree"
4343

44-
if [ -d $PROJECT_PATH ]; then
45-
rm -rf $PROJECT_PATH
44+
if [ -d "$PROJECT_PATH" ]; then
45+
rm -rf "$PROJECT_PATH"
4646
fi
4747

48-
mkdir $PROJECT_PATH
49-
cd $PROJECT_PATH || exit 1
48+
mkdir "$PROJECT_PATH"
49+
cd "$PROJECT_PATH" || exit 1
5050

5151
echo "Project path: $PROJECT_PATH"
5252

5353
# checkout AUR repository
5454
git clone --depth=1 ssh://[email protected]/qownnotes.git aur -b master
5555

5656
# checkout the source code
57-
git clone --depth=1 [email protected]:pbek/QOwnNotes.git QOwnNotes -b $BRANCH
57+
git clone --depth=1 [email protected]:pbek/QOwnNotes.git QOwnNotes -b "$BRANCH"
5858
cd QOwnNotes || exit 1
5959

6060
gitCommitHash=$(git rev-parse HEAD)
6161
echo "Current commit: $gitCommitHash"
6262

63-
if [ -z $QOWNNOTES_VERSION ]; then
63+
if [ -z "$QOWNNOTES_VERSION" ]; then
6464
# get version from version.h
6565
QOWNNOTES_VERSION=$(cat src/version.h | sed "s/[^0-9,.]//g")
6666
fi

build-systems/build-all.sh

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ if [ "$1" = "--docker" ]; then
88
echo "Importing PGP key..."
99
gpg --import ~/private.pgp
1010
echo "Adding AUR ssh key..."
11-
eval $(ssh-agent -s)
11+
eval "$(ssh-agent -s)"
1212
ssh-add ~/.ssh/aur_rsa
1313
fi
1414

@@ -39,78 +39,107 @@ zellij delete-session deploy-qownnotes
3939
# start a new deployment session with all deployment scripts from releaser.kdl
4040
zellij --layout releaser.kdl attach deploy-qownnotes -c
4141

42+
# shellcheck disable=SC2317
4243
exit
4344

45+
# The following code is unreachable but kept as fallback documentation
46+
47+
# shellcheck disable=SC2317
4448
# fallback if zellij doesn't work
49+
# shellcheck disable=SC2317
4550
../ubuntu-launchpad/build-for-launchpad.sh
51+
# shellcheck disable=SC2317
4652
../ubuntu-launchpad/build-for-launchpad-qt6.sh
53+
# shellcheck disable=SC2317
4754
../obs/build-for-obs.sh
55+
# shellcheck disable=SC2317
4856
aur/build-for-aur.sh
57+
# shellcheck disable=SC2317
4958
gentoo/build-for-gentoo.sh
59+
# shellcheck disable=SC2317
5060
slackware/build-for-slackware.sh
61+
# shellcheck disable=SC2317
5162
snap/build-for-launchpad-snap.sh
63+
# shellcheck disable=SC2317
5264
obs/cmake-qt6/build-for-obs.sh
5365

66+
# shellcheck disable=SC2317
5467
exit
5568

69+
# shellcheck disable=SC2317
5670
#
5771
# this was the previous konsole tabs implementation
5872
#
5973

74+
# shellcheck disable=SC2317
6075
# List of commands to run, with parameters, in quotes, space-separated; do not use quotes inside (see bash arrays)
76+
# shellcheck disable=SC2317
6177
COMMANDS=("$DIR/../ubuntu-launchpad/build-for-launchpad.sh" "$DIR/../obs/build-for-obs.sh" "$DIR/aur/build-for-aur.sh" "$DIR/gentoo/build-for-gentoo.sh" "$DIR/slackware/build-for-slackware.sh" "$DIR/snap/build-for-launchpad-snap.sh" "$DIR/obs/cmake-qt6/build-for-obs.sh")
6278
# "$DIR/snap/build-for-local-snap.sh"
6379

6480
# KDS=$KONSOLE_DBUS_SERVICE # This is the ref of the current konsole and only works in a konsole
6581
# KDS=$(org.kde.konsole) # This is found in some examples but is incomplete
6682

67-
qdbus >/tmp/q0 # Get the current list of konsoles
83+
# shellcheck disable=SC2317
84+
qdbus >/tmp/q0 # Get the current list of konsoles
85+
# shellcheck disable=SC2317
6886
/usr/bin/konsole & # Launch a new konsole
6987
# PID=$! # And get its PID - But for some reason this is off by a few
88+
# shellcheck disable=SC2317
7089
sleep 1
90+
# shellcheck disable=SC2317
7191
qdbus >/tmp/q1 # Get the new list of konsoles
7292
# KDS=org.kde.konsole-$PID
7393
# KDS=org.kde.konsole # Sometimes
94+
# shellcheck disable=SC2317
7495
KDS=$(diff /tmp/q{0,1} | grep konsole) # Let's hope there's only one
7596
#echo $KDS
97+
# shellcheck disable=SC2317
7698
KDS=${KDS:3}
99+
# shellcheck disable=SC2317
77100
echo "$KDS"
78101

79-
echo $KDS >/tmp/KDS
80-
echo >>/tmp/KDS
81-
82-
qdbus "$KDS" >>/tmp/KDS || exit
83-
echo >>/tmp/KDS
102+
# shellcheck disable=SC2317
103+
{
104+
echo "$KDS"
105+
echo
106+
qdbus "$KDS"
107+
echo
108+
} >/tmp/KDS
84109

85110
# See note https://docs.kde.org/trunk5/en/applications/konsole/scripting.html about using /Konsole
86-
qdbus $KDS /Windows/1 >>/tmp/KDS
111+
# shellcheck disable=SC2317
112+
qdbus "$KDS" /Windows/1 >>/tmp/KDS
113+
# shellcheck disable=SC2317
87114
echo >>/tmp/KDS
88115

116+
# shellcheck disable=SC2317
89117
FirstTime=1
90118

119+
# shellcheck disable=SC2317
91120
for i in "${COMMANDS[@]}"; do
92121
echo "Starting: $i"
93122
echo >>/tmp/KDS
94-
if [ $FirstTime -eq 1 ]; then
95-
session=$(qdbus $KDS /Windows/1 currentSession)
123+
if [ "$FirstTime" -eq 1 ]; then
124+
session=$(qdbus "$KDS" /Windows/1 currentSession)
96125
FirstTime=0
97126
else
98-
session=$(qdbus $KDS /Windows/1 newSession)
127+
session=$(qdbus "$KDS" /Windows/1 newSession)
99128
fi
100-
echo $session >>/tmp/KDS
129+
echo "$session" >>/tmp/KDS
101130

102131
# Test: Display possible actions
103-
qdbus $KDS /Sessions/${session} >>/tmp/KDS
132+
qdbus "$KDS" /Sessions/"${session}" >>/tmp/KDS
104133

105134
# Doesn't work well, maybe use setTabTitleFormat 0/1 instead
106135
# Title "0" appears to be the initial title, title "1" is the title used after commands are executed.
107136
#qdbus $KDS /Sessions/${session} setTitle 0 $i
108137
#qdbus $KDS /Sessions/${session} setTitle 1 $i
109138

110139
# The line break is necessary to commit the command. \n doesn't work
111-
qdbus $KDS /Sessions/${session} sendText "${i}
140+
qdbus "$KDS" /Sessions/"${session}" sendText "${i}
112141
"
113142

114143
# Optional: will ping when there's no more output in the window
115-
qdbus $KDS /Sessions/${session} setMonitorSilence true
144+
qdbus "$KDS" /Sessions/"${session}" setMonitorSilence true
116145
done

build-systems/build-qt6.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ if [ "$1" = "--docker" ]; then
88
echo "Importing PGP key..."
99
gpg --import ~/private.pgp
1010
echo "Adding AUR ssh key..."
11-
eval $(ssh-agent -s)
11+
eval "$(ssh-agent -s)"
1212
ssh-add ~/.ssh/aur_rsa
1313
fi
1414

build-systems/gentoo/build-for-gentoo.sh

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,29 @@ if [[ ! -f ${_QQwnNotesCheckSumVarFile} ]]; then
2323
exit 1
2424
fi
2525

26-
source ${_QQwnNotesCheckSumVarFile}
26+
# shellcheck source=/dev/null
27+
source "${_QQwnNotesCheckSumVarFile}"
2728

2829
# check checksum variable from build-systems/github/build-github-src.sh
29-
if [ -z ${QOWNNOTES_ARCHIVE_SHA512} ]; then
30+
if [ -z "${QOWNNOTES_ARCHIVE_SHA512}" ]; then
3031
echo "QOWNNOTES_ARCHIVE_SHA512 was not set!"
3132
exit 1
3233
fi
3334

34-
if [ -z ${QOWNNOTES_ARCHIVE_SIZE} ]; then
35+
if [ -z "${QOWNNOTES_ARCHIVE_SIZE}" ]; then
3536
echo "QOWNNOTES_ARCHIVE_SIZE was not set!"
3637
exit 1
3738
fi
3839

3940
list_old_ebuilds_to_delete() {
40-
all_files=($(find . -maxdepth 1 -type f -name 'qownnotes-*.ebuild' -printf '%f\n'))
41+
local all_files majors latest_major to_delete files
42+
mapfile -t all_files < <(find . -maxdepth 1 -type f -name 'qownnotes-*.ebuild' -printf '%f\n')
4143
majors=$(printf '%s\n' "${all_files[@]}" | sed -E 's/^qownnotes-([0-9]+)\..*/\1/' | sort -u)
42-
latest_major=$(printf '%s\n' $majors | sort -n | tail -n 1)
44+
latest_major=$(printf '%s\n' "$majors" | sort -n | tail -n 1)
4345
to_delete=()
4446

4547
for major in ${majors}; do
46-
files=($(printf '%s\n' "${all_files[@]}" | grep "^qownnotes-${major}\." | sort -V))
48+
mapfile -t files < <(printf '%s\n' "${all_files[@]}" | grep "^qownnotes-${major}\." | sort -V)
4749

4850
if [[ $major -eq $latest_major ]]; then
4951
# Keep the last 3 for latest major
@@ -65,23 +67,23 @@ list_old_ebuilds_to_delete() {
6567

6668
echo "Started the ebuild packaging process, using latest '$BRANCH' git tree"
6769

68-
if [ -d $PROJECT_PATH ]; then
69-
rm -rf $PROJECT_PATH
70+
if [ -d "$PROJECT_PATH" ]; then
71+
rm -rf "$PROJECT_PATH"
7072
fi
7173

72-
mkdir $PROJECT_PATH
73-
cd $PROJECT_PATH || exit 1
74+
mkdir "$PROJECT_PATH"
75+
cd "$PROJECT_PATH" || exit 1
7476

7577
echo "Project path: $PROJECT_PATH"
7678

7779
# checkout AUR repository
7880
git clone --depth=1 [email protected]:qownnotes/gentoo-overlay.git overlay
7981

8082
# checkout the source code
81-
git clone --depth=1 [email protected]:pbek/QOwnNotes.git QOwnNotes -b $BRANCH
83+
git clone --depth=1 [email protected]:pbek/QOwnNotes.git QOwnNotes -b "$BRANCH"
8284
cd QOwnNotes || exit 1
8385

84-
if [ -z $QOWNNOTES_VERSION ]; then
86+
if [ -z "$QOWNNOTES_VERSION" ]; then
8587
# get version from version.h
8688
QOWNNOTES_VERSION=$(cat src/version.h | sed "s/[^0-9,.]//g")
8789
fi
@@ -95,7 +97,7 @@ cp ../../../QOwnNotes/build-systems/gentoo/metadata.xml .
9597
ebuilds_to_delete="$(list_old_ebuilds_to_delete)"
9698

9799
# Remove to-be-deleted versions from Manifest
98-
read -r -a ebuilds_to_delete_array <<<${ebuilds_to_delete}
100+
read -r -a ebuilds_to_delete_array <<<"${ebuilds_to_delete}"
99101
patterns=$(for f in "${ebuilds_to_delete_array[@]}"; do
100102
base=${f%.ebuild}
101103
echo "DIST ${base}.tar.xz"
@@ -106,15 +108,17 @@ grep -vF -f <(printf '%s\n' "$patterns") Manifest >Manifest.new && mv Manifest.n
106108
echo "DIST ${ARCHIVE_FILE} ${QOWNNOTES_ARCHIVE_SIZE} SHA512 ${QOWNNOTES_ARCHIVE_SHA512}" >>Manifest
107109

108110
eBuildFile="qownnotes-$QOWNNOTES_VERSION.ebuild"
109-
mv qownnotes.ebuild ${eBuildFile}
111+
mv qownnotes.ebuild "${eBuildFile}"
110112

111113
echo "Committing changes..."
114+
# shellcheck disable=SC2086
112115
[ -n "${ebuilds_to_delete}" ] && git rm ${ebuilds_to_delete}
113-
git add ${eBuildFile}
114-
git commit -m "releasing version $QOWNNOTES_VERSION" ${eBuildFile} Manifest metadata.xml ${ebuilds_to_delete}
116+
git add "${eBuildFile}"
117+
# shellcheck disable=SC2086
118+
git commit -m "releasing version $QOWNNOTES_VERSION" "${eBuildFile}" Manifest metadata.xml ${ebuilds_to_delete}
115119
git push
116120

117121
# remove everything after we are done
118-
if [ -d $PROJECT_PATH ]; then
119-
rm -rf $PROJECT_PATH
122+
if [ -d "$PROJECT_PATH" ]; then
123+
rm -rf "$PROJECT_PATH"
120124
fi

build-systems/github/build-github-src.sh

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ cd QOwnNotes || exit 1
4545
# build binary translation files
4646
lrelease src/QOwnNotes.pro
4747

48-
if [ -z $QOWNNOTES_VERSION ]; then
48+
if [ -z "$QOWNNOTES_VERSION" ]; then
4949
# get version from version.h
5050
QOWNNOTES_VERSION=$(cat src/version.h | sed "s/[^0-9,.]//g")
5151
else
@@ -67,38 +67,40 @@ cp CHANGELOG.md src
6767
cp webpage/src/getting-started/shortcuts.md src
6868

6969
# rename the src directory
70-
mv src $qownnotesSrcDir
70+
mv src "$qownnotesSrcDir"
7171

7272
archiveFile="$qownnotesSrcDir.tar.xz"
7373

7474
# archive the source code
7575
echo "Creating archive $archiveFile..."
76-
tar -cJf $archiveFile $qownnotesSrcDir
76+
tar -cJf "$archiveFile" "$qownnotesSrcDir"
7777

78-
QOWNNOTES_ARCHIVE_MD5=$(md5sum ${archiveFile} | awk '{ print $1 }' | tee ${archiveFile}.md5)
79-
QOWNNOTES_ARCHIVE_SHA256=$(sha256sum ${archiveFile} | awk '{ print $1 }' | tee ${archiveFile}.sha256)
80-
QOWNNOTES_ARCHIVE_SHA512=$(sha512sum ${archiveFile} | awk '{ print $1 }' | tee ${archiveFile}.sha512)
81-
QOWNNOTES_ARCHIVE_SIZE=$(stat -c "%s" ${archiveFile})
78+
QOWNNOTES_ARCHIVE_MD5=$(md5sum "${archiveFile}" | awk '{ print $1 }' | tee "${archiveFile}.md5")
79+
QOWNNOTES_ARCHIVE_SHA256=$(sha256sum "${archiveFile}" | awk '{ print $1 }' | tee "${archiveFile}.sha256")
80+
QOWNNOTES_ARCHIVE_SHA512=$(sha512sum "${archiveFile}" | awk '{ print $1 }' | tee "${archiveFile}.sha512")
81+
QOWNNOTES_ARCHIVE_SIZE=$(stat -c "%s" "${archiveFile}")
8282

8383
# also create checksum files that are compatible with sha256sum and sha512sum
84-
sha256sum ${archiveFile} >${archiveFile}.sha256sum
85-
sha512sum ${archiveFile} >${archiveFile}.sha512sum
84+
sha256sum "${archiveFile}" >"${archiveFile}.sha256sum"
85+
sha512sum "${archiveFile}" >"${archiveFile}.sha512sum"
8686

8787
echo ""
8888
echo "Sums:"
89-
echo $QOWNNOTES_ARCHIVE_MD5
90-
echo $QOWNNOTES_ARCHIVE_SHA256
91-
echo $QOWNNOTES_ARCHIVE_SHA512
89+
echo "$QOWNNOTES_ARCHIVE_MD5"
90+
echo "$QOWNNOTES_ARCHIVE_SHA256"
91+
echo "$QOWNNOTES_ARCHIVE_SHA512"
9292
echo ""
9393
echo "Size:"
94-
echo $QOWNNOTES_ARCHIVE_SIZE
94+
echo "$QOWNNOTES_ARCHIVE_SIZE"
9595

9696
# write temporary checksum variable file for the deployment scripts
9797
_QQwnNotesCheckSumVarFile="/tmp/QOwnNotes.checksum.vars"
98-
echo "QOWNNOTES_ARCHIVE_MD5=$QOWNNOTES_ARCHIVE_MD5" >${_QQwnNotesCheckSumVarFile}
99-
echo "QOWNNOTES_ARCHIVE_SHA256=$QOWNNOTES_ARCHIVE_SHA256" >>${_QQwnNotesCheckSumVarFile}
100-
echo "QOWNNOTES_ARCHIVE_SHA512=$QOWNNOTES_ARCHIVE_SHA512" >>${_QQwnNotesCheckSumVarFile}
101-
echo "QOWNNOTES_ARCHIVE_SIZE=$QOWNNOTES_ARCHIVE_SIZE" >>${_QQwnNotesCheckSumVarFile}
98+
{
99+
echo "QOWNNOTES_ARCHIVE_MD5=$QOWNNOTES_ARCHIVE_MD5"
100+
echo "QOWNNOTES_ARCHIVE_SHA256=$QOWNNOTES_ARCHIVE_SHA256"
101+
echo "QOWNNOTES_ARCHIVE_SHA512=$QOWNNOTES_ARCHIVE_SHA512"
102+
echo "QOWNNOTES_ARCHIVE_SIZE=$QOWNNOTES_ARCHIVE_SIZE"
103+
} >"${_QQwnNotesCheckSumVarFile}"
102104

103105
echo "Uploading files to GitHub..."
104106

@@ -107,7 +109,7 @@ echo "Uploading files to GitHub..."
107109
timeout=$((5 * 60))
108110
interval=5
109111
start_time=$(date +%s)
110-
while ! gh release upload --clobber v$QOWNNOTES_VERSION ${archiveFile}*; do
112+
while ! gh release upload --clobber "v$QOWNNOTES_VERSION" "${archiveFile}"*; do
111113
now=$(date +%s)
112114
elapsed=$((now - start_time))
113115
if [ $elapsed -ge $timeout ]; then

0 commit comments

Comments
 (0)