# POSIX sh-compatible shell definitions # # Copyright (C) 2021, 2023 Sean Whitton # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or (at # your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . tab="$(printf '\t')" cchars="$(printf '*[\001-\037\177]*')" fail () { echo >&2 "${0##*/}: $*" exit 127 } dir_contents () { ( cd "$1"; find . ! -name . ! -name "$cchars" -print -prune ) } # Copied from src/connection.lisp in Consfigurator, which see for commentary. mkstemp () { local template="${1:-${TMPDIR:-/tmp}/tmp.XXXXXX}" err= # Use a subshell in case the parent script is using the third file # descriptor and to avoid changing its umask, though chances are we were # called in a subshell, e.g. "$(mkstemp)", anyway. ( umask 077 exec 3>&1 if err="$(if command -v m4 >/dev/null; then echo "mkstemp($template)" | m4 2>&1 1>&3 else mktemp "$template" 2>&1 1>&3 fi)"; then case "$err" in ?*) printf >&2 "%s\n" "$err"; exit 1 ;; *) exit 0 ;; esac else case "$err" in ?*) printf >&2 "%s\n" "$err" ;; esac exit 1 fi ) }