]> git.donarmstrong.com Git - ca-certificates.git/blob - debian/config.in
Import Debian version 20110502
[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_settitle ca-certificates/title
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_input critical ca-certificates/new_crts || true
146   db_go
147   
148   if db_get ca-certificates/new_crts; then
149      if test "$CERTS_ENABLED" = ""; then
150         CERTS_ENABLED="$RET"
151      else
152         CERTS_ENABLED="$CERTS_ENABLED, $RET"
153      fi
154   fi
155   # XXX: old certificates keep current state?
156   seen=true
157 fi
158 # mark seen true, so that dont ask again while postinst 
159 db_fset ca-certificates/new_crts seen true
160
161 # Ideally, we would be able to ask debconf for the language it's using, or
162 # at least have a shell binding for setlocale(). Since we don't, we have to
163 # do it all by hand.
164 is_pt_BR () {
165   current_lc_messages="$(eval `locale`; echo "$LC_MESSAGES")"
166   case "$LANGUAGE" in
167     pt_BR*)
168       return 0
169       ;;
170     *)
171       case "$current_lc_messages" in
172         pt_BR*)
173           return 0
174           ;;
175       esac
176   esac
177   return 1
178 }
179
180 PRIO=low
181 set_values=true
182
183 if dpkg --compare-versions "$cur_version" lt-nl "$pt_BR_fixed_version"; then
184   asked="false"
185   if db_fget ca-certificates/enable_crts asked_pt_br_question; then
186     asked="$RET"
187   fi
188   if [ "$asked" != "true" ]; then
189     if [ -e "/etc/ssl/certs/ca-certificates.crt" ] && [ ! -s "/etc/ssl/certs/ca-certificates.crt" ]; then
190       pt_seen="false"
191       if db_fget ca-certificates/enable_crts seen; then
192         pt_seen="$RET"
193       fi
194       if [ "$pt_seen" = "false" ]; then
195         CERTS_ENABLED="$CERTS_AVAILABLE"
196       elif is_pt_BR; then
197         PRIO=critical
198         CERTS_ENABLED="$CERTS_AVAILABLE"
199         seen=false
200       else
201         seen=true
202       fi
203     fi
204   else
205     set_values=false
206   fi
207 fi
208
209 if [ "$set_values" = "true" ]; then
210   db_set ca-certificates/enable_crts "$CERTS_ENABLED"
211   db_subst ca-certificates/enable_crts enable_crts "$CERTS_AVAILABLE"
212   if test "$seen" != true; then
213    db_fset ca-certificates/enable_crts seen false
214   fi
215   db_input $PRIO ca-certificates/enable_crts || true
216   db_go
217
218   if [ "$PRIO" = "critical" ]; then
219     db_fset ca-certificates/enable_crts asked_pt_br_question true
220   fi
221 fi
222
223 exit 0