]> git.donarmstrong.com Git - ca-certificates.git/blob - debian/postinst
Broken symlinks on upgrade due to plain c_rehash call #643667
[ca-certificates.git] / debian / postinst
1 #! /bin/sh -e
2 # postinst script for ca-certificates
3 #
4 # see: dh_installdeb(1)
5
6 # summary of how this script can be called:
7 #        * <postinst> `configure' <most-recently-configured-version>
8 #        * <old-postinst> `abort-upgrade' <new version>
9 #        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
10 #          <new-version>
11 #        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
12 #          <failed-install-package> <version> `removing'
13 #          <conflicting-package> <version>
14 # for details, see /usr/share/doc/packaging-manual/
15 #
16 # quoting from the policy:
17 #     Any necessary prompting should almost always be confined to the
18 #     post-installation script, and should be protected with a conditional
19 #     so that unnecessary prompting doesn't happen if a package's
20 #     installation fails and the `postinst' is called with `abort-upgrade',
21 #     `abort-remove' or `abort-deconfigure'.
22
23 each_value() {
24  echo "$1" |tr ',' '\n' | sed -e 's/^[[:space:]]*//' 
25 }
26
27 memberp() {
28  m="$1"
29  l="$2"
30  each_value "$l" | grep -q "^$m\$"
31 }
32
33 delca() {
34  m="$1"
35  l="$2"
36  echo "$l" |sed -e 's|'"$m"', ||' -e 's|'"$m"'$||' -e 's/,[[:space:]]*,/, /' -e 's/^[[:space:]]*//' -e 's/,[[:space:]]*$//'
37 }
38
39 case "$1" in
40     configure)
41         if [ ! -e /usr/local/share/ca-certificates ]
42         then
43             if mkdir /usr/local/share/ca-certificates 2>/dev/null
44             then
45                 chown root:staff /usr/local/share/ca-certificates
46                 chmod 2775 /usr/local/share/ca-certificates
47             fi
48         fi
49
50         . /usr/share/debconf/confmodule
51         db_version 2.0
52         db_capb multiselect
53         db_metaget ca-certificates/enable_crts choices
54         CERTS_AVAILABLE="$RET"
55         db_get ca-certificates/enable_crts
56         CERTS_ENABLED="$RET"
57         # XXX unmark seen for next configuration
58         db_fset ca-certificates/new_crts seen false
59         # We should clean up this value now, as everyone will have
60         # upgraded to a fixed version.
61         db_fset ca-certificates/enable_crts asked_pt_br_question false
62         db_stop || true
63         if test -f /etc/ca-certificates.conf; then
64           # XXX: while in subshell?
65           while read line
66           do
67             if echo "$line" | grep -q '^#'; then
68              echo "$line"
69             else
70              case "$line" in
71              !*) ca=$(echo "$line" | sed -e 's/^!//');;
72              *)   ca="$line";;
73              esac
74              if memberp "$ca" "$CERTS_ENABLED"; then
75                echo "$ca"
76                # CERTS_ENABLED=$(delca "$ca" "$CERTS_ENABLED")
77          elif memberp "$ca" "$CERTS_AVAILABLE" ||
78               echo "$line" | grep -q '^!'; then
79            echo "!$ca"
80          elif [ -f /usr/share/ca-certificates/"$ca" ] || \
81               [ -f /usr/local/share/ca-certificates/"$ca" ]; then
82            echo "$ca"
83              else
84                echo "!$ca"
85              fi
86              # CERTS_AVAILABLE=$(delca "$ca" "$CERTS_AVAILABLE")
87             fi
88           done < /etc/ca-certificates.conf > /etc/ca-certificates.conf.dpkg-new
89           if echo "$CERTS_ENABLED" | egrep -q "^([[:space:]]*,)*[[:space:]]*$"; then
90               :
91           else
92             each_value "$CERTS_ENABLED" | while read ca
93             do
94               if grep -q "^$ca" /etc/ca-certificates.conf.dpkg-new; then
95                   :
96               else
97                   echo "$ca" >> /etc/ca-certificates.conf.dpkg-new
98               fi
99             done
100           fi
101           each_value "$CERTS_AVAILABLE" | while read ca
102           do
103             if memberp "$ca" "$CERTS_ENABLED"; then
104                 :
105             elif grep -q "^!$ca" /etc/ca-certificates.conf.dpkg-new; then
106                 :
107             else
108                 echo "!$ca" >> /etc/ca-certificates.conf.dpkg-new
109             fi
110           done
111           if cmp -s /etc/ca-certificates.conf /etc/ca-certificates.conf.dpkg-new; then
112             rm -f /etc/ca-certificates.conf.dpkg-new
113           else
114             mv -f /etc/ca-certificates.conf /etc/ca-certificates.conf.dpkg-old
115             mv /etc/ca-certificates.conf.dpkg-new /etc/ca-certificates.conf
116           fi
117         else
118           # new file
119           cat > /etc/ca-certificates.conf <<EOF
120 # This file lists certificates that you wish to use or to ignore to be
121 # installed in /etc/ssl/certs.
122 # update-ca-certificates(8) will update /etc/ssl/certs by reading this file.
123 #
124 # This is autogenerated by dpkg-reconfigure ca-certificates.
125 # Certificates should be installed under /usr/share/ca-certificates
126 # and files with extension '.crt' is recognized as available certs.
127 #
128 # line begins with # is comment.
129 # line begins with ! is certificate filename to be deselected.
130 #
131 EOF
132           (echo $CERTS_ENABLED | tr ',' '\n'; \
133            echo $CERTS_AVAILABLE | tr ',' '\n') | \
134             sed -e 's/^[[:space:]]*//' | \
135             sort | uniq -c | \
136             sed -e 's/^[[:space:]]*2[[:space:]]*//' \
137                 -e 's/^[[:space:]]*1[[:space:]]*/!/' \
138             >> /etc/ca-certificates.conf
139         fi
140         # fix bogus symlink to ca-certificates.crt on upgrades; see
141         # Debian #643667; drop after wheezy
142         if dpkg --compare-versions "$2" lt-nl 20110502+nmu2+643667; then
143             update-ca-certificates --fresh
144         else
145             update-ca-certificates
146         fi
147     ;;
148
149     abort-upgrade|abort-remove|abort-deconfigure)
150
151     ;;
152
153     *)
154         echo "postinst called with unknown argument \`$1'" >&2
155         exit 1
156     ;;
157 esac
158
159 # dh_installdeb will replace this with shell code automatically
160 # generated by other debhelper scripts.
161
162 #DEBHELPER#
163
164 exit 0
165
166