xref: /expo/bin/expotools (revision 58b9ee98)
1#!/usr/bin/env bash
2
3set -euo pipefail
4
5script_dir=$(dirname "$0")
6
7repository_root="${script_dir}/.."
8nix_dir="${repository_root}/nix"
9target="${script_dir}/expotools-built"
10up_to_date_package="$(nix path-info -f "${nix_dir}" expotools 2>/dev/null || true)"
11
12buildAndLink() {
13  nix build -f "${nix_dir}" --out-link "${target}" expotools
14}
15
16if ! ls "${target}/bin/expotools" &>/dev/null; then
17  echo "No version of expotools linked. Rebuilding..."
18  buildAndLink
19elif [ -z "${up_to_date_package}" ]; then
20  read -r -t 7 -n 1 -p "Linked expotools is out of date. Rebuild (Y/n)? " choice || true
21  choice=${choice:-Y}
22  case "$choice" in
23    y|Y ) buildAndLink ;;
24    * ) echo "Using previously-built expotools." ;;
25  esac
26elif [ "$(readlink "${target}")" != "${up_to_date_package}" ]; then
27  echo "Wrong version of expotools linked. Re-linking..."
28  buildAndLink
29fi
30
31exec "${target}/bin/expotools" "$@"
32