#!/usr/bin/env bash # ============================================================================ # fin-terminal installer # Installs the FIN financier's terminal into your home directory: # ~/.fin/ (engine, config, cache, journal) # ~/bin/mkt (realtime TUI dashboard, when compatible) # ~/.bashrc (one hook that sources ~/.fin/fin.sh) # # Idempotent: safe to run again, never overwrites your worth.tsv / finrc. # Usage: ./install.sh (or) bash install.sh # ============================================================================ set -u FIN_HOME="${FIN_HOME:-$HOME/.fin}" SRC_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" WARN=0 cecho() { printf '\033[%sm%s\033[0m\n' "$@"; } info() { cecho "36" "[fin] $*"; } good() { cecho "32" "[fin] ✓ $*"; } warn() { cecho "33" "[fin] ! $*"; } fail() { cecho "31" "[fin] ✗ $*"; } echo "" info "FIN · financier's terminal installer" info "install target: $FIN_HOME" # --- 1. core files ---------------------------------------------------------- mkdir -p "$FIN_HOME/cache" "$FIN_HOME/journal" "$HOME/bin" cp -f "$SRC_DIR/fin.sh" "$FIN_HOME/fin.sh" cp -f "$SRC_DIR/completions.bash" "$FIN_HOME/completions.bash" good "engine installed → $FIN_HOME/fin.sh" if [ ! -f "$FIN_HOME/finrc" ]; then cp -f "$SRC_DIR/finrc" "$FIN_HOME/finrc" good "config created → $FIN_HOME/finrc (edit it to your taste)" else warn "finrc already exists — leaving it untouched ($FIN_HOME/finrc)" fi if [ ! -f "$FIN_HOME/worth.tsv" ]; then cp -f "$SRC_DIR/worth.tsv" "$FIN_HOME/worth.tsv" good "sample net-worth ledger created → $FIN_HOME/worth.tsv" else warn "worth.tsv already exists — leaving it untouched" fi # --- 2. TUI binary (mkt) ---------------------------------------------------- case "$(uname -s)-$(uname -m)" in Linux-x86_64|Linux-amd64) cp -f "$SRC_DIR/bin/mkt" "$HOME/bin/mkt" chmod +x "$HOME/bin/mkt" good "TUI dashboard installed → $HOME/bin/mkt" ;; *) WARN=$((WARN+1)) warn "prebuilt 'mkt' TUI not available for $(uname -s)-$(uname -m);" warn " 'markets / tape / q / ma' still work without it (mkt/dash/ticker will not)" ;; esac # --- 3. ~/.bashrc hook ------------------------------------------------------ RC="$HOME/.bashrc" if [ -f "$RC" ] && grep -q 'FINANCIER TERMINAL (fin)' "$RC" 2>/dev/null; then good "~/.bashrc already wired — nothing to do" else if [ -f "$RC" ] && [ -s "$RC" ] && [ "$(tail -c1 "$RC" | wc -l)" -eq 0 ]; then printf '\n' >> "$RC" fi cat >> "$RC" </dev/null 2>&1; then info "dependency ok: $tool" else WARN=$((WARN+1)) warn "missing dependency: $tool (Debian/Ubuntu: sudo apt install $tool)" fi done # --- 5. done ----------------------------------------------------------------- echo "" good "FIN installed. Start it now:" echo "" printf ' \033[1msource ~/.bashrc\033[0m\n' echo "" printf ' \033[1mfin help\033[0m the crash-course\n' printf ' \033[1mma\033[0m / \033[1mmorocco\033[0m the Casablanca board (MASI, dirham, movers)\n' printf ' \033[1mmarkets\033[0m indices · crypto · fx snapshot\n' echo "" exit 0