louise
The Louise language: compiler, runtime, std, tooling
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runRéussi#88 · main · 15 min 30 s
0Étoiles
0Forks
40Issues
| 1 | #!/bin/sh |
| 2 | # The Louise installer: the latest release's prebuilt compiler and runtime |
| 3 | # archives into ~/.local/bin. |
| 4 | # |
| 5 | # curl -fsSL https://toboggan.cloud/gabla108/louise/raw/main/scripts/install.sh | sh |
| 6 | # |
| 7 | # Knobs (environment): |
| 8 | # LOUISE_INSTALL_DIR where louise and liblouise_rt*.a land (~/.local/bin) |
| 9 | # LOUISE_VERSION install this tag (0.1.0 or v0.1.0) instead of the latest |
| 10 | # LOUISE_TOKEN read the forge with this token (while the repository is |
| 11 | # internal; TOBOGGAN_TOKEN and tob's sign-in work too) |
| 12 | # LOUISE_FORCE replace an existing install without asking |
| 13 | # NO_COLOR no colors, no animations (also: not a tty) |
| 14 | # |
| 15 | # POSIX sh; needs curl, tar (xz), sha256sum, uname, mktemp. |
| 16 | |
| 17 | set -eu |
| 18 | |
| 19 | HOST="${LOUISE_HOST:-toboggan.cloud}" |
| 20 | REPO="${LOUISE_REPO:-gabla108/louise}" |
| 21 | DIR="${LOUISE_INSTALL_DIR:-$HOME/.local/bin}" |
| 22 | PLATFORM="x86_64-linux" # the only prebuilt so far |
| 23 | |
| 24 | # ------------------------------------------------------------ output |
| 25 | |
| 26 | if [ -t 1 ] && [ -z "${NO_COLOR:-}" ]; then |
| 27 | B=$(printf '\033[1m') D=$(printf '\033[2m') G=$(printf '\033[32m') |
| 28 | R=$(printf '\033[31m') C=$(printf '\033[36m') N=$(printf '\033[0m') |
| 29 | else |
| 30 | B='' D='' G='' R='' C='' N='' |
| 31 | fi |
| 32 | |
| 33 | say() { printf '%s\n' "$*"; } |
| 34 | step() { printf '%s==>%s %s\n' "$C$B" "$N" "$*"; } |
| 35 | ok() { printf ' %s✓%s %s\n' "$G" "$N" "$*"; } |
| 36 | die() { printf ' %s✗%s %s\n' "$R$B" "$N" "$*" >&2; exit 1; } |
| 37 | |
| 38 | # spinner <pid> <message>: braille frames on stderr while <pid> runs. |
| 39 | spin() { |
| 40 | [ -t 2 ] || { wait "$1"; return $?; } |
| 41 | frames='⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏' |
| 42 | i=0 |
| 43 | while kill -0 "$1" 2>/dev/null; do |
| 44 | i=$(( (i + 1) % 10 )) |
| 45 | printf '\r %s%s%s %s' "$C" "$(printf '%s' "$frames" | cut -c "$i")" "$N" "$2" >&2 |
| 46 | sleep 0.1 2>/dev/null || sleep 1 |
| 47 | done |
| 48 | printf '\r%40s\r' '' >&2 |
| 49 | wait "$1" |
| 50 | } |
| 51 | |
| 52 | # fetch <url> <dest> [progress-message]: download with auth when there is |
| 53 | # one; a progress bar on a tty, a spinner otherwise. |
| 54 | fetch() { |
| 55 | url=$1 dest=$2 msg=${3:-} |
| 56 | auth= |
| 57 | token=$(token) |
| 58 | [ -n "$token" ] && auth="Authorization: Bearer $token" |
| 59 | if [ -t 2 ]; then |
| 60 | # shellcheck disable=SC2086 |
| 61 | curl -fsSL ${auth:+-H "$auth"} --connect-timeout 20 \ |
| 62 | --speed-time 30 --speed-limit 1000 --progress-bar "$url" -o "$dest" >&2 |
| 63 | else |
| 64 | # shellcheck disable=SC2086 |
| 65 | curl -fsSL ${auth:+-H "$auth"} --connect-timeout 20 \ |
| 66 | --speed-time 30 --speed-limit 1000 -sS "$url" -o "$dest" 2>/dev/null & |
| 67 | spin $! "${msg:-downloading}" |
| 68 | fi |
| 69 | } |
| 70 | |
| 71 | # The token, first match wins: LOUISE_TOKEN, TOBOGGAN_TOKEN, tob's |
| 72 | # hosts.toml (tob auth login --hostname toboggan.cloud). |
| 73 | token() { |
| 74 | if [ -n "${LOUISE_TOKEN:-}" ]; then printf '%s' "$LOUISE_TOKEN"; return; fi |
| 75 | if [ -n "${TOBOGGAN_TOKEN:-}" ]; then printf '%s' "$TOBOGGAN_TOKEN"; return; fi |
| 76 | conf="${XDG_CONFIG_HOME:-$HOME/.config}/tob/hosts.toml" |
| 77 | [ -f "$conf" ] || return 0 |
| 78 | awk -F'"' -v host="$HOST" ' |
| 79 | /^\[hosts\./ { s = ($0 ~ host) ? 1 : 0 } |
| 80 | s && /^token/ { print $2; exit } |
| 81 | ' "$conf" |
| 82 | } |
| 83 | |
| 84 | # ------------------------------------------------------------ the steps |
| 85 | |
| 86 | banner() { |
| 87 | [ -t 1 ] || return 0 |
| 88 | printf '%s%s' "$B" "$C" |
| 89 | cat <<'EOF' |
| 90 | ░██ ░█▒ |
| 91 | ░██ ░█ |
| 92 | ░██ ░█████╗ ░██╗ ░██╗░░░ ░███░░░░ ░█████╗ |
| 93 | ░██ ░██║ ░██║░██║ ░██║░░ ░█▒░██╗ ░██║░░░██╗ |
| 94 | ░██ ░██║ ░██║░██║ ░██║ ░██ ░██╗ ░██║ ░░ |
| 95 | ░██ ░██║ ░██║░██║ ░██║ ░██ ░██╗░██║ ░░ |
| 96 | ░██ ░█████╔╝ ░██████╔╝░░ ░██░░░██║░░█████╔╝ |
| 97 | ░═╝ ░═════╝ ░═════╝═╝ ░═╝ ░══╝ ░═════╝ |
| 98 | EOF |
| 99 | printf '%s%s A statically typed language with algebraic effects and actors.\n\n' "$N" "$D" |
| 100 | } |
| 101 | |
| 102 | check_platform() { |
| 103 | step "Checking the platform" |
| 104 | [ "$(uname -s)" = "Linux" ] && [ "$(uname -m)" = "x86_64" ] || |
| 105 | die "prebuilt binaries are x86_64-linux only for now; build from source (README, \"Getting started\")" |
| 106 | for tool in curl tar sha256sum; do |
| 107 | command -v "$tool" >/dev/null || die "needs $tool" |
| 108 | done |
| 109 | ok "linux x86_64, curl, tar, sha256sum" |
| 110 | } |
| 111 | |
| 112 | # The latest release's tag, from the /releases/latest redirect (plain |
| 113 | # HTTP; the API answers MessagePack, which a shell cannot read). |
| 114 | latest_tag() { |
| 115 | auth= |
| 116 | t=$(token) |
| 117 | [ -n "$t" ] && auth="Authorization: Bearer $t" |
| 118 | loc=$( |
| 119 | # GET, not HEAD: the route is GET-only. -D - prints the headers. |
| 120 | # shellcheck disable=SC2086 |
| 121 | curl -sS ${auth:+-H "$auth"} --connect-timeout 20 -o /dev/null -D - \ |
| 122 | "https://$HOST/$REPO/releases/latest" 2>/dev/null | |
| 123 | tr -d '\r' | sed -n 's/^location:.*\/tag\/\([^[:space:]]*\)$/\1/p' | head -1 |
| 124 | ) |
| 125 | [ -n "$loc" ] || die "no release found (none tagged yet, or the repository asks for a sign-in — LOUISE_TOKEN reads it then); build from source (README)" |
| 126 | printf '%s' "$loc" |
| 127 | } |
| 128 | |
| 129 | find_tag() { |
| 130 | if [ -n "${LOUISE_VERSION:-}" ]; then |
| 131 | case "$LOUISE_VERSION" in v*) tag="$LOUISE_VERSION" ;; *) tag="v$LOUISE_VERSION" ;; esac |
| 132 | step "Release $tag (pinned)" |
| 133 | else |
| 134 | step "Finding the latest release" |
| 135 | tag=$(latest_tag) |
| 136 | fi |
| 137 | ok "$tag" |
| 138 | } |
| 139 | |
| 140 | already() { |
| 141 | if command -v louise >/dev/null 2>&1 && [ -z "${LOUISE_FORCE:-}" ]; then |
| 142 | have=$(louise --version 2>/dev/null || true) |
| 143 | say " ${D}$have already installed;${N} ${B}louise self update${N} upgrades it (or LOUISE_FORCE=1 to reinstall)" |
| 144 | exit 0 |
| 145 | fi |
| 146 | } |
| 147 | |
| 148 | download() { |
| 149 | step "Downloading louise-$tag-$PLATFORM.tar.xz" |
| 150 | tmp=$(mktemp -d) |
| 151 | trap 'rm -rf "$tmp"' EXIT |
| 152 | base="https://$HOST/api/$REPO/releases/tag/$tag/assets" |
| 153 | tarball="louise-$tag-$PLATFORM.tar.xz" |
| 154 | fetch "$base/$tarball" "$tmp/$tarball" "downloading louise $tag" |
| 155 | fetch "$base/$tarball.sha256" "$tmp/$tarball.sha256" "the checksum" |
| 156 | ok "$(stat -c%s "$tmp/$tarball") bytes" |
| 157 | } |
| 158 | |
| 159 | verify() { |
| 160 | step "Verifying the checksum" |
| 161 | (cd "$tmp" && sha256sum -c "$tarball.sha256" >/dev/null) || |
| 162 | die "the checksum does not match; not installing (try again — a cut short download is the usual cause)" |
| 163 | ok "sha256 matches the release's" |
| 164 | } |
| 165 | |
| 166 | install_it() { |
| 167 | step "Installing to $DIR" |
| 168 | mkdir -p "$DIR" |
| 169 | (cd "$tmp" && tar -xJf "$tarball") |
| 170 | src="$tmp/louise-$tag-$PLATFORM" |
| 171 | [ -d "$src" ] || src=$(find "$tmp" -maxdepth 1 -mindepth 1 -type d | head -1) |
| 172 | [ -n "$src" ] || die "the tarball holds no directory" |
| 173 | for f in liblouise_rt.a liblouise_rt-fast.a liblouise_rt-lto.a liblouise_rt-lto.llvm; do |
| 174 | [ -f "$src/$f" ] && install -m 644 "$src/$f" "$DIR/$f" |
| 175 | done |
| 176 | install -m 755 "$src/louise" "$DIR/louise" # the compiler last |
| 177 | ok "$("$DIR/louise" --version)" |
| 178 | } |
| 179 | |
| 180 | path_note() { |
| 181 | case ":$PATH:" in |
| 182 | *":$DIR:"*) ;; |
| 183 | *) |
| 184 | say "" |
| 185 | step "One more thing: $DIR is not on your PATH" |
| 186 | say " bash/zsh: echo 'export PATH=\"$DIR:\$PATH\"' >> ~/.bashrc # or ~/.zshrc" |
| 187 | say " fish: fish_add_path $DIR" |
| 188 | ;; |
| 189 | esac |
| 190 | } |
| 191 | |
| 192 | finale() { |
| 193 | [ -t 1 ] || return 0 |
| 194 | printf '\n %s%sLouise is installed.%s Try it:\n\n' "$B" "$G" "$N" |
| 195 | say " mkdir hello && cd hello" |
| 196 | say " printf 'import std/io\npub fn main :: -> () / <io> { io.println(\"hello\") }\n' > main.lse" |
| 197 | say " louise run main.lse" |
| 198 | say "" |
| 199 | say " ${D}Later: louise self update upgrades in place. Editors: README, \"Getting started\".${N}" |
| 200 | } |
| 201 | |
| 202 | banner |
| 203 | check_platform |
| 204 | already |
| 205 | find_tag |
| 206 | download |
| 207 | verify |
| 208 | install_it |
| 209 | path_note |
| 210 | finale |