forked from pyllyukko/user.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen-readme.sh
executable file
·132 lines (110 loc) · 6.32 KB
/
gen-readme.sh
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
# Generate 'What does it do' README section
# https://github.com/pyllyukko/user.js/
# License: MIT
# Abort on error
set -o errexit
###################################
# Configuration:
# Text used to generate/replace subsection headers
SECTION_HTML5_ID='HTML5 / APIs / DOM'
SECTION_HTML5_MDOWN="HTML5 / [APIs](https://wiki.mozilla.org/WebAPI) / [DOM](https://en.wikipedia.org/wiki/Document_Object_Model) related settings. Mozilla is keen to implement every new HTML5 feature, which have had unforeseen security or privacy implications. This section disables many of those new and yet to be proven technologies."
SECTION_MISC_ID='Misc'
SECTION_MISC_MDOWN="Settings that do not belong to other sections or are user specific preferences."
SECTION_EXTENSIONS_ID='Extensions / plugins'
SECTION_EXTENSIONS_MDOWN="Harden preferences related to external plugins"
SECTION_FEATURES_ID='Firefox (anti-)features / components'
SECTION_FEATURES_MDOWN="Disable Firefox integrated metrics/reporting/experiments, disable potentially insecure/invasive/[undesirable](https://en.wikipedia.org/wiki/Feature_creep) features"
SECTION_AUTOCONNECT_ID='Automatic connections'
SECTION_AUTOCONNECT_MDOWN="Prevents the browser from [auto-connecting](https://support.mozilla.org/en-US/kb/how-stop-firefox-making-automatic-connections) to some Mozilla services, and from predictively opening connections to websites during browsing."
SECTION_HTTP_ID='HTTP'
SECTION_HTTP_MDOWN="HTTP protocol related entries. This affects cookies, the user agent, referer and others."
SECTION_CACHING_ID='Caching'
SECTION_CACHING_MDOWN="Enable and configure private browsing mode, don't store information locally during the browsing session"
SECTION_UI_ID='UI related'
SECTION_UI_MDOWN="Improve visibility of security-related elements, mitigate shoulder-surfing"
SECTION_CRYPTO_ID='Cryptography'
SECTION_CRYPTO_MDOWN="[TLS](https://en.wikipedia.org/wiki/Transport_Layer_Security) protocol related settings"
SECTION_CIPHERS_ID='Cipher suites'
SECTION_CIPHERS_MDOWN="This section tweaks the cipher suites used by Firefox. The idea is to support only the strongest ones with emphasis on [forward secrecy](https://en.wikipedia.org/wiki/Forward_secrecy), but without compromising compatibility with all those sites on the internet. As new crypto related flaws are discovered quite often, the cipher suites can be [tweaked to mitigate these newly discovered threats](https://github.com/pyllyukko/user.js/pull/18)."
###################################
function _gen_entries() {
# generate the "What does it do" README section from user.js PREF/SECTION fields and adjacent links
grep -E --line-number "SECTION\:|PREF\:" user.js | grep -E -v '\(disabled\)' | sed -e 's/ \+\*//g' | \
while read -r LINE; do
LINENUM=$(echo "$LINE" | awk -F ':' '{ print $1 }')
LINETYPE=$(echo "$LINE" | awk -F '[:/\*\ ]*' '{ print $2 }' 2>/dev/null)
LINENAME=$(echo "$LINE" | sed -e 's/.*PREF\: //g; s/.*SECTION\: //g')
if [ "$LINETYPE" = "SECTION" ]; then
INDENT=''
REF_LIST=''
LINENAME=$(_gen_section_header "$LINENAME")
else #if $LINETYPE = PREF
# Build a list of reference links
REF_LINE=$(( LINENUM + 1 ))
REF_NUMBER=1
REF_LIST=''
# while next lines start with 'http', generate markdown links and append them to the list
while sed "${REF_LINE}q;d" user.js | grep -E "^// http" >/dev/null; do
REF_URL=$(sed "${REF_LINE}q;d" user.js | cut -c4-) #
REF_MD_LINK="[${REF_NUMBER}](${REF_URL}) "
REF_LINE=$(( REF_LINE + 1 ))
REF_NUMBER=$(( REF_NUMBER + 1 ))
REF_LIST="${REF_LIST}${REF_MD_LINK}"
done
# if references list is not empty, add decoration chars [ ]
if [ ! "$REF_LIST" = "" ]; then
REF_LIST=" [ ${REF_LIST}]"
fi
INDENT='* '
fi
MARKDOWNLINE="${INDENT}${LINENAME}${REF_LIST}"
echo "$MARKDOWNLINE"
done
}
function _gen_section_header() {
# generate section headers from a predefined list
# replace section headers extracted from user.js with more detailed descriptions
# in markdown format (configurable above)
SECTION_NAME="$*"
case "$SECTION_NAME" in
"$SECTION_HTML5_ID") echo -e "\n### ${SECTION_HTML5_ID}\n\n${SECTION_HTML5_MDOWN}\n" ;;
"$SECTION_MISC_ID") echo -e "\n### ${SECTION_MISC_ID}\n\n${SECTION_MISC_MDOWN}\n" ;;
"$SECTION_EXTENSIONS_ID") echo -e "\n### ${SECTION_EXTENSIONS_ID}\n\n${SECTION_EXTENSIONS_MDOWN}\n" ;;
"$SECTION_FEATURES_ID") echo -e "\n### ${SECTION_FEATURES_ID}\n\n${SECTION_FEATURES_MDOWN}\n" ;;
"$SECTION_AUTOCONNECT_ID") echo -e "\n### ${SECTION_AUTOCONNECT_ID}\n\n${SECTION_AUTOCONNECT_MDOWN}\n" ;;
"$SECTION_HTTP_ID") echo -e "\n### ${SECTION_HTTP_ID}\n\n${SECTION_HTTP_MDOWN}\n" ;;
"$SECTION_CACHING_ID") echo -e "\n### ${SECTION_CACHING_ID}\n\n${SECTION_CACHING_MDOWN}\n" ;;
"$SECTION_UI_ID") echo -e "\n### ${SECTION_UI_ID}\n\n${SECTION_UI_MDOWN}\n" ;;
"$SECTION_CRYPTO_ID") echo -e "\n### ${SECTION_CRYPTO_ID}\n\n${SECTION_CRYPTO_MDOWN}\n" ;;
"$SECTION_CIPHERS_ID") echo -e "\n### ${SECTION_CIPHERS_ID}\n\n${SECTION_CIPHERS_MDOWN}\n" ;;
"*") echo -e "ERROR: unsupported section $SECTION_NAME"; exit 1 ;;
esac
}
function _gen_problems() {
grep 'NOTICE:' user.js | sed 's|// NOTICE: |* |g'
}
function _write_readme() {
# write generated sections to README.md (section delimited by html comments BEGIN/END SECTION)
# https://stackoverflow.com/questions/21876431
echo "$README_SECTION" > whatdoesitdo.tmp.md
awk '
BEGIN {p=1}
/BEGIN SECTION/ {print;system("cat whatdoesitdo.tmp.md");p=0}
/END SECTION/ {p=1}
p' README.md > README-new.md
mv README-new.md README.md
rm whatdoesitdo.tmp.md
echo "$PROBLEMS_SECTION" > knownproblems.tmp.md
awk '
BEGIN {p=1}
/BEGIN PROBLEMS-LIMITATIONS/ {print;system("cat knownproblems.tmp.md");p=0}
/END PROBLEMS-LIMITATIONS/ {p=1}
p' README.md > README-new.md
mv README-new.md README.md
rm knownproblems.tmp.md
}
###################################
README_SECTION=$(_gen_entries)
PROBLEMS_SECTION=$(_gen_problems)
_write_readme