annotate repoint @ 80:f84e12a1553c tip

Update server certificate fingerprints
author Chris Cannam
date Wed, 14 Aug 2019 14:58:48 +0100
parents a6c9a0ca493e
children
rev   line source
Chris@70 1 #!/bin/bash
Chris@70 2
Chris@70 3 # Disable shellcheck warnings for useless-use-of-cat. UUOC is good
Chris@70 4 # practice, not bad: clearer, safer, less error-prone.
Chris@70 5 # shellcheck disable=SC2002
Chris@70 6
Chris@76 7 sml="$REPOINT_SML"
Chris@70 8
Chris@70 9 set -eu
Chris@70 10
Chris@76 11 # avoid gussying up output
Chris@76 12 export HGPLAIN=true
Chris@76 13
Chris@70 14 mydir=$(dirname "$0")
Chris@76 15 program="$mydir/repoint.sml"
Chris@70 16
Chris@70 17 hasher=
Chris@70 18 local_install=
Chris@70 19 if [ -w "$mydir" ]; then
Chris@70 20 if echo | sha256sum >/dev/null 2>&1 ; then
Chris@70 21 hasher=sha256sum
Chris@70 22 local_install=true
Chris@70 23 elif echo | shasum >/dev/null 2>&1 ; then
Chris@70 24 hasher=shasum
Chris@70 25 local_install=true
Chris@70 26 else
Chris@70 27 echo "WARNING: sha256sum or shasum program not found" 1>&2
Chris@70 28 fi
Chris@70 29 fi
Chris@70 30
Chris@70 31 if [ -n "$local_install" ]; then
Chris@70 32 hash=$(echo "$sml" | cat "$program" - | $hasher | cut -c1-16)
Chris@76 33 gen_sml=$mydir/.repoint-$hash.sml
Chris@76 34 gen_out=$mydir/.repoint-$hash.bin
Chris@70 35 trap 'rm -f $gen_sml' 0
Chris@70 36 else
Chris@76 37 gen_sml=$(mktemp /tmp/repoint-XXXXXXXX.sml)
Chris@76 38 gen_out=$(mktemp /tmp/repoint-XXXXXXXX.bin)
Chris@70 39 trap 'rm -f $gen_sml $gen_out' 0
Chris@70 40 fi
Chris@70 41
Chris@70 42 if [ -x "$gen_out" ]; then
Chris@70 43 exec "$gen_out" "$@"
Chris@70 44 fi
Chris@70 45
Chris@76 46 # We need one of Poly/ML, SML/NJ, MLton, or MLKit. Since we're running
Chris@76 47 # a single-file SML program as if it were a script, our order of
Chris@76 48 # preference is usually based on startup speed. An exception is the
Chris@76 49 # local_install case, where we retain a persistent binary
Chris@70 50
Chris@70 51 if [ -z "$sml" ]; then
Chris@70 52 if [ -n "$local_install" ] && mlton 2>&1 | grep -q 'MLton'; then
Chris@70 53 sml="mlton"
Chris@70 54 elif sml -h 2>&1 | grep -q 'Standard ML of New Jersey'; then
Chris@70 55 sml="smlnj"
Chris@70 56 # We would prefer Poly/ML to SML/NJ, except that Poly v5.7 has a
Chris@70 57 # nasty bug that occasionally causes it to deadlock on startup.
Chris@76 58 # That is fixed in v5.7.1, so we could promote it up the order
Chris@76 59 # again at some point in future
Chris@70 60 elif echo | poly -v 2>/dev/null | grep -q 'Poly/ML'; then
Chris@70 61 sml="poly"
Chris@70 62 elif mlton 2>&1 | grep -q 'MLton'; then
Chris@70 63 sml="mlton"
Chris@76 64 # MLKit is at the bottom because it leaves compiled files around
Chris@76 65 # in an MLB subdir in the current directory
Chris@76 66 elif mlkit 2>&1 | grep -q 'MLKit'; then
Chris@76 67 sml="mlkit"
Chris@70 68 else cat 1>&2 <<EOF
Chris@70 69
Chris@70 70 ERROR: No supported SML compiler or interpreter found
Chris@70 71 EOF
Chris@70 72 cat 1>&2 <<EOF
Chris@70 73
Chris@76 74 The Repoint external source code manager needs a Standard ML (SML)
Chris@70 75 compiler or interpreter to run.
Chris@70 76
Chris@70 77 Please ensure you have one of the following SML implementations
Chris@70 78 installed and present in your PATH, and try again.
Chris@70 79
Chris@70 80 1. Standard ML of New Jersey
Chris@76 81 - may be found in a distribution package called: smlnj
Chris@70 82 - executable name: sml
Chris@70 83
Chris@70 84 2. Poly/ML
Chris@76 85 - may be found in a distribution package called: polyml
Chris@70 86 - executable name: poly
Chris@70 87
Chris@70 88 3. MLton
Chris@76 89 - may be found in a distribution package called: mlton
Chris@70 90 - executable name: mlton
Chris@70 91
Chris@76 92 4. MLKit
Chris@76 93 - may be found in a distribution package called: mlkit
Chris@76 94 - executable name: mlkit
Chris@76 95
Chris@70 96 EOF
Chris@70 97 exit 2
Chris@70 98 fi
Chris@70 99 fi
Chris@70 100
Chris@70 101 arglist=""
Chris@70 102 for arg in "$@"; do
Chris@70 103 if [ -n "$arglist" ]; then arglist="$arglist,"; fi
Chris@70 104 if echo "$arg" | grep -q '["'"'"']' ; then
Chris@70 105 arglist="$arglist\"usage\""
Chris@70 106 else
Chris@70 107 arglist="$arglist\"$arg\""
Chris@70 108 fi
Chris@70 109 done
Chris@70 110
Chris@70 111 case "$sml" in
Chris@70 112 poly)
Chris@70 113 if [ -n "$local_install" ] && polyc --help >/dev/null 2>&1 ; then
Chris@70 114 if [ ! -x "$gen_out" ]; then
Chris@70 115 polyc -o "$gen_out" "$program"
Chris@70 116 fi
Chris@70 117 "$gen_out" "$@"
Chris@70 118 else
Chris@76 119 echo 'use "'"$program"'"; repoint ['"$arglist"'];' |
Chris@70 120 poly -q --error-exit
Chris@70 121 fi ;;
Chris@70 122 mlton)
Chris@70 123 if [ ! -x "$gen_out" ]; then
Chris@76 124 echo "[Precompiling Repoint binary...]" 1>&2
Chris@70 125 echo "val _ = main ()" | cat "$program" - > "$gen_sml"
Chris@70 126 mlton -output "$gen_out" "$gen_sml"
Chris@70 127 fi
Chris@70 128 "$gen_out" "$@" ;;
Chris@76 129 mlkit)
Chris@76 130 if [ ! -x "$gen_out" ]; then
Chris@76 131 echo "[Precompiling Repoint binary...]" 1>&2
Chris@76 132 echo "val _ = main ()" | cat "$program" - > "$gen_sml"
Chris@76 133 mlkit -output "$gen_out" "$gen_sml"
Chris@76 134 fi
Chris@76 135 "$gen_out" "$@" ;;
Chris@70 136 smlnj)
Chris@70 137 cat "$program" | (
Chris@70 138 cat <<EOF
Chris@70 139 val smlrun__cp =
Chris@70 140 let val x = !Control.Print.out in
Chris@70 141 Control.Print.out := { say = fn _ => (), flush = fn () => () };
Chris@70 142 x
Chris@70 143 end;
Chris@70 144 val smlrun__prev = ref "";
Chris@70 145 Control.Print.out := {
Chris@70 146 say = fn s =>
Chris@70 147 (if String.isSubstring " Error" s
Chris@70 148 then (Control.Print.out := smlrun__cp;
Chris@70 149 (#say smlrun__cp) (!smlrun__prev);
Chris@70 150 (#say smlrun__cp) s)
Chris@70 151 else (smlrun__prev := s; ())),
Chris@70 152 flush = fn s => ()
Chris@70 153 };
Chris@70 154 EOF
Chris@70 155 cat -
Chris@70 156 cat <<EOF
Chris@76 157 val _ = repoint [$arglist];
Chris@70 158 val _ = OS.Process.exit (OS.Process.success);
Chris@70 159 EOF
Chris@70 160 ) > "$gen_sml"
Chris@70 161 CM_VERBOSE=false sml "$gen_sml" ;;
Chris@70 162 *)
Chris@70 163 echo "ERROR: Unknown SML implementation name: $sml" 1>&2;
Chris@70 164 exit 2 ;;
Chris@70 165 esac
Chris@70 166