summaryrefslogtreecommitdiff
blob: 72a4ba1a6ddbd5167a997b3a73af8e16fb98e52a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
--- a/usr/sbin/update-ca-certificates
+++ b/usr/sbin/update-ca-certificates
@@ -23,6 +23,7 @@
 
 verbose=0
 fresh=0
+ROOT=""
 while [ $# -gt 0 ];
 do
   case $1 in
@@ -30,6 +31,9 @@
   	verbose=1;;
   --fresh|-f)
 	fresh=1;;
+  --root|-r)
+	ROOT=$(readlink -f "$2")
+	shift;;
   --help|-h|*)
-	echo "$0: [--verbose] [--fresh]"
+	echo "$0: [--verbose] [--fresh] [--root <dir>]"
 	exit;;
@@ -37,11 +41,11 @@
   shift
 done
 
-CERTSCONF=/etc/ca-certificates.conf
-CERTSDIR=/usr/share/ca-certificates
-LOCALCERTSDIR=/usr/local/share/ca-certificates
+CERTSCONF="$ROOT/etc/ca-certificates.conf"
+CERTSDIR="$ROOT/usr/share/ca-certificates"
+LOCALCERTSDIR="$ROOT/usr/local/share/ca-certificates"
 CERTBUNDLE=ca-certificates.crt
-ETCCERTSDIR=/etc/ssl/certs
+ETCCERTSDIR="$ROOT/etc/ssl/certs"
 
 cleanup() {
   rm -f "$TEMPBUNDLE"
@@ -66,7 +70,7 @@
                                                   -e 's/,/_/g').pem"
   if ! test -e "$PEM" || [ "$(readlink "$PEM")" != "$CERT" ]
   then
-    ln -sf "$CERT" "$PEM"
+    ln -sf "${CERT#$ROOT}" "$PEM"
     echo +$PEM >> "$ADDED"
   fi
   cat "$CERT" >> "$TEMPBUNDLE"
@@ -78,22 +82,22 @@
   if test -L "$PEM"
   then
     rm -f "$PEM"
-    echo -$PEM >> "$REMOVED"
+    echo "-$PEM" >> "$REMOVED"
   fi
 }
 
-cd $ETCCERTSDIR
+cd "$ETCCERTSDIR"
 if [ "$fresh" = 1 ]; then
   echo -n "Clearing symlinks in $ETCCERTSDIR..."
   find . -type l -print | while read symlink
   do
-     case $(readlink $symlink) in
-     $CERTSDIR*) rm -f $symlink;;
+     case $(readlink "$symlink") in
+     "$CERTSDIR"*) rm -f "$symlink";;
      esac
   done
   find . -type l -print | while read symlink
   do
-     test -f $symlink || rm -f $symlink
+     test -f "$symlink" || rm -f "$symlink"
   done
   echo "done."
 fi
@@ -102,12 +106,12 @@
 
 # Handle certificates that should be removed.  This is an explicit act
 # by prefixing lines in the configuration files with exclamation marks (!).
-sed -n -e '/^$/d' -e 's/^!//p' $CERTSCONF | while read crt
+sed -n -e '/^$/d' -e 's/^!//p' "$CERTSCONF" | while read crt
 do
   remove "$CERTSDIR/$crt"
 done
 
-sed -e '/^$/d' -e '/^#/d' -e '/^!/d' $CERTSCONF | while read crt
+sed -e '/^$/d' -e '/^#/d' -e '/^!/d' "$CERTSCONF" | while read crt
 do
   if ! test -f "$CERTSDIR/$crt"
   then
@@ -146,14 +150,14 @@
 
 echo "$ADDED_CNT added, $REMOVED_CNT removed; done."
 
-HOOKSDIR=/etc/ca-certificates/update.d
+HOOKSDIR="$ROOT/etc/ca-certificates/update.d"
 echo -n "Running hooks in $HOOKSDIR...."
 VERBOSE_ARG=
 [ "$verbose" = 0 ] || VERBOSE_ARG=--verbose
-eval run-parts $VERBOSE_ARG --test -- $HOOKSDIR | while read hook
+eval run-parts $VERBOSE_ARG --test -- \""$HOOKSDIR"\" | while read hook
 do
   ( cat $ADDED
-    cat $REMOVED ) | $hook || echo E: $hook exited with code $?.
+    cat $REMOVED ) | "$hook" || echo E: "$hook" exited with code $?.
 done
 echo "done."