|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# update-elf2tag-manpage - update the elf2tag.1 manpage from adoc source |
| 4 | +# |
| 5 | +# Usage: ./path/to/update-elf2tag-manpage |
| 6 | +# |
| 7 | +# Changes to the directory where update-elf2tag-manpage and elf2tag.1.adoc |
| 8 | +# are, runs elf2tag.1.adoc through asciidoctor to produce a man page, but |
| 9 | +# only updates the elf2tag.1 file in the case of actual changes. |
| 10 | +# |
| 11 | +# Just the asciidoctor version or the current date being different from |
| 12 | +# the last asciidoctor run is not an actual change. |
| 13 | +# |
| 14 | +# Requires asciidoctor to be installed. |
| 15 | +# |
| 16 | +# Environment variables used (if unset, uses the command from PATH): |
| 17 | +# ASCIIDOCTOR the asciidoctor command to run |
| 18 | +# CMP the cmp command to run (e.g. "busybox cmp") |
| 19 | +# SED the sed command to run (e.g. "busybox sed") |
| 20 | + |
| 21 | +# This script uses the shell feature called "process substitution" which |
| 22 | +# is implemented by bash and busybox sh, but not by e.g. dash and can |
| 23 | +# therefore not be a /bin/sh script. |
| 24 | + |
| 25 | +set -e |
| 26 | + |
| 27 | +case "$1" in |
| 28 | + -h | --help ) |
| 29 | + ${SED-sed} -n '/^#\( .*\)$/,$p' "$0" \ |
| 30 | + | ${SED-sed} '/^#\( .*\)\?$/!q' \ |
| 31 | + | ${SED-sed} '/^$/d' \ |
| 32 | + | ${SED-sed} 's|^#$||; s|^# ||' |
| 33 | + exit 0 |
| 34 | + ;; |
| 35 | +esac |
| 36 | + |
| 37 | +cd "$(dirname "$0")" |
| 38 | + |
| 39 | +test -s elf2tag.1.adoc |
| 40 | +test -s elf2tag |
| 41 | + |
| 42 | +normalize_manpage() { |
| 43 | + ${SED-sed} -f <(cat<<EOF |
| 44 | +s|^\.\\" Generator: Asciidoctor .*|.\\" Generator: GENERATOR| |
| 45 | +s|^\.\\" Date: 20[0-9][0-9]-[0-1][0-9]-[0-3][0-9]|.\\" Date: DATE| |
| 46 | +s|^.TH "ELF2TAG" "1" "20[0-9][0-9]-[0-1][0-9]-[0-3][0-9]" "avrdude" "avrdude Manual"|\.\\" TH HEADER| |
| 47 | +EOF |
| 48 | +) < "$1" > "$2" |
| 49 | +} |
| 50 | + |
| 51 | +tmpdir="tmp$$" |
| 52 | + |
| 53 | +if ! ${ASCIIDOCTOR-asciidoctor} -b manpage -D "$tmpdir" elf2tag.1.adoc; then |
| 54 | + echo "Error updating elf2tag.1" |
| 55 | + exit 2 |
| 56 | +fi |
| 57 | + |
| 58 | +if ! test -e elf2tag.1; then |
| 59 | + echo "Generate elf2tag.1" |
| 60 | + mv -f "$tmpdir/elf2tag.1" elf2tag.1 |
| 61 | + rmdir "$tmpdir" |
| 62 | + exit 0 |
| 63 | +fi |
| 64 | + |
| 65 | +normalize_manpage elf2tag.1 "$tmpdir/elf2tag.1.old" |
| 66 | +normalize_manpage "$tmpdir/elf2tag.1" "$tmpdir/elf2tag.1.new" |
| 67 | + |
| 68 | +if ${CMP-cmp} "$tmpdir/elf2tag.1.old" "$tmpdir/elf2tag.1.new" > /dev/null; then |
| 69 | + echo "elf2tag.1 is up to date" |
| 70 | + rm -f "$tmpdir/elf2tag.1" |
| 71 | + rm -f "$tmpdir/elf2tag.1.old" |
| 72 | + rm -f "$tmpdir/elf2tag.1.new" |
| 73 | + rmdir "$tmpdir" |
| 74 | + exit 0 |
| 75 | +fi |
| 76 | + |
| 77 | +echo "Updating elf2tag.1" |
| 78 | +mv -f "$tmpdir/elf2tag.1" elf2tag.1 |
| 79 | +rm -f "$tmpdir/elf2tag.1.old" |
| 80 | +rm -f "$tmpdir/elf2tag.1.new" |
| 81 | +rmdir "$tmpdir" |
| 82 | +exit 0 |
0 commit comments