This repository was archived by the owner on Nov 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathmake-trivial-rule
More file actions
executable file
·77 lines (63 loc) · 1.63 KB
/
make-trivial-rule
File metadata and controls
executable file
·77 lines (63 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/sh
# THIS IS NOT A RULE, but a shell script to create simple rules for a
# specified domain.
#
# Create $1.xml, mapping $1 and www.$1 to https://$2 (or simply http:
# to https: by default).
if [ -z "$1" ]
then
echo "syntax: $0 example.com [secure.example.com]" >&2
exit 1
fi
capitalized=$(echo "$1" | cut -c 1 | tr a-z A-Z)$(echo "$1" | cut -c 2-)
dest="$capitalized".xml
if [ -f "$dest" ]
then
echo "error: $dest already exists." >&2
exit 1
fi
if echo "$1" | grep -i '^www' >/dev/null
then
echo "error: omit leading www" >&2
exit 1
fi
if echo "$1" | grep -v '\.' >/dev/null
then
echo "error: domain should probably contain a dot" >&2
exit 1
fi
lower=$(echo "$1" | tr A-Z a-z)
escaped=$(echo "$lower" | sed 's/\./\\./g' )
duplicate=$(find . -name '*.xml' -exec grep -EHin '<target\s+host="(w+\.)?'$escaped'"\s*/>' -- {} +)
if [ -n "$duplicate" ]
then
echo "error: $lower already exists:" >&2
echo "$duplicate" >&2
exit 1
fi
if [ "$#" -gt 1 ] ; then
to="$2"
else
to="www.$lower"
fi
cat > "$dest" <<END
<!--
Note to ruleset creator: if you are aware of any nonfunctional hosts relevant
to this ruleset, please list them below, replacing the example.
Alternatively, if you are unaware of any such hosts, please delete this comment
in its entirety.
Nonfunctional hosts in *.$lower:
# Example: foobar.$lower (m)
h: http redirect
m: certificate mismatch
r: connection refused
s: self-signed certificate
t: timeout on https
-->
<ruleset name="$capitalized">
<target host="$lower" />
<target host="www.$lower" />
<rule from="^http:" to="https:" />
</ruleset>
END
echo "$0: created $dest; please examine it." >&2