|
| 1 | +#!/usr/bin/env bash |
| 2 | +# scripts/setup.sh - install minimal developer prerequisites (non-destructive) |
| 3 | +set -euo pipefail |
| 4 | + |
| 5 | +usage(){ |
| 6 | + cat <<EOF |
| 7 | +Usage: $(basename "$0") [--dry-run] |
| 8 | +
|
| 9 | +Installs or suggests installation steps for common developer dependencies used by the |
| 10 | +Veraison documentation (docker, docker-compose, protoc, shellcheck). |
| 11 | +This script is conservative: it prints commands and prompts before making changes. |
| 12 | +EOF |
| 13 | +} |
| 14 | + |
| 15 | +DRY_RUN=0 |
| 16 | +while [[ ${#} -gt 0 ]]; do |
| 17 | + case "$1" in |
| 18 | + --dry-run) DRY_RUN=1; shift;; |
| 19 | + -h|--help) usage; exit 0;; |
| 20 | + *) echo "Unknown arg: $1"; usage; exit 2;; |
| 21 | + esac |
| 22 | +done |
| 23 | + |
| 24 | +echo "Checking common tools..." |
| 25 | +need_install=() |
| 26 | +check(){ |
| 27 | + if ! command -v "$1" >/dev/null 2>&1; then |
| 28 | + need_install+=("$1") |
| 29 | + echo " - $1: MISSING" |
| 30 | + else |
| 31 | + echo " - $1: found ($(command -v "$1"))" |
| 32 | + fi |
| 33 | +} |
| 34 | + |
| 35 | +check docker |
| 36 | +check docker-compose || check docker-compose |
| 37 | +check protoc |
| 38 | +check shellcheck |
| 39 | + |
| 40 | +if [[ ${#need_install[@]} -eq 0 ]]; then |
| 41 | + echo "All common tools detected." |
| 42 | + exit 0 |
| 43 | +fi |
| 44 | + |
| 45 | +echo "\nTools suggested for install: ${need_install[*]}" |
| 46 | +if [[ $DRY_RUN -eq 1 ]]; then |
| 47 | + echo "Dry run: not installing anything." |
| 48 | + exit 0 |
| 49 | +fi |
| 50 | + |
| 51 | +read -r -p "Proceed with printed install suggestions? [y/N] " ans |
| 52 | +case "$ans" in |
| 53 | + [Yy]*) ;; |
| 54 | + *) echo "Aborting per user request."; exit 0;; |
| 55 | +esac |
| 56 | + |
| 57 | +for t in "${need_install[@]}"; do |
| 58 | + echo "\nSuggested install for: $t" |
| 59 | + case "$t" in |
| 60 | + docker) |
| 61 | + cat <<'CMD' |
| 62 | +On Debian/Ubuntu: |
| 63 | + sudo apt-get update && sudo apt-get install -y ca-certificates curl gnupg lsb-release |
| 64 | + curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg |
| 65 | + echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null |
| 66 | + sudo apt-get update && sudo apt-get install -y docker-ce docker-ce-cli containerd.io |
| 67 | +CMD |
| 68 | + ;; |
| 69 | + docker-compose) |
| 70 | + cat <<'CMD' |
| 71 | +Install via pip (if using compose v1) or use Docker's compose plugin: |
| 72 | + python3 -m pip install --user docker-compose |
| 73 | +Or on modern systems: |
| 74 | + sudo apt-get install -y docker-compose-plugin |
| 75 | +CMD |
| 76 | + ;; |
| 77 | + protoc) |
| 78 | + echo "Visit https://github.com/protocolbuffers/protobuf/releases and download a release for your OS. On debian/ubuntu: sudo apt-get install -y protobuf-compiler" |
| 79 | + ;; |
| 80 | + shellcheck) |
| 81 | + echo "On Debian/Ubuntu: sudo apt-get install -y shellcheck" |
| 82 | + ;; |
| 83 | + *) |
| 84 | + echo "No automated instruction for $t; please install it using your platform package manager." |
| 85 | + ;; |
| 86 | + esac |
| 87 | +done |
| 88 | + |
| 89 | +echo "\nSetup script finished. Re-run 'scripts/validate-setup.sh' to verify the environment." |
0 commit comments