#!/usr/bin/env bash set -Eeuo pipefail usage() { cat <<'EOF' Quicksh arch 0.1.0 — Arch Linux developer essentials Usage: bash arch.sh [--help|-h|--version|--packages|--install] Default: report OS, kernel, architecture, pacman, and basic developer tools. --packages List the recommended packages without making changes. --install Preview pacman -S --needed, then require a terminal and typed yes. Packages: base-devel git bash curl ca-certificates Only genuine Arch Linux (ID=arch) is supported, not derivatives. Installation may install dependencies and update requested packages. pacman shows its transaction and asks for confirmation too. No database refresh, full upgrade, package removal, or unattended confirmation is performed here. EOF } install_packages() { local -a packages=(base-devel git bash curl ca-certificates) local -a elevate=() if (( EUID != 0 )); then if ! command -v sudo >/dev/null 2>&1; then printf 'quicksh arch: sudo is required for --install as a non-root user.\n' >&2 return 1 fi elevate=(sudo --) fi printf '\nProposed command:\n ' printf '%s ' "${elevate[@]}" pacman -S --needed "${packages[@]}" printf '\nThis installs essentials and dependencies, and may update requested packages.\n' printf 'Package databases are NOT refreshed; no full system upgrade is run.\n' printf 'On a stale system, cancel and review a full pacman -Syu separately first.\n' printf 'Do not work around stale databases by running pacman -Sy alone.\n' if [[ ! -t 0 || ! -t 1 ]]; then printf 'quicksh arch: --install requires interactive stdin and stdout; no changes made.\n' >&2 return 1 fi local answer printf 'Proceed to the pacman transaction? Type yes to continue: ' if ! IFS= read -r answer; then printf '\nquicksh arch: confirmation could not be read; no changes made.\n' >&2 return 1 fi if [[ "$answer" != yes ]]; then printf 'Cancelled; no changes made.\n' return 0 fi if ! "${elevate[@]}" pacman -S --needed "${packages[@]}"; then printf 'quicksh arch: pacman failed or was cancelled. Review its output; no automatic retry.\n' >&2 return 1 fi printf 'Package command completed.\n' } main() { if (( $# > 1 )); then printf 'quicksh arch: expected at most one option. Use --help.\n' >&2 return 2 fi case "${1:-}" in --help|-h) usage; return ;; --version) printf 'Quicksh arch 0.1.0\n'; return ;; ''|--packages|--install) ;; *) printf 'quicksh arch: unsupported option: %s. Use --help.\n' "$1" >&2; return 2 ;; esac local ID=unknown PRETTY_NAME='Unknown system' if [[ ! -r /etc/os-release ]]; then printf 'quicksh arch: cannot identify the OS; expected /etc/os-release.\n' >&2 return 1 fi # shellcheck disable=SC1091 if ! . /etc/os-release; then printf 'quicksh arch: could not read OS identification.\n' >&2 return 1 fi if [[ "$ID" != arch ]]; then printf 'quicksh arch: unsupported OS: %s. Requires ID=arch; no changes made.\n' "$ID" >&2 return 1 fi printf 'Quicksh arch 0.1.0\nOS: %s\n' "$PRETTY_NAME" if [[ "${1:-}" == --packages ]]; then printf 'Recommended: base-devel git bash curl ca-certificates\n' printf 'Compiler/build tools, Git, Bash, HTTPS downloads, and trusted CA certificates.\n' printf 'Review --install to opt in; listing packages makes no changes.\n' return 0 fi if ! command -v pacman >/dev/null 2>&1; then printf 'quicksh arch: pacman is not available in PATH.\n' >&2 return 1 fi if [[ "${1:-}" == --install ]]; then install_packages return fi local system tool if ! system=$(uname -srmo); then printf 'quicksh arch: could not read kernel and architecture information.\n' >&2 return 1 fi printf 'System: %s\n\nTool availability:\n' "$system" for tool in pacman git bash curl make cc; do if command -v "$tool" >/dev/null 2>&1; then printf ' [ok] %s\n' "$tool" else printf ' [missing] %s\n' "$tool" fi done printf '\nUse --packages for recommendations or --install for an interactive opt-in.\n' } main "$@"