33set -euo pipefail
44
55# 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
99
1010# Downloads file at URL to destination path using wget or curl. Prints an error and exits if wget or curl is not present.
1111function download {
@@ -162,18 +162,18 @@ GODEL_BASE_DIR=${GODEL_HOME:-$HOME/.godel}
162162OS=" "
163163EXPECTED_CHECKSUM=" "
164164case " $( 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+ ;;
177177esac
178178
179179# path to godel binary
@@ -198,8 +198,11 @@ if [ ! -f "$CMD" ]; then
198198 mkdir -p " $GODEL_BASE_DIR /downloads"
199199
200200 # 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
202204 download " $DOWNLOAD_URL " " $DOWNLOAD_DST "
205+ trap ' rm -rf "$DOWNLOAD_DST"' EXIT
203206 if [ -n " $DOWNLOAD_CHECKSUM " ]; then
204207 verify_checksum " $DOWNLOAD_DST " " $DOWNLOAD_CHECKSUM "
205208 fi
@@ -211,9 +214,12 @@ if [ ! -f "$CMD" ]; then
211214 tar zxvf " $DOWNLOAD_DST " -C " $TMP_DIST_DIR " > /dev/null 2>&1
212215 verify_godel_version " $TMP_DIST_DIR " " $VERSION " " $OS "
213216
217+ # rename downloaded file to remove PID portion
218+ mv " $DOWNLOAD_DST " " $GODEL_BASE_DIR /downloads/godel-$VERSION .tgz"
219+
214220 # if destination directory for distribution already exists, remove it
215221 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 "
217223 fi
218224
219225 # ensure that parent directory of destination exists
@@ -222,6 +228,17 @@ if [ ! -f "$CMD" ]; then
222228 # move expanded distribution directory to destination location. The location of the unarchived directory is known to
223229 # be in the same directory tree as the destination, so "mv" should always work.
224230 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
225242fi
226243
227244verify_checksum " $CMD " " $EXPECTED_CHECKSUM "
0 commit comments