]> git.donarmstrong.com Git - ca-certificates.git/blob - debian/config.in
209bf3d2a6fc40b0dee4251423f84cb66cac2d17
[ca-certificates.git] / debian / config.in
1 #!/bin/sh
2 # $1 = action ('configure' or 'reconfigure')
3 # $2 = current-installed-version
4 set -e
5
6 action="$1"
7 cur_version="$2"
8 this_version='#VERSION#'
9 pt_BR_fixed_version="20080616"
10
11 if test -f /etc/ca-certificates.conf; then
12   CERTSCONF=/etc/ca-certificates.conf
13 else
14   CERTSCONF=/dev/null
15 fi
16
17 # CERTS_DISABLED: certs that user dont trust
18 CERTS_DISABLED=$(sed -ne 's/^!\(.*\)/\1/p' $CERTSCONF)
19
20 # CERTS_TRUST: certs that user already trust
21 CERTS_TRUST=$(sed -e '/^#/d' -e '/^!/d' $CERTSCONF)
22
23
24 # CERTS_AVAILABLE: certs that user can choices
25 CERTS_AVAILABLE=""
26
27 # CERTS_ENABLED: certs that user already trusted
28 CERTS_ENABLED=""
29
30 # CERTS_LIST: certs that will be installed
31 CERTS_LIST="#INITIAL_CERTS#"
32
33 # CERTS_NEW: new certificates that will be installed
34 CERTS_NEW=""
35
36 members()
37 {
38   echo "$1" | tr ',' '\n' | sed -e 's/^[[:space:]]*//' | while read ca
39   do
40     if echo "$2" | grep -q "$ca" > /dev/null 2>&1; then
41       echo match
42     fi
43   done | grep -q match
44 }
45
46 . /usr/share/debconf/confmodule || exit
47 db_version 2.0
48 db_capb multiselect
49
50 db_title "ca-certificates configuration"
51 db_input medium ca-certificates/trust_new_crts || true
52 db_go
53
54 trust_new="yes"
55 if db_get ca-certificates/trust_new_crts; then
56   trust_new="$RET"
57 fi
58
59 seen=false
60 if db_fget ca-certificates/enable_crts seen; then
61   seen="$RET"
62 fi
63 # XXX: in case reconfigure, force to select all available certificates
64 if test "$action" = "reconfigure" || test "$DEBCONF_RECONFIGURE" = "1"; then
65   seen=false
66   trust_new=no
67 fi
68
69 if test -d /usr/share/ca-certificates; then
70   cd /usr/share/ca-certificates
71   crts=$( (find . -type f -name '*.crt' -print | sed -e 's/^\.\///'; \
72            echo "$CERTS_LIST" | tr ',' '\n' | sed -e 's/^[[:space:]]*//') | \
73            sort | uniq)
74   for crt in $crts
75   do
76    if test "$CERTS_AVAILABLE" = ""; then
77      CERTS_AVAILABLE="$crt"
78    else
79      CERTS_AVAILABLE="$CERTS_AVAILABLE, $crt"
80    fi
81    if (echo "$CERTS_DISABLED" | grep -F -q -x "$crt") > /dev/null 2>&1; then
82      : # echo "I: ignore $crt"
83    elif (echo "$CERTS_TRUST" | grep -F -q -x "$crt") > /dev/null 2>&1; then
84      # already trusted
85      if test "$CERTS_ENABLED" = ""; then
86        CERTS_ENABLED="$crt"
87      else
88        CERTS_ENABLED="$CERTS_ENABLED, $crt"
89      fi
90    else
91      # new certs?
92      if test "$trust_new" = "yes"; then
93        if test "$CERTS_ENABLED" = ""; then
94           CERTS_ENABLED="$crt"
95        else
96           CERTS_ENABLED="$CERTS_ENABLED, $crt"
97        fi
98      elif test "$trust_new" = "ask"; then
99        if test "$CERTS_NEW" = ""; then
100           CERTS_NEW="$crt"
101        else
102           CERTS_NEW="$CERTS_NEW, $crt"
103        fi
104      else
105          : # trust_new=no, default disabled
106      fi
107    fi
108   done
109 else
110   # initial installation
111   CERTS_AVAILABLE="$CERTS_LIST"
112   CERTS_ENABLED="$CERTS_AVAILABLE"
113   # XXX: ca-certificates/enable_crts should be used, so no need to ask new
114   #     in this session
115   trust_new="yes"
116   CERTS_NEW=""
117 fi
118
119 enable_crts=""
120 if db_get ca-certificates/enable_crts; then
121  enable_crts="$RET"
122 fi
123
124 new_seen=false
125 if dpkg --compare-versions "$cur_version" lt 20040808; then
126   db_fset ca-certificates/new_crts seen false
127 fi
128 if db_fget ca-certificates/new_crts seen; then
129   new_seen="$RET"
130 fi
131 if members "$CERTS_NEW" "$enable_crts"; then
132     # already selected new_crts?
133     new_seen=true
134 fi
135 db_subst ca-certificates/new_crts new_crts "$CERTS_NEW"
136
137 if test "$trust_new" = "ask" && test "$new_seen" = "true"; then
138  # XXX: run this again in postinst
139  CERTS_ENABLED="$enable_crts"
140 fi
141
142 if test "$trust_new" = "ask" && test "$CERTS_NEW" != "" && test "$new_seen" = "false"; then
143   # New certificates added
144   db_fset ca-certificates/new_crts seen false
145   db_title "ca-certificates configuration"
146   db_input critical ca-certificates/new_crts || true
147   db_go
148   
149   if db_get ca-certificates/new_crts; then
150      if test "$CERTS_ENABLED" = ""; then
151         CERTS_ENABLED="$RET"
152      else
153         CERTS_ENABLED="$CERTS_ENABLED, $RET"
154      fi
155   fi
156   # XXX: old certificates keep current state?
157   seen=true
158 fi
159 # mark seen true, so that dont ask again while postinst 
160 db_fset ca-certificates/new_crts seen true
161
162 # Ideally, we would be able to ask debconf for the language it's using, or
163 # at least have a shell binding for setlocale(). Since we don't, we have to
164 # do it all by hand.
165 is_pt_BR () {
166   current_lc_messages="$(eval `locale`; echo "$LC_MESSAGES")"
167   case "$LANGUAGE" in
168     pt_BR*)
169       return 0
170       ;;
171     *)
172       case "$current_lc_messages" in
173         pt_BR*)
174           return 0
175           ;;
176       esac
177   esac
178   return 1
179 }
180
181 PRIO=low
182 set_values=true
183
184 if dpkg --compare-versions "$cur_version" lt-nl "$pt_BR_fixed_version"; then
185   asked="false"
186   if db_fget ca-certificates/enable_crts asked_pt_br_question; then
187     asked="$RET"
188   fi
189   if [ "$asked" != "true" ]; then
190     if [ -e "/etc/ssl/certs/ca-certificates.crt" ] && [ ! -s "/etc/ssl/certs/ca-certificates.crt" ]; then
191       pt_seen="false"
192       if db_fget ca-certificates/enable_crts seen; then
193         pt_seen="$RET"
194       fi
195       if [ "$pt_seen" = "false" ]; then
196         CERTS_ENABLED="$CERTS_AVAILABLE"
197       elif is_pt_BR; then
198         PRIO=critical
199         CERTS_ENABLED="$CERTS_AVAILABLE"
200         seen=false
201       else
202         seen=true
203       fi
204     fi
205   else
206     set_values=false
207   fi
208 fi
209
210 if [ "$set_values" = "true" ]; then
211   db_set ca-certificates/enable_crts "$CERTS_ENABLED"
212   db_subst ca-certificates/enable_crts enable_crts "$CERTS_AVAILABLE"
213   if test "$seen" != true; then
214    db_fset ca-certificates/enable_crts seen false
215   fi
216   db_title "ca-certificates configuration"
217   db_input $PRIO ca-certificates/enable_crts || true
218   db_go
219
220   if [ "$PRIO" = "critical" ]; then
221     db_fset ca-certificates/enable_crts asked_pt_br_question true
222   fi
223 fi
224
225 exit 0