|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# This script installs doltgres on your Linux or macOS computer. |
| 4 | +# It should be run as root, and can be run directly from a GitHub |
| 5 | +# release, for example as: |
| 6 | +# |
| 7 | +# curl https://github.com/dolthub/dolt/releases/download/v__DOLTGRES_VERSION__/install.sh | sudo bash |
| 8 | +# |
| 9 | +# All downloads occur over HTTPS from the Github releases page. |
| 10 | + |
| 11 | +if test -z "$BASH_VERSION"; then |
| 12 | + echo "Please run this script using bash, not sh or any other shell." >&2 |
| 13 | + exit 1 |
| 14 | +fi |
| 15 | + |
| 16 | +_() { |
| 17 | + |
| 18 | +set -euo pipefail |
| 19 | + |
| 20 | +DOLTGRES_VERSION='__DOLTGRES_VERSION__' |
| 21 | +RELEASES_BASE_URL="https://github.com/dolthub/doltgresql/releases/download/v$DOLTGRES_VERSION" |
| 22 | +INSTALL_URL="$RELEASES_BASE_URL/install.sh" |
| 23 | + |
| 24 | +CURL_USER_AGENT="${CURL_USER_AGENT:-dolt-installer}" |
| 25 | + |
| 26 | +OS= |
| 27 | +ARCH= |
| 28 | +WORK_DIR= |
| 29 | + |
| 30 | +PLATFORM_TUPLE= |
| 31 | + |
| 32 | +error() { |
| 33 | + if [ "$#" != 0 ]; then |
| 34 | + printf '\e[0;31m%s\e[0m\n' "$*" >&2 |
| 35 | + fi |
| 36 | +} |
| 37 | + |
| 38 | +fail() { |
| 39 | + local error_code="$1" |
| 40 | + shift |
| 41 | + echo '*** INSTALLATION FAILED ***' >&2 |
| 42 | + echo '' >&2 |
| 43 | + error "$@" |
| 44 | + echo '' >&2 |
| 45 | + exit 1 |
| 46 | +} |
| 47 | + |
| 48 | +assert_linux_or_macos() { |
| 49 | + OS="$(uname)" |
| 50 | + ARCH="$(uname -m)" |
| 51 | + if [ "$OS" != 'Linux' ] && [ "$OS" != 'Darwin' ]; then |
| 52 | + fail 'E_UNSUPPORTED_OS' 'dolt install.sh only supports macOS and Linux.' |
| 53 | + fi |
| 54 | + |
| 55 | + # Translate aarch64 to arm64, since that's what GOARCH calls it |
| 56 | + if [ "$ARCH" == 'aarch64' ]; then |
| 57 | + ARCH='arm64' |
| 58 | + fi |
| 59 | + |
| 60 | + if [ "$ARCH-$OS" != 'x86_64-Linux' ] && [ "$ARCH-$OS" != 'x86_64-Darwin' ] && [ "$ARCH-$OS" != 'arm64-Linux' ] && [ "$ARCH-$OS" != 'arm64-Darwin' ]; then |
| 61 | + fail 'E_UNSUPPOSED_ARCH' 'dolt install.sh only supports installing dolt on Linux-x86_64, Darwin-x86_64, Linux-aarch64, or Darwin-arm64.' |
| 62 | + fi |
| 63 | + |
| 64 | + if [ "$OS" == 'Linux' ]; then |
| 65 | + PLATFORM_TUPLE=linux |
| 66 | + else |
| 67 | + PLATFORM_TUPLE=darwin |
| 68 | + fi |
| 69 | + |
| 70 | + if [ "$ARCH" == 'x86_64' ]; then |
| 71 | + PLATFORM_TUPLE="$PLATFORM_TUPLE-amd64" |
| 72 | + else |
| 73 | + PLATFORM_TUPLE="$PLATFORM_TUPLE-arm64" |
| 74 | + fi |
| 75 | +} |
| 76 | + |
| 77 | +assert_dependencies() { |
| 78 | + type -p curl > /dev/null || fail 'E_CURL_MISSING' 'Please install curl(1).' |
| 79 | + type -p tar > /dev/null || fail 'E_TAR_MISSING' 'Please install tar(1).' |
| 80 | + type -p uname > /dev/null || fail 'E_UNAME_MISSING' 'Please install uname(1).' |
| 81 | + type -p install > /dev/null || fail 'E_INSTALL_MISSING' 'Please install install(1).' |
| 82 | + type -p mktemp > /dev/null || fail 'E_MKTEMP_MISSING' 'Please install mktemp(1).' |
| 83 | +} |
| 84 | + |
| 85 | +assert_uid_zero() { |
| 86 | + uid="$(id -u)" |
| 87 | + if [ "$uid" != 0 ]; then |
| 88 | + fail 'E_UID_NONZERO' "dolt install.sh must run as root; please try running with sudo or running\n\`curl $INSTALL_URL | sudo bash\`." |
| 89 | + fi |
| 90 | +} |
| 91 | + |
| 92 | +create_workdir() { |
| 93 | + WORK_DIR="$(mktemp -d -t dolt-installer.XXXXXX)" |
| 94 | + cleanup() { |
| 95 | + rm -rf "$WORK_DIR" |
| 96 | + } |
| 97 | + |
| 98 | + trap cleanup EXIT |
| 99 | + cd "$WORK_DIR" |
| 100 | +} |
| 101 | + |
| 102 | +install_binary_release() { |
| 103 | + local FILE="doltgresql-$PLATFORM_TUPLE.tar.gz" |
| 104 | + local URL="$RELEASES_BASE_URL/$FILE" |
| 105 | + |
| 106 | + echo "Downloading: $URL" |
| 107 | + curl -A "$CURL_USER_AGENT" -fsL "$URL" > "$FILE" |
| 108 | + tar zxf "$FILE" |
| 109 | + |
| 110 | + echo 'Installing dolt into /usr/local/bin.' |
| 111 | + [ ! -d /usr/local/bin ] && install -o 0 -g 0 -d /usr/local/bin |
| 112 | + install -o 0 -g 0 "doltgresql-$PLATFORM_TUPLE/bin/doltgres" /usr/local/bin |
| 113 | + install -o 0 -g 0 -d /usr/local/share/doc/doltgresql/ |
| 114 | + # TODO: vend licenses |
| 115 | +# install -o 0 -g 0 -m 644 "dolt-$PLATFORM_TUPLE/LICENSES" /usr/local/share/doc/doltgresql/ |
| 116 | +} |
| 117 | + |
| 118 | +assert_linux_or_macos |
| 119 | +assert_dependencies |
| 120 | +assert_uid_zero |
| 121 | +create_workdir |
| 122 | +install_binary_release |
| 123 | + |
| 124 | +} |
| 125 | + |
| 126 | +_ "$0" "$@" |
0 commit comments