#!/usr/bin/env bash# Project Euler Solver — one-line installer## curl -fsSL https://raw.githubusercontent.com/vikasmunshi/euler/master/install.sh | bash# curl -fsSL https://raw.githubusercontent.com/vikasmunshi/euler/master/install.sh | bash -s -- --dir ~/projects/euler## Options:# --dir <path> Clone destination (default: ~/euler)# --help Show this message## Author: Vikas Munshi <vikas.munshi@gmail.com># Licensed under the MIT License.set-euopipefailREPO_URL="https://github.com/vikasmunshi/euler.git"INSTALL_DIR="${HOME}/euler"while[[$#-gt0]];docase"$1"in--dir)[[-n"${2-}"]]||{echo"error: --dir requires a value">&2;exit1;}INSTALL_DIR="$2";shift2;;--dir=*)INSTALL_DIR="${1#*=}";shift;;-h|--help)echo"Usage: curl -fsSL .../install.sh | bash -s -- [--dir <path>]"exit0;;*)echo"Unknown option: $1">&2;exit1;;esacdoneif[[$EUID-eq0]];thenecho"error: do not run as root — sudo will be used when needed">&2exit1fi# Platform guard — the build installs Python 3.14 from the deadsnakes PPA and# the Makefile runs `python3.14 -m venv`. That toolchain is only validated on# Ubuntu 24.04+; on Ubuntu 22.04 (and older) `make install-all` fails deep in# apt, so bail out early here with a clear message instead.MIN_UBUNTU_MAJOR=24if[["$(uname-s)"!="Linux"]];thenecho"error: this installer supports Ubuntu Linux only (found $(uname-s)).">&2exit1fiif!command-vapt-get&>/dev/null;thenecho"error: 'apt-get' not found — this installer requires Ubuntu/Debian.">&2exit1fiif[[-r/etc/os-release]];then# shellcheck disable=SC1091./etc/os-releasecase"${ID:-}"inubuntu)ubuntu_major="${VERSION_ID%%.*}"if[[-z"$ubuntu_major"||!"$ubuntu_major"=~^[0-9]+$]];thenecho"warning: could not parse Ubuntu version '${VERSION_ID:-?}'; continuing.">&2elif((ubuntu_major<MIN_UBUNTU_MAJOR));thenecho"error: Ubuntu ${VERSION_ID:-?} is not supported.">&2echo" This project needs Python 3.14 and is tested on Ubuntu ${MIN_UBUNTU_MAJOR}.04+.">&2echo" Please upgrade to Ubuntu ${MIN_UBUNTU_MAJOR}.04 or newer.">&2exit1fi;;*)echo"warning: '${PRETTY_NAME:-${ID:-unknown}}' is untested.">&2echo" This installer is validated on Ubuntu ${MIN_UBUNTU_MAJOR}.04+ and may fail elsewhere.">&2;;esacelseecho"warning: /etc/os-release not found; skipping OS version check.">&2fi# Ensure git is available (needed to clone the repository below)if!command-vgit&>/dev/null;thensudoaptinstall-ygitfi# Ensure make is available (pulls in build-essential on Debian/Ubuntu)if!command-vmake&>/dev/null;thensudoaptinstall-ybuild-essentialfi# Clone or updateINSTALL_DIR="${INSTALL_DIR%/}"if[[-d"${INSTALL_DIR}/.git"]];thenecho"Repository already exists at ${INSTALL_DIR} — pulling latest."git-C"$INSTALL_DIR"pull--ff-onlyelsegitclone"$REPO_URL""$INSTALL_DIR"ficd"$INSTALL_DIR"makeinstall-allecho""echo"Installation complete. To get started:"echo" cd ${INSTALL_DIR}"echo" source .venv/bin/activate"echo" solver # interactive terminal shell"echo" solver-host # the same, plus the web host's commands (for the operator)"