#!/bin/sh # # CodeIT repository setup. https://repo.codeit.guru/setup # # curl -fsSL https://repo.codeit.guru/setup | sudo sh # curl -fsSL https://repo.codeit.guru/setup | sudo sh -s -- --print # # Detects the distribution, downloads the matching codeit-repo-release package # and installs it. Nothing else: the package is what configures the repository # and installs the signing keys, so the repository layout and the keys can be # changed later by shipping a new package rather than by asking every user to # edit a file they pasted from a web page years ago. set -eu PREFIX=https://repo.codeit.guru PRINT_ONLY=0 # Overridable so the detection can be tested against a captured os-release # from every distribution we care about, and so this can be pointed at a # mounted root when working out why a container detected wrongly. : "${OS_RELEASE:=/etc/os-release}" for arg in "$@"; do case "$arg" in --print|--dry-run) PRINT_ONLY=1 ;; -h|--help) sed -n '2,12p' "$0" | sed 's/^# \{0,1\}//' exit 0 ;; *) echo "unknown option: $arg" >&2 echo "usage: setup [--print]" >&2 exit 2 ;; esac done die() { echo "codeit-setup: $*" >&2 ; exit 1 ; } # --- download -------------------------------------------------------------- # curl on most, wget on minimal Debian images. Both are told to fail loudly on # a 404 rather than saving the error page as if it were a package. fetch() { url="$1" ; dest="$2" if command -v curl > /dev/null 2>&1; then curl -fsSL --proto '=https' --tlsv1.2 -o "$dest" "$url" elif command -v wget > /dev/null 2>&1; then wget -q -O "$dest" "$url" else die "neither curl nor wget is installed" fi } # --- which distribution ---------------------------------------------------- FAMILY= TARGET= # `rpm -E %{rhel}` first, and not $releasever. # # dnf's $releasever is whatever the release package sets, and it is not the # major version everywhere: RHEL 7 reports "7Server", RHEL 8/9 report "8.10" / # "9.4", CentOS Stream reports "9-stream", and Amazon Linux reports "2". Every # one of those produces a 404 against a tree laid out by major version. # %{rhel} is the EL generation and is what Alma, Rocky, Oracle, CentOS Stream # and RHEL all agree on. if command -v rpm > /dev/null 2>&1; then rhel=$(rpm -E '%{rhel}' 2>/dev/null || echo '') case "$rhel" in [0-9]|[0-9][0-9]) FAMILY=el ; TARGET="$rhel" ;; esac fi if [ -z "$FAMILY" ] && [ -r "$OS_RELEASE" ]; then # shellcheck disable=SC1091 . "$OS_RELEASE" case "${ID:-}${ID_LIKE:+ $ID_LIKE}" in *debian*|*ubuntu*) FAMILY=deb # UBUNTU_CODENAME first: derivatives (Mint, Pop!_OS, Zorin) put # their own name in VERSION_CODENAME and the Ubuntu one here. TARGET="${UBUNTU_CODENAME:-${VERSION_CODENAME:-}}" ;; *rhel*|*fedora*|*centos*) # rpm was missing or %{rhel} was undefined; fall back to the # major part of VERSION_ID, which handles "9.4" and "7". FAMILY=el TARGET="${VERSION_ID%%.*}" ;; esac fi [ -n "$FAMILY" ] || die "could not identify this distribution. Please follow the manual instructions at https://codeit.guru/" [ -n "$TARGET" ] || die "could not identify this release. Please follow the manual instructions at https://codeit.guru/" # --- what we are going to do ----------------------------------------------- if [ "$FAMILY" = el ]; then PKG="codeit-repo-release.el$TARGET.rpm" if command -v dnf > /dev/null 2>&1; then INSTALL="dnf install -y" else INSTALL="yum install -y" fi else PKG="codeit-repo-release.$TARGET.deb" INSTALL="dpkg -i" fi URL="$PREFIX/$PKG" echo "Detected: $FAMILY / $TARGET" echo "Package: $URL" if [ "$PRINT_ONLY" = 1 ]; then echo echo "Would run:" if [ "$FAMILY" = el ]; then echo " $INSTALL $URL" else echo " curl -fsSLO $URL" echo " $INSTALL $PKG && apt-get update" fi exit 0 fi [ "$(id -u)" = 0 ] || die "must run as root - pipe into 'sudo sh' rather than 'sh'" # --- install --------------------------------------------------------------- if [ "$FAMILY" = el ]; then # yum/dnf take the URL directly and handle the download, so there is no # temporary file to clean up and no second failure mode. $INSTALL "$URL" || die "could not install $PKG. If this is a 404, there is no package published for EL $TARGET yet." echo echo "Done. The CodeIT repository is enabled." if [ "$TARGET" = 7 ]; then echo "For the nginx mainline branch:" echo " yum-config-manager --enable CodeIT-mainline --save" else echo "Module streams available:" echo " dnf module enable nginx:codeit-mainline" echo " dnf module enable nginx:codeit-stable" echo " dnf module enable httpd:codeit" fi else tmp=$(mktemp -d) trap 'rm -rf "$tmp"' EXIT INT TERM fetch "$URL" "$tmp/$PKG" || die "could not download $PKG. If this is a 404, there is no package published for $TARGET yet." $INSTALL "$tmp/$PKG" apt-get update echo echo "Done. The CodeIT repository is enabled." echo "The testing suite is installed but disabled; enable it by setting" echo " Enabled: yes in /etc/apt/sources.list.d/codeit.sources" fi