summaryrefslogtreecommitdiff
path: root/Master/tlpkg/bin/tl-sign-file
blob: fbe71a41179f63d698bf83856ccb75e261a289b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/sh
# $Id$
# Public domain.  Originally written 2016, Norbert Preining.
# Sign a file for release in TeX Live. Used in tl-update-images, etc.
# See tlpkg/gpg/tl-key-extension.txt for some info.

if test $# -ne 1; then
  echo "$0: Exactly one argument must be given, the file to sign." >&2
  exit 1
fi

# remove previous signature
rm -f "$1.asc"

prg=gpg
gpgopts="--batch --homedir /home/texlive/.gnupg  \
  --passphrase-file /home/texlive/.gnupg/passphrase \
  --local-user 0x06BAB6BC "
gpgmainopts="--armor --detach-sign"

# use the environment variables if available
if test -n "$TL_GNUPG" ; then
  prg=$TL_GNUPG
fi
if test -n "$TL_GNUPGOPTS" ; then
  gpgopts=$TL_GNUPGOPTS
fi
if test -n "$TL_GNUPGMAINOPTS" ; then
  gpgmainopts=$TL_GNUPGMAINOPTS
fi

# sign, check that result doesn't use something expired.
# both --detach-sign and --verify exit 0 even when something is expired.
if "$prg" $gpgmainopts $gpgopts "$1"; then
  if "$prg" --verify "$1".asc 2>&1 | grep xpired >/dev/null; then
    echo "$0: expired key, output from $prg --verify $1.asc:" >&2
    "$prg" --verify "$1".asc
    echo "$0: expired key, moving $1.asc to $1.asc.xpir." >&2
    mv "$1".asc "$1".asc.xpir || exit 1
    echo "$0: gpg command was:" >&2
    echo "$0:" "$prg" $gpgmainopts $gpgopts "$1" >&2
    echo "$0: good luck and goodbye." >&2
    exit 1
  fi
else
  echo "$0: gpg failed, exiting." >&2
  echo "$0: gpg command was:" >&2
  echo "$0:" "$prg" $gpgmainopts $gpgopts "$1" >&2
  exit 1
fi

exit 0