#!/bin/sh # The Lens Flash installer. It downloads Lens Flash 9.0.0 for Linux (x86_64) from r7n.solutions, checks the # download's SHA-256, and runs the install.sh inside it, which puts Lens Flash in ~/.local/share/lens-flash and the # `flash` command in ~/.local/bin (added to your PATH). Nothing else on your machine is changed. # # curl -fsSL https://r7n.solutions/install.sh | sh # # LENS_FLASH_BASE=URL-or-folder downloads from another place instead. # (In the lens-flash source this is tools/get.sh; tools/deliver.sh --site-files writes it with the version filled in.) set -eu V=9.0.0 BASE=${LENS_FLASH_BASE:-https://r7n.solutions/download} NAME=lens-flash-$V-linux-x86_64.tar.gz say() { printf '%s\n' "$*"; } fail() { printf 'lens-flash install: %s\n' "$*" >&2; exit 1; } case "$(uname -s)-$(uname -m)" in Linux-x86_64) ;; *) fail "lens-flash runs on Linux (x86_64), including WSL on Windows; this machine is $(uname -s) $(uname -m)";; esac for t in tar gzip; do command -v "$t" > /dev/null 2>&1 || fail "it needs $t: install it (sudo apt install $t), then run this again"; done if command -v sha256sum > /dev/null 2>&1; then sum() { sha256sum "$1" | cut -d' ' -f1; } elif command -v shasum > /dev/null 2>&1; then sum() { shasum -a 256 "$1" | cut -d' ' -f1; } else fail "it needs sha256sum (coreutils) to check the download"; fi FROM=${LENS_FLASH_BASE:+ (LENS_FLASH_BASE)} fetch() { # URL OUT: 0, or a reason why not in $WHY WHY= case "$1" in http://*|https://*) if command -v curl > /dev/null 2>&1; then code=$(curl -sSL --retry 2 -o "$2" -w '%{http_code}' "$1" 2> "$T/err") || { WHY="could not reach ${1%/*}$FROM: check your connection (or proxy) and try again"; return 1; } case "$code" in 2*) ;; 404) WHY="there is no $(basename "$1") at ${1%/*}$FROM"; return 1;; *) WHY="${1%/*}$FROM answered HTTP $code for $(basename "$1"); try again later"; return 1;; esac elif command -v wget > /dev/null 2>&1; then wget -q -O "$2" "$1" || { WHY="could not download $1$FROM: check your connection (or proxy) and try again"; return 1; } else fail "it needs curl or wget: install one (sudo apt install curl), then run this again"; fi;; *) [ -f "$1" ] || { WHY="there is no $1$FROM"; return 1; }; cp "$1" "$2";; esac } T=$(mktemp -d) trap 'rm -rf "$T"' EXIT INT TERM say "Downloading lens-flash $V" fetch "$BASE/$NAME" "$T/$NAME" || fail "$WHY" fetch "$BASE/$NAME.sha256" "$T/$NAME.sha256" || fail "$WHY" want=$(cut -d' ' -f1 < "$T/$NAME.sha256") got=$(sum "$T/$NAME") [ "$want" = "$got" ] || fail "the download is damaged (its SHA-256 does not match); run this again. If it says this again, the copy at $BASE is damaged: nothing was installed" mkdir "$T/x" tar -xzf "$T/$NAME" -C "$T/x" || fail "the download does not unpack; run this again" sh "$T/x/lens-flash-$V-linux-x86_64/install.sh" < /dev/null