44#
55# Usage:
66# ./path/to/update-elf2tag-manpage
7+ # ./path/to/update-elf2tag-manpage --verify
78#
8- # Changes into the directory where update-elf2tag-manpage and
9- # elf2tag.1.adoc are, runs asciidoctor to produce a man page elf2tag.1
10- # from elf2tag.1.adoc, but only updates the elf2tag.1 file in the case
11- # of actual changes.
9+ # Without a command line argument given, changes into the directory
10+ # where update- elf2tag-manpage and elf2tag .1.adoc are, runs
11+ # asciidoctor to produce a man page elf2tag.1 from elf2tag.1.adoc, but
12+ # only updates the elf2tag.1 file in the case of actual changes.
1213#
1314# Just the asciidoctor version or the current date being different
1415# from the last asciidoctor run is not considered an actual change.
1516#
17+ # With the --verify argument given, only verify that elf2tag.1 and
18+ # elf2tag.1.adoc are consistent with each other, i.e. elf2tag.1 would
19+ # not be changed.
20+ #
1621# Requires asciidoctor to be installed.
1722#
1823# Environment variables used (if unset, uses the command from PATH):
1924# ASCIIDOCTOR the asciidoctor command to run
2025# CMP the cmp command to run (e.g. "busybox cmp")
26+ # DIFF the diff command to run with -u (used with --verify only)
2127# SED the sed command to run (e.g. "busybox sed")
2228
2329# This script uses the shell feature called "process substitution" which
@@ -33,6 +39,7 @@ if test "$#" -gt 1; then
3339 exit 2
3440fi
3541
42+ verify=false
3643if test " $# " -eq 1; then
3744 case " $1 " in
3845 -h | --help )
@@ -42,6 +49,9 @@ if test "$#" -eq 1; then
4249 | ${SED-sed} ' s|^#$||; s|^# ||'
4350 exit 0
4451 ;;
52+ --verify )
53+ verify=:
54+ ;;
4555 * )
4656 echo " $prog : Unhandled command line argument."
4757 exit 2
8999fi
90100
91101if ! test -e elf2tag.1; then
102+ if " $verify " ; then
103+ echo " $prog : Cannot ensure consistency if there is no old elf2tag.1 file"
104+ rm -rf " $tmpdir "
105+ exit 1
106+ fi
92107 echo " $prog : Generate elf2tag.1"
93108 mv -f " $tmpdir /elf2tag.1" elf2tag.1
94109 rmdir " $tmpdir "
@@ -107,6 +122,16 @@ if ${CMP-cmp} "$tmpdir/elf2tag.1.norm-old" "$tmpdir/elf2tag.1.norm-new" > /dev/n
107122 exit 0
108123fi
109124
125+ if " $verify " ; then
126+ echo " $prog : Error: src/elf2tag.1 is inconsistent with src/elf2tag.1.adoc"
127+ ${DIFF-diff} -u " $tmpdir /elf2tag.1.norm-old" " $tmpdir /elf2tag.1.norm-new" || :
128+ rm -f " $tmpdir /elf2tag.1"
129+ rm -f " $tmpdir /elf2tag.1.norm-old"
130+ rm -f " $tmpdir /elf2tag.1.norm-new"
131+ rmdir " $tmpdir "
132+ exit 1
133+ fi
134+
110135echo " Updating elf2tag.1"
111136mv -f " $tmpdir /elf2tag.1" elf2tag.1
112137rm -f " $tmpdir /elf2tag.1.norm-old"
0 commit comments