Commit | Line | Data |
---|---|---|
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_]*)-@\*/ { | |
fcc208c5 MW |
15 | out = $0; |
16 | sub(/^.*\*@-/, "", out); | |
17 | sub(/-@\*.*$/, "", out); | |
18 | system(sprintf("rm %s/%s.m4", dir, out)); | |
a7855629 | 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--@\*/ { | |
fcc208c5 MW |
27 | if (out != "") close(out); |
28 | out = "NOTICE"; | |
29 | notice = $0 "\n"; | |
30 | next; | |
a7855629 | 31 | } |
32 | /\*@-([a-zA-Z0-9][-a-zA-Z0-9_]*)-@\*/ { | |
fcc208c5 MW |
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); | |
a7855629 | 40 | } |
41 | /\*@--[-a-zA-Z0-9_]*-@\*/ { next; } | |
42 | { | |
fcc208c5 MW |
43 | if (out == "NOTICE") |
44 | notice = notice $0 "\n"; | |
45 | else | |
46 | if (out != "") print $0 >(out); | |
a7855629 | 47 | } |
48 | END { | |
fcc208c5 MW |
49 | for (f in files) |
50 | system(sprintf("mv %s/%s.new %s/%s.m4", dir, f, dir, f)); | |
a7855629 | 51 | }' <"$glob" |
52 | echo "done." | |
53 | ;; | |
54 | *) echo >&2 "bad mode argument"; exit 1;; | |
55 | esac |