Skip to content

Instantly share code, notes, and snippets.

@danielrichman
Last active December 23, 2018 02:43
Show Gist options
  • Save danielrichman/b5e75e6672c76374ad2d to your computer and use it in GitHub Desktop.
Save danielrichman/b5e75e6672c76374ad2d to your computer and use it in GitHub Desktop.
Simple OCaml setup

Simple OCaml Setup

Goal: quickly install OCaml, Core, Async, and other JS libraries.

Plan: do it once, and then make a .deb that can be applied to other boxes.

It would be nicer if I could do the Debian packaging properly, but for now this is a quick fix.

Problems / warnings / notes

  • I delete the opam repository; so you need to opam update before it's usable again.
  • I add a sudo rule to preserve the OPAMROOT environment variable. sudo purges environment variables in the name of security. This should only be a problem if you have exotic sudo restrictions, and you will want to check this.
  • Includes git-patdiff-wrapper for free! (For use with GIT_EXTERNAL_DIFF)

Usage

  • Run the script as root on a clean Debian/Ubuntu VM/chroot of the version that you are targeting.
  • Copy ocaml-bundle.deb, patdiff.deb, and patdiff from / or /root, and nuke the VM/chroot from orbit.
  • Apply debs to other machines. It has some dependencies (build-essential, libpcre3-dev); resolve these via your favourite means (dpkg -i x.deb; apt-get install -f works).
#!/bin/bash
set -xe
exec 2> >(tee ocaml-bundle.log)
exec 1>&2
# shutdown -h -P +60 &
wget https://github.com/ocaml/opam/releases/download/2.0.2/opam-2.0.2-x86_64-linux -O /usr/local/bin/opam
chmod +x /usr/local/bin/opam
which opam || export PATH=/usr/local/bin:$PATH
apt-get update
apt-get install -y build-essential rsync git libpcre3-dev libncurses-dev pkg-config m4 unzip aspcud autoconf bubblewrap
COMP_VERSION=4.07.0
opam init --root=/usr/local/opam --comp=${COMP_VERSION} -y
eval `opam env --root=/usr/local/opam --set-root`
opam repository add -k git janestreet https://github.com/janestreet/opam-repository.git
opam install -y core async ocaml_plugin utop patdiff incremental dune
cat > /usr/local/opam/${COMP_VERSION}/bin/git-patdiff-wrapper <<"EOF"
#!/bin/sh
patdiff "$2" -alt-old "$1 $4" "$5" -alt-new "$1 $7" || true
EOF
chmod +x /usr/local/opam/${COMP_VERSION}/bin/git-patdiff-wrapper
cp /usr/local/opam/${COMP_VERSION}/bin/{git-patdiff-wrapper,patdiff} .
mkdir build-ocaml-bundle
mkdir -p build-ocaml-bundle/{DEBIAN,usr/local{,/bin},etc/{profile.d,sudoers.d}}
mv /usr/local/bin/opam build-ocaml-bundle/usr/local/bin/
mv /usr/local/opam build-ocaml-bundle/usr/local/
rm -rf build-ocaml-bundle/usr/local/opam/{log,repo/default/packages,state.cache}
mkdir build-patdiff
mkdir -p build-patdiff/{DEBIAN,usr/bin}
cp {git-patdiff-wrapper,patdiff} build-patdiff/usr/bin/
cat > build-ocaml-bundle/DEBIAN/control <<EOF
Package: ocaml-bundle
Version: 1
Architecture: amd64
Maintainer: Daniel Richman <main@danielrichman.co.uk>
Depends: build-essential, libpcre3-dev
Recommends: rsync, git, unzip, aspcud
Provides: ocaml-bundle
Section: ocaml
Priority: optional
Homepage: https://gist.github.com/danielrichman/b5e75e6672c76374ad2d
Description: OCaml Bundle
.
Description TBA
EOF
ln -s /usr/local/opam/opam-init/init.sh build-ocaml-bundle/etc/profile.d/ocaml-bundle.sh
echo 'Defaults env_keep+=OPAMROOT' > build-ocaml-bundle/etc/sudoers.d/ocaml-bundle
cat > build-patdiff/DEBIAN/control <<EOF
Package: patdiff
Version: 1
Architecture: amd64
Maintainer: Daniel Richman <main@danielrichman.co.uk>
Depends: libpcre3
Provides: patdiff
Section: vcs
Priority: optional
Homepage: https://github.com/janestreet/patdiff
Description: Jane Street's patdiff
.
Description TBA
EOF
# xz seems to be substantially better here(!)
dpkg-deb -Z xz --build build-ocaml-bundle ocaml-bundle.deb
dpkg-deb -Z xz --build build-patdiff patdiff.deb
rm -rf build-ocaml-bundle build-patdiff
# 4.03.0 plus dev versions as of 11 Nov 2016
db7aeace5d5c0f4fd46f9faa333c49d688a9397a401dedba3412ed465d72659e https://s3-eu-west-1.amazonaws.com/ocaml-bundle/debian-jessie/ocaml-bundle.deb
8c11b083d2d1aad560195fa6626fd960a5a7a07037a8428ca67f917c81994b61 https://s3-eu-west-1.amazonaws.com/ocaml-bundle/debian-jessie/patdiff.deb
e56e4fa10b6282683bbd81853795828ac927cc036b8e501f41aefcfbe3073f08 https://s3-eu-west-1.amazonaws.com/ocaml-bundle/debian-jessie/patdiff
# 112.35.00 on 4.02.1, built 1 Aug 2015
b09f47aa8f21513eb82177ad9a8df4d2b556552173218d3d4d76cb0c5a130286 https://s3-eu-west-1.amazonaws.com/ocaml-bundle/debian-wheezy/ocaml-bundle.deb
c7d4852ff61218f6cb33771d07321593269f3c3f2af91a63851c46a5cf36afc3 https://s3-eu-west-1.amazonaws.com/ocaml-bundle/debian-wheezy/patdiff.deb
2f8e804da851c275cdcb8f9f5d09d379f1b11faf90b5cea76ac0a58d45c7bf99 https://s3-eu-west-1.amazonaws.com/ocaml-bundle/debian-wheezy/patdiff
7b553fcd195457f8688275836a8fb3189e591ce48d4ad4807f938c640a3ef30d https://s3-eu-west-1.amazonaws.com/ocaml-bundle/ubuntu-14.04/ocaml-bundle.deb
8fe3d4e16c300f3d23357f4f11d562c8fe3e087ec272f60192f8bb2ee4003f1e https://s3-eu-west-1.amazonaws.com/ocaml-bundle/ubuntu-14.04/patdiff.deb
fd74da5095801baa9e0c45e637488ea95eaa336f4baff0fab591e448329e776f https://s3-eu-west-1.amazonaws.com/ocaml-bundle/ubuntu-14.04/patdiff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment