#!/bin/sh # Installs MiniCRM from mayorana.ch. # # curl -fsSL https://mayorana.ch/install/minicrm.sh | sh # # macOS: copies MiniCRM into /Applications (or ~/Applications). # Linux: extracts it to ~/minicrm-linux-x86_64 and links ~/.local/bin/minicrm. # Source: https://github.com/bennekrouf/minicrm # Licence: PolyForm Noncommercial 1.0.0; commercial use needs a plan, # see https://mayorana.ch/pricing set -eu APP='MiniCRM' ID='minicrm' MAC_URL='https://mayorana.ch/downloads/minicrm/latest/minicrm-macos.dmg' MAC_ARM_ONLY=0 LINUX_URL='https://mayorana.ch/downloads/minicrm/latest/minicrm-linux-x86_64.tar.gz' UA="mayorana-install/1 ($ID)" QUERY='utm_source=install-script&utm_medium=cli' say() { printf '%s\n' "$*"; } fail() { printf 'error: %s\n' "$*" >&2; exit 1; } fetch() { curl -fL --progress-bar -A "$UA" -o "$2" "$1?$QUERY"; } cleanup() { if [ -d "$tmp/mnt" ]; then hdiutil detach -quiet "$tmp/mnt" 2>/dev/null || true; fi rm -rf "$tmp" } install_mac() { [ -n "$MAC_URL" ] || fail "$APP has no macOS build." if [ "$MAC_ARM_ONLY" = 1 ] && [ "$(uname -m)" != arm64 ]; then fail "$APP's macOS build is for Apple Silicon; this Mac is $(uname -m)." fi say "Downloading $APP for macOS..." fetch "$MAC_URL" "$tmp/$ID.dmg" mkdir "$tmp/mnt" hdiutil attach -nobrowse -readonly -quiet -mountpoint "$tmp/mnt" "$tmp/$ID.dmg" app=$(find "$tmp/mnt" -maxdepth 1 -name '*.app' | head -n 1) [ -n "$app" ] || fail "no application found in the disk image." dest=/Applications if [ ! -w "$dest" ]; then dest="$HOME/Applications" mkdir -p "$dest" fi name=$(basename "$app") rm -rf "${dest:?}/$name" ditto "$app" "$dest/$name" say "Installed $name in $dest." } install_linux() { [ -n "$LINUX_URL" ] || fail "$APP has no Linux build." [ "$(uname -m)" = x86_64 ] || fail "$APP's Linux build is for x86_64; this machine is $(uname -m)." case "$LINUX_URL" in *.deb) command -v apt-get >/dev/null 2>&1 || fail "$APP's Linux build is a .deb package, for Debian and Ubuntu." say "Downloading $APP for Linux..." fetch "$LINUX_URL" "$tmp/$ID.deb" say "Installing the package with apt (sudo will ask for your password)..." sudo apt-get install -y "$tmp/$ID.deb" say "Installed $APP. Start it from your applications menu, or run: $ID" ;; *) say "Downloading $APP for Linux..." fetch "$LINUX_URL" "$tmp/$ID.tar.gz" dir="$HOME/$ID-linux-x86_64" rm -rf "$dir" tar -xzf "$tmp/$ID.tar.gz" -C "$HOME" [ -x "$dir/$ID" ] || fail "the archive did not contain $ID-linux-x86_64/$ID." mkdir -p "$HOME/.local/bin" ln -sf "$dir/$ID" "$HOME/.local/bin/$ID" say "Installed $APP in $dir and linked ~/.local/bin/$ID." case ":$PATH:" in *":$HOME/.local/bin:"*) ;; *) say "Add ~/.local/bin to your PATH to run it as: $ID" ;; esac if [ -x "$dir/setup-linux.sh" ]; then say "" say "One-time setup (runtime libraries and a menu entry; needs sudo):" say " sudo $dir/setup-linux.sh" fi ;; esac } # Everything runs from here, so a download cut off half way runs nothing. main() { command -v curl >/dev/null 2>&1 || fail "curl is required." tmp=$(mktemp -d) trap cleanup EXIT case "$(uname -s)" in Darwin) install_mac ;; Linux) install_linux ;; *) fail "this script is for macOS and Linux. On Windows, run in PowerShell: irm https://mayorana.ch/install/minicrm.ps1 | iex" ;; esac } main