From 74c67f47c24c2aba8773ecc99272fd0f502e8df2 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Tue, 13 Oct 2026 04:07:42 +0000 Subject: feat: add a standalone compiler and manual installer Support custom prefixes and DESTDIR staging, validate inputs and artifacts, and install the executable and manual with explicit permissions. Co-Authored-By: Claude Fable 5.1 --- install.sh | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100755 install.sh diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..eded452 --- /dev/null +++ b/install.sh @@ -0,0 +1,66 @@ +#!/bin/sh +set -eu + +usage() { + cat <<'EOF' +Usage: install.sh [--prefix DIR] [--source-dir DIR] + +Install cpsc and its man page to DIR/bin and DIR/share/man/man1. +The default prefix is /usr/local. The source directory defaults to the +directory containing this script and must contain cpsc and doc/cpsc.1. +Use --source-dir build when running this script from the source checkout. +DESTDIR may be set to stage an installation without changing the prefix. +EOF +} + +die() { + printf 'install.sh: %s\n' "$*" >&2 + exit 1 +} + +prefix=/usr/local +source_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) +while [ "$#" -gt 0 ]; do + case "$1" in + --prefix|--source-dir) + [ "$#" -ge 2 ] || die "$1 requires a directory" + [ -n "$2" ] || die "$1 requires a nonempty directory" + case "$2" in --*) die "$1 requires a directory, got $2" ;; esac + case "$1" in + --prefix) prefix=$2 ;; + --source-dir) source_dir=$2 ;; + esac + shift 2 + ;; + -h|--help) usage; exit 0 ;; + *) die "unknown argument: $1 (see --help)" ;; + esac +done + +case "$prefix" in /*) ;; *) die "--prefix must be an absolute path" ;; esac +destdir=${DESTDIR:-} +case "$destdir" in ''|/*) ;; *) die "DESTDIR must be an absolute path" ;; esac +source_dir=$(CDPATH= cd -- "$source_dir" && pwd) || die "cannot open source directory: $source_dir" +[ -f "$source_dir/cpsc" ] && [ -r "$source_dir/cpsc" ] && [ -x "$source_dir/cpsc" ] \ + || die "missing readable executable: $source_dir/cpsc; build cpsc first" +[ -f "$source_dir/doc/cpsc.1" ] && [ -r "$source_dir/doc/cpsc.1" ] \ + || die "missing readable manual: $source_dir/doc/cpsc.1; run make doc first" +command -v install >/dev/null 2>&1 || die "required command not found: install" + +bin_dir=$destdir${prefix%/}/bin +man_dir=$destdir${prefix%/}/share/man/man1 +install -d "$bin_dir" "$man_dir" \ + || die "cannot create installation directories; check permissions or choose a writable --prefix" +install -m 755 "$source_dir/cpsc" "$bin_dir/cpsc" \ + || die "cannot install cpsc to $bin_dir; check permissions" +install -m 644 "$source_dir/doc/cpsc.1" "$man_dir/cpsc.1" \ + || die "cannot install the manual to $man_dir; check permissions" + +printf 'Installed %s\nInstalled %s\n' "$bin_dir/cpsc" "$man_dir/cpsc.1" +if [ -z "$destdir" ]; then + case ":${PATH:-}:" in + *":${prefix%/}/bin:"*) ;; + *) printf 'Add %s/bin to PATH to run cpsc by name.\n' "${prefix%/}" ;; + esac + printf 'Read the manual with: man cpsc\n' +fi -- cgit v1.3.1-4-g156e