Skip to content

Commit d792688

Browse files
committed
Merge branch 'shellcheck'
commit 19d0a8b Author: pyllyukko <[email protected]> Date: Sun Dec 3 19:21:00 2017 +0200 Added ShellCheck to Makefile tests commit 93b0add Author: pyllyukko <[email protected]> Date: Sun Dec 3 19:20:38 2017 +0200 Added ShellCheck to Travis packages commit cbba4ed Author: pyllyukko <[email protected]> Date: Sun Dec 3 19:15:56 2017 +0200 Fixed SC2197 commit 33baec7 Author: pyllyukko <[email protected]> Date: Sun Dec 3 19:14:54 2017 +0200 Fixed SC2166 commit f997eeb Author: pyllyukko <[email protected]> Date: Sun Dec 3 19:13:57 2017 +0200 Fixed SC2162 commit 46456ca Author: pyllyukko <[email protected]> Date: Sun Dec 3 19:12:34 2017 +0200 Fixed SC2196 commit 6d046e0 Author: pyllyukko <[email protected]> Date: Sun Dec 3 19:11:09 2017 +0200 Fixed SC2124 commit 674ad48 Author: pyllyukko <[email protected]> Date: Sun Dec 3 19:08:06 2017 +0200 Fixed SC2034 commit 1740c11 Author: pyllyukko <[email protected]> Date: Sun Dec 3 19:05:06 2017 +0200 Fixed SC2004 commit b8ac426 Author: pyllyukko <[email protected]> Date: Sun Dec 3 19:03:12 2017 +0200 Fixed SC2086 commit 211b7c0 Author: pyllyukko <[email protected]> Date: Sun Dec 3 18:55:51 2017 +0200 Fixed SC2002 commit 88ebefc Author: pyllyukko <[email protected]> Date: Sun Dec 3 18:54:08 2017 +0200 Fixed SC2128
1 parent c16b51b commit d792688

File tree

4 files changed

+45
-37
lines changed

4 files changed

+45
-37
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ script:
77
- acorn --silent user.js
88
- bash -n cas.sh
99
- make tests
10+
addons:
11+
apt:
12+
packages:
13+
- shellcheck
1014
notifications:
1115
irc:
1216
channels:

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ whatdoesitdo:
1010

1111
# To decrease tests verbosity, comment out unneeded targets
1212
.PHONY: tests
13-
tests: sourceprefs.js checkdeprecated stats acorn bash_syntax
13+
tests: sourceprefs.js checkdeprecated stats acorn bash_syntax shellcheck
1414

1515
.PHONY: acorn
1616
acorn:
@@ -20,6 +20,10 @@ acorn:
2020
bash_syntax:
2121
$(foreach i,$(wildcard *.sh),bash -n $(i);)
2222

23+
.PHONY: shellcheck
24+
shellcheck:
25+
shellcheck *.sh
26+
2327
# download and sort all known preferences files from Firefox (mozilla-central) source
2428
# specify wanted Firefox version/revision below (eg. "tip", "FIREFOX_AURORA_45_BASE", "9577ddeaafd85554c2a855f385a87472a089d5c0"). See https://hg.mozilla.org/mozilla-central/tags
2529
SOURCEVERSION=tip

cas.sh

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ for PROGRAM in \
3838
do
3939
if ! hash "${PROGRAM}" 2>/dev/null
4040
then
41-
printf "error: command not found in PATH: %s\n" "${PROGRAM}" >&2
41+
printf "[-] error: command not found in PATH: %s\n" "${PROGRAM}" >&2
4242
exit 1
4343
fi
4444
done
@@ -48,7 +48,7 @@ unset PROGRAM
4848
export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
4949
declare -A CAs=()
5050
declare -A CERT8_CAs=()
51-
declare -A CERT8_NICKS=()
51+
#declare -A CERT8_NICKS=()
5252
# this uses all the available firefox profiles
5353
INDEX_ALL_CERT8=0
5454
declare -a BASIC_LIST=(
@@ -92,7 +92,7 @@ function import_cas() {
9292

9393
if [ -z "${FF_HOME}" ]
9494
then
95-
echo "${FUNCNAME}(): error: FF_HOME not defined!" 1>&2
95+
echo "[-] error: FF_HOME not defined!" 1>&2
9696
return 1
9797
fi
9898

@@ -106,14 +106,14 @@ function import_cas() {
106106
#fi
107107
if [ ! -f "${REQUIRED_CA}" ]
108108
then
109-
echo "error: file \`${REQUIRED_CA}' not found!" 1>&2
109+
echo "[-] error: file \`${REQUIRED_CA}' not found!" 1>&2
110110
continue
111111
fi
112112
echo " ${REQUIRED_CA}"
113113
# certutil requires a "nickname", so we'll use the CN or OU
114114
# TODO: change this?
115115
NICKNAME=$( openssl x509 -in "${REQUIRED_CA}" -noout -subject | sed 's/^.*\(CN\|OU\)=//' )
116-
cat "${REQUIRED_CA}" | certutil -A -n "${NICKNAME}" -t CT,c,c -a -d "${FF_HOME}"
116+
certutil -A -n "${NICKNAME}" -t CT,c,c -a -d "${FF_HOME}" 0<"${REQUIRED_CA}"
117117

118118
# TEST!!! allow code signing
119119
#cat "${REQUIRED_CA}" | certutil -A -n "${NICKNAME}" -t CT,c,C -a -d "${FF_HOME}"
@@ -127,7 +127,7 @@ function expand_cert_path() {
127127
local FILE="${1}"
128128
if [ ! -f "${FILE}" ]
129129
then
130-
echo "${FUNCNAME}(): error: file \`${FILE}' not found!" 1>&2
130+
echo "[-] error: file \`${FILE}' not found!" 1>&2
131131
return 1
132132
fi
133133
while [ -h "${FILE}" ]
@@ -151,17 +151,17 @@ function get_required_cas_list() {
151151

152152
if [ -z "${CP}" ]
153153
then
154-
echo "error: no CertPatrol path defined!" 1>&2
154+
echo "[-] error: no CertPatrol path defined!" 1>&2
155155
return 1
156156
elif [ ! -f "${CP}" ]
157157
then
158-
echo "error: certpatrol DB \`${CP}' not found!" 1>&2
158+
echo "[-] error: certpatrol DB \`${CP}' not found!" 1>&2
159159
return 1
160160
fi
161161

162162
# read all the issuer fingerprints from certificate patrol's DB
163163
echo "reading issuer fingerprints from certpatrol's DB"
164-
FINGERPRINTS=( $( sqlite3 ${CP} 0<<<"select distinct issuerSha1Fingerprint from certificates where issuerSha1Fingerprint is not '';" ) )
164+
FINGERPRINTS=( $( sqlite3 "${CP}" 0<<<"select distinct issuerSha1Fingerprint from certificates where issuerSha1Fingerprint is not '';" ) )
165165
echo -e "${#FINGERPRINTS[*]} issuer fingerprints found\n"
166166
for FINGERPRINT in ${FINGERPRINTS[*]}
167167
do
@@ -185,7 +185,7 @@ function get_required_cas_list() {
185185
if [ -z "${REQUIRED_CA}" ]
186186
then
187187
# TODO: check if the cert actually is root CA
188-
echo -e " ${WRN}WARNING${RST}: no root CA found for this cert -> continue"
188+
echo -e " [${WRN}-${RST}]WARNING: no root CA found for this cert -> continue"
189189
continue
190190
fi
191191
echo " root CA found on file system: ${REQUIRED_CA}"
@@ -194,13 +194,13 @@ function get_required_cas_list() {
194194
#certutil -L -n "${CERT8_CAs[${FINGERPRINT}]}" -a -d "${OLD_FF_HOME}" | openssl verify -CAfile "${REQUIRED_CA}"
195195
else
196196
# issuer cert not found
197-
if (( ${DEBUG} ))
197+
if (( DEBUG ))
198198
then
199-
ISSUER_CN=$( sqlite3 ${CP} 0<<<"select distinct issuerCommonName from certificates where issuerSha1Fingerprint is \"${FINGERPRINT}\";" )
199+
ISSUER_CN=$( sqlite3 "${CP}" 0<<<"select distinct issuerCommonName from certificates where issuerSha1Fingerprint is \"${FINGERPRINT}\";" )
200200
echo -e "${FINGERPRINT}: \033[1;31mnot\033[0m found \"${ISSUER_CN}\"!" 1>&2
201201
# print hosts that use this issuer
202202
echo " sites that use this CA:"
203-
sqlite3 ${CP} 0<<<"select host from certificates where issuerSha1Fingerprint is \"${FINGERPRINT}\";" | sed 's/^/ /'
203+
sqlite3 "${CP}" 0<<<"select host from certificates where issuerSha1Fingerprint is \"${FINGERPRINT}\";" | sed 's/^/ /'
204204
fi
205205
fi
206206
if [ -n "${REQUIRED_CA}" ]
@@ -223,7 +223,7 @@ function print_required_cas_list() {
223223
echo " ${REQUIRED_CA}"
224224
if [ ! -f "${REQUIRED_CA}" ]
225225
then
226-
echo " WARNING: not found!" 1>&2
226+
echo " [-] WARNING: not found!" 1>&2
227227
fi
228228
done
229229
@@ -238,7 +238,7 @@ function print_countries() {
238238
OIFS=${IFS}
239239
IFS=$'\n'
240240
# get the "nicknames", as this is the way certutil handles the certs
241-
NICKNAMES=( $( certutil -L -d "${FF_HOME}" | fgrep -v ",," | sed '1,4d' | gawk 'NF--' ) )
241+
NICKNAMES=( $( certutil -L -d "${FF_HOME}" | grep -F -v ",," | sed '1,4d' | gawk 'NF--' ) )
242242
IFS=${OIFS}
243243
for NICKNAME in "${NICKNAMES[@]}"
244244
do
@@ -248,7 +248,7 @@ function print_countries() {
248248
then
249249
echo "${COUNTRY#C=}"
250250
else
251-
echo "warning: country not found for \`${NICKNAME}'!" 1>&2
251+
echo "[-] warning: country not found for \`${NICKNAME}'!" 1>&2
252252
fi
253253
done | sort | uniq -c
254254
@@ -265,13 +265,13 @@ function reverse_index() {
265265
266266
if [ -z "${FF_HOME}" ]
267267
then
268-
echo "${FUNCNAME}(): error: FF_HOME not defined!" 1>&2
268+
echo "[-] error: FF_HOME not defined!" 1>&2
269269
return 1
270270
fi
271271
272272
OIFS=${IFS}
273273
IFS=$'\n'
274-
NICKNAMES=( $( certutil -L -d "${FF_HOME}" | sed '1,4d' | fgrep -v ',,' | gawk 'NF--' ) )
274+
NICKNAMES=( $( certutil -L -d "${FF_HOME}" | sed '1,4d' | grep -F -v ',,' | gawk 'NF--' ) )
275275
IFS=${OIFS}
276276
277277
for NICKNAME in "${NICKNAMES[@]}"
@@ -280,7 +280,7 @@ function reverse_index() {
280280
FP=$( certutil -L -n "${NICKNAME}" -a -d "${FF_HOME}" | openssl x509 -noout -fingerprint -sha1 | sed 's/^.*Fingerprint=//' )
281281
if [ -z "${FP}" ]
282282
then
283-
echo "WARNING: could not get fingerprint for \`${NICKNAME}'!" 1>&2
283+
echo "[-] WARNING: could not get fingerprint for \`${NICKNAME}'!" 1>&2
284284
fi
285285
#FPS+=( $( certutil -L -n "${NICKNAME}" -a -d "${FF_HOME}" | openssl x509 -noout -fingerprint -sha1 | sed 's/^.*Fingerprint=//' ) )
286286
FPS+=( ${FP} )
@@ -294,7 +294,7 @@ function reverse_index() {
294294
then
295295
echo "${CAs[${FP}]}"
296296
else
297-
echo "WARNING: \`${NICKNAME}' not found (fp=${FP})!" 1>&2
297+
echo "[-] WARNING: \`${NICKNAME}' not found (fp=${FP})!" 1>&2
298298
fi
299299
done
300300
@@ -342,13 +342,13 @@ function index_cas() {
342342
343343
if [ -z "${OLD_FF_HOME}" ]
344344
then
345-
echo "${FUNCNAME}(): WARNING: OLD_FF_HOME not defined -> returning" 1>&2
345+
echo "[-] WARNING: OLD_FF_HOME not defined -> returning" 1>&2
346346
return 1
347347
fi
348348
349349
# cert8.db
350350
# use all available firefox profiles
351-
if (( ${INDEX_ALL_CERT8} ))
351+
if (( INDEX_ALL_CERT8 ))
352352
then
353353
OIFS=${IFS}
354354
IFS=$'\n'
@@ -374,7 +374,7 @@ function index_cas() {
374374
then
375375
#echo "${NICKNAME}: ${FP}"
376376
CERT8_CAs["${FP}"]="${NICKNAME}"
377-
CERT8_NICKS["${NICKNAME}"]="${FP}"
377+
#CERT8_NICKS["${NICKNAME}"]="${FP}"
378378
fi
379379
done
380380
done
@@ -440,9 +440,9 @@ do
440440
CP="${OLD_FF_HOME}/CertPatrol.sqlite"
441441
;;
442442
"P")
443-
if [ -z "${OPTARG}" -o ! -d "${OPTARG}" ]
443+
if [ -z "${OPTARG}" ] || [ ! -d "${OPTARG}" ]
444444
then
445-
echo "error: -P requires an option!" 1>&2
445+
echo "[-] error: -P requires an option!" 1>&2
446446
exit 1
447447
fi
448448
FF_HOME="${OPTARG}"
@@ -453,8 +453,8 @@ do
453453
"C")
454454
if [ ! -d /usr/share/ca-certificates ]
455455
then
456-
echo "error: directory \`/usr/share/ca-certificates' does not exist!" 1>&2
457-
echo " you might be running RH/CentOS, which has different system for CAs. see https://github.com/pyllyukko/user.js/issues/140" 1>&2
456+
echo "[-] error: directory \`/usr/share/ca-certificates' does not exist!" 1>&2
457+
echo " you might be running RH/CentOS, which has different system for CAs. see https://github.com/pyllyukko/user.js/issues/140" 1>&2
458458
exit 1
459459
fi
460460
REQUIRED_CAs=( ${BASIC_LIST[*]/#/\/usr\/share\/ca-certificates\/} )
@@ -481,7 +481,7 @@ case "${ACTION}" in
481481
"rev") reverse_index ;;
482482
"renamelib") rename_libnssckbi ;;
483483
*)
484-
echo "error: no action defined." 1>&2
484+
echo "[-] error: no action defined." 1>&2
485485
exit 1
486486
;;
487487
esac

gen-readme.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ SECTION_CIPHERS_MDOWN="This section tweaks the cipher suites used by Firefox. Th
4545

4646
function _gen_entries() {
4747
# generate the "What does it do" README section from user.js PREF/SECTION fields and adjacent links
48-
egrep --line-number "SECTION\:|PREF\:" user.js | egrep -v '\(disabled\)' | sed -e 's/ \+\*//g' | \
49-
while read LINE; do
48+
grep -E --line-number "SECTION\:|PREF\:" user.js | grep -E -v '\(disabled\)' | sed -e 's/ \+\*//g' | \
49+
while read -r LINE; do
5050
LINENUM=$(echo "$LINE" | awk -F ':' '{ print $1 }')
5151
LINETYPE=$(echo "$LINE" | awk -F '[:/\*\ ]*' '{ print $2 }' 2>/dev/null)
5252
LINENAME=$(echo "$LINE" | sed -e 's/.*PREF\: //g; s/.*SECTION\: //g')
@@ -56,22 +56,22 @@ function _gen_entries() {
5656
LINENAME=$(_gen_section_header "$LINENAME")
5757
else #if $LINETYPE = PREF
5858
# Build a list of reference links
59-
REF_LINE=$(( $LINENUM + 1 ))
59+
REF_LINE=$(( LINENUM + 1 ))
6060
REF_NUMBER=1
6161
REF_LIST=''
6262
# while next lines start with 'http', generate markdown links and append them to the list
63-
while sed "${REF_LINE}q;d" user.js | egrep "^// http" >/dev/null; do
63+
while sed "${REF_LINE}q;d" user.js | grep -E "^// http" >/dev/null; do
6464
REF_URL=$(sed "${REF_LINE}q;d" user.js | cut -c4-) #
6565
REF_MD_LINK="[${REF_NUMBER}](${REF_URL}) "
66-
REF_LINE=$(( $REF_LINE + 1 ))
67-
REF_NUMBER=$(( $REF_NUMBER + 1 ))
66+
REF_LINE=$(( REF_LINE + 1 ))
67+
REF_NUMBER=$(( REF_NUMBER + 1 ))
6868
REF_LIST="${REF_LIST}${REF_MD_LINK}"
6969
done
7070
# if references list is not empty, add decoration chars [ ]
7171
if [ ! "$REF_LIST" = "" ]; then
7272
REF_LIST=" [ ${REF_LIST}]"
7373
fi
74-
INDENT='* '; SECTIONDESC=''
74+
INDENT='* '
7575
fi
7676
MARKDOWNLINE="${INDENT}${LINENAME}${REF_LIST}"
7777
echo "$MARKDOWNLINE"
@@ -82,7 +82,7 @@ function _gen_section_header() {
8282
# generate section headers from a predefined list
8383
# replace section headers extracted from user.js with more detailed descriptions
8484
# in markdown format (configurable above)
85-
SECTION_NAME="$@"
85+
SECTION_NAME="$*"
8686
case "$SECTION_NAME" in
8787
"$SECTION_HTML5_ID") echo -e "\n### ${SECTION_HTML5_ID}\n\n${SECTION_HTML5_MDOWN}\n" ;;
8888
"$SECTION_MISC_ID") echo -e "\n### ${SECTION_MISC_ID}\n\n${SECTION_MISC_MDOWN}\n" ;;

0 commit comments

Comments
 (0)