Merge ~cjwatson/launchpad:shellcheck into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: cadc72c95dbad49f077180bce683e8ea26fc5e27
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:shellcheck
Merge into: launchpad:master
Diff against target: 149 lines (+21/-11)
8 files modified
.pre-commit-config.yaml (+4/-0)
cronscripts/publishing/cron.base-ppa.sh (+3/-1)
cronscripts/publishing/cron.daily-ppa (+3/-2)
cronscripts/publishing/cron.publish-copy-archives (+0/-2)
cronscripts/publishing/cron.publish-ppa (+1/-0)
utilities/launchpad-database-setup (+3/-0)
utilities/rocketfuel-get (+2/-1)
utilities/rocketfuel-setup (+5/-5)
Reviewer Review Type Date Requested Status
Jürgen Gmach Approve
Review via email: mp+425317@code.launchpad.net

Commit message

Enforce shellcheck in pre-commit

Description of the change

Fix an assorted collection of minor `shellcheck` complaints, and enforce this in `pre-commit` so that they don't come back.

To post a comment you must log in.
Revision history for this message
Jürgen Gmach (jugmac00) wrote :

You have added great insight in the commit messages why we do things differently as one might expect, and especially as the linter expects.

Could you please add the reasoning also to the source code as a comment?

Probably nobody except you and maybe William would know something like "However, this structure is deliberate: we use it when migrating between PostgreSQL versions. Disable the warning."

While `git blame` makes it easy to view the current commit message, after some time and changes it is pretty cumbersome to dig out relevant information.

review: Approve
Revision history for this message
Colin Watson (cjwatson) wrote :

I think it was only relevant to a couple of the most recent commits in this branch, but sure - I amended in a couple of extra comments.

