a7855629 |
1 | #! /bin/sh |
2 | |
3 | set -e |
4 | if [ $# -ne 3 ]; then |
5 | echo >&2 "usage: $0 install|rm GLOB DIR" |
6 | exit 1 |
7 | fi |
8 | |
9 | mode=$1 glob=$2 dir=$3 |
10 | case $mode in |
11 | rm) |
12 | printf "Uninstalling aclocal fragments... " |
13 | awk -v dir="$dir" ' |
14 | /\*@-([a-zA-Z0-9][-a-zA-Z0-9_]*)-@\*/ { |
15 | out = $0; |
16 | sub(/^.*\*@-/, "", out); |
17 | sub(/-@\*.*$/, "", out); |
18 | system(sprintf("rm %s/%s.m4", dir, out)); |
19 | }' <"$glob" |
20 | echo "done." |
21 | ;; |
22 | install) |
23 | printf "Installing aclocal fragments... " |
24 | awk -v dir="$dir" ' |
25 | BEGIN { out = ""; delete files; notice = ""} |
26 | /\*@--NOTICE--@\*/ { |
27 | if (out != "") close(out); |
28 | out = "NOTICE"; |
29 | notice = $0 "\n"; |
30 | next; |
31 | } |
32 | /\*@-([a-zA-Z0-9][-a-zA-Z0-9_]*)-@\*/ { |
33 | if (out != "") close(out); |
34 | out = $0; |
35 | sub(/^.*\*@-/, "", out); |
36 | sub(/-@\*.*$/, "", out); |
37 | files[out] = 1; |
38 | out = sprintf("%s/%s.new", dir, out); |
39 | printf "%s", notice >(out); |
40 | } |
41 | /\*@--[-a-zA-Z0-9_]*-@\*/ { next; } |
42 | { |
43 | if (out == "NOTICE") |
44 | notice = notice $0 "\n"; |
45 | else |
46 | if (out != "") print $0 >(out); |
47 | } |
48 | END { |
49 | for (f in files) |
50 | system(sprintf("mv %s/%s.new %s/%s.m4", dir, f, dir, f)); |
51 | }' <"$glob" |
52 | echo "done." |
53 | ;; |
54 | *) echo >&2 "bad mode argument"; exit 1;; |
55 | esac |