#!/bin/sh
# Murmur installer — adds the murmurlinux APT repo and installs Murmur.
#
# Recommended invocation (review the script before running):
#
#     wget -O install.sh https://murmurlinux.com/install.sh
#     sudo sh install.sh
#
# The script assumes it runs as root (via sudo). It does NOT call sudo
# internally — keeps it portable across systems where sudo isn't installed
# (minimal containers, recovery shells) and avoids surprising re-prompts.

set -eu

if [ "$(id -u)" -ne 0 ]; then
    echo "error: this installer must run as root." >&2
    echo "  re-run with: sudo sh $0" >&2
    exit 1
fi

if ! command -v apt-get >/dev/null 2>&1; then
    echo "error: this installer requires apt-get (Debian / Ubuntu)." >&2
    echo "  for other distributions see https://murmurlinux.com/download" >&2
    exit 1
fi

echo "==> installing prerequisites (wget, gpg, apt-transport-https)..."
apt-get update -qq
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
    wget gpg apt-transport-https ca-certificates >/dev/null

echo "==> adding murmurlinux signing key..."
install -m 0755 -d /etc/apt/keyrings
wget -qO /etc/apt/keyrings/murmur.asc https://murmurlinux.github.io/apt/gpg.key
chmod 0644 /etc/apt/keyrings/murmur.asc

echo "==> adding murmurlinux apt repository..."
cat >/etc/apt/sources.list.d/murmur.list <<EOF
deb [signed-by=/etc/apt/keyrings/murmur.asc] https://murmurlinux.github.io/apt/ stable main
EOF

echo "==> installing murmur..."
apt-get update -qq
DEBIAN_FRONTEND=noninteractive apt-get install -y murmur

echo
echo "Murmur installed. Launch it from your application menu, or run: murmur"
