From d0629f4cb6cd336e222195c0881ed1b3613b7dc8 Mon Sep 17 00:00:00 2001 From: Brennan Kinney <5098581+polarathene@users.noreply.github.com> Date: Tue, 4 Mar 2025 10:58:42 +1300 Subject: [PATCH] chore: Revise utility install scripts + add Smallstep `step` CLI (#4376) Changes: - `jaq` should probably live in `/usr/local/bin` with other third-party sourced binaries. - `swaks` install properly with just `tar`, no `mv` + `rm` needed. - Added Smallstep `step` CLI. This serves similar purpose to `openssl` commands, but is generally nicer for usage with generation and inspection of certs/keys. I've talked up using in DMS a few times in the past for our TLS helper and unifying DKIM support (_instead of separate OpenDKIM/Rspamd generators_). - Including `step` for both AMD64 / ARM64 archs needs the alternate naming convention that it's published to GH releases with. - Added commentary about the `tar` usage. The ownership is a common concern with GH release sources, technically a non-issue when running as `root` --- CHANGELOG.md | 10 +++++++++ target/scripts/build/packages.sh | 36 +++++++++++++++++++++++++++----- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 39af02b7..8b041d7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ All notable changes to this project will be documented in this file. The format > **Note**: Changes and additions listed here are contained in the `:edge` image tag. These changes may not be as stable as released changes. +### Added + +- **Internal:** + - Added the Smallstep `step` CLI command for future internal usage ([#4376](https://github.com/docker-mailserver/docker-mailserver/pull/4376)) + ### Fixes - **Postfix:** @@ -13,6 +18,11 @@ All notable changes to this project will be documented in this file. The format - **Internal:** - A permissions fix for `/var/log/mail` that was [added in DMS v15]((https://github.com/docker-mailserver/docker-mailserver/pull/4374)) no longer encounters an error when no log files are present during a container restart, such as with a `tmpfs` volume mount ([#4391](https://github.com/docker-mailserver/docker-mailserver/pull/4391)) +### Updates + +- **Internal:** + - Minor improvements to `_install_utils()` in `packages.sh` ([#4376](https://github.com/docker-mailserver/docker-mailserver/pull/4376)) + ## [v15.0.0](https://github.com/docker-mailserver/docker-mailserver/releases/tag/v15.0.0) ### Breaking diff --git a/target/scripts/build/packages.sh b/target/scripts/build/packages.sh index bcfdcbcb..cfd510de 100644 --- a/target/scripts/build/packages.sh +++ b/target/scripts/build/packages.sh @@ -36,20 +36,46 @@ function _pre_installation_steps() { apt-get "${QUIET}" install --no-install-recommends "${EARLY_PACKAGES[@]}" 2>/dev/null } +# Install third-party commands to /usr/local/bin function _install_utils() { + local ARCH_A + ARCH_A=$(uname --machine) + # Alternate naming convention support: x86_64 (amd64) / aarch64 (arm64) + # https://en.wikipedia.org/wiki/X86-64#Industry_naming_conventions + local ARCH_B + case "${ARCH_A}" in + ( 'x86_64' ) ARCH_B='amd64' ;; + ( 'aarch64' ) ARCH_B='arm64' ;; + ( * ) + _log 'error' "Unsupported arch: '${ARCH_A}'" + return 1 + ;; + esac + + # TIP: `*.tar.gz` releases tend to forget to reset UID/GID ownership when archiving. + # When extracting with `tar` as `root` the archived UID/GID is kept, unless using `--no-same-owner`. + # Likewise when the binary is in a nested location the full archived path + # must be provided + `--strip-components` to extract the file to the target directory. + # Doing this avoids the need for (`mv` + `rm`) or (`--to-stdout` + `chmod +x`) _log 'debug' 'Installing utils sourced from Github' + _log 'trace' 'Installing jaq' local JAQ_TAG='v2.1.0' - curl -sSfL "https://github.com/01mf02/jaq/releases/download/${JAQ_TAG}/jaq-$(uname -m)-unknown-linux-gnu" -o /usr/bin/jaq - chmod +x /usr/bin/jaq + curl -sSfL "https://github.com/01mf02/jaq/releases/download/${JAQ_TAG}/jaq-$(uname -m)-unknown-linux-gnu" -o /usr/local/bin/jaq + chmod +x /usr/local/bin/jaq + + _log 'trace' 'Installing step' + local STEP_RELEASE='0.28.2' + curl -sSfL "https://github.com/smallstep/cli/releases/download/v${STEP_RELEASE}/step_linux_${STEP_RELEASE}_${ARCH_B}.tar.gz" \ + | tar -xz --directory /usr/local/bin --no-same-owner --strip-components=2 "step_${STEP_RELEASE}/bin/step" _log 'trace' 'Installing swaks' + # `perl-doc` is required for `swaks --help` to work: apt-get "${QUIET}" install --no-install-recommends perl-doc local SWAKS_VERSION='20240103.0' local SWAKS_RELEASE="swaks-${SWAKS_VERSION}" - curl -sSfL "https://github.com/jetmore/swaks/releases/download/v${SWAKS_VERSION}/${SWAKS_RELEASE}.tar.gz" | tar -xz - mv "${SWAKS_RELEASE}/swaks" /usr/local/bin - rm -r "${SWAKS_RELEASE}" + curl -sSfL "https://github.com/jetmore/swaks/releases/download/v${SWAKS_VERSION}/${SWAKS_RELEASE}.tar.gz" \ + | tar -xz --directory /usr/local/bin --no-same-owner --strip-components=1 "${SWAKS_RELEASE}/swaks" } function _install_postfix() {