#!/bin/sh # mdma installer — https://mdma.run # Usage: curl -fsSL https://mdma.run | bash # curl -fsSL https://mdma.run | MDMA_AUTO=1 bash set -e # ── Config ───────────────────────────────────────────────────────── MDMA_HOME="${MDMA_HOME:-$HOME/.mdma}" MDMA_REPO="${MDMA_REPO:-https://git42.mdma.sh/mdma/mdma.sh.git}" MDMA_PKG="${MDMA_PKG:-https://pkg42.dev/s3/mdma}" MDMA_AUTO="${MDMA_AUTO:-0}" # ── Helpers ──────────────────────────────────────────────────────── info() { printf ' \033[1;34m→\033[0m %s\n' "$*"; } ok() { printf ' \033[1;32m✓\033[0m %s\n' "$*"; } warn() { printf ' \033[1;33m!\033[0m %s\n' "$*" >&2; } die() { printf ' \033[1;31m✗\033[0m %s\n' "$*" >&2; exit 1; } need() { command -v "$1" >/dev/null 2>&1 || die "Required command not found: $1" } confirm() { if [ "$MDMA_AUTO" = "1" ]; then return 0 fi printf ' \033[1;33m?\033[0m %s [Y/n] ' "$1" read -r answer /dev/null || warn "Git pull failed, continuing with existing" else if [ -d "$MDMA_HOME" ]; then warn "$MDMA_HOME exists but is not a git repo" if ! confirm "Remove and re-clone?"; then die "Aborted" fi rm -rf "$MDMA_HOME" fi info "Cloning mdma..." git clone --quiet "$MDMA_REPO" "$MDMA_HOME" || die "Failed to clone repository" fi ok "Repository ready" # ── 2. Download trusted binaries (m + mdma-crypto) ─────────────── info "Downloading binaries for $PLATFORM..." BIN_DIR="$MDMA_HOME/bin" LIBEXEC_DIR="$MDMA_HOME/libexec" mkdir -p "$BIN_DIR" "$LIBEXEC_DIR" for binary in m mdma-crypto; do url="$MDMA_PKG/latest/${PLATFORM}/${binary}" dest="$BIN_DIR/$binary" if [ "$binary" = "mdma-crypto" ]; then dest="$LIBEXEC_DIR/$binary" fi if ! curl -fsSL "$url" -o "$dest" 2>/dev/null; then die "Failed to download $binary from $url" fi chmod +x "$dest" done # macOS: ad-hoc codesign to prevent Gatekeeper SIGKILL if [ "$OS" = "darwin" ]; then codesign --sign - --force "$BIN_DIR/m" 2>/dev/null || true codesign --sign - --force "$LIBEXEC_DIR/mdma-crypto" 2>/dev/null || true fi ok "Binaries installed" # ── 3. Create symlinks ────────────────────────────────────────── # Comma alias: , → m ln -sf m "$BIN_DIR/," 2>/dev/null || true # ── 4. Shell integration ───────────────────────────────────────── SHELL_NAME="$(basename "${SHELL:-/bin/sh}")" INIT_MARKER="# mdma init" case "$SHELL_NAME" in zsh) RC_FILE="$HOME/.zshrc" INIT_LINE="eval \"\$($MDMA_HOME/bin/m env zsh)\"" ;; bash) RC_FILE="$HOME/.bashrc" INIT_LINE="eval \"\$($MDMA_HOME/bin/m env bash)\"" ;; fish) RC_FILE="${XDG_CONFIG_HOME:-$HOME/.config}/fish/config.fish" INIT_LINE="$MDMA_HOME/bin/m env fish | source" ;; *) RC_FILE="" warn "Unknown shell: $SHELL_NAME — add shell init manually" ;; esac if [ -n "$RC_FILE" ]; then if [ -f "$RC_FILE" ] && grep -qF "$INIT_MARKER" "$RC_FILE" 2>/dev/null; then ok "Shell init already in $RC_FILE" elif confirm "Add mdma to $RC_FILE?"; then mkdir -p "$(dirname "$RC_FILE")" printf '\n%s\n%s\n' "$INIT_MARKER" "$INIT_LINE" >> "$RC_FILE" ok "Added to $RC_FILE" else info "Skipped. Add manually:" info " $INIT_LINE" fi fi # ── 5. Bootstrap ───────────────────────────────────────────────── info "Running bootstrap..." "$BIN_DIR/m" init 2>/dev/null || true # ── Done ───────────────────────────────────────────────────────── printf '\n \033[1;32mmdma installed!\033[0m\n\n' info "Open a new shell, or run:" info " source $RC_FILE" printf '\n' } main "$@"