* admin/emacs-shell-lib: New file for shared bash code.
* admin/automerge:
* admin/diff-tar-files:
* admin/emacs-shell-lib:
* admin/make-manuals:
* admin/update_autogen:
* admin/upload-manuals: Simplify and improve using above new library.
## it with the -d option in the repository directory, in case a pull
## updates this script while it is working.
-set -o nounset
-
-die () # write error to stderr and exit
-{
- [ $# -gt 0 ] && echo "$PN: $*" >&2
- exit 1
-}
-
-PN=${0##*/} # basename of script
-PD=${0%/*}
-
-[ "$PD" = "$0" ] && PD=. # if PATH includes PWD
+source "${0%/*}/emacs-shell-lib"
usage ()
{
[ "$test" ] && build=1
-if [ -x "$(command -v mktemp)" ]; then
- tempfile=$(mktemp "/tmp/$PN.XXXXXXXXXX")
-else
- tempfile=/tmp/$PN.$$
-fi
-
-trap 'rm -f $tempfile 2> /dev/null' EXIT
+tempfile="$(emacs_mktemp)"
[ -e Makefile ] && [ "$build" ] && {
exit 0
-
-### automerge ends here
-#! /bin/sh
+#!/bin/bash
# Copyright (C) 2001-2022 Free Software Foundation, Inc.
# You should have received a copy of the GNU General Public License
# along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
+source "${0%/*}/emacs-shell-lib"
if [ $# != 2 ]; then
cat <<EOF
old_tar=$1
new_tar=$2
-old_tmp=/tmp/old.$$
-new_tmp=/tmp/new.$$
-trap "rm -f $old_tmp $new_tmp; exit 1" 1 2 15
+old_tmp="$(emacs_mktemp ${PN}-old)"
+new_tmp="$(emacs_mktemp ${PN}-new)"
tar tf "$old_tar" | sed -e 's,^[^/]*,,' | sort > $old_tmp
tar tf "$new_tar" | sed -e 's,^[^/]*,,' | sort > $new_tmp
--- /dev/null
+#!/bin/bash
+### emacs-shell-lib - shared code for Emacs shell scripts
+
+## Copyright (C) 2022 Free Software Foundation, Inc.
+
+## Author: Stefan Kangas <stefankangas@gmail.com>
+
+## This file is part of GNU Emacs.
+
+## GNU Emacs 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.
+
+## GNU Emacs 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
+
+### Code:
+
+# Set an explicit umask.
+umask 077
+
+# Treat unset variables as an error.
+set -o nounset
+
+# Exit immediately on error.
+set -o errexit
+
+# Avoid non-standard command output from non-C locales.
+unset LANG LC_ALL LC_MESSAGES
+
+PN=${0##*/} # basename of script
+PD=${0%/*} # script directory
+
+[ "$PD" = "$0" ] && PD=. # if PATH includes PWD
+
+die () # write error to stderr and exit
+{
+ [ $# -gt 0 ] && echo "$PN: $@" >&2
+ exit 1
+}
+
+emacs_tempfiles=()
+
+emacs_tempfiles_cleanup ()
+{
+ for file in ${emacs_tempfiles[@]}; do
+ rm -f "${file}" 2> /dev/null
+ done
+}
+
+trap '
+ ret=$?
+ emacs_tempfiles_cleanup
+ exit $ret
+' EXIT
+
+emacs_mktemp ()
+{
+ local readonly file="${1-}"
+ local tempfile
+ local prefix
+
+ if [ -z "$file" ]; then
+ prefix="$PN"
+ else
+ prefix="$1"
+ fi
+
+ if [ -x "$(command -v mktemp)" ]; then
+ tempfile=$(mktemp "${TMPDIR-/tmp}/${prefix}.XXXXXXXXXX")
+ else
+ tempfile="${TMPDIR-/tmp}/${prefix}.$RANDOM$$"
+ (umask 077 && touch "$tempfile")
+ fi
+
+ [ -z "${tempfile}" ] && die "Creating temporary file failed"
+
+ emacs_tempfiles+=("${tempfile}")
+
+ echo "$tempfile"
+}
### Code:
-set -o nounset
-
-die () # write error to stderr and exit
-{
- [ $# -gt 0 ] && echo "$PN: $@" >&2
- exit 1
-}
-
-PN=${0##*/} # basename of script
+source "${0%/*}/emacs-shell-lib"
usage ()
{
[ -e admin/admin.el ] || die "admin/admin.el not found"
-tempfile=/tmp/$PN.$$
-trap "rm -f $tempfile 2> /dev/null" EXIT
+tempfile="$(emacs_mktemp)"
[ "$continue" ] || rm -rf $outdir
### Code:
-set -o nounset
-
-die () # write error to stderr and exit
-{
- [ $# -gt 0 ] && echo "$PN: $@" >&2
- exit 1
-}
-
-PN=${0##*/} # basename of script
-PD=${0%/*}
-
-[ "$PD" = "$0" ] && PD=. # if PATH includes PWD
+source "${0%/*}/emacs-shell-lib"
## This should be the admin directory.
cd $PD || exit
[ "$basegen" ] || die "internal error"
-tempfile=/tmp/$PN.$$
-
-trap 'rm -f $tempfile 2> /dev/null' EXIT
-
+tempfile="$(emacs_mktemp)"
while getopts ":hcfqA:CL" option ; do
case $option in
exit 0
-
-### update_autogen ends here
### Code:
-set -o nounset
-
-die () # write error to stderr and exit
-{
- [ $# -gt 0 ] && echo "$PN: $@" >&2
- exit 1
-}
-
-PN=${0##*/} # basename of script
+source "${0%/*}/emacs-shell-lib"
usage ()
{