install.sh

2.2 KB · raw

1#!/bin/sh2set -e34# ANSI color codes — empty when stdout/stderr is not a terminal5if [ -t 2 ]; then6  BOLD='\033[1m'7  DIM='\033[2m'8  CYAN='\033[36m'9  GREEN='\033[32m'10  YELLOW='\033[33m'11  RESET='\033[0m'12else13  BOLD='' DIM='' CYAN='' GREEN='' YELLOW='' RESET=''14fi1516INSTALL_CMD="nix profile add 'https://kepr.uk/nina/archive/HEAD.tar.gz#nina'"1718banner() {19  printf >&2 '\n'20  printf >&2 "${CYAN}        _${RESET}\n"21  printf >&2 "${CYAN}  _ __ (_)_ __   __ _${RESET}\n"22  printf >&2 "${CYAN} | '_ \\| | '_ \\ / _\` |${RESET}\n"23  printf >&2 "${CYAN} | | | | | | | | (_| |${RESET}\n"24  printf >&2 "${CYAN} |_| |_|_|_| |_|\\__,_|${RESET}\n"25  printf >&2 '\n'26  printf >&2 "  ${BOLD}NixOS Intuitive Navigation Assistant${RESET}  ${DIM}·${RESET}  ${DIM}kepr.uk/nina${RESET}\n"27  printf >&2 '\n'28}2930main() {31  banner3233  printf >&2 "  nina is installed directly with nix:\n\n"34  printf >&2 "    ${YELLOW}%s${RESET}\n\n" "$INSTALL_CMD"3536  # Always prompt via /dev/tty so this works when piped through curl | sh.37  # /dev/tty's permission bits are readable even with no controlling38  # terminal attached (e.g. CI, provisioning, SSH without a pty) — only an39  # actual open reveals that, so probe it instead of using a plain -r test.40  if ! ( : </dev/tty ) 2>/dev/null; then41    printf >&2 "  No terminal to prompt on — run this yourself when ready:\n\n"42    printf >&2 "    ${YELLOW}%s${RESET}\n\n" "$INSTALL_CMD"43    exit 044  fi45  printf >&2 "  Run it now? [Y/n] "46  read -r answer </dev/tty47  case "${answer:-y}" in48    [nN]*)49      printf >&2 '\n  Copy the command above and run it whenever you are ready.\n\n'50      exit 051      ;;52  esac53  printf >&2 '\n'5455  nix profile add 'https://kepr.uk/nina/archive/HEAD.tar.gz#nina'5657  printf >&2 '\n'58  printf >&2 "  ${GREEN}${BOLD}✓ Thank you for installing nina!${RESET}\n"59  printf >&2 '\n'60  printf >&2 "  ${BOLD}Getting started${RESET}\n\n"61  printf >&2 "    ${CYAN}nina help${RESET}       — explore what nina can do\n"62  printf >&2 "    ${CYAN}nina goodbye${RESET}    — remove nina cleanly if it's not a good fit\n"63  printf >&2 '\n'64  printf >&2 "  ${BOLD}Issues & feedback${RESET}\n\n"65  printf >&2 "    ${DIM}https://${RESET}kepr.uk/nina   ${DIM}— no account required${RESET}\n"66  printf >&2 '\n'67}6869main