Permalink
Browse files

Check the md5sum of downloaded archives.

This should fix #563

Remark1: this will break the compilation of hosts which don't have md5 or md5sum installed. I'll add that in the sources.

Remark2: I've writtent md5check in ML because md5 (on OSX) and md5sum (on linux) don't have the same command-line interface.
  • Loading branch information...
1 parent cd5dc8f commit 5071d40ed0396ba539352cbdd0a467660bce4724 @samoht committed Mar 27, 2013
Showing with 70 additions and 3 deletions.
  1. +47 −0 shell/md5check.ml
  2. +23 −3 src_ext/Makefile
View
@@ -0,0 +1,47 @@
+#load "unix.cma"
+
+let command, file, md5 =
+ if Array.length Sys.argv <> 4 then (
+ Printf.eprintf "usage: ocaml %s <md5-command> <file> <md5>\n" Sys.argv.(0);
+ exit 1
+ ) else
+ Sys.argv.(1), Sys.argv.(2), Sys.argv.(3)
+
+let input_line fmt =
+ Printf.kprintf (fun cmd ->
+ try
+ let ic = Unix.open_process_in cmd in
+ let r = input_line ic in
+ match Unix.close_process_in ic with
+ | Unix.WEXITED 0 -> r
+ | _ -> failwith "cmd_input_line"
+ with
+ | End_of_file
+ | Unix.Unix_error _ -> failwith "cmd_input_line"
+ ) fmt
+
+let md5_of_file =
+ match command with
+ | "md5" -> input_line "md5 -q %s" file
+ | "md5sum" ->
+ let line = input_line "md5sum %s" file in
+ begin try
+ let i = String.index line ' ' in
+ String.sub line 0 i
+ with _ ->
+ ""
+ end
+ | x ->
+ Printf.eprintf "%S is not a valid md5 command name." x;
+ exit 2
+
+let () =
+ if md5 <> md5_of_file then (
+ Printf.eprintf
+ "MD5 for %s differ:\n\
+ \ expected: %s\n\
+ \ actual: %s\n"
+ file md5 md5_of_file;
+ Unix.unlink file
+ ) else
+ Printf.printf "%s has the expected MD5.\n" file
View
@@ -1,11 +1,25 @@
-include ../Makefile.config
-CUDF = cudf-0.6.3
-EXTLIB = extlib-1.5.3
+CUDF = cudf-0.6.3
+CUDFMD5 = 40c4e2c50ea96d0c9e565db16d20639a
+
+EXTLIB = extlib-1.5.3
+EXTLIBMD5 = 3de5f4e0a95fda7b2f3819c4a655b17c
+
DOSE = dose3-3.1.2
-CMDLINER = cmdliner-0.9.3
+DOSEMD5 = e98ff720fcc3873def46c85c6a980a1b
+
+CMDLINER = cmdliner-0.9.3
+CMDLINERMD5 = d63dd3b03966d65fc242246859c831c7
+
GRAPH = ocamlgraph-1.8.1
+GRAPHMD5 = 5aa256e9587a6d264d189418230af698
+
RE = ocaml-re-1.2.0
+REMD5 = 5cbfc137683ef2b0e91f931577f2e673
+
+# Portable md5check
+MD5CHECK = ocaml ../shell/md5check.ml $(MD5SUM)
all: clone depends.ocp
@@ -17,6 +31,7 @@ clone: cudf.stamp extlib.stamp ocaml-re.stamp ocamlgraph.stamp dose.stamp cmdlin
$(CUDF).tar.gz:
$(FETCH) https://gforge.inria.fr/frs/download.php/31910/$(CUDF).tar.gz
+ $(MD5CHECK) $(CUDF).tar.gz $(CUDFMD5)
cudf.stamp: $(CUDF).tar.gz
tar xfz $(CUDF).tar.gz
@@ -26,6 +41,7 @@ cudf.stamp: $(CUDF).tar.gz
$(EXTLIB).tar.gz:
$(FETCH) http://ocaml-extlib.googlecode.com/files/$(EXTLIB).tar.gz
+ $(MD5CHECK) $(EXTLIB).tar.gz $(EXTLIBMD5)
extlib.stamp: $(EXTLIB).tar.gz
tar xfz $(EXTLIB).tar.gz
@@ -43,6 +59,7 @@ dose3-git:
$(DOSE).tar.gz:
$(FETCH) https://gforge.inria.fr/frs/download.php/31595/$(DOSE).tar.gz
+ $(MD5CHECK) $(DOSE).tar.gz $(DOSEMD5)
dose.stamp: $(DOSE).tar.gz
tar xfz $(DOSE).tar.gz
@@ -53,6 +70,7 @@ dose.stamp: $(DOSE).tar.gz
$(CMDLINER).tbz:
$(FETCH) http://erratique.ch/software/cmdliner/releases/$(CMDLINER).tbz
+ $(MD5CHECK) $(CMDLINER).tbz $(CMDLINERMD5)
cmdliner.stamp: $(CMDLINER).tbz
tar xfj $(CMDLINER).tbz
@@ -62,6 +80,7 @@ cmdliner.stamp: $(CMDLINER).tbz
$(GRAPH).tar.gz:
$(FETCH) http://ocamlgraph.lri.fr/download/$(GRAPH).tar.gz
+ $(MD5CHECK) $(GRAPH).tar.gz $(GRAPHMD5)
ocamlgraph.stamp: $(GRAPH).tar.gz
tar xfz $(GRAPH).tar.gz
@@ -71,6 +90,7 @@ ocamlgraph.stamp: $(GRAPH).tar.gz
$(RE).tar.gz:
$(FETCH) https://github.com/ocaml/ocaml-re/archive/$(RE).tar.gz
+ $(MD5CHECK) $(RE).tar.gz $(REMD5)
ocaml-re.stamp: $(RE).tar.gz
tar xfz $(RE).tar.gz

0 comments on commit 5071d40

Please sign in to comment.