1 | #!/bin/bash |
---|
2 | |
---|
3 | |
---|
4 | USER_NAME=$USER # User name |
---|
5 | USER_HOME="" # Home user folder |
---|
6 | FF_PROFILE_PATH="" # Absolute path to user firefox profile |
---|
7 | TH_PROFILE_PATH="" # Absolute path to user firefox profile |
---|
8 | LIBRARY="secmod.db" |
---|
9 | ROUTE_LIBRARY="/var/lib/nssdb" |
---|
10 | ROUTE_MOZILLA="/usr/lib/firefox/browser/defaults/profile/" |
---|
11 | ROUTE_THUNDERBIRD="/usr/lib/thunderbird/defaults/profile/" |
---|
12 | ACCV_FILES="/usr/share/accv-files" |
---|
13 | |
---|
14 | LIST_LIB_COMMON1="libccid pcscd libpcsclite1" |
---|
15 | LIST_LIB_COMMON2="libwxbase2.8-0 libwxgtk2.8-0" |
---|
16 | |
---|
17 | |
---|
18 | ACTION="$1" |
---|
19 | |
---|
20 | |
---|
21 | user_home(){ |
---|
22 | USER_HOME=$(getent passwd "$USER_NAME" | cut -d: -f 6) |
---|
23 | } |
---|
24 | |
---|
25 | |
---|
26 | make_link(){ |
---|
27 | |
---|
28 | #Preparo el sistema con la libreria original renombrada |
---|
29 | if [ -f "$ROUTE_LIBRARY/secmod_orig.db" ]; then |
---|
30 | cp $ACCV_FILES/secmod.db /var/lib/nssdb/secmod.db |
---|
31 | echo "$ROUTE_LIBRARY/secmod_orig.db exists in your system only make the COPY again." |
---|
32 | else |
---|
33 | mv $ROUTE_LIBRARY/$LIBRARY $ROUTE_LIBRARY/secmod_orig.db |
---|
34 | cp $ACCV_FILES/$LIBRARY $ROUTE_LIBRARY/$LIBRARY |
---|
35 | echo "$ROUTE_LIBRARY/secmod_orig.db don't exists in your system, make MOVE and COPY." |
---|
36 | fi |
---|
37 | |
---|
38 | |
---|
39 | # Compruebo si existe la libreria que necesito. |
---|
40 | if [ ! -e $ROUTE_MOZILLA$LIBRARY ]; then |
---|
41 | echo "Library for firefox don't exists in firefox default" |
---|
42 | |
---|
43 | #No existe la libreria compruebo que el directorio donde he de crear el enlace existe, sino lo creo. |
---|
44 | if [ ! -d $ROUTE_MOZILLA ]; then |
---|
45 | echo "Create directory in firefox for ln" |
---|
46 | mkdir -p $ROUTE_MOZILLA |
---|
47 | fi |
---|
48 | |
---|
49 | #Compruebo que existe la libreria de origen. |
---|
50 | if [ -e $ROUTE_LIBRARY/$LIBRARY ]; then |
---|
51 | echo "Make the ln from original file to mozilla firefox directory" |
---|
52 | ln -s $ROUTE_LIBRARY/$LIBRARY $ROUTE_MOZILLA$LIBRARY || echo " Link is not done: $ROUTE_MOZILLA$LIBRARY " |
---|
53 | |
---|
54 | else |
---|
55 | echo " * Warning : $ROUTE_LIBRARY/$LIBRARY not found in your system." |
---|
56 | echo "Abort installation">> $ACCV_LOG |
---|
57 | exit 1 |
---|
58 | fi |
---|
59 | else |
---|
60 | echo "Mozilla FIREFOX default preseed has the link" |
---|
61 | fi |
---|
62 | echo "Link for library has created in $ROUTE_MOZILLA$LIBRARY" |
---|
63 | |
---|
64 | # Compruebo si existe la libreria que necesito. |
---|
65 | if [ ! -e $ROUTE_THUNDERBIRD$LIBRARY ]; then |
---|
66 | echo "Library don't exists in thunderbird default" |
---|
67 | |
---|
68 | #No existe la libreria compruebo que el directorio donde he de crear el enlace existe, sino lo creo. |
---|
69 | if [ ! -d $ROUTE_THUNDERBIRD ]; then |
---|
70 | echo "Create thunderbird directory for ln" |
---|
71 | mkdir -p $ROUTE_THUNDERBIRD |
---|
72 | fi |
---|
73 | |
---|
74 | #Compruebo que existe la libreria de origen. |
---|
75 | if [ -e $ROUTE_LIBRARY/$LIBRARY ]; then |
---|
76 | echo "Make the ln from original file to thunderbird directory" |
---|
77 | ln -s $ROUTE_LIBRARY/$LIBRARY $ROUTE_THUNDERBIRD$LIBRARY || echo " Link is not done: $ROUTE_THUNDERBIRD$LIBRARY " |
---|
78 | |
---|
79 | else |
---|
80 | echo " * Warning : $ROUTE_LIBRARY/$LIBRARY not found in your system." |
---|
81 | echo "Abort installation" |
---|
82 | exit 1 |
---|
83 | fi |
---|
84 | else |
---|
85 | echo "Mozilla THUNDERBIRD default preseed has the link" |
---|
86 | fi |
---|
87 | echo "Link for THUNDERBIRD library has created in $ROUTE_MOZILLA$LIBRARY" |
---|
88 | |
---|
89 | |
---|
90 | } |
---|
91 | |
---|
92 | test_installed_package(){ |
---|
93 | |
---|
94 | TEST=$( dpkg-query -s $1 2> /dev/null| grep Status | cut -d " " -f 4 ) |
---|
95 | if [ "$TEST" == 'installed' ]; then |
---|
96 | return 0 |
---|
97 | else |
---|
98 | return 1 |
---|
99 | fi |
---|
100 | } |
---|
101 | |
---|
102 | test_running_firefox(){ |
---|
103 | |
---|
104 | is_running=$(ps -aux | grep /usr/lib/firefox/firefox | grep -v grep | wc -l) |
---|
105 | if [ $is_running -gt 0 ]; then |
---|
106 | while [ $is_running -gt 0 ] ; do |
---|
107 | echo "Firefox is running. Stop it!..." |
---|
108 | is_running=$(ps -aux | grep /usr/lib/firefox/firefox | grep -v grep | wc -l) |
---|
109 | done |
---|
110 | fi |
---|
111 | return 0 |
---|
112 | } |
---|
113 | |
---|
114 | test_running_thunderbird(){ |
---|
115 | |
---|
116 | is_running=$(ps -fe | grep thunderbird | grep -v grep | wc -l) |
---|
117 | if [ $is_running -gt 0 ]; then |
---|
118 | while [ $is_running -gt 0 ] ; do |
---|
119 | echo "Thunderbird is running. Stop it!" |
---|
120 | is_running=$(ps -fe | grep thunderbird | grep -v grep | wc -l) |
---|
121 | done |
---|
122 | fi |
---|
123 | return 0 |
---|
124 | } |
---|
125 | |
---|
126 | get_firefox_default_profile(){ |
---|
127 | |
---|
128 | # Getting Mozilla products default profile |
---|
129 | # http://kb.mozillazine.org/Profiles.ini_file |
---|
130 | # |
---|
131 | # Get default profile info |
---|
132 | # This script must be capable of dealing with multiple profiles |
---|
133 | # and relative or absolute paths, for now ... buff!! |
---|
134 | # |
---|
135 | # This script get Default path profile if Default=1 or |
---|
136 | # get first profile in other case |
---|
137 | |
---|
138 | TMP_FILE=$(mktemp) |
---|
139 | cat $FF_PATH/profiles.ini | awk -F ' *= *' '{ if ($1 ~ /^\[/) section=$1; else if ($1 !~ /^$/) print $1 section "=" "\"" $2 "\"" }' > $TMP_FILE |
---|
140 | DEFAULT_EXISTS=$(grep ^Default $TMP_FILE) |
---|
141 | if [ -n $DEFAULT_EXISTS ]; then |
---|
142 | PROFILE_ID=$(cat $TMP_FILE | grep -m 1 Profile[0-9] | cut -d"[" -f 2 | cut -d"]" -f 1 ) |
---|
143 | else |
---|
144 | PROFILE_ID=$(echo $DEFAULT_EXISTS | grep -m 1 Profile[0-9] | cut -d"[" -f 2 | cut -d"]" -f 1 ) |
---|
145 | fi |
---|
146 | IS_RELATIVE=$(cat $TMP_FILE | grep $PROFILE_ID | grep ^IsRelative | cut -d"=" -f 2 | sed -e 's/\"//g') |
---|
147 | TMP_PATH=$(cat $TMP_FILE | grep $PROFILE_ID | grep ^Path | cut -d"=" -f 2 | sed -e 's/\"//g') |
---|
148 | if [ $IS_RELATIVE = "0" ]; then |
---|
149 | FF_PROFILE_PATH=$TMP_PATH |
---|
150 | else |
---|
151 | FF_PROFILE_PATH=$FF_PATH/$TMP_PATH |
---|
152 | fi |
---|
153 | rm -f $TMP_FILE |
---|
154 | } |
---|
155 | |
---|
156 | |
---|
157 | get_thunderbird_default_profile(){ |
---|
158 | |
---|
159 | # Getting Mozilla products default profile |
---|
160 | # http://kb.mozillazine.org/Profiles.ini_file |
---|
161 | # |
---|
162 | # Get default profile info |
---|
163 | # This script must be capable of dealing with multiple profiles |
---|
164 | # and relative or absolute paths, for now ... buff!! |
---|
165 | # |
---|
166 | # This script get Default path profile if Default=1 or |
---|
167 | # get first profile in other case |
---|
168 | |
---|
169 | TMP_FILE=$(mktemp) |
---|
170 | cat $TH_PATH/profiles.ini | awk -F ' *= *' '{ if ($1 ~ /^\[/) section=$1; else if ($1 !~ /^$/) print $1 section "=" "\"" $2 "\"" }' > $TMP_FILE |
---|
171 | DEFAULT_EXISTS=$(grep ^Default $TMP_FILE) |
---|
172 | if [ -n $DEFAULT_EXISTS ]; then |
---|
173 | PROFILE_ID=$(cat $TMP_FILE | grep -m 1 Profile[0-9] | cut -d"[" -f 2 | cut -d"]" -f 1 ) |
---|
174 | else |
---|
175 | PROFILE_ID=$(echo $DEFAULT_EXISTS | grep -m 1 Profile[0-9] | cut -d"[" -f 2 | cut -d"]" -f 1 ) |
---|
176 | fi |
---|
177 | IS_RELATIVE=$(cat $TMP_FILE | grep $PROFILE_ID | grep ^IsRelative | cut -d"=" -f 2 | sed -e 's/\"//g') |
---|
178 | TMP_PATH=$(cat $TMP_FILE | grep $PROFILE_ID | grep ^Path | cut -d"=" -f 2 | sed -e 's/\"//g') |
---|
179 | if [ $IS_RELATIVE = "0" ]; then |
---|
180 | TH_PROFILE_PATH=$TMP_PATH |
---|
181 | else |
---|
182 | TH_PROFILE_PATH=$TH_PATH/$TMP_PATH |
---|
183 | fi |
---|
184 | rm -f $TMP_FILE |
---|
185 | } |
---|
186 | |
---|
187 | |
---|
188 | remove_accv_module_firefox(){ |
---|
189 | |
---|
190 | |
---|
191 | if [ -f $FF_PROFILE_PATH/$LIBRARY ]; then |
---|
192 | echo "Removing ACCV modules in Firefox..." |
---|
193 | rm $FF_PROFILE_PATH/$LIBRARY |
---|
194 | fi |
---|
195 | } |
---|
196 | |
---|
197 | remove_accv_module_thunderbird(){ |
---|
198 | |
---|
199 | if [ -f $TH_PROFILE_PATH/$LIBRARY ]; then |
---|
200 | echo "Removing ACCV modules in Thunderbird..." |
---|
201 | rm $TH_PROFILE_PATH/$LIBRARY |
---|
202 | fi |
---|
203 | } |
---|
204 | |
---|
205 | |
---|
206 | enable_accv_module_firefox(){ |
---|
207 | |
---|
208 | echo "Enabling ACCV modules in Firefox..." |
---|
209 | su $USER -c "ln -s $ROUTE_LIBRARY/$LIBRARY $FF_PROFILE_PATH" |
---|
210 | } |
---|
211 | |
---|
212 | |
---|
213 | enable_accv_module_thunderbird(){ |
---|
214 | |
---|
215 | echo "Enabling ACCV modules in Thunderbid..." |
---|
216 | su $USER -c "ln -s $ROUTE_LIBRARY/$LIBRARY $TH_PROFILE_PATH" |
---|
217 | |
---|
218 | } |
---|
219 | |
---|
220 | |
---|
221 | test_firefox_user_profile() { |
---|
222 | |
---|
223 | if [ -d $FF_PATH ]; then |
---|
224 | get_firefox_default_profile |
---|
225 | if [ ! -d $FF_PROFILE_PATH ]; then |
---|
226 | echo "Error: Some problem with firefox profile" |
---|
227 | return 1 |
---|
228 | fi |
---|
229 | return 0 |
---|
230 | else |
---|
231 | echo "Creating Firefox profile. Now it will be launched, then please close Firefox and installation continues" |
---|
232 | |
---|
233 | su $USER -c "firefox" |
---|
234 | test_running_firefox |
---|
235 | get_firefox_default_profile |
---|
236 | return 0 |
---|
237 | fi |
---|
238 | |
---|
239 | } |
---|
240 | |
---|
241 | test_thunderbird_user_profile() { |
---|
242 | |
---|
243 | if [ -d $TH_PATH ]; then |
---|
244 | get_thunderbird_default_profile |
---|
245 | if [ ! -d $TH_PROFILE_PATH ]; then |
---|
246 | echo "Error: some problem with thunderbird profile" |
---|
247 | return 1 |
---|
248 | fi |
---|
249 | return 0 |
---|
250 | else |
---|
251 | echo "Creating Thunderbird profile. Now it will be launched, then please close Thunderbird and installation continues" |
---|
252 | su $USER -c "thunderbird" |
---|
253 | test_running_thunderbird |
---|
254 | get_thunderbird_default_profile |
---|
255 | return 0 |
---|
256 | fi |
---|
257 | |
---|
258 | } |
---|
259 | |
---|
260 | do_firefox(){ |
---|
261 | |
---|
262 | test_installed_package firefox |
---|
263 | TESTED=$? |
---|
264 | if [ "$TESTED" == "0" ] ; then |
---|
265 | test_running_firefox |
---|
266 | if [ $? -gt 0 ]; then |
---|
267 | echo "Firefox is running. Stop it!..." |
---|
268 | exit 2 |
---|
269 | else |
---|
270 | test_firefox_user_profile |
---|
271 | if [ $? == 0 ]; then |
---|
272 | remove_accv_module_firefox |
---|
273 | enable_accv_module_firefox |
---|
274 | else |
---|
275 | echo "Configuration of the ACCV module in Firefox has failed" |
---|
276 | exit 1 |
---|
277 | fi |
---|
278 | fi |
---|
279 | else |
---|
280 | echo "Firefox is not installed" |
---|
281 | exit 1 |
---|
282 | fi |
---|
283 | } |
---|
284 | |
---|
285 | |
---|
286 | |
---|
287 | do_thunderbird(){ |
---|
288 | |
---|
289 | test_installed_package thunderbird |
---|
290 | TESTED=$? |
---|
291 | if [ "$TESTED" == "0" ] ; then |
---|
292 | test_running_thunderbird |
---|
293 | if [ $? -gt 0 ]; then |
---|
294 | echo "Thunderbird is running. Stop it!" |
---|
295 | exit 2 |
---|
296 | else |
---|
297 | test_thunderbird_user_profile |
---|
298 | if [ $? == 0 ]; then |
---|
299 | remove_accv_module_thunderbird |
---|
300 | enable_accv_module_thunderbird |
---|
301 | else |
---|
302 | echo "Configuration of the ACCV module in Thunderbird has failed" |
---|
303 | exit 1 |
---|
304 | fi |
---|
305 | fi |
---|
306 | else |
---|
307 | |
---|
308 | echo "Thunderbird is not installed" |
---|
309 | exit 1 |
---|
310 | fi |
---|
311 | } |
---|
312 | |
---|
313 | |
---|
314 | case $ACTION in |
---|
315 | |
---|
316 | preInstall) |
---|
317 | |
---|
318 | for ix in $LIST_LIB_COMMON1 |
---|
319 | do |
---|
320 | apt-get install -y $ix |
---|
321 | |
---|
322 | if ! [ $? -eq 0 ];then |
---|
323 | exit 1 |
---|
324 | fi |
---|
325 | done |
---|
326 | |
---|
327 | if [[ $(arch) == "x86" ]];then |
---|
328 | apt-get install -y libtiff4 |
---|
329 | if ! [ $? -eq 0 ];then |
---|
330 | exit 1 |
---|
331 | fi |
---|
332 | fi |
---|
333 | |
---|
334 | for ix in $LIST_LIB_COMMON2 |
---|
335 | do |
---|
336 | apt-get install -y $ix |
---|
337 | |
---|
338 | if ! [ $? -eq 0 ];then |
---|
339 | exit 1 |
---|
340 | fi |
---|
341 | done |
---|
342 | |
---|
343 | ;; |
---|
344 | |
---|
345 | postInstall) |
---|
346 | |
---|
347 | user_home |
---|
348 | echo "Configuring Safesign..." |
---|
349 | [ -d $USER_HOME/.safesign ] || su - $USER -c "mkdir ~/.safesign" |
---|
350 | su - $USER -c "cp $ACCV_FILES/registry ~/.safesign" |
---|
351 | |
---|
352 | make_link |
---|
353 | sleep 1 |
---|
354 | echo "Configuring ACCV modules in Firefox..." |
---|
355 | FF_MODULE_NAME="ACCV_GYD_PKCS_11" |
---|
356 | FF_PATH="$USER_HOME/.mozilla/firefox" |
---|
357 | do_firefox |
---|
358 | echo "Configuring ACCV modules in Thunderbird..." |
---|
359 | TH_MODULE_NAME="ACCV_GYD_PKCS_11" |
---|
360 | TH_PATH="$USER_HOME/.thunderbird" |
---|
361 | do_thunderbird |
---|
362 | echo "ACCV module configuration completed successfully" |
---|
363 | |
---|
364 | ;; |
---|
365 | |
---|
366 | esac |
---|
367 | exit 0 |
---|