Skip to content

Commit

Permalink
Implement hash-checking on downloaded dependencies
Browse files Browse the repository at this point in the history
Dependencies will be checked at extraction-time, and have their checksums stored
in deps/checksums/. The deps/jlchecksum command tests a given filename against the
checksums stored in that file, supporting MD5 and SHA512 checksums for all
recorded files.  SHA512 is preferred, with MD5 available as a fallback in the
case that `shasum` is not available.  If the hashes do not match, an error is
thrown and compilation is halted.  If a file is asked for and no hash has been
given for that file, the hash is generated for both SHA512 and MD5, and stored
  • Loading branch information
staticfloat committed May 12, 2014
1 parent 6de4d3b commit 183dffb
Show file tree
Hide file tree
Showing 43 changed files with 171 additions and 7 deletions.
1 change: 1 addition & 0 deletions Make.inc
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ endif
endif

JLDOWNLOAD = $(JULIAHOME)/deps/jldownload
JLCHECKSUM = $(JULIAHOME)/deps/jlchecksum

# Figure out OS and architecture
OS := $(BUILD_OS)
Expand Down
37 changes: 30 additions & 7 deletions deps/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,19 @@ else
endif

llvm-$(LLVM_VER)/configure: $(LLVM_TAR) $(LLVM_CLANG_TAR) $(LLVM_COMPILER_RT_TAR) $(LLVM_LIBCXX_TAR)
ifneq ($(LLVM_CLANG_TAR),)
$(JLCHECKSUM) $(LLVM_CLANG_TAR)
endif
ifneq ($(LLVM_COMPILER_RT_TAR),)
$(JLCHECKSUM) $(LLVM_COMPILER_RT_TAR)
endif

ifneq ($(LLVM_LIBCXX_TAR),)
$(JLCHECKSUM) $(LLVM_LIBCXX_TAR)
endif
ifneq ($(LLVM_VER),svn)
$(JLCHECKSUM) $(LLVM_TAR)
endif
ifneq ($(LLVM_VER),svn)
mkdir -p llvm-$(LLVM_VER) && \
$(TAR) -C llvm-$(LLVM_VER) --strip-components 1 -xf $(LLVM_TAR)
Expand Down Expand Up @@ -460,6 +473,7 @@ PCRE_OBJ_TARGET = $(build_shlibdir)/libpcre.$(SHLIB_EXT)
pcre-$(PCRE_VER).tar.bz2:
$(JLDOWNLOAD) $@ http:https://sourceforge.net/projects/pcre/files/pcre/$(PCRE_VER)/$@/download
pcre-$(PCRE_VER)/configure: pcre-$(PCRE_VER).tar.bz2
$(JLCHECKSUM) $<
$(TAR) jxf $<
touch -c $@
pcre-$(PCRE_VER)/config.status: pcre-$(PCRE_VER)/configure
Expand Down Expand Up @@ -503,6 +517,7 @@ double-conversion-$(GRISU_VER).tar.gz:
$(JLDOWNLOAD) $@ http:https://double-conversion.googlecode.com/files/$@
touch -c $@
double-conversion-$(GRISU_VER)/Makefile: double-conversion-$(GRISU_VER).tar.gz
$(JLCHECKSUM) $<
mkdir -p double-conversion-$(GRISU_VER) && \
$(TAR) -C double-conversion-$(GRISU_VER) --strip-components 1 -xf double-conversion-$(GRISU_VER).tar.gz
touch -c $@
Expand Down Expand Up @@ -639,6 +654,7 @@ dsfmt-$(DSFMT_VER).tar.gz:
$(JLDOWNLOAD) $@ http:https://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/dSFMT-src-$(DSFMT_VER).tar.gz
touch -c $@
dsfmt-$(DSFMT_VER)/config.status: dsfmt-$(DSFMT_VER).tar.gz
$(JLCHECKSUM) $<
mkdir -p dsfmt-$(DSFMT_VER) && \
$(TAR) -C dsfmt-$(DSFMT_VER) --strip-components 1 -xf dsfmt-$(DSFMT_VER).tar.gz && \
cd dsfmt-$(DSFMT_VER) && patch < ../dSFMT.h.patch && patch < ../dSFMT.c.patch
Expand Down Expand Up @@ -777,6 +793,7 @@ endif
openblas-$(OPENBLAS_VER).tar.gz:
$(JLDOWNLOAD) $@ https://github.com/xianyi/OpenBLAS/tarball/$(OPENBLAS_VER)
openblas-$(OPENBLAS_VER)/config.status: openblas-$(OPENBLAS_VER).tar.gz
$(JLCHECKSUM) $<
mkdir -p openblas-$(OPENBLAS_VER) && \
$(TAR) -C openblas-$(OPENBLAS_VER) --strip-components 1 -xf $<
perl -i -ple 's/^\s*(EXTRALIB\s*\+=\s*-lSystemStubs)\s*$$/# $$1/g' $@.system
Expand Down Expand Up @@ -909,6 +926,7 @@ endif
lapack-$(LAPACK_VER).tgz:
$(JLDOWNLOAD) $@ http:https://www.netlib.org/lapack/$@
lapack-$(LAPACK_VER)/Makefile: lapack-$(LAPACK_VER).tgz
$(JLCHECKSUM) $<
$(TAR) zxf $<
cd lapack-$(LAPACK_VER)/SRC && patch < ../../dlasd4-lapack-3.4.2.patch && patch < ../../slasd4-lapack-3.4.2.patch
touch -c $@
Expand Down Expand Up @@ -972,16 +990,10 @@ arpack-ng_$(ARPACK_VER).tar.gz:
$(JLDOWNLOAD) $@ http:https://forge.scilab.org/index.php/p/arpack-ng/downloads/get/$@
touch -c $@
arpack-ng-$(ARPACK_VER)/configure: arpack-ng_$(ARPACK_VER).tar.gz
$(JLCHECKSUM) $<
$(TAR) zxf $<
touch -c $@

#arpack-ng-$(ARPACK_VER).tar.gz:
# $(JLDOWNLOAD) $@ http:https://forge.scilab.org/index.php/p/arpack-ng/downloads/get/arpack-ng-$(ARPACK_VER).tar.gz
# touch -c $@
#arpack-ng-$(ARPACK_VER)/configure: arpack-ng-$(ARPACK_VER).tar.gz
# $(TAR) zxf $<
# touch -c $@

ifeq ($(USE_ATLAS), 1)
arpack-ng-$(ARPACK_VER)/config.status: | $(ATLAS_OBJ_TARGET)
endif
Expand Down Expand Up @@ -1058,6 +1070,7 @@ fftw-$(FFTW_VER).tar.gz:
$(JLDOWNLOAD) $@ http:https://www.fftw.org/$@

fftw-$(FFTW_VER)-single/configure: fftw-$(FFTW_VER).tar.gz
$(JLCHECKSUM) $<
mkdir -p fftw-$(FFTW_VER)-single && \
$(TAR) -C fftw-$(FFTW_VER)-single --strip-components 1 -xf $<
ifeq ($(OS),WINNT)
Expand Down Expand Up @@ -1095,6 +1108,7 @@ endif
touch -c $@

fftw-$(FFTW_VER)-double/configure: fftw-$(FFTW_VER).tar.gz
$(JLCHECKSUM) $<
mkdir -p fftw-$(FFTW_VER)-double && \
$(TAR) -C fftw-$(FFTW_VER)-double --strip-components 1 -xf $<
ifeq ($(OS),WINNT)
Expand Down Expand Up @@ -1170,6 +1184,7 @@ utf8proc-v$(UTF8PROC_VER).tar.gz:
$(JLDOWNLOAD) $@ http:https://www.public-software-group.org/pub/projects/utf8proc/v$(UTF8PROC_VER)/$@

utf8proc-v$(UTF8PROC_VER)/Makefile: utf8proc-v$(UTF8PROC_VER).tar.gz
$(JLCHECKSUM) $<
$(TAR) -xzf $<
patch $@ < utf8proc_Makefile.patch
cd utf8proc-v$(UTF8PROC_VER) && patch < ../utf8proc_msvc.patch
Expand Down Expand Up @@ -1221,6 +1236,7 @@ SUITESPARSE_MFLAGS = CC="$(CC)" CXX="$(CXX)" F77="$(FC)" AR="$(AR)" RANLIB="$(RA
SuiteSparse-$(SUITESPARSE_VER).tar.gz:
$(JLDOWNLOAD) $@ http:https://www.cise.ufl.edu/research/sparse/SuiteSparse/$@
SuiteSparse-$(SUITESPARSE_VER)/Makefile: SuiteSparse-$(SUITESPARSE_VER).tar.gz
$(JLCHECKSUM) $<
mkdir -p SuiteSparse-$(SUITESPARSE_VER)
$(TAR) -C SuiteSparse-$(SUITESPARSE_VER) --strip-components 1 -zxf $<
touch -c $@
Expand Down Expand Up @@ -1310,6 +1326,7 @@ LIBUNWIND_CFLAGS = $(CFLAGS) -U_FORTIFY_SOURCE $(fPIC)
libunwind-$(UNWIND_VER).tar.gz:
$(JLDOWNLOAD) $@ http:https://download.savannah.gnu.org/releases/libunwind/$@
libunwind-$(UNWIND_VER)/configure: libunwind-$(UNWIND_VER).tar.gz
$(JLCHECKSUM) $<
$(TAR) xfz $<
touch -c $@
libunwind-$(UNWIND_VER)/config.status: libunwind-$(UNWIND_VER)/configure
Expand Down Expand Up @@ -1355,6 +1372,7 @@ libosxunwind-$(OSXUNWIND_VER).tar.gz:
$(JLDOWNLOAD) $@ https://github.com/JuliaLang/libosxunwind/archive/v$(OSXUNWIND_VER).tar.gz

libosxunwind-$(OSXUNWIND_VER)/Makefile: libosxunwind-$(OSXUNWIND_VER).tar.gz
$(JLCHECKSUM) $<
$(TAR) xfz $<
touch -c $@

Expand Down Expand Up @@ -1386,6 +1404,7 @@ GMP_OBJ_TARGET = $(build_shlibdir)/libgmp.$(SHLIB_EXT)
gmp-$(GMP_VER).tar.bz2:
$(JLDOWNLOAD) $@ ftp:https://ftp.gmplib.org/pub/gmp-$(GMP_VER)/$@
gmp-$(GMP_VER)/configure: gmp-$(GMP_VER).tar.bz2
$(JLCHECKSUM) $<
$(TAR) jxf $<
touch -c $@
gmp-$(GMP_VER)/config.status: gmp-$(GMP_VER)/configure
Expand Down Expand Up @@ -1434,6 +1453,7 @@ endif
mpfr-$(MPFR_VER).tar.bz2:
$(JLDOWNLOAD) $@ http:https://www.mpfr.org/mpfr-current/$@
mpfr-$(MPFR_VER)/configure: mpfr-$(MPFR_VER).tar.bz2
$(JLCHECKSUM) $<
$(TAR) jxf $<
touch -c $@
mpfr-$(MPFR_VER)/config.status: mpfr-$(MPFR_VER)/configure $(MPFR_DEPS)
Expand Down Expand Up @@ -1482,6 +1502,7 @@ endif
zlib-$(ZLIB_VER).tar.gz:
$(JLDOWNLOAD) $@ http:https://zlib.net/$@
zlib-$(ZLIB_VER)/configure: zlib-$(ZLIB_VER).tar.gz
$(JLCHECKSUM) $<
$(TAR) zxf $<
touch -c $@
zlib-$(ZLIB_VER)/config.status: zlib-$(ZLIB_VER)/configure
Expand Down Expand Up @@ -1534,6 +1555,7 @@ install-patchelf: $(PATCHELF_TARGET)
patchelf-$(PATCHELF_VER).tar.bz2:
$(JLDOWNLOAD) $@ http:https://hydra.nixos.org/build/1524660/download/2/$@
patchelf-$(PATCHELF_VER)/configure: patchelf-$(PATCHELF_VER).tar.bz2
$(JLCHECKSUM) $<
$(TAR) jxf $<
touch -c $@
patchelf-$(PATCHELF_VER)/config.status: patchelf-$(PATCHELF_VER)/configure
Expand Down Expand Up @@ -1573,6 +1595,7 @@ GIT_TARGET = $(build_prefix)/git
git-$(GIT_VER).tar.gz:
$(JLDOWNLOAD) $@ http:https://git-core.googlecode.com/files/$@
git-$(GIT_VER)/configure: git-$(GIT_VER).tar.gz
$(JLCHECKSUM) $<
$(TAR) zxf $<
touch -c $@
git-$(GIT_VER)/config.status: git-$(GIT_VER)/configure
Expand Down
1 change: 1 addition & 0 deletions deps/checksums/SuiteSparse-4.2.1.tar.gz/md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4628df9eeae10ae5f0c486f1ac982fce
1 change: 1 addition & 0 deletions deps/checksums/SuiteSparse-4.2.1.tar.gz/sha512
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
df8828886682681e2984bf1a1e01d88aaa30edda8801c29445c2d2d37395407748634beb76df6244f9319738ee8c5c7362616a781f715b819ac8c2e3be5d1552
1 change: 1 addition & 0 deletions deps/checksums/arpack-ng-3.1.3.tar.gz/md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
90ba42eae70b517ebdb72921cb4186df
1 change: 1 addition & 0 deletions deps/checksums/arpack-ng-3.1.3.tar.gz/sha512
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
30bee66edc31d1144d029a4c6c4b03f08782bdcbe1b9627e0c3df8d142121111e9c9dd875158345918931815341a2338cd889a010939016509a7cfdd1e829426
1 change: 1 addition & 0 deletions deps/checksums/arpack-ng_3.1.5.tar.gz/md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f773f34079a9c24807da6bc2e72fe6df
1 change: 1 addition & 0 deletions deps/checksums/arpack-ng_3.1.5.tar.gz/sha512
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4876b0babb89bbcc39e92b63d4537b860e9cd0b8a188937d3ba815041b7261623cdac25c91c8bef20ebce4271f822307c492cf6c9f22ec3d740218405337a515
1 change: 1 addition & 0 deletions deps/checksums/cfe-3.3.src.tar.gz/md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8284891e3e311829b8e44ac813d0c9ef
1 change: 1 addition & 0 deletions deps/checksums/cfe-3.3.src.tar.gz/sha512
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
06773f43f7d3529f06edb029f7de398f06a700a0f2476e00c4727e70c291028221bfac23625dfd2c220d6ac91a21670848187a934b99a21801c695127371afcc
1 change: 1 addition & 0 deletions deps/checksums/compiler-rt-3.3.src.tar.gz/md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9c129ce24514467cfe492cf2fed8e2c4
1 change: 1 addition & 0 deletions deps/checksums/compiler-rt-3.3.src.tar.gz/sha512
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3e86aa8ab9810b4fbac54a40fc93a717a55c642520858c0db215a5324c1e495b4d8fcec9620251cca8e4e5f9afa34bc14364d7f785880a0700469d0201827929
1 change: 1 addition & 0 deletions deps/checksums/double-conversion-1.1.1.tar.gz/md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
29b533ed4311161267bff1a9a97e2953
1 change: 1 addition & 0 deletions deps/checksums/double-conversion-1.1.1.tar.gz/sha512
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e116196eb60077565050995b060049747a3c72e743eea21c6c9fb68414adc533d456d19e1ca241f08895cca97a38511477bdc7d2e0cae38d149c83cb9d6896ad
1 change: 1 addition & 0 deletions deps/checksums/dsfmt-2.2.tar.gz/md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cb61be3be7254eae39684612c524740d
1 change: 1 addition & 0 deletions deps/checksums/dsfmt-2.2.tar.gz/sha512
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e59d54166dc2df9f6e6abd68658c3624082feabe445215256fead47a8944c41578d11c2b4ba57eac174587a45e445b2aabd867db24fd9e951842513cf914f60b
1 change: 1 addition & 0 deletions deps/checksums/fftw-3.3.3.tar.gz/md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0a05ca9c7b3bfddc8278e7c40791a1c2
1 change: 1 addition & 0 deletions deps/checksums/fftw-3.3.3.tar.gz/sha512
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1d88b6376ba8c15cceafd3381de1d181a974b921b72b31dd89c297e5771e8d665aa3c121ef2504a70e7b0bb562b1e0612ac2a02121c412d27df06c4d687507c4
1 change: 1 addition & 0 deletions deps/checksums/gmp-5.1.3.tar.bz2/md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a082867cbca5e898371a97bb27b31fea
1 change: 1 addition & 0 deletions deps/checksums/gmp-5.1.3.tar.bz2/sha512
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f42ce1fa02962d25f94e21c79837f0eac1f8fc8d5c7804b7413926be8739ae0e8da33c63b5cebad17b3b6caae495ace0ef2e54dd2f194a0870e85c48172382dc
1 change: 1 addition & 0 deletions deps/checksums/libcxx-3.3.src.tar.gz/md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
59006e659ffb33f5222a7b79d4cd071e
1 change: 1 addition & 0 deletions deps/checksums/libcxx-3.3.src.tar.gz/sha512
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
806ee0321ceac4d0bdcdad581208e8589d13f688124dfa75f484242fe299b8d423f6bd0172d674a01daf57b4f1e1a9751f5f331e734639917aa24f427b2f5e2c
1 change: 1 addition & 0 deletions deps/checksums/libosxunwind-0.0.1-rc3.tar.gz/md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0da56a466a2a5c6502fb4d4353196ac6
1 change: 1 addition & 0 deletions deps/checksums/libosxunwind-0.0.1-rc3.tar.gz/sha512
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6e18be3730a99c6df4868174409c688e43d037a53b58accaab019e9f13799dc61fa4428748b4a498939c425399307ecbf725a069382b856e3c53b95169e597aa
1 change: 1 addition & 0 deletions deps/checksums/libunwind-1.1.tar.gz/md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fb4ea2f6fbbe45bf032cd36e586883ce
1 change: 1 addition & 0 deletions deps/checksums/libunwind-1.1.tar.gz/sha512
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bfe04f2bfac9f9e47c37f0b23ed2f264d8d3d3d6f1392fe9d794ee13cad216b3740979e922e4276fb65c1ccdc836fce48812cb5459ecdd2a89a621036a35d7c1
1 change: 1 addition & 0 deletions deps/checksums/llvm-3.3.src.tar.gz/md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
40564e1dc390f9844f1711c08b08e391
1 change: 1 addition & 0 deletions deps/checksums/llvm-3.3.src.tar.gz/sha512
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1b7f7c5e907a68f642dcbe48fdff9585cb1504022bc9d386f310ebe5d25103d0d5f7cf0abf19e0e3fd666970160a98c90033754e2b79b2fac0cf866c984f8038
1 change: 1 addition & 0 deletions deps/checksums/mpfr-3.1.2.tar.bz2/md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ee2c3ac63bf0c2359bf08fc3ee094c19
1 change: 1 addition & 0 deletions deps/checksums/mpfr-3.1.2.tar.bz2/sha512
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0312a1ac813c51737e7d2b40fa771a73adb796ef962bbbd81ffd5e18a16b13346dd20875710e29f5304146750253d7d3755dc4c7b28c1b3b6cd527a6a7affd14
1 change: 1 addition & 0 deletions deps/checksums/openblas-v0.2.8.tar.gz/md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
b58ad6312e9c9a284fd72de7b6a0a076
1 change: 1 addition & 0 deletions deps/checksums/openblas-v0.2.8.tar.gz/sha512
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
590ffc77377e3d40f91bd91156554140da0f3eee334098cfdbd53d427173cd4374eca0f8f9a167054ea88bdcc1b3a685a6ecdc5fd70f3df0ad267d569049db79
1 change: 1 addition & 0 deletions deps/checksums/openblas-v0.2.9.rc1.tar.gz/md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
34b03e26a7240c640978a4d3b87849a3
1 change: 1 addition & 0 deletions deps/checksums/openblas-v0.2.9.rc1.tar.gz/sha512
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
db1fa3ac4572869dbdf4c887fa6112419464accbfb311d9c9ca8bcde8882208001963dbbeb6afa350ca0d72c13fdda0ab7c6bc464de93d9af0889a0b361c0f97
1 change: 1 addition & 0 deletions deps/checksums/patchelf-0.6.tar.bz2/md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5087261514b4b5814a39c3d3a36eb6ef
1 change: 1 addition & 0 deletions deps/checksums/patchelf-0.6.tar.bz2/sha512
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0b228c7058b1d32104648a77b37720fd942cd53942d542dccc5662f6012b8d4487d5d1512a68319e73fda05640330611c9ea41ed7d94a0d109056f471a79dfc6
1 change: 1 addition & 0 deletions deps/checksums/pcre-8.31.tar.bz2/md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1c9a276af932b5599157f96e945391f0
1 change: 1 addition & 0 deletions deps/checksums/pcre-8.31.tar.bz2/sha512
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bdc369b967f1d9db36d228fb291a436611d19c2f7df64a265a5c748f797763b8d66e161fd0ecd60a8a9f28fa3bc7d22d61e619c9a16c5a26c71923e2b1802145
1 change: 1 addition & 0 deletions deps/checksums/utf8proc-v1.1.6.tar.gz/md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2462346301fac2994c34f5574d6c3ca7
1 change: 1 addition & 0 deletions deps/checksums/utf8proc-v1.1.6.tar.gz/sha512
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3bec2388298c201d9d6992cdd36330f1109d26a37b3411ba633f006f40da9e494ba0565051b763a7d3014e6113cd1e7754e6b95d5cbb2d7b50cee55193f0fdc1
1 change: 1 addition & 0 deletions deps/checksums/zlib-1.2.8.tar.gz/md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
44d667c142d7cda120332623eab69f40
1 change: 1 addition & 0 deletions deps/checksums/zlib-1.2.8.tar.gz/sha512
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ece209d4c7ec0cb58ede791444dc754e0d10811cbbdebe3df61c0fd9f9f9867c1c3ccd5f1827f847c005e24eef34fb5bf87b5d3f894d75da04f1797538290e4a
100 changes: 100 additions & 0 deletions deps/jlchecksum
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/bin/bash
#
# usage: jlchecksum <filename>
#

if [ -z "$1" ]; then
echo "Usage: ./jlchecksum <filename>" >&2
exit 1
fi

# Get the directory of this script
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# Get the basename of the file we're trying to checksum
BASENAME=$(basename $1)

# Print out a hash, and wrap around if we're longer than 64 characters
print_hash()
{
if [ ${#1} -gt 64 ]; then
NUM_LINES=$(( (${#1} + 63) / 64))
for (( i=0; i<$NUM_LINES; i++ )); do
echo " ${1:$((i*64)):64}"
done
else
echo " $1" >&2
fi
}

checksum_error()
{
echo "===============================================================================" >&2
echo "ERROR: $CHECKSUM_TYPE checksum failure on $BASENAME, should be:" >&2
print_hash "$TRUE_CHECKSUM"
echo "But calculating with \`$CHECKSUM_PROG\` is actually:" >&2
print_hash "$CURR_CHECKSUM"
echo "===============================================================================" >&2
exit 2
}

find_checksum()
{
if [ ! -f "$DIR/checksums/$BASENAME/$CHECKSUM_TYPE" ]; then
echo "WARNING: $CHECKSUM_TYPE checksum for $BASENAME not found in deps/checksums/, autogenerating..." >&2

# Generate as many checksum types as we can
mkdir -p checksums/$BASENAME
if [ ! -z "$MD5_PROG" ]; then
echo $(eval $MD5_PROG) > "$DIR/checksums/$BASENAME/md5"
fi
if [ ! -z "$SHA512_PROG" ]; then
echo $(eval $SHA512_PROG) > "$DIR/checksums/$BASENAME/sha512"
fi
fi

TRUE_CHECKSUM=$(cat "$DIR/checksums/$BASENAME/$CHECKSUM_TYPE")
}

# These are the programs we run to hash a file
SHA512_PROG=""
MD5_PROG=""
find_checksum_progs()
{
if [ ! -z $(which shasum) ]; then
SHA512_PROG="shasum -a 512 $BASENAME | awk '{ print \$1; }'"
fi

if [ ! -z $(which md5sum) ]; then
MD5_PROG="md5sum $BASENAME | awk '{ print \$1; }'"
elif [ ! -z $(which md5) ]; then
MD5_PROG="md5 -q $BASENAME"
fi
}


# Search for checksum programs and store them into SHA512_PROG, MD5_PROG, etc...
find_checksum_progs

# Choose final checksumming program, preferring SHA512 over MD5
if [ ! -z "$SHA512_PROG" ]; then
CHECKSUM_TYPE="sha512"
CHECKSUM_PROG=$SHA512_PROG
elif [ ! -z "$MD5_PROG" ]; then
CHECKSUM_TYPE="md5"
CHECKSUM_PROG=$MD5_PROG
else
echo "WARNING: No checksumming programs found, cannot verify downloads" >&2
exit 0
fi

# Find true checksum
find_checksum "$CHECKSUM_TYPE"

# Calculate actual checksum
CURR_CHECKSUM=$(eval $CHECKSUM_PROG)

# Make sure they're the same. If not, error out!
if [ "$TRUE_CHECKSUM" != "$CURR_CHECKSUM" ]; then
checksum_error
fi

0 comments on commit 183dffb

Please sign in to comment.