Revision history for this message
Otto Co-Pilot (otto-copilot) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
2index a1c7bb0..1297eef 100644
3--- a/.pre-commit-config.yaml
4+++ b/.pre-commit-config.yaml
5@@ -100,3 +100,7 @@ repos:
6 - id: lp-lint-doctest
7 args: [--allow-option-flag, IGNORE_EXCEPTION_MODULE_IN_PYTHON2]
8 exclude: ^doc/.*
9+- repo: https://github.com/shellcheck-py/shellcheck-py
10+ rev: v0.8.0.4
11+ hooks:
12+ - id: shellcheck
13diff --git a/cronscripts/publishing/cron.base-ppa.sh b/cronscripts/publishing/cron.base-ppa.sh
14index f9d8d70..0065021 100644
15--- a/cronscripts/publishing/cron.base-ppa.sh
16+++ b/cronscripts/publishing/cron.base-ppa.sh
17@@ -1,11 +1,13 @@
18+# shellcheck shell=bash
19 # Copyright 2009 Canonical Ltd. This software is licensed under the
20 # GNU Affero General Public License version 3 (see the file LICENSE).
21
22 # Initial setup for PPA cronscripts.
23
24 # DO NOT set LPCONFIG here, it should come from the crontab or the shell.
25-# Define common variables.
26+# Define common variables (also used by cron.daily-ppa).
27 PPAROOT=/srv/launchpad.net/ppa-archive
28+# shellcheck disable=SC2034 # not used here, but used by cron.daily-ppa
29 P3AROOT=/srv/launchpad.net/private-ppa-archive
30 LOCKFILE=$PPAROOT/.lock
31 # Default lockfile options, retry once if it's locked.
32diff --git a/cronscripts/publishing/cron.daily-ppa b/cronscripts/publishing/cron.daily-ppa
33index e95937e..5edec8d 100755
34--- a/cronscripts/publishing/cron.daily-ppa
35+++ b/cronscripts/publishing/cron.daily-ppa
36@@ -10,8 +10,9 @@ set -x
37 LOCKFILEOPTIONS="-r-1"
38
39 # Variables, lockfile and exit handler for PPA scripts.
40+# shellcheck source-path=SCRIPTDIR
41 source "$(dirname "$0")/cron.base-ppa.sh"
42
43 # Clear out empty and thus redundant dirs.
44-find "$PPAROOT" -type d -empty | xargs -r rmdir
45-find "$P3AROOT" -type d -empty | xargs -r rmdir
46+find "$PPAROOT" -type d -empty -exec rmdir {} +
47+find "$P3AROOT" -type d -empty -exec rmdir {} +
48diff --git a/cronscripts/publishing/cron.publish-copy-archives b/cronscripts/publishing/cron.publish-copy-archives
49index 5c35e56..c21826e 100755
50--- a/cronscripts/publishing/cron.publish-copy-archives
51+++ b/cronscripts/publishing/cron.publish-copy-archives
52@@ -21,8 +21,6 @@ set -u
53 # Informational -- this *MUST* match the database.
54 ARCHIVEROOT=/srv/launchpad.net/rebuild-test/ubuntu
55 DISTSROOT=$ARCHIVEROOT/dists
56-OVERRIDEROOT=$ARCHIVEROOT/../ubuntu-overrides
57-INDICES=$ARCHIVEROOT/indices
58 PRODUCTION_CONFIG=ftpmaster-publish
59
60 if [ "$LPCONFIG" = "$PRODUCTION_CONFIG" ]; then
61diff --git a/cronscripts/publishing/cron.publish-ppa b/cronscripts/publishing/cron.publish-ppa
62index 7c93542..fe11a32 100755
63--- a/cronscripts/publishing/cron.publish-ppa
64+++ b/cronscripts/publishing/cron.publish-ppa
65@@ -6,6 +6,7 @@
66 set -x
67
68 # Variables, lockfile and exit handler for PPA scripts.
69+# shellcheck source-path=SCRIPTDIR
70 source "$(dirname "$0")/cron.base-ppa.sh"
71
72 LPCURRENT="$(dirname "$0")/../.."
73diff --git a/utilities/launchpad-database-setup b/utilities/launchpad-database-setup
74index 729f941..e78931e 100755
75--- a/utilities/launchpad-database-setup
76+++ b/utilities/launchpad-database-setup
77@@ -21,6 +21,9 @@ fi
78 # initial Launchpad setup on an otherwise unconfigured postgresql instance
79
80 pgversion=
81+# This loop contains multiple versions when we are in the process of
82+# migrating between PostgreSQL versions.
83+# shellcheck disable=SC2043
84 for try_pgversion in 10
85 do
86 if sudo grep -qs "^auto" /etc/postgresql/$try_pgversion/main/start.conf; then
87diff --git a/utilities/rocketfuel-get b/utilities/rocketfuel-get
88index c41416e..678ccb6 100755
89--- a/utilities/rocketfuel-get
90+++ b/utilities/rocketfuel-get
91@@ -11,7 +11,7 @@
92 set -eu
93
94 # A rough measure of how much stuff we can do in parallel.
95-CPU_COUNT="$(egrep -c '^processor\b' /proc/cpuinfo)"
96+CPU_COUNT="$(grep -Ec '^processor\b' /proc/cpuinfo)"
97
98 # Helper function to run a child process, indenting stdout to aid
99 # readability.
100@@ -22,6 +22,7 @@ run-child() {
101 # Load local settings.
102 if [ -e "$HOME/.rocketfuel-env.sh" ]
103 then
104+ # shellcheck disable=SC1091
105 source "$HOME/.rocketfuel-env.sh"
106 else
107 echo "Please run rocketfuel-setup first." >&2
108diff --git a/utilities/rocketfuel-setup b/utilities/rocketfuel-setup
109index ab29385..53c236e 100755
110--- a/utilities/rocketfuel-setup
111+++ b/utilities/rocketfuel-setup
112@@ -8,7 +8,7 @@
113 # as utilities/rocketfuel-setup
114
115 # load up Ubuntu release details so we know which repos to enable
116-source /etc/lsb-release
117+DISTRIB_CODENAME="$(lsb_release -sc)"
118 DO_WORKSPACE=1
119 INSTALL_OPTS=""
120 getopt_output="$(getopt -o '' -l no-workspace,lpusername:,assume-yes -- "$@")" || exit 1
121@@ -35,9 +35,9 @@ done
122
123 if [ -z "$lpusername" ]; then
124 # Establish LP username
125- whoami=`whoami`
126- printf "What is your Launchpad username? [$whoami] "
127- read lpusername
128+ whoami=$(whoami)
129+ printf "What is your Launchpad username? [%s] " "$whoami"
130+ read -r lpusername
131 if [ -z "$lpusername" ]; then
132 lpusername=${whoami}
133 fi
134@@ -61,7 +61,6 @@ if ! grep -q "^127.0.0.88" /etc/hosts; then
135 echo "launchpad.test added to /etc/hosts"
136 fi
137
138-declare -a hostnames
139 hostnames=$(cat <<EOF
140 answers.launchpad.test
141 archive.launchpad.test
142@@ -224,6 +223,7 @@ LP_SOURCEDEPS_PATH=\$(eval echo \${LP_SOURCEDEPS_PATH})
143 " > "$HOME/.rocketfuel-env.sh"
144 fi
145
146+# shellcheck disable=SC1091
147 if ! source "$HOME/.rocketfuel-env.sh"; then
148 echo "Something went wrong with rocketfuel-setup!"
149 exit 1

Subscribers

People subscribed via source and target branches

to status/vote changes: