3
3
set -euo pipefail
4
4
5
5
# Version and checksums for godel. Values are populated by the godel "dist" task.
6
- VERSION=2.26 .0
7
- DARWIN_CHECKSUM=195d6a32f0fb357d131d444c78b3f49f7ecef2cdfdf00ee707427c76970c45ef
8
- LINUX_CHECKSUM=2ff4039d95fcb85891d8d9affa0294bcba40ba3b31d7fee34ca31f6f81db9c44
6
+ VERSION=2.36 .0
7
+ DARWIN_CHECKSUM=ac46bc231177ddd78343ef66fab222de7a91d9e691f8480f1d644561a08e92d0
8
+ LINUX_CHECKSUM=604db3bba458be15360c0a9669119b6797cebf013d839de88d0a7eca59adf03e
9
9
10
10
# Downloads file at URL to destination path using wget or curl. Prints an error and exits if wget or curl is not present.
11
11
function download {
@@ -162,18 +162,18 @@ GODEL_BASE_DIR=${GODEL_HOME:-$HOME/.godel}
162
162
OS=" "
163
163
EXPECTED_CHECKSUM=" "
164
164
case " $( uname) " in
165
- Darwin* )
166
- OS=darwin
167
- EXPECTED_CHECKSUM=$DARWIN_CHECKSUM
168
- ;;
169
- Linux* )
170
- OS=linux
171
- EXPECTED_CHECKSUM=$LINUX_CHECKSUM
172
- ;;
173
- * )
174
- echo " Unsupported operating system: $( uname) "
175
- exit 1
176
- ;;
165
+ Darwin* )
166
+ OS=darwin
167
+ EXPECTED_CHECKSUM=$DARWIN_CHECKSUM
168
+ ;;
169
+ Linux* )
170
+ OS=linux
171
+ EXPECTED_CHECKSUM=$LINUX_CHECKSUM
172
+ ;;
173
+ * )
174
+ echo " Unsupported operating system: $( uname) "
175
+ exit 1
176
+ ;;
177
177
esac
178
178
179
179
# path to godel binary
@@ -198,8 +198,11 @@ if [ ! -f "$CMD" ]; then
198
198
mkdir -p " $GODEL_BASE_DIR /downloads"
199
199
200
200
# download tgz and verify its contents
201
- DOWNLOAD_DST=$GODEL_BASE_DIR /downloads/godel-$VERSION .tgz
201
+ # Download to unique location that includes PID ($$) and use trap ensure that temporary download file is cleaned up
202
+ # if script is terminated before the file is moved to its destination.
203
+ DOWNLOAD_DST=$GODEL_BASE_DIR /downloads/godel-$VERSION -$$ .tgz
202
204
download " $DOWNLOAD_URL " " $DOWNLOAD_DST "
205
+ trap ' rm -rf "$DOWNLOAD_DST"' EXIT
203
206
if [ -n " $DOWNLOAD_CHECKSUM " ]; then
204
207
verify_checksum " $DOWNLOAD_DST " " $DOWNLOAD_CHECKSUM "
205
208
fi
@@ -211,9 +214,12 @@ if [ ! -f "$CMD" ]; then
211
214
tar zxvf " $DOWNLOAD_DST " -C " $TMP_DIST_DIR " > /dev/null 2>&1
212
215
verify_godel_version " $TMP_DIST_DIR " " $VERSION " " $OS "
213
216
217
+ # rename downloaded file to remove PID portion
218
+ mv " $DOWNLOAD_DST " " $GODEL_BASE_DIR /downloads/godel-$VERSION .tgz"
219
+
214
220
# if destination directory for distribution already exists, remove it
215
221
if [ -d " $GODEL_BASE_DIR /dists/godel-$VERSION " ]; then
216
- rm -rf " $GODEL_BASE_DIR /dists/godel-$VERSION "
222
+ rm -rf " $GODEL_BASE_DIR /dists/godel-$VERSION "
217
223
fi
218
224
219
225
# ensure that parent directory of destination exists
@@ -222,6 +228,17 @@ if [ ! -f "$CMD" ]; then
222
228
# move expanded distribution directory to destination location. The location of the unarchived directory is known to
223
229
# be in the same directory tree as the destination, so "mv" should always work.
224
230
mv " $TMP_DIST_DIR /godel-$VERSION " " $GODEL_BASE_DIR /dists/godel-$VERSION "
231
+
232
+ # edge case cleanup: if the destination directory "$GODEL_BASE_DIR/dists/godel-$VERSION" was created prior to the
233
+ # "mv" operation above, then the move operation will move the source directory into the destination directory. In
234
+ # this case, remove the directory. It should always be safe to remove this directory because if the directory
235
+ # existed in the distribution and was non-empty, then the move operation would fail (because non-empty directories
236
+ # cannot be overwritten by mv). All distributions of a given version are also assumed to be identical. The only
237
+ # instance in which this would not work is if the distribution purposely contained an empty directory that matched
238
+ # the name "godel-$VERSION", and this is assumed to never be true.
239
+ if [ -d " $GODEL_BASE_DIR /dists/godel-$VERSION /godel-$VERSION " ]; then
240
+ rm -rf " $GODEL_BASE_DIR /dists/godel-$VERSION /godel-$VERSION "
241
+ fi
225
242
fi
226
243
227
244
verify_checksum " $CMD " " $EXPECTED_CHECKSUM "
0 commit comments