]> git.donarmstrong.com Git - ca-certificates.git/blob - sbin/update-ca-certificates
Applied a patch by Martin F. Krafft to support hooks scripts. (Closes: #377314)
[ca-certificates.git] / sbin / update-ca-certificates
1 #!/bin/sh -e
2 #
3 # update-ca-certificates
4 #
5 # Copyright (c) 2003 Fumitoshi UKAI <ukai@debian.or.jp>
6
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20 #
21
22 verbose=0
23 fresh=0
24 while [ $# -gt 0 ];
25 do
26   case $1 in
27   --verbose|-v)
28         verbose=1;;
29   --fresh|-f)
30         fresh=1;;
31   --help|-h|*)
32         echo "$0: [--verbose] [--fresh]"
33         exit;;
34   esac
35   shift
36 done
37
38 CERTSCONF=/etc/ca-certificates.conf
39 CERTSDIR=/usr/share/ca-certificates
40 CERTBUNDLE=ca-certificates.crt
41 ETCCERTSDIR=/etc/ssl/certs
42 cd $ETCCERTSDIR
43 if [ "$fresh" = 1 ]; then
44   echo -n "Clearing symlinks in $ETCCERTSDIR..."
45   find . -type l -print | while read symlink
46   do
47      case $(readlink $symlink) in
48      $CERTSDIR*) rm -f $symlink;;
49      esac
50   done
51   find . -type l -print | while read symlink
52   do
53      test -f $symlink || rm -f $symlink
54   done
55   echo "done."
56 fi
57 echo -n "Updating certificates in $ETCCERTSDIR...."
58
59 bundletmp=`mktemp "${CERTBUNDLE}.tmp.XXXXXX"`
60 removed="$(sed -ne 's/^!//p' $CERTSCONF | while read crt
61 do
62  if test "$crt" = ""; then continue; fi
63  pem=$(basename "$crt" .crt).pem
64  if test -e "$pem"; then
65   rm -f "$pem"
66   echo "-$ETCCERTSDIR/$pem"
67  fi
68 done)"
69
70 added="$(sed -e '/^#/d' -e '/^!/d' $CERTSCONF | while read crt
71 do
72  if test "$crt" = ""; then continue; fi
73  if ! test -f "$CERTSDIR/$crt"; then continue; fi
74  pem=$(basename "$crt" .crt).pem
75  if ! test -e "$pem"; then echo "+$ETCCERTSDIR/$pem"; fi
76  ln -sf "$CERTSDIR/$crt" "$pem"
77  cat "$CERTSDIR/$crt" >> "$bundletmp"
78 done)"
79 chmod 0644 "$bundletmp"
80 mv -f "$bundletmp" "$CERTBUNDLE"
81
82 if [ -n "$added" ] || [ -n "$removed" ]; then
83   # only run if set of files has changed
84
85   if [ "$verbose" = 0 ]; then
86     c_rehash . > /dev/null 2>&1
87   else
88     c_rehash .
89   fi
90   echo "done."
91
92   HOOKSDIR=/etc/ca-certificates/update.d
93   echo -n "Running hooks in $HOOKSDIR...."
94   VERBOSE_ARG=
95   [ "$verbose" = 0 ] || VERBOSE_ARG=--verbose
96   eval run-parts $VERB_ARG --test -- $HOOKSDIR | while read hook; do
97   printf -- "${removed:+$removed\n}${added:+$added\n}" | eval $hook
98   done
99   echo "done."
100 else
101   echo "done."
102 fi