#!/bin/sh # DreamCoder installer for macOS (Apple silicon) and Debian/Ubuntu (x86_64). # # curl -fsSL https://www.dreamcoder.ai/install.sh | sh # # Everything runs inside main(), called on the last line, so a download that # stops part-way cannot run half of this script. say() { printf '%s\n' "$*" } fail() { printf 'DreamCoder: %s\n' "$*" >&2 exit 1 } make_work_dir() { dreamcoder_work=$(mktemp -d "${TMPDIR:-/tmp}/dreamcoder.XXXXXX") trap 'rm -rf "$dreamcoder_work"' EXIT trap 'exit 1' HUP INT TERM } install_macos() { [ "$(uname -m)" = arm64 ] || fail "DreamCoder for macOS needs a Mac with Apple silicon (M1 or later)." dreamcoder_app=/Applications/DreamCoder.app make_work_dir say "Downloading DreamCoder..." curl -fL --progress-bar -o "$dreamcoder_work/DreamCoder.zip" https://www.dreamcoder.ai/downloads/files/private/1.0.11/macos/dreamcoder-1.0.11-macos-arm64.zip say "Unpacking..." ditto -xk "$dreamcoder_work/DreamCoder.zip" "$dreamcoder_work/unpacked" [ -d "$dreamcoder_work/unpacked/DreamCoder.app" ] || fail "The download did not contain DreamCoder.app." if [ -e "$dreamcoder_app" ]; then say "Closing and replacing the DreamCoder already in Applications..." osascript -e 'if application "DreamCoder" is running then tell application "DreamCoder" to quit' >/dev/null 2>&1 || true rm -rf "$dreamcoder_app" fi say "Installing into /Applications..." ditto "$dreamcoder_work/unpacked/DreamCoder.app" "$dreamcoder_app" # macOS may refuse to open an app that carries the download quarantine # mark. This clears the mark from DreamCoder only; a copy that never had # the mark is fine as it is. say "Removing the download quarantine mark..." xattr -dr com.apple.quarantine "$dreamcoder_app" 2>/dev/null || true say "Opening DreamCoder..." open "$dreamcoder_app" } install_linux() { [ "$(uname -m)" = x86_64 ] || fail "Only Debian/Ubuntu-style x86_64 (amd64) systems are supported." command -v apt-get >/dev/null 2>&1 || fail "Only Debian/Ubuntu-style systems (with apt-get) are supported." if [ "$(id -u)" -ne 0 ] && ! command -v sudo >/dev/null 2>&1; then fail "Installing the package needs root, and sudo is not installed. Run this as root instead." fi make_work_dir # apt-get reads the package as an unprivileged user, so let it into the folder. chmod 755 "$dreamcoder_work" dreamcoder_deb="$dreamcoder_work/"dreamcoder-dreamcoder_1.0.11_amd64.deb say "Downloading DreamCoder..." curl -fL --progress-bar -o "$dreamcoder_deb" https://www.dreamcoder.ai/downloads/files/private/1.0.11/linux-deb/dreamcoder-dreamcoder_1.0.11_amd64.deb chmod 644 "$dreamcoder_deb" say "Installing the package with apt-get..." if [ "$(id -u)" -eq 0 ]; then apt-get install -y "$dreamcoder_deb" else sudo apt-get install -y "$dreamcoder_deb" fi say "DreamCoder is installed. Run 'dreamcoder', or open DreamCoder from your applications menu." say "Then go to http://localhost:9889" } main() { set -eu case "$(uname -s)" in Darwin) install_macos ;; Linux) install_linux ;; *) fail "This installer supports macOS and Debian/Ubuntu only. See "https://www.dreamcoder.ai/downloads ;; esac } main "$@"