From de242c2d7f1ed13a6416e97889fe27be9b0f0591 Mon Sep 17 00:00:00 2001 From: Travis Glenn Hansen Date: Tue, 21 Jan 2025 18:32:30 -0700 Subject: [PATCH] better talos and nixos support with wrapper scripts Signed-off-by: Travis Glenn Hansen --- docker/iscsiadm | 23 ++++++++++++++++++++--- docker/mount | 16 +++++++++++++--- docker/multipath | 14 ++++++++++++-- docker/oneclient | 14 ++++++++++++-- docker/umount | 16 +++++++++++++--- docker/zfs | 14 ++++++++++++-- docker/zpool | 14 ++++++++++++-- 7 files changed, 94 insertions(+), 17 deletions(-) diff --git a/docker/iscsiadm b/docker/iscsiadm index 551a9f5..1769006 100755 --- a/docker/iscsiadm +++ b/docker/iscsiadm @@ -1,14 +1,30 @@ -#!/bin/bash +#!/usr/bin/env bash : "${ISCSIADM_HOST_STRATEGY:=chroot}" : "${ISCSIADM_HOST_PATH:=iscsiadm}" echoerr() { printf "%s\n" "$*" >&2; } +P="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/run/current-system/sw/bin" + case ${ISCSIADM_HOST_STRATEGY} in chroot) - # https://engineering.docker.com/2019/07/road-to-containing-iscsi/ - chroot /host /usr/bin/env -i PATH="/usr/sbin:/usr/bin:/sbin:/bin:/run/current-system/sw/bin" ${ISCSIADM_HOST_PATH} "${@:1}" + # https://www.docker.com/blog/road-to-containing-iscsi/ + + if [[ "${ISCSIADM_HOST_PATH}" =~ ^\/ && -f "/host${ISCSIADM_HOST_PATH}" ]]; then + chroot /host "${ISCSIADM_HOST_PATH}" "${@:1}" + exit $? + fi + + for p in $(echo $P | cut -d ":" -f 1- --output-delimiter=" "); do + if [[ -f "/host${p}/iscsiadm" ]]; then + chroot /host "${p}/iscsiadm" "${@:1}" + exit $? + fi + done + + chroot /host /usr/bin/env -i PATH="${P}" ${ISCSIADM_HOST_PATH} "${@:1}" + exit $? ;; nsenter) @@ -19,6 +35,7 @@ case ${ISCSIADM_HOST_STRATEGY} in exit 1 fi nsenter --mount="/proc/${iscsid_pid}/ns/mnt" --net="/proc/${iscsid_pid}/ns/net" -- ${ISCSIADM_HOST_PATH} "${@:1}" + exit $? ;; *) diff --git a/docker/mount b/docker/mount index c0603e6..90400cf 100755 --- a/docker/mount +++ b/docker/mount @@ -1,4 +1,6 @@ -#!/bin/bash +#!/usr/bin/env bash + +P="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/run/current-system/sw/bin" container_supported_filesystems=( "ext2" @@ -31,7 +33,15 @@ while getopts "t:" opt; do done if [[ ${USE_HOST_MOUNT_TOOLS} -eq 1 ]]; then - chroot /host /usr/bin/env -i PATH="/usr/sbin:/usr/bin:/sbin:/bin:/run/current-system/sw/bin" mount "${@:1}" + for p in $(echo $P | cut -d ":" -f 1- --output-delimiter=" "); do + if [[ -f "/host${p}/mount" ]]; then + chroot /host "${p}/mount" "${@:1}" + exit $? + fi + done + chroot /host /usr/bin/env -i PATH="${P}" mount "${@:1}" + exit $? else - /usr/bin/env -i PATH="/usr/sbin:/usr/bin:/sbin:/bin:/run/current-system/sw/bin" mount "${@:1}" + /usr/bin/env -i PATH="${P}" mount "${@:1}" + exit $? fi diff --git a/docker/multipath b/docker/multipath index ac097d4..7b204d1 100755 --- a/docker/multipath +++ b/docker/multipath @@ -1,3 +1,13 @@ -#!/bin/bash +#!/usr/bin/env bash -chroot /host /usr/bin/env -i PATH="/usr/sbin:/usr/bin:/sbin:/bin:/run/current-system/sw/bin" multipath "${@:1}" +P="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/run/current-system/sw/bin" + +for p in $(echo $P | cut -d ":" -f 1- --output-delimiter=" "); do + if [[ -f "/host${p}/multipath" ]]; then + chroot /host "${p}/multipath" "${@:1}" + exit $? + fi +done + +chroot /host /usr/bin/env -i PATH="${P}" multipath "${@:1}" +echo $? diff --git a/docker/oneclient b/docker/oneclient index 373cefd..467ac4d 100755 --- a/docker/oneclient +++ b/docker/oneclient @@ -1,3 +1,13 @@ -#!/bin/bash +#!/usr/bin/env bash -chroot /host /usr/bin/env -i PATH="/usr/sbin:/usr/bin:/sbin:/bin:/run/current-system/sw/bin" oneclient "${@:1}" +P="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/run/current-system/sw/bin" + +for p in $(echo $P | cut -d ":" -f 1- --output-delimiter=" "); do + if [[ -f "/host${p}/oneclient" ]]; then + chroot /host "${p}/oneclient" "${@:1}" + exit $? + fi +done + +chroot /host /usr/bin/env -i PATH="${P}" oneclient "${@:1}" +exit $? diff --git a/docker/umount b/docker/umount index 1bcd0f2..70507de 100755 --- a/docker/umount +++ b/docker/umount @@ -1,4 +1,6 @@ -#!/bin/bash +#!/usr/bin/env bash + +P="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/run/current-system/sw/bin" container_supported_filesystems=( "ext2" @@ -31,7 +33,15 @@ while getopts "t:" opt; do done if [[ ${USE_HOST_MOUNT_TOOLS} -eq 1 ]]; then - chroot /host /usr/bin/env -i PATH="/usr/sbin:/usr/bin:/sbin:/bin:/run/current-system/sw/bin" umount "${@:1}" + for p in $(echo $P | cut -d ":" -f 1- --output-delimiter=" "); do + if [[ -f "/host${p}/umount" ]]; then + chroot /host "${p}/umount" "${@:1}" + exit $? + fi + done + chroot /host /usr/bin/env -i PATH="${P}" umount "${@:1}" + exit $? else - /usr/bin/env -i PATH="/usr/sbin:/usr/bin:/sbin:/bin:/run/current-system/sw/bin" umount "${@:1}" + /usr/bin/env -i PATH="${P}" umount "${@:1}" + exit $? fi diff --git a/docker/zfs b/docker/zfs index aceb182..2efd259 100755 --- a/docker/zfs +++ b/docker/zfs @@ -1,3 +1,13 @@ -#!/bin/bash +#!/usr/bin/env bash -chroot /host /usr/bin/env -i PATH="/usr/sbin:/usr/bin:/sbin:/bin:/run/current-system/sw/bin" zfs "${@:1}" +P="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/run/current-system/sw/bin" + +for p in $(echo $P | cut -d ":" -f 1- --output-delimiter=" "); do + if [[ -f "/host${p}/zfs" ]]; then + chroot /host "${p}/zfs" "${@:1}" + exit $? + fi +done + +chroot /host /usr/bin/env -i PATH="${P}" zfs "${@:1}" +exit $? diff --git a/docker/zpool b/docker/zpool index a4696aa..ec0d5b4 100755 --- a/docker/zpool +++ b/docker/zpool @@ -1,3 +1,13 @@ -#!/bin/bash +#!/usr/bin/env bash -chroot /host /usr/bin/env -i PATH="/usr/sbin:/usr/bin:/sbin:/bin:/run/current-system/sw/bin" zpool "${@:1}" +P="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/run/current-system/sw/bin" + +for p in $(echo $P | cut -d ":" -f 1- --output-delimiter=" "); do + if [[ -f "/host${p}/zpool" ]]; then + chroot /host "${p}/zpool" "${@:1}" + exit $? + fi +done + +chroot /host /usr/bin/env -i PATH="${P}" zpool "${@:1}" +exit $?