#!/usr/bin/env bash set -Eeuo pipefail usage() { cat <<'EOF' Quicksh ubuntu 0.1.0 — Ubuntu developer essentials Usage: bash ubuntu.sh [--help|-h|--version|--packages|--install] Default: report OS, kernel, architecture, apt, and basic developer tools. --packages List the recommended packages without making changes. --install Preview apt-get update and install, then require a terminal and yes. Packages: build-essential git bash curl ca-certificates Only genuine Ubuntu (ID=ubuntu) is supported, not derivatives. Installation refreshes package indexes and installs essentials/dependencies; requested packages may be updated. apt-get also confirms its transaction. No -y, automatic full upgrade, or automatic package removal is used. EOF } install_packages() { local -a packages=(build-essential git bash curl ca-certificates) local -a elevate=() if (( EUID != 0 )); then if ! command -v sudo >/dev/null 2>&1; then printf 'quicksh ubuntu: sudo is required for --install as a non-root user.\n' >&2 return 1 fi elevate=(sudo --) fi printf '\nProposed commands:\n ' printf '%s ' "${elevate[@]}" apt-get update printf '\n ' printf '%s ' "${elevate[@]}" apt-get install "${packages[@]}" printf '\nThis refreshes package indexes, then installs essentials and dependencies.\n' printf 'Requested packages may be updated; there is no full system upgrade.\n' if [[ ! -t 0 || ! -t 1 ]]; then printf 'quicksh ubuntu: --install requires interactive stdin and stdout; no changes made.\n' >&2 return 1 fi local answer printf 'Proceed to the apt-get commands? Type yes to continue: ' if ! IFS= read -r answer; then printf '\nquicksh ubuntu: 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[@]}" apt-get update; then printf 'quicksh ubuntu: package index update failed; installation was not attempted.\n' >&2 return 1 fi if ! "${elevate[@]}" apt-get install "${packages[@]}"; then printf 'quicksh ubuntu: installation failed or was cancelled. Indexes may already be updated.\n' >&2 return 1 fi printf 'Package commands completed.\n' } main() { if (( $# > 1 )); then printf 'quicksh ubuntu: expected at most one option. Use --help.\n' >&2 return 2 fi case "${1:-}" in --help|-h) usage; return ;; --version) printf 'Quicksh ubuntu 0.1.0\n'; return ;; ''|--packages|--install) ;; *) printf 'quicksh ubuntu: 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 ubuntu: cannot identify the OS; expected /etc/os-release.\n' >&2 return 1 fi # shellcheck disable=SC1091 if ! . /etc/os-release; then printf 'quicksh ubuntu: could not read OS identification.\n' >&2 return 1 fi if [[ "$ID" != ubuntu ]]; then printf 'quicksh ubuntu: unsupported OS: %s. Requires ID=ubuntu; no changes made.\n' "$ID" >&2 return 1 fi printf 'Quicksh ubuntu 0.1.0\nOS: %s\n' "$PRETTY_NAME" if [[ "${1:-}" == --packages ]]; then printf 'Recommended: build-essential 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 apt >/dev/null 2>&1 || ! command -v apt-get >/dev/null 2>&1; then printf 'quicksh ubuntu: apt and apt-get must be 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 ubuntu: could not read kernel and architecture information.\n' >&2 return 1 fi printf 'System: %s\n\nTool availability:\n' "$system" for tool in apt apt-get 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 "$@"