#!/bin/sh # Installs the newest Termilly on Debian or Ubuntu (64-bit): # # curl -fsSL https://termilly.com/install.sh | sh # # It reads https://termilly.com/downloads/latest.json, downloads the package named there, checks its SHA-256 # against that file and installs it with apt, which brings .NET and WebKitGTK with it. It's short on purpose, # so you can read it before you run it. TERMILLY_SITE points it at another server, for testing. set -eu # Everything is in main, which runs on the last line: a download cut short runs nothing. main() { site="${TERMILLY_SITE:-https://termilly.com}" command -v apt-get >/dev/null 2>&1 || fail "This script is for Debian and Ubuntu (it needs apt). Other systems: $site/#download" command -v curl >/dev/null 2>&1 || fail "This script needs curl: sudo apt install curl" command -v sha256sum >/dev/null 2>&1 || fail "This script needs sha256sum (coreutils)." arch="$(dpkg --print-architecture)" [ "$arch" = amd64 ] || fail "Termilly is built for 64-bit PCs (amd64), and this one is $arch." sudo="" if [ "$(id -u)" -ne 0 ]; then command -v sudo >/dev/null 2>&1 || fail "Installing needs root: run this as root, or install sudo." sudo=sudo fi # latest.json may be on one line or spread over several: without the whitespace, the "linux" part is # {"deb":"","sha256":""} either way. manifest="$(fetch "$site/downloads/latest.json")" || fail "Couldn't read $site/downloads/latest.json." manifest="$(printf '%s' "$manifest" | tr -d ' \t\r\n')" version="$(field "$manifest" version)" linux="$(printf '%s' "$manifest" | sed -n 's/.*"linux":{\([^}]*\)}.*/\1/p')" url="$(field "$linux" deb)" sum="$(field "$linux" sha256)" [ -n "$version" ] && [ -n "$url" ] && [ -n "$sum" ] || fail "$site/downloads/latest.json doesn't name a Linux package." # apt reads the package as its own user (_apt), so the folder and the file are readable by everyone. dir="$(mktemp -d)" trap 'rm -rf "$dir"' EXIT chmod 755 "$dir" deb="$dir/termilly_amd64.deb" echo "Downloading Termilly $version" fetch "$url" > "$deb" || fail "Couldn't download $url." chmod 644 "$deb" echo "$sum $deb" | sha256sum -c --status - || fail "The download doesn't match the SHA-256 in latest.json, so it wasn't installed. Try again later." echo "Installing it with apt" $sudo apt-get update -qq || fail "apt-get update failed." $sudo apt-get install -y "$deb" || fail "apt-get couldn't install the package." echo "Termilly $version is installed. Start it from your applications, or type termilly in a terminal." } # HTTPS only, redirects too (http:// only when TERMILLY_SITE asks for it). fetch() { case "$1" in https://*) curl -fsSL --proto =https --proto-redir =https "$1" ;; *) curl -fsSL --proto-redir =https "$1" ;; esac } # The string value of a key in compact JSON: field '{"a":"b"}' a prints b. field() { printf '%s' "$1" | sed -n "s/.*\"$2\":\"\([^\"]*\)\".*/\1/p" } fail() { echo "termilly install: $1" >&2 exit 1 } main "$@"