@@ -1,6 +1,6 @@
#!/bin/sh -
#!/bin/sh -
#
#
# Copyright 2018, 2022 John-Mark Gurney.
# Copyright 2018, 2022-2023 John-Mark Gurney.
# All rights reserved.
# All rights reserved.
#
#
# Redistribution and use in source and binary forms, with or without
# Redistribution and use in source and binary forms, with or without
@@ -24,8 +24,6 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
# SUCH DAMAGE.
#
#
# $Id$
#
set -e
set -e
@@ -35,6 +33,9 @@ set -e
# snapshot.idx, and then run "sh addinfo.sh -c YYYYMMDD" with the oldest
# snapshot.idx, and then run "sh addinfo.sh -c YYYYMMDD" with the oldest
# known snapshot.
# known snapshot.
SNAPDIR=$(dirname $0)
MAILDIR="$SNAPDIR"/mail
usage() {
usage() {
echo "Usage: $0 [ -m ] <file>"
echo "Usage: $0 [ -m ] <file>"
echo "Usage: $0 -c <date>"
echo "Usage: $0 -c <date>"
@@ -72,6 +73,10 @@ while :; do
;;
;;
esac
esac
done
done
if [ ! -d "$MAILDIR" ]; then
echo 'ERROR: '"$MAILDIR"' does not exist.'
exit 3
fi
if [ x"$complete" = x"1" -a x"$more" = x"1" ]; then
if [ x"$complete" = x"1" -a x"$more" = x"1" ]; then
echo '-m and -c cannot be specified at the same time.'
echo '-m and -c cannot be specified at the same time.'
usage 2
usage 2
@@ -87,9 +92,11 @@ while ! mkdir "$0.running"; do
sleep 1;
sleep 1;
done
done
trap 'rmdir "$0.running"' 0
export SNAPAID_SH=source
export SNAPAID_SH=source
. $(dirname $0) /snapaid.sh
. "$SNAPDIR" /snapaid.sh
if [ x"$complete" = x"1" ]; then
if [ x"$complete" = x"1" ]; then
if [ ! -f snapshot.complete.idx ]; then
if [ ! -f snapshot.complete.idx ]; then
@@ -114,7 +121,6 @@ if [ x"$complete" = x"1" ]; then
mv snapshot.idx.new.xz snapshot.idx.xz
mv snapshot.idx.new.xz snapshot.idx.xz
mv snapshot.complete.idx.new.xz snapshot.complete.idx.xz
mv snapshot.complete.idx.new.xz snapshot.complete.idx.xz
rm snapshot.idx snapshot.complete.idx
rm snapshot.idx snapshot.complete.idx
rmdir "$0.running"
exit 0
exit 0
fi
fi
@@ -129,8 +135,26 @@ if ! verifygpgfile "$tmpfname"; then
exit 1
exit 1
fi
fi
mid="$(awk 'tolower($1) == "message-id:" {
MID=$2
sub(".*<", "", MID)
sub(">.*", "", MID)
printf "%s", MID
exit 0
}' "$tmpfname")"
midfile="$MAILDIR/$mid"
if [ -e "$midfile" ]; then
echo "ERROR: $midfile already exists, failed processing $tmpfname"
exit 3
fi
# process file
# process file
awk -f ./mksnapidx.awk "$tmpfname" > additional
awk -f ./mksnapidx.awk "$tmpfname" > additional
cp "$tmpfname" "$midfile"
chmod og+rX "$midfile"
rm "$tmpfname"
rm "$tmpfname"
# only check if there isn't more to come
# only check if there isn't more to come
@@ -164,5 +188,3 @@ else
mv snapshot.idx.new.xz snapshot.idx.xz
mv snapshot.idx.new.xz snapshot.idx.xz
mv snapshot.complete.idx.new.xz snapshot.complete.idx.xz
mv snapshot.complete.idx.new.xz snapshot.complete.idx.xz
fi
fi
rmdir "$0.running"