| 1 |
#!/bin/sh |
| 2 |
# $1 = action ('configure' or 'reconfigure') |
| 3 |
# $2 = current-installed-version |
| 4 |
set -e |
| 5 |
|
| 6 |
action="$1" |
| 7 |
|
| 8 |
if test -f /etc/ca-certificates.conf; then |
| 9 |
CERTSCONF=/etc/ca-certificates.conf |
| 10 |
else |
| 11 |
CERTSCONF=/dev/null |
| 12 |
fi |
| 13 |
|
| 14 |
# CERTS_DISABLED: certs that user dont trust |
| 15 |
CERTS_DISABLED=$(sed -ne 's/^!\(.*\)/\1/p' $CERTSCONF) |
| 16 |
|
| 17 |
# CERTS_TRUST: certs that user already trust |
| 18 |
CERTS_TRUST=$(sed -e '/^#/d' -e '/^!/d' $CERTSCONF) |
| 19 |
|
| 20 |
|
| 21 |
# CERTS_AVAILABLE: certs that user can choices |
| 22 |
CERTS_AVAILABLE="" |
| 23 |
|
| 24 |
# CERTS_ENABLED: certs that user already trusted |
| 25 |
CERTS_ENABLED="" |
| 26 |
|
| 27 |
# CERTS_LIST: certs that will be installed |
| 28 |
CERTS_LIST="#INITIAL_CERTS#" |
| 29 |
|
| 30 |
# CERTS_NEW: new certificates that will be installed |
| 31 |
CERTS_NEW="" |
| 32 |
|
| 33 |
members() |
| 34 |
{ |
| 35 |
echo "$1" | tr ',' '\n' | sed -e 's/^[[:space:]]*//' | while read ca |
| 36 |
do |
| 37 |
if echo "$2" | grep -q "$ca" > /dev/null 2>&1; then |
| 38 |
echo match |
| 39 |
fi |
| 40 |
done | grep -q match |
| 41 |
} |
| 42 |
|
| 43 |
. /usr/share/debconf/confmodule || exit |
| 44 |
db_version 2.0 |
| 45 |
db_capb multiselect |
| 46 |
|
| 47 |
db_settitle ca-certificates/title |
| 48 |
db_input medium ca-certificates/trust_new_crts || true |
| 49 |
db_go |
| 50 |
|
| 51 |
trust_new="yes" |
| 52 |
if db_get ca-certificates/trust_new_crts; then |
| 53 |
trust_new="$RET" |
| 54 |
fi |
| 55 |
|
| 56 |
seen=false |
| 57 |
if db_fget ca-certificates/enable_crts seen; then |
| 58 |
seen="$RET" |
| 59 |
fi |
| 60 |
# XXX: in case reconfigure, force to select all available certificates |
| 61 |
if test "$action" = "reconfigure" || test "$DEBCONF_RECONFIGURE" = "1"; then |
| 62 |
seen=false |
| 63 |
trust_new=no |
| 64 |
fi |
| 65 |
|
| 66 |
if test -d /usr/share/ca-certificates; then |
| 67 |
cd /usr/share/ca-certificates |
| 68 |
crts=$( (find . -type f -name '*.crt' -print | sed -e 's/^\.\///'; \ |
| 69 |
echo "$CERTS_LIST" | tr ',' '\n' | sed -e 's/^[[:space:]]*//') | \ |
| 70 |
sort | uniq) |
| 71 |
for crt in $crts |
| 72 |
do |
| 73 |
if test "$CERTS_AVAILABLE" = ""; then |
| 74 |
CERTS_AVAILABLE="$crt" |
| 75 |
else |
| 76 |
CERTS_AVAILABLE="$CERTS_AVAILABLE, $crt" |
| 77 |
fi |
| 78 |
if (echo "$CERTS_DISABLED" | grep -F -q -x "$crt") > /dev/null 2>&1; then |
| 79 |
: # echo "I: ignore $crt" |
| 80 |
elif (echo "$CERTS_TRUST" | grep -F -q -x "$crt") > /dev/null 2>&1; then |
| 81 |
# already trusted |
| 82 |
if test "$CERTS_ENABLED" = ""; then |
| 83 |
CERTS_ENABLED="$crt" |
| 84 |
else |
| 85 |
CERTS_ENABLED="$CERTS_ENABLED, $crt" |
| 86 |
fi |
| 87 |
else |
| 88 |
# new certs? |
| 89 |
if test "$trust_new" = "yes"; then |
| 90 |
if test "$CERTS_ENABLED" = ""; then |
| 91 |
CERTS_ENABLED="$crt" |
| 92 |
else |
| 93 |
CERTS_ENABLED="$CERTS_ENABLED, $crt" |
| 94 |
fi |
| 95 |
elif test "$trust_new" = "ask"; then |
| 96 |
if test "$CERTS_NEW" = ""; then |
| 97 |
CERTS_NEW="$crt" |
| 98 |
else |
| 99 |
CERTS_NEW="$CERTS_NEW, $crt" |
| 100 |
fi |
| 101 |
else |
| 102 |
: # trust_new=no, default disabled |
| 103 |
fi |
| 104 |
fi |
| 105 |
done |
| 106 |
else |
| 107 |
# initial installation |
| 108 |
CERTS_AVAILABLE="$CERTS_LIST" |
| 109 |
CERTS_ENABLED="$CERTS_AVAILABLE" |
| 110 |
# XXX: ca-certificates/enable_crts should be used, so no need to ask new |
| 111 |
# in this session |
| 112 |
trust_new="yes" |
| 113 |
CERTS_NEW="" |
| 114 |
fi |
| 115 |
|
| 116 |
enable_crts="" |
| 117 |
if db_get ca-certificates/enable_crts; then |
| 118 |
enable_crts="$RET" |
| 119 |
fi |
| 120 |
|
| 121 |
new_seen=false |
| 122 |
if db_fget ca-certificates/new_crts seen; then |
| 123 |
new_seen="$RET" |
| 124 |
fi |
| 125 |
if members "$CERTS_NEW" "$enable_crts"; then |
| 126 |
# already selected new_crts? |
| 127 |
new_seen=true |
| 128 |
fi |
| 129 |
db_subst ca-certificates/new_crts new_crts "$CERTS_NEW" |
| 130 |
|
| 131 |
if test "$trust_new" = "ask" && test "$new_seen" = "true"; then |
| 132 |
# XXX: run this again in postinst |
| 133 |
CERTS_ENABLED="$enable_crts" |
| 134 |
fi |
| 135 |
|
| 136 |
if test "$trust_new" = "ask" && test "$CERTS_NEW" != "" && test "$new_seen" = "false"; then |
| 137 |
# New certificates added |
| 138 |
db_fset ca-certificates/new_crts seen false |
| 139 |
db_input critical ca-certificates/new_crts || true |
| 140 |
db_go |
| 141 |
|
| 142 |
if db_get ca-certificates/new_crts; then |
| 143 |
if test "$CERTS_ENABLED" = ""; then |
| 144 |
CERTS_ENABLED="$RET" |
| 145 |
else |
| 146 |
CERTS_ENABLED="$CERTS_ENABLED, $RET" |
| 147 |
fi |
| 148 |
fi |
| 149 |
# XXX: old certificates keep current state? |
| 150 |
seen=true |
| 151 |
fi |
| 152 |
# mark seen true, so that dont ask again while postinst |
| 153 |
db_fset ca-certificates/new_crts seen true |
| 154 |
|
| 155 |
db_set ca-certificates/enable_crts "$CERTS_ENABLED" |
| 156 |
db_subst ca-certificates/enable_crts enable_crts "$CERTS_AVAILABLE" |
| 157 |
if test "$seen" != true; then |
| 158 |
db_fset ca-certificates/enable_crts seen false |
| 159 |
fi |
| 160 |
db_input low ca-certificates/enable_crts || true |
| 161 |
db_go |
| 162 |
|
| 163 |
exit 0 |