File: md5check.ml

package info (click to toggle)
opam 2.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,500 kB
  • sloc: ml: 61,414; sh: 2,963; ansic: 1,147; makefile: 479; sed: 6; csh: 1
file content (26 lines) | stat: -rw-r--r-- 614 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
let file, md5 =
  if Array.length Sys.argv <> 3 then (
    Printf.eprintf "usage: ocaml %s <file> <md5>\n" Sys.argv.(0);
    exit 1
  ) else
    Sys.argv.(1), Sys.argv.(2)

let md5_of_file =
  Digest.to_hex (Digest.file file)

let () =
  if md5 <> md5_of_file then (
    Printf.eprintf
      "MD5 for %s differs:\n\
      \  expected: %s\n\
      \    actual: %s\n"
      file md5 md5_of_file;
    Sys.remove file;
    exit 1
  ) else
    let silent =
      try Sys.getenv "OPAM_MD5_SILENT" = "true"
      with Not_found -> false
    in
    if not silent then
      Printf.printf "%s has the expected MD5.\n" file