#!/usr/bin/env bash # Novalina launcher installer for Linux (x86_64) and macOS. # # curl -fsSL https://novalina.fun/install.sh | bash # curl -fsSL https://novalina.fun/install.sh | bash -s -- --version 1.2.3 # # Downloads come from the Novalina site (https://novalina.fun): the copy served there has its # address filled in below (DEFAULT_BASE), a copy that was never filled in (e.g. straight from the # repository) uses https://novalina.fun as well. NOVALINA_BASE=https://... overrides it; # NOVALINA_BASE=github uses the GitHub releases instead (secondary, e.g. when the site is down). # # Re-running it updates the launcher. Needs no root. Uses only curl and sha256sum (shasum on macOS); # python3 is used to read manifest.json when it is there, otherwise a small built-in parser. # # What it installs: # Linux: ~/.local/bin/novalina (the AppImage) # ~/.local/share/applications/novalina.desktop (app launcher entry) # ~/.local/share/icons/hicolor/256x256/apps/novalina.png (icon) # macOS: /Applications/novalina.app (or ~/Applications/novalina.app) # # Everything is inside main(), which runs on the last line: a download cut off half-way does nothing. set -euo pipefail REPO="SlowlyTz/novalina" APP_ID="dev.novalina.launcher" # Replaced with the download server's address when the server renders this file. DEFAULT_BASE="https://novalina.fun" # Used when DEFAULT_BASE was never filled in. FALLBACK_BASE="https://novalina.fun" # Set in main(): the download server (empty = GitHub), the guide and where to report problems. SITE_BASE="" DOCS_URL="https://github.com/${REPO}/tree/main/docs/installation" SUPPORT_URL="https://github.com/${REPO}/issues" say() { printf '%s\n' "$*"; } # colours only on a terminal if [ -t 1 ]; then B=$'\033[1m' N=$'\033[0m'; else B='' N=''; fi if [ -t 2 ]; then Y=$'\033[33m' RD=$'\033[31m' N2=$'\033[0m'; else Y='' RD='' N2=''; fi step() { printf '%s==>%s %s\n' "$B" "$N" "$*"; } warn() { printf '%swarning:%s %s\n' "$Y" "$N2" "$*" >&2; } die() { printf '%serror:%s %s\n' "$RD" "$N2" "$*" >&2 exit 1 } usage() { cat < : prints launcher.., or the top-level # when the key is empty. Prints nothing when it is missing. manifest_get() { local file="$1" key="$2" field="$3" if command -v python3 >/dev/null 2>&1; then # -I: isolated, ignores the current directory and PYTHON* variables python3 -I - "$file" "$key" "$field" <<'PY' 2>/dev/null && return 0 import json, sys path, key, field = sys.argv[1:4] with open(path, encoding="utf-8") as f: data = json.load(f) node = data.get("launcher", {}).get(key) if key else data value = node.get(field) if isinstance(node, dict) else None if isinstance(value, (str, int)) and not isinstance(value, bool): print(value) PY fi # Fallback without python3: flatten the file to one line, cut out the launcher entry (its # object holds no nested braces) and read the string field from it. local flat obj flat=$(tr -d '\r\n\t' <"$file") if [ -n "$key" ]; then obj=$(printf '%s' "$flat" | grep -o "\"${key}\"[[:space:]]*:[[:space:]]*{[^}]*}" | head -n 1) || true else obj="$flat" fi [ -n "$obj" ] || return 0 printf '%s' "$obj" | grep -o "\"${field}\"[[:space:]]*:[[:space:]]*\"[^\"]*\"" | head -n 1 | sed -e 's/^.*:[[:space:]]*"//' -e 's/"$//' || true } # ---- helpers ---------------------------------------------------------------------------------- download() { # download curl -fL --proto '=https' --tlsv1.2 --retry 3 --connect-timeout 15 --progress-bar -o "$2" "$1" } sha256_of() { if command -v sha256sum >/dev/null 2>&1; then sha256sum "$1" | cut -d ' ' -f 1 elif command -v shasum >/dev/null 2>&1; then shasum -a 256 "$1" | cut -d ' ' -f 1 else die "neither sha256sum nor shasum found, cannot verify the download" fi } verify() { # verify local actual expected expected=$(printf '%s' "$2" | tr 'A-F' 'a-f') actual=$(sha256_of "$1") [ "$actual" = "$expected" ] || die "checksum mismatch for $(basename "$1") expected $expected got $actual Nothing was installed. Try again; if it keeps failing, report it at ${SUPPORT_URL}" } # A file name from the manifest must be a plain asset name, never a path. check_asset_name() { case "$1" in "" | */* | .* | *..*) die "manifest.json names an invalid file: '$1'" ;; esac } unsupported() { say "" say "Novalina has no installer for $1 yet." say "See the installation guide: ${DOCS_URL}" exit 1 } # ---- Linux -------------------------------------------------------------------------------------- install_linux() { local manifest="$1" base="$2" version="$3" tmp="$4" local file sha file=$(manifest_get "$manifest" linux-appimage file) sha=$(manifest_get "$manifest" linux-appimage sha256) [ -n "$file" ] && [ -n "$sha" ] || die "release ${version} has no Linux AppImage. See ${DOCS_URL}" check_asset_name "$file" local bin_dir="$HOME/.local/bin" local data_home="${XDG_DATA_HOME:-$HOME/.local/share}" case "$data_home" in /*) ;; *) data_home="$HOME/.local/share" ;; esac local target="$bin_dir/novalina" local apps_dir="$data_home/applications" local icon_dir="$data_home/icons/hicolor/256x256/apps" if [ -e "$target" ] && [ ! -L "$target" ] && [ "$(sha256_of "$target")" = "$(printf '%s' "$sha" | tr 'A-F' 'a-f')" ]; then step "Novalina ${version} is already installed in $target" else step "Downloading $file" download "$base/$file" "$tmp/novalina.AppImage" step "Verifying checksum" verify "$tmp/novalina.AppImage" "$sha" mkdir -p "$bin_dir" chmod 755 "$tmp/novalina.AppImage" # copy next to the target first, then rename: a running launcher keeps its old file cp "$tmp/novalina.AppImage" "$target.new" mv -f "$target.new" "$target" step "Installed the launcher to $target" fi # Icon from the download server, or from the same tag (main for the latest release) on GitHub; # optional, the entry works without. local icon_url if [ -n "$SITE_BASE" ]; then icon_url="$SITE_BASE/novalina.png" else local ref="main" [ -n "${PINNED:-}" ] && ref="v${version}" icon_url="https://raw.githubusercontent.com/${REPO}/${ref}/launcher/src-tauri/icons/128x128@2x.png" fi mkdir -p "$icon_dir" "$apps_dir" if download "$icon_url" "$tmp/icon.png" 2>/dev/null; then cp "$tmp/icon.png" "$icon_dir/novalina.png" else warn "could not download the icon, the app entry has none" fi cat >"$apps_dir/novalina.desktop" </dev/null 2>&1 && update-desktop-database "$apps_dir" >/dev/null 2>&1 || true command -v gtk-update-icon-cache >/dev/null 2>&1 && gtk-update-icon-cache -q -t "$data_home/icons/hicolor" >/dev/null 2>&1 || true step "Added Novalina to your app launcher" # AppImages need FUSE 2 to start. (Read the list first: grep -q in a pipe trips pipefail.) local libs="" if command -v ldconfig >/dev/null 2>&1; then libs=$(ldconfig -p 2>/dev/null) || libs="" case "$libs" in *libfuse.so.2*) ;; *) warn "libfuse2 seems to be missing. If Novalina does not start, install it (Debian/Ubuntu: libfuse2 or libfuse2t64, Fedora: fuse-libs, Arch: fuse2)" ;; esac fi say "" say "Done. Start Novalina from your app launcher or with: novalina" case ":${PATH}:" in *":$bin_dir:"*) ;; *) say "" say "Note: $bin_dir is not in your PATH. To start it by name, add this to your shell profile:" say " export PATH=\"\$HOME/.local/bin:\$PATH\"" ;; esac } # ---- macOS -------------------------------------------------------------------------------------- install_macos() { local manifest="$1" base="$2" version="$3" tmp="$4" local file sha file=$(manifest_get "$manifest" macos file) sha=$(manifest_get "$manifest" macos sha256) if [ -z "$file" ] || [ -z "$sha" ]; then say "" say "Release ${version} has no macOS build yet." say "See the installation guide: ${DOCS_URL}" exit 1 fi check_asset_name "$file" step "Downloading $file" download "$base/$file" "$tmp/novalina.dmg" step "Verifying checksum" verify "$tmp/novalina.dmg" "$sha" local dest="/Applications" if [ ! -w "$dest" ]; then dest="$HOME/Applications" mkdir -p "$dest" fi local mnt="$tmp/mnt" mkdir -p "$mnt" step "Mounting the disk image" hdiutil attach -nobrowse -readonly -noautoopen -mountpoint "$mnt" "$tmp/novalina.dmg" >/dev/null MOUNTED="$mnt" local app="" for candidate in "$mnt"/*.app; do [ -d "$candidate" ] || continue app="$candidate" break done [ -n "$app" ] || die "no .app found in $file" local name name=$(basename "$app") case "$name" in "" | */* | .*) die "unexpected app name in the disk image: '$name'" ;; esac local target="$dest/$name" step "Copying $name to $dest" if [ -d "$target" ]; then rm -rf "${target:?}" fi cp -R "$app" "$target" hdiutil detach -quiet "$mnt" || true MOUNTED="" # The app is not signed: drop the quarantine flag so Gatekeeper lets it start. xattr -dr com.apple.quarantine "$target" 2>/dev/null || true say "" say "Done. Novalina ${version} is installed in $target" say "Start it from Launchpad or Spotlight." } # ---- main --------------------------------------------------------------------------------------- main() { local version="" while [ $# -gt 0 ]; do case "$1" in --version) [ $# -ge 2 ] || die "--version needs a value, e.g. --version 1.2.3" version="$2" shift 2 ;; --version=*) version="${1#--version=}" shift ;; -h | --help) usage exit 0 ;; *) die "unknown option: $1 (see --help)" ;; esac done version="${version#v}" if [ -n "$version" ]; then printf '%s' "$version" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+([-+][0-9A-Za-z.-]+)?$' || die "not a version: '$version' (expected X.Y.Z)" fi command -v curl >/dev/null 2>&1 || die "curl is needed" # Download server: NOVALINA_BASE, else the address filled in by the server, else (the # placeholder of an unrendered copy) https://novalina.fun. NOVALINA_BASE=github means GitHub. local site="${NOVALINA_BASE:-$DEFAULT_BASE}" site="${site%/}" case "$site" in github) SITE_BASE="" ;; https://?*) SITE_BASE="$site" ;; *) [ -z "${NOVALINA_BASE:-}" ] || die "NOVALINA_BASE must be an https:// URL or github, got '$NOVALINA_BASE'" SITE_BASE="$FALLBACK_BASE" ;; esac local releases_page="https://github.com/${REPO}/releases" if [ -n "$SITE_BASE" ]; then DOCS_URL="$SITE_BASE/" SUPPORT_URL="$SITE_BASE/" releases_page="$SITE_BASE/" fi local os arch os=$(uname -s) arch=$(uname -m) case "$os" in Linux) case "$arch" in x86_64 | amd64) ;; *) unsupported "Linux on $arch" ;; esac ;; Darwin) command -v hdiutil >/dev/null 2>&1 || die "hdiutil not found" ;; MINGW* | MSYS* | CYGWIN*) say "" say "This is the installer for Linux and macOS." if [ -n "$SITE_BASE" ]; then say "On Windows, run this in PowerShell instead:" say " irm $SITE_BASE/install.ps1 | iex" else say "For Windows, see the installation guide: ${DOCS_URL}" fi exit 1 ;; *) unsupported "$os" ;; esac if [ "$(id -u)" = "0" ]; then warn "running as root installs Novalina for root only; run it as your normal user instead" fi local base if [ -n "$version" ]; then PINNED=1 if [ -n "$SITE_BASE" ]; then base="$SITE_BASE/releases/${version}" else base="https://github.com/${REPO}/releases/download/v${version}" fi else PINNED="" if [ -n "$SITE_BASE" ]; then base="$SITE_BASE/releases/latest" else base="https://github.com/${REPO}/releases/latest/download" fi fi local tmp tmp=$(mktemp -d "${TMPDIR:-/tmp}/novalina-install.XXXXXX") TMP_DIR="$tmp" MOUNTED="" trap cleanup EXIT step "Fetching the release manifest${version:+ for $version}" download "$base/manifest.json" "$tmp/manifest.json" 2>/dev/null || die "could not download manifest.json from $base ${version:+Is $version a released version? }See ${releases_page}" local release release=$(manifest_get "$tmp/manifest.json" "" version) [ -n "$release" ] || die "manifest.json has no version" if [ -n "$version" ] && [ "$release" != "$version" ]; then die "the manifest of v${version} says it is version ${release}, stopping" fi say "Novalina $release" case "$os" in Linux) install_linux "$tmp/manifest.json" "$base" "$release" "$tmp" ;; Darwin) install_macos "$tmp/manifest.json" "$base" "$release" "$tmp" ;; esac } cleanup() { if [ -n "${MOUNTED:-}" ]; then hdiutil detach -quiet "$MOUNTED" 2>/dev/null || true fi if [ -n "${TMP_DIR:-}" ] && [ -d "$TMP_DIR" ]; then case "$TMP_DIR" in */novalina-install.*) rm -rf "${TMP_DIR:?}" ;; esac fi } main "$@"