Skip to content

Commit 2868ffb

Browse files
aduh95danielleadams
authored andcommitted
tools: remove bashisms from release script
PR-URL: #36123 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent b885409 commit 2868ffb

File tree

1 file changed

+67
-69
lines changed

1 file changed

+67
-69
lines changed

tools/release.sh

+67-69
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env bash
1+
#!/bin/sh
22

33
# To promote and sign a release that has been prepared by the build slaves, use:
44
# release.sh
@@ -28,7 +28,7 @@ while getopts ":i:s:" option; do
2828
echo "Invalid option -$OPTARG."
2929
exit 1
3030
;;
31-
:)
31+
*)
3232
echo "Option -$OPTARG takes a parameter."
3333
exit 1
3434
;;
@@ -42,109 +42,107 @@ shift $((OPTIND-1))
4242
echo "# Selecting GPG key ..."
4343

4444
gpgkey=$(gpg --list-secret-keys --keyid-format SHORT | awk -F'( +|/)' '/^(sec|ssb)/{print $3}')
45-
keycount=$(echo $gpgkey | wc -w)
45+
keycount=$(echo "$gpgkey" | wc -w)
4646

47-
if [ $keycount -eq 0 ]; then
47+
if [ "$keycount" -eq 0 ]; then
48+
# shellcheck disable=SC2016
4849
echo 'Need at least one GPG key, please make one with `gpg --gen-key`'
4950
echo 'You will also need to submit your key to a public keyserver, e.g.'
5051
echo ' https://sks-keyservers.net/i/#submit'
5152
exit 1
52-
elif [ $keycount -ne 1 ]; then
53-
echo -e 'You have multiple GPG keys:\n'
53+
elif [ "$keycount" -ne 1 ]; then
54+
printf "You have multiple GPG keys:\n\n"
5455

5556
gpg --list-secret-keys
5657

57-
while true; do
58-
echo $gpgkey | awk '{ for(i = 1; i <= NF; i++) { print i ") " $i; } }'
59-
echo -n 'Select a key: '
60-
read keynum
61-
62-
if $(test "$keynum" -eq "$keynum" > /dev/null 2>&1); then
63-
_gpgkey=$(echo $gpgkey | awk '{ print $'${keynum}'}')
64-
keycount=$(echo $_gpgkey | wc -w)
65-
if [ $keycount -eq 1 ]; then
66-
echo ""
67-
gpgkey=$_gpgkey
68-
break
69-
fi
70-
fi
58+
keynum=
59+
while [ -z "${keynum##*[!0-9]*}" ] || [ "$keynum" -le 0 ] || [ "$keynum" -gt "$keycount" ]; do
60+
echo "$gpgkey" | awk '{ for(i = 1; i <= NF; i++) { print i ") " $i; } }'
61+
printf 'Select a key: '
62+
read -r keynum
7163
done
64+
echo ""
65+
gpgkey=$(echo "$gpgkey" | awk "{ print \$${keynum}}")
7266
fi
7367

74-
gpgfing=$(gpg --keyid-format 0xLONG --fingerprint $gpgkey | grep 'Key fingerprint =' | awk -F' = ' '{print $2}' | tr -d ' ')
68+
gpgfing=$(gpg --keyid-format 0xLONG --fingerprint "$gpgkey" | grep 'Key fingerprint =' | awk -F' = ' '{print $2}' | tr -d ' ')
69+
70+
grep "$gpgfing" README.md || (\
71+
echo 'Error: this GPG key fingerprint is not listed in ./README.md' && \
72+
exit 1 \
73+
)
7574

76-
if ! test "$(grep $gpgfing README.md)"; then
77-
echo 'Error: this GPG key fingerprint is not listed in ./README.md'
78-
exit 1
79-
fi
8075

8176
echo "Using GPG key: $gpgkey"
8277
echo " Fingerprint: $gpgfing"
8378

84-
function checktag {
85-
local version=$1
79+
checktag() {
80+
# local version=$1
8681

87-
if ! git tag -v $version 2>&1 | grep "${gpgkey}" | grep key > /dev/null; then
88-
echo "Could not find signed tag for \"${version}\" or GPG key is not yours"
82+
if ! git tag -v "$1" 2>&1 | grep "${gpgkey}" | grep key > /dev/null; then
83+
echo "Could not find signed tag for \"$1\" or GPG key is not yours"
8984
exit 1
9085
fi
9186
}
9287

9388
################################################################################
9489
## Create and sign checksums file for a given version
9590

96-
function sign {
97-
echo -e "\n# Creating SHASUMS256.txt ..."
91+
sign() {
92+
printf "\n# Creating SHASUMS256.txt ...\n"
9893

99-
local version=$1
94+
# local version=$1
10095

101-
ghtaggedversion=$(curl -sL https://raw.githubusercontent.com/nodejs/node/${version}/src/node_version.h \
96+
ghtaggedversion=$(curl -sL https://raw.githubusercontent.com/nodejs/node/"$1"/src/node_version.h \
10297
| awk '/define NODE_(MAJOR|MINOR|PATCH)_VERSION/{ v = v "." $3 } END{ v = "v" substr(v, 2); print v }')
103-
if [ "${version}" != "${ghtaggedversion}" ]; then
98+
if [ "$1" != "${ghtaggedversion}" ]; then
10499
echo "Could not find tagged version on github.com/nodejs/node, did you push your tag?"
105100
exit 1
106101
fi
107102

108-
shapath=$(ssh ${customsshkey} ${webuser}@${webhost} $signcmd nodejs $version)
103+
# shellcheck disable=SC2029
104+
shapath=$(ssh "${customsshkey}" "${webuser}@${webhost}" $signcmd nodejs "$1")
109105

110-
if ! [[ ${shapath} =~ ^/.+/SHASUMS256.txt$ ]]; then
111-
echo 'Error: No SHASUMS file returned by sign!'
106+
echo "${shapath}" | grep -q '^/.*/SHASUMS256.txt$' || \
107+
echo 'Error: No SHASUMS file returned by sign!' \
112108
exit 1
113-
fi
114109

115-
echo -e "\n# Signing SHASUMS for ${version}..."
110+
echo ""
111+
echo "# Signing SHASUMS for $1..."
116112

117-
shafile=$(basename $shapath)
118-
shadir=$(dirname $shapath)
113+
shafile=$(basename "$shapath")
114+
shadir=$(dirname "$shapath")
119115
tmpdir="/tmp/_node_release.$$"
120116

121117
mkdir -p $tmpdir
122118

123-
scp ${customsshkey} ${webuser}@${webhost}:${shapath} ${tmpdir}/${shafile}
119+
scp "${customsshkey}" "${webuser}@${webhost}:${shapath}" "${tmpdir}/${shafile}"
124120

125-
gpg --default-key $gpgkey --clearsign --digest-algo SHA256 ${tmpdir}/${shafile}
126-
gpg --default-key $gpgkey --detach-sign --digest-algo SHA256 ${tmpdir}/${shafile}
121+
gpg --default-key "$gpgkey" --clearsign --digest-algo SHA256 ${tmpdir}/"${shafile}"
122+
gpg --default-key "$gpgkey" --detach-sign --digest-algo SHA256 ${tmpdir}/"${shafile}"
127123

128124
echo "Wrote to ${tmpdir}/"
129125

130-
echo -e "Your signed ${shafile}.asc:\n"
126+
echo "Your signed ${shafile}.asc:"
127+
echo ""
131128

132-
cat ${tmpdir}/${shafile}.asc
129+
cat "${tmpdir}/${shafile}.asc"
133130

134131
echo ""
135132

136133
while true; do
137-
echo -n "Upload files? [y/n] "
134+
printf "Upload files? [y/n] "
138135
yorn=""
139-
read yorn
136+
read -r yorn
140137

141-
if [ "X${yorn}" == "Xn" ]; then
138+
if [ "X${yorn}" = "Xn" ]; then
142139
break
143140
fi
144141

145-
if [ "X${yorn}" == "Xy" ]; then
146-
scp ${customsshkey} ${tmpdir}/${shafile} ${tmpdir}/${shafile}.asc ${tmpdir}/${shafile}.sig ${webuser}@${webhost}:${shadir}/
147-
ssh ${customsshkey} ${webuser}@${webhost} chmod 644 ${shadir}/${shafile}.asc ${shadir}/${shafile}.sig
142+
if [ "X${yorn}" = "Xy" ]; then
143+
scp "${customsshkey}" "${tmpdir}/${shafile}" "${tmpdir}/${shafile}.asc" "${tmpdir}/${shafile}.sig" "${webuser}@${webhost}:${shadir}/"
144+
#shellcheck disable=SC2029
145+
ssh "${customsshkey}" "${webuser}@${webhost}" chmod 644 "${shadir}/${shafile}.asc" "${shadir}/${shafile}.sig"
148146
break
149147
fi
150148
done
@@ -154,8 +152,8 @@ function sign {
154152

155153

156154
if [ -n "${signversion}" ]; then
157-
checktag $signversion
158-
sign $signversion
155+
checktag "$signversion"
156+
sign "$signversion"
159157
exit 0
160158
fi
161159

@@ -164,16 +162,17 @@ fi
164162
################################################################################
165163
## Look for releases to promote
166164

167-
echo -e "\n# Checking for releases ..."
165+
printf "\n# Checking for releases ...\n"
168166

169-
promotable=$(ssh ${customsshkey} ${webuser}@${webhost} $promotablecmd nodejs)
167+
promotable=$(ssh "${customsshkey}" "$webuser@$webhost" $promotablecmd nodejs)
170168

171-
if [ "X${promotable}" == "X" ]; then
169+
if [ "X${promotable}" = "X" ]; then
172170
echo "No releases to promote!"
173171
exit 0
174172
fi
175173

176-
echo -e "Found the following releases / builds ready to promote:\n"
174+
echo "Found the following releases / builds ready to promote:"
175+
echo ""
177176
echo "$promotable" | sed 's/^/ * /'
178177
echo ""
179178

@@ -184,28 +183,27 @@ versions=$(echo "$promotable" | cut -d: -f1)
184183

185184
for version in $versions; do
186185
while true; do
187-
files=$(echo "$promotable" | grep "^${version}" | sed 's/^'${version}': //')
188-
echo -n "Promote ${version} files (${files})? [y/n] "
186+
files=$(echo "$promotable" | grep "^${version}" | sed 's/^'"${version}"': //')
187+
printf "Promote %s files (%s)? [y/n] " "${version}" "${files}"
189188
yorn=""
190-
read yorn
189+
read -r yorn
191190

192-
if [ "X${yorn}" == "Xn" ]; then
191+
if [ "X${yorn}" = "Xn" ]; then
193192
break
194193
fi
195194

196195
if [ "X${yorn}" != "Xy" ]; then
197196
continue
198197
fi
199198

200-
checktag $version
201-
202-
echo -e "\n# Promoting ${version}..."
199+
checktag "$version"
203200

204-
ssh ${customsshkey} ${webuser}@${webhost} $promotecmd nodejs $version
201+
echo ""
202+
echo "# Promoting ${version}..."
205203

206-
if [ $? -eq 0 ];then
207-
sign $version
208-
fi
204+
# shellcheck disable=SC2029
205+
ssh "${customsshkey}" "$webuser@$webhost" $promotecmd nodejs "$version" && \
206+
sign "$version"
209207

210208
break
211209
done

0 commit comments

Comments
 (0)