Nix bashisms.

This isn't fully POSIX shell, because POSIX shell still doesn't have
`local' variable declarations, but at least it is reasonably portable
now.

fix https://github.com/heimdal/heimdal/issues/1299
This commit is contained in:
Taylor R Campbell
2026-01-21 14:55:17 +00:00
committed by Nico Williams
parent f11debe689
commit 82f7b8072c
10 changed files with 43 additions and 31 deletions

View File

@@ -1,41 +1,49 @@
#! /bin/bash
#! /bin/sh
set -e
DAYS=182500
key() {
local key=$1; shift
local key="$1"; shift
if [ ! -f "${key}.pem" ]; then
openssl ecparam -name prime256v1 |
openssl genpkey \
-paramfile <(openssl ecparam -name prime256v1) \
-paramfile /dev/stdin \
-out "${key}.pem"
fi
}
req() {
local key=$1; shift
local dn=$1; shift
local key="$1"; shift
local dn="$1"; shift
printf "[req]\n%s\n%s\n[dn]\nCN_default=foo\n" \
"prompt = yes" "distinguished_name = dn" |
openssl req -new -sha256 -key "${key}.pem" \
-config <(printf "[req]\n%s\n%s\n[dn]\nCN_default=foo\n" \
"prompt = yes" "distinguished_name = dn") \
-config - \
-subj "${dn}"
}
cert() {
local cert=$1; shift
local exts=$1; shift
local cert="$1"; shift
local exts="$1"; shift
openssl x509 -req -sha256 -out "${cert}.pem" \
-extfile <(printf "%s\n" "$exts") "$@"
trap 'rm -f mkcert.req' EXIT HUP INT TERM
rm -f mkcert.req
cat >mkcert.req
printf "%s\n" "$exts" |
openssl x509 -req -sha256 -in mkcert.req -out "${cert}.pem" \
-extfile - "$@"
rm -f mkcert.req
trap - EXIT HUP INT TERM
}
genroot() {
local dn=$1; shift
local key=$1; shift
local cert=$1; shift
local dn="$1"; shift
local key="$1"; shift
local cert="$1"; shift
exts=$(printf "%s\n%s\n%s\n%s\n" \
"subjectKeyIdentifier = hash" \
@@ -48,11 +56,11 @@ genroot() {
}
genee() {
local dn=$1; shift
local key=$1; shift
local cert=$1; shift
local cakey=$1; shift
local cacert=$1; shift
local dn="$1"; shift
local key="$1"; shift
local cert="$1"; shift
local cakey="$1"; shift
local cacert="$1"; shift
exts=$(printf "%s\n%s\n%s\n%s\n" \
"subjectKeyIdentifier = hash" \

View File

@@ -142,7 +142,7 @@ test_section() {
# Get caller location if available (bash only)
if [ -n "$BASH_VERSION" ]; then
line_info=" (${BASH_LINENO[0]})"
eval 'line_info=" (${BASH_LINENO[0]})"'
fi
# Print section header with line number
@@ -164,10 +164,11 @@ test_run() {
local rc=0
local cmd_out
local line_info=""
local restore_opts
# Get caller location if available (bash only)
if [ -n "$BASH_VERSION" ]; then
line_info=" (${BASH_SOURCE[1]:-}:${BASH_LINENO[0]:-})"
eval 'line_info=" (${BASH_SOURCE[1]:-}:${BASH_LINENO[0]:-})"'
fi
cmd_out=$(mktemp "${TMPDIR:-/tmp}/test_run.XXXXXX") || {
@@ -178,8 +179,11 @@ test_run() {
# Run command, capturing stdout and stderr
if [ "${TEST_VERBOSE:-0}" = "1" ]; then
# Verbose mode: show output in real-time and capture
restore_opts="$(set +o)"
set -o pipefail
"$@" 2>&1 | tee "$cmd_out"
rc=${PIPESTATUS[0]:-$?}
rc=$?
eval "$restore_opts"
else
# Normal mode: capture output silently
"$@" > "$cmd_out" 2>&1
@@ -260,7 +264,7 @@ test_run_x() {
local line_info=""
if [ -n "$BASH_VERSION" ]; then
line_info=" (${BASH_SOURCE[1]:-}:${BASH_LINENO[0]:-})"
eval 'line_info=" (${BASH_SOURCE[1]:-}:${BASH_LINENO[0]:-})"'
fi
cmd_out=$(mktemp "${TMPDIR:-/tmp}/test_out.XXXXXX") || return 1

View File

@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
#
# Copyright (c) 2007 Kungliga Tekniska Högskolan
# (Royal Institute of Technology, Stockholm, Sweden).

View File

@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
#
# Copyright (c) 2006 - 2008 Kungliga Tekniska Högskolan
# (Royal Institute of Technology, Stockholm, Sweden).

View File

@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
#
# Copyright (c) 2006 Kungliga Tekniska Högskolan
# (Royal Institute of Technology, Stockholm, Sweden).

View File

@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
#
# Copyright (c) 2006 Kungliga Tekniska Högskolan
# (Royal Institute of Technology, Stockholm, Sweden).

View File

@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
#
# Copyright (c) 2006 Kungliga Tekniska Högskolan
# (Royal Institute of Technology, Stockholm, Sweden).

View File

@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
#
# Copyright (c) 2007 Kungliga Tekniska Högskolan
# (Royal Institute of Technology, Stockholm, Sweden).

View File

@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
#
# Copyright (c) 2006 Kungliga Tekniska Högskolan
# (Royal Institute of Technology, Stockholm, Sweden).

View File

@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
#
# Copyright (c) 2006 - 2008 Kungliga Tekniska Högskolan
# (Royal Institute of Technology, Stockholm, Sweden).