source: zero-lliurex-dni/trunk/fuentes/zero-lliurex-dni.zlaunchers/zero-lliurex-accv.zmd @ 1858

Last change on this file since 1858 was 1858, checked in by daduve, 5 years ago

Changing script for accv

File size: 15.5 KB
Line 
1#!/bin/bash
2
3#set -x
4
5## Global Variables
6###################
7
8
9USER_NAME=$USER # User name
10USER_HOME="" # Home user folder
11FF_PROFILE_PATH="" # Absolute path to user firefox profile
12TH_PROFILE_PATH="" # Absolute path to user firefox profile
13LIBRARY="secmod.db"
14ROUTE_LIBRARY="/var/lib/nssdb"
15ROUTE_MOZILLA="/usr/lib/firefox/browser/defaults/profile/"
16ROUTE_THUNDERBIRD="/usr/lib/thunderbird/defaults/profile/"
17ACCV_FILES="/usr/share/accv-files"
18ERROR=0
19ACCV_LOG="/tmp/accv.log"
20ACCV_ERROR="/tmp/.accv_error.log"
21
22export TEXTDOMAIN="zero-lliurex-accv"
23
24# MSGS
25MSG_LIBRARY_NOT_FOUND="$(gettext 'Library not found:')"
26MSG_SOME_PROBLEM_FIREFOX="$(gettext 'Some problem with firefox profile')"
27MSG_ONCE_FIREFOX="$(gettext 'Start firefox once at least')"
28MSG_SOME_PROBLEM_THUNDER="$(gettext 'Some problem with Thunderbird profile')"
29MSG_ONCE_THUNDER="$(gettext 'Start Thunderbird once at least')"
30MSG_RUNNING_FIREFOX="$(gettext 'Firefox is running. Stop it!')"
31MSG_RUNNING_THUNDER="$(gettext 'Thunderbird is running. Stop it!')"
32MSG_NOT_FIREFOX="$(gettext 'Firefox is not installed')"
33MSG_NOT_THUNDER="$(gettext 'Thunderbird is not installed')"
34MSG_INSTALLING_ACCV_PROGRESS="$(gettext 'Installing ACCV in your computer...')"
35MSG_ZENITY_ACCV_FIREFOX_1="$(gettext 'Installing ACCV modules in your system')"
36MSG_ZENITY_ACCV_FIREFOX_2="$(gettext 'ACCV modules in Firefox')"
37MSG_ZENITY_ACCV_THUNDER_1="$(gettext 'ACCV modules in Thunderbird')"
38MSG_FINAL_ACCV_ERROR="$(gettext 'Impossible to install ACCV module, correct the problems and execute this program again please.')"
39MSG_FINAL_ACCV_OK="$(gettext 'ACCV modules are installed with success in Firefox and Thunderbird profile, for others users you have to execute this action again on each session.')"
40MSG_CREATING_THUNDER="$(gettext 'We have to create your Thundebird profile, now it will be launched, please close thunderbird and installation continues')"
41MSG_CREATING_FIREFOX="$(gettext 'We have to create your Firefox profile, now it will be launched, then please close Firefox and installation continues')"
42
43
44
45
46
47
48
49
50
51user_home(){
52   
53   USER_HOME=$(getent passwd "$USER_NAME" | cut -d: -f 6)
54   echo "My USER_HOME is: $USER_HOME" >> $ACCV_LOG
55}
56
57test_running_firefox(){
58
59   is_running=$(ps -aux | grep /usr/lib/firefox/firefox | grep -v grep | wc -l)
60        if [ $is_running -gt 0 ]; then
61                while [ $is_running -gt 0 ] ; do 
62                        zenity --info --text="$MSG_RUNNING_FIREFOX"
63                        is_running=$(ps -aux | grep /usr/lib/firefox/firefox | grep -v grep | wc -l)
64                done
65        fi
66        return 0
67}
68
69test_running_thunderbird(){
70
71   is_running=$(ps -fe | grep thunderbird | grep -v grep | wc -l)
72        if [ $is_running -gt 0 ]; then
73                while [ $is_running -gt 0 ] ; do 
74                        zenity --info --text="$MSG_RUNNING_THUNDER"
75                        is_running=$(ps -fe | grep thunderbird | grep -v grep | wc -l)
76                done
77        fi
78        return 0
79}
80
81test_installed_package(){
82
83   TEST=$( dpkg-query -s $1 2> /dev/null| grep Status | cut -d " " -f 4 )
84        if [ "$TEST" == 'installed' ]; then
85                ERROR=0
86                echo "$ERROR $1 is installed in your system" > $ACCV_ERROR
87                return 0
88        else
89                ERROR=1
90                echo "$ERROR test_installed_package" > $ACCV_ERROR
91                return 1       
92        fi
93}
94
95
96
97## Firefox functions
98####################
99
100get_firefox_default_profile(){
101   
102   # Getting Mozilla products default profile
103   # http://kb.mozillazine.org/Profiles.ini_file
104   #
105   # Get default profile info
106   # This script must be capable of dealing with multiple profiles
107   # and relative or absolute paths, for now ... buff!!
108   #
109   # This script get Default path profile if Default=1 or
110   # get first profile in other case
111 
112   TMP_FILE=$(mktemp)
113   cat $FF_PATH/profiles.ini | awk -F ' *= *' '{ if ($1 ~ /^\[/) section=$1; else if ($1 !~ /^$/) print $1 section "=" "\"" $2 "\"" }' > $TMP_FILE
114   DEFAULT_EXISTS=$(grep ^Default $TMP_FILE)
115   if [ -n $DEFAULT_EXISTS ]; then
116        PROFILE_ID=$(cat $TMP_FILE | grep -m 1 Profile[0-9] | cut -d"[" -f 2 | cut -d"]" -f 1 )
117   else
118        PROFILE_ID=$(echo $DEFAULT_EXISTS | grep -m 1 Profile[0-9] | cut -d"[" -f 2 | cut -d"]" -f 1 )
119   fi
120   IS_RELATIVE=$(cat $TMP_FILE | grep $PROFILE_ID | grep ^IsRelative | cut -d"=" -f 2 | sed -e 's/\"//g')
121   TMP_PATH=$(cat $TMP_FILE | grep $PROFILE_ID | grep ^Path | cut -d"=" -f 2 | sed -e 's/\"//g')
122   if [ $IS_RELATIVE = "0" ]; then
123      FF_PROFILE_PATH=$TMP_PATH
124   else
125      FF_PROFILE_PATH=$FF_PATH/$TMP_PATH
126   fi
127   echo "My Firefox Profile is $FF_PROFILE_PATH" >> $ACCV_LOG
128   rm -f $TMP_FILE
129}
130
131
132
133## Thunderbird functions
134####################
135
136get_thunderbird_default_profile(){
137   
138   # Getting Mozilla products default profile
139   # http://kb.mozillazine.org/Profiles.ini_file
140   #
141   # Get default profile info
142   # This script must be capable of dealing with multiple profiles
143   # and relative or absolute paths, for now ... buff!!
144   #
145   # This script get Default path profile if Default=1 or
146   # get first profile in other case
147 
148   TMP_FILE=$(mktemp)
149   cat $TH_PATH/profiles.ini | awk -F ' *= *' '{ if ($1 ~ /^\[/) section=$1; else if ($1 !~ /^$/) print $1 section "=" "\"" $2 "\"" }' > $TMP_FILE
150   DEFAULT_EXISTS=$(grep ^Default $TMP_FILE)
151   if [ -n $DEFAULT_EXISTS ]; then
152        PROFILE_ID=$(cat $TMP_FILE | grep -m 1 Profile[0-9] | cut -d"[" -f 2 | cut -d"]" -f 1 )
153   else
154        PROFILE_ID=$(echo $DEFAULT_EXISTS | grep -m 1 Profile[0-9] | cut -d"[" -f 2 | cut -d"]" -f 1 )
155   fi
156   IS_RELATIVE=$(cat $TMP_FILE | grep $PROFILE_ID | grep ^IsRelative | cut -d"=" -f 2 | sed -e 's/\"//g')
157   TMP_PATH=$(cat $TMP_FILE | grep $PROFILE_ID | grep ^Path | cut -d"=" -f 2 | sed -e 's/\"//g')
158   if [ $IS_RELATIVE = "0" ]; then
159      TH_PROFILE_PATH=$TMP_PATH
160   else
161      TH_PROFILE_PATH=$TH_PATH/$TMP_PATH
162   fi
163   echo "My Thunderbird Profile is $TH_PROFILE_PATH" >> $ACCV_LOG
164   rm -f $TMP_FILE
165}
166
167test_firefox_user_profile() {
168
169   if [ -d $FF_PATH ]; then
170        get_firefox_default_profile
171        if [ ! -d $FF_PROFILE_PATH ]; then
172                zenity --info --text="$MSG_SOME_PROBLEM_FIREFOX"
173                return 1
174        fi
175        ERROR=0
176        echo "$ERROR firefox_user_profile" > $ACCV_ERROR
177        return 0
178   else
179      zenity --info --text="$MSG_CREATING_FIREFOX"
180      echo "$MSG_CREATING_FIREFOX" >> $ACCV_LOG
181        su $USER -c "firefox"
182        test_running_firefox
183        get_firefox_default_profile
184        return 0
185   fi
186       
187}
188
189test_thunderbird_user_profile() {
190
191   if [ -d $TH_PATH ]; then
192        get_thunderbird_default_profile
193        if [ ! -d $TH_PROFILE_PATH ]; then
194                zenity --info --text="$MSG_SOME_PROBLEM_THUNDER"
195                return 1
196        fi
197        ERROR=0
198        echo "$ERROR thunderbird user profile" > $ACCV_ERROR
199        return 0
200   else
201        zenity --info --text="$MSG_CREATING_THUNDER"
202        echo "$MSG_CREATING_THUNDER" >> $ACCV_LOG
203        su $USER -c "thunderbird"
204        test_running_thunderbird
205        get_thunderbird_default_profile
206        return 0
207   fi
208       
209}
210
211
212remove_accv_module_firefox(){
213
214   #su $USER -c "modutil -disable $FF_MODULE_NAME -force -dbdir $FF_PROFILE_PATH 2>&1"
215   #su $USER -c "modutil -delete $FF_MODULE_NAME -force -dbdir $FF_PROFILE_PATH 2>&1"
216        if [ -f $FF_PROFILE_PATH/$LIBRARY ]; then
217                rm $FF_PROFILE_PATH/$LIBRARY>> $ACCV_LOG
218                echo "Deleting obsolete library in firefox home $FF_PROFILE_PATH/secmod.db" >> $ACCV_LOG
219        fi
220}
221
222remove_accv_module_thunderbird(){
223
224        if [ -f $TH_PROFILE_PATH/$LIBRARY ]; then
225                rm $TH_PROFILE_PATH/$LIBRARY>> $ACCV_LOG
226                echo "Deleting obsolete library in thunderbird home $TH_PROFILE_PATH/secmod.db" >> $ACCV_LOG
227        fi
228}
229
230enable_accv_module_firefox(){
231
232   #su $USER -c "modutil -add $FF_MODULE_NAME -force -libfile $LIBRARY -dbdir $FF_PROFILE_PATH 2>&1"
233   #su $USER -c "modutil -enable $FF_MODULE_NAME -force -dbdir $FF_PROFILE_PATH 2>&1"
234        su $USER -c "ln -s $ROUTE_LIBRARY/$LIBRARY $FF_PROFILE_PATH" >> $ACCV_LOG
235        echo "Creating link to firefox home, from $ROUTE_LIBRARY/$LIBRARY to $FF_PROFILE_PATH/secmod.db" >> $ACCV_LOG
236               
237}
238
239enable_accv_module_thunderbird(){
240
241        su $USER -c "ln -s $ROUTE_LIBRARY/$LIBRARY $TH_PROFILE_PATH" >> $ACCV_LOG
242        echo "Creating link to thunderbird home, from $ROUTE_LIBRARY/$LIBRARY to $TH_PROFILE_PATH/secmod.db" >> $ACCV_LOG
243}
244
245do_firefox(){
246
247   test_installed_package firefox
248   #rgrep 0 $ACCV_ERROR
249   TESTED=$?
250   if [ "$TESTED" == "0" ] ; then
251        test_running_firefox
252        if [ $? -gt 0 ]; then
253                zenity --info --text="$MSG_RUNNING_FIREFOX"
254                ERROR=1
255                echo "$ERROR do_firefox" > $ACCV_ERROR
256                exit 2
257        else
258                test_firefox_user_profile
259                if [ $? == 0 ]; then
260                        echo "---> PERFIL DE FIREFOX CONOCIDO CONTINUAMOS <---" >> $ACCV_LOG
261                        remove_accv_module_firefox
262                        enable_accv_module_firefox
263                fi
264        fi
265   else
266      zenity --info --text="$MSG_NOT_FIREFOX"
267      ERROR=1
268        echo "$ERROR do_firefox_else" > $ACCV_ERROR
269        echo "*** $MSG_NOT_FIREFOX ***" >> $ACCV_LOG
270      exit 1
271   fi
272}
273
274do_thunderbird(){
275
276   test_installed_package thunderbird
277   TESTED=$?
278   if [ "$TESTED" == "0" ] ; then
279        test_running_thunderbird
280        if [ $? -gt 0 ]; then
281                zenity --info --text="$MSG_RUNNING_THUNDER"
282                 ERROR=1
283                echo "$ERROR do_thunderbird" > $ACCV_ERROR
284                exit 2
285        else
286                test_thunderbird_user_profile
287                if [ $? == 0 ]; then
288                        echo "---> PERFIL DE THUNDERBIRD CONOCIDO CONTINUAMOS <---" >> $ACCV_LOG
289                        remove_accv_module_thunderbird
290                        enable_accv_module_thunderbird
291                fi
292        fi
293   else
294      zenity --info --text="$MSG_NOT_THUNDER"
295      ERROR=1
296      echo "$ERROR do_thunderbird_else" > $ACCV_ERROR
297      echo "*** $MSG_NOT_THUNDER ***" >> $ACCV_LOG
298      exit 1
299   fi
300}
301
302
303make_link(){
304
305        #Preparo el sistema con la libreria original renombrada
306        if [ -f  "$ROUTE_LIBRARY/secmod_orig.db" ]; then
307                cp $ACCV_FILES/secmod.db /var/lib/nssdb/secmod.db
308                echo "$ROUTE_LIBRARY/secmod_orig.db exists in your system only make the COPY again." >> $ACCV_LOG
309        else 
310                mv $ROUTE_LIBRARY/$LIBRARY $ROUTE_LIBRARY/secmod_orig.db
311                cp $ACCV_FILES/$LIBRARY $ROUTE_LIBRARY/$LIBRARY
312                echo "$ROUTE_LIBRARY/secmod_orig.db don't exists in your system, make MOVE and COPY." >> $ACCV_LOG
313        fi
314               
315       
316        # Compruebo si existe la libreria que necesito.
317        if [ ! -e $ROUTE_MOZILLA$LIBRARY ]; then
318                echo "Library for firefox don't exists in firefox default">> $ACCV_LOG
319               
320                #No existe la libreria compruebo que el directorio donde he de crear el enlace existe, sino lo creo.
321                if [ ! -d $ROUTE_MOZILLA ]; then
322                        echo "Create directory in firefox for ln">> $ACCV_LOG
323                        mkdir -p  $ROUTE_MOZILLA
324                fi
325               
326                #Compruebo que existe la libreria de origen.
327                if [ -e $ROUTE_LIBRARY/$LIBRARY ]; then
328                echo "Make the ln from original file to mozilla firefox directory">> $ACCV_LOG
329                        ln -s $ROUTE_LIBRARY/$LIBRARY $ROUTE_MOZILLA$LIBRARY || echo " Link is not done: $ROUTE_MOZILLA$LIBRARY " >> $ACCV_LOG
330       
331                else
332                        echo " * Warning :  $ROUTE_LIBRARY/$LIBRARY     not found in your system.">> $ACCV_LOG
333                        echo "">> $ACCV_LOG
334                        echo "Abort installation">> $ACCV_LOG
335                        zenity --error --text="Impossible to create ln with $ROUTE_LIBRARY/$LIBRARY because is not in your system. $MSG_FINAL_ACCV_ERROR" 
336                        exit 1
337                fi
338        else 
339                echo "Mozilla FIREFOX default preseed has the link" >> $ACCV_LOG
340        fi
341        echo "Link for library has created in $ROUTE_MOZILLA$LIBRARY" >> $ACCV_LOG
342       
343        # Compruebo si existe la libreria que necesito.
344        if [ ! -e $ROUTE_THUNDERBIRD$LIBRARY ]; then
345                echo "Library don't exists in thunderbird default">> $ACCV_LOG
346               
347                #No existe la libreria compruebo que el directorio donde he de crear el enlace existe, sino lo creo.
348                if [ ! -d $ROUTE_THUNDERBIRD ]; then
349                        echo "Create thunderbird directory for ln">> $ACCV_LOG
350                        mkdir -p  $ROUTE_THUNDERBIRD
351                fi
352               
353                #Compruebo que existe la libreria de origen.
354                if [ -e $ROUTE_LIBRARY/$LIBRARY ]; then
355                echo "Make the ln from original file to thunderbird directory">> $ACCV_LOG
356                        ln -s $ROUTE_LIBRARY/$LIBRARY $ROUTE_THUNDERBIRD$LIBRARY || echo " Link is not done: $ROUTE_THUNDERBIRD$LIBRARY " >> $ACCV_LOG
357       
358                else
359                        echo " * Warning :  $ROUTE_LIBRARY/$LIBRARY     not found in your system.">> $ACCV_LOG
360                        echo "">> $ACCV_LOG
361                        echo "Abort installation">> $ACCV_LOG
362                        zenity --error --text="Impossible to create ln with $ROUTE_LIBRARY/$LIBRARY because is not in your system. $MSG_FINAL_ACCV_ERROR" 
363                        exit 1
364                fi
365        else 
366                echo "Mozilla THUNDERBIRD default preseed has the link" >> $ACCV_LOG
367        fi
368        echo "Link for THUNDERBIRD library has created in $ROUTE_MOZILLA$LIBRARY" >> $ACC
369       
370
371}
372
373
374#funcion de error en caso de no poder instalar un deb
375check_install(){
376        if [ $1 != 0 ] ; then 
377                zenity --error --text="Impossible to install $2, problems with repos. $MSG_FINAL_ACCV_ERROR" 
378                ERROR=1
379                echo "$ERROR check_install" > $ACCV_ERROR
380                exit 1
381        fi
382}
383
384#############################################
385##############MAIN PROGRAM####################
386#############################################
387
388#####################################################
389echo "#####################################################" >> $ACCV_LOG
390echo "Start smartcard installation at "`date` > $ACCV_LOG
391echo "#####################################################" >> $ACCV_LOG
392echo " " >> $ACCV_LOG
393ERROR=0
394echo "$ERROR inicializacion" > $ACCV_ERROR
395USER_HOME=$(pwd)
396USER=$(who | awk '{print $1;}')
397
398touch /tmp/kk.txt
399#instalo paquetes necesarios de los repositorios segun la arquitectura.
400
401if ( (uname -a | grep -i "x86_64" > /dev/null) ); then 
402       
403        #echo "Es 64 bits"
404        zero-installer install libccid >> $ACCV_LOG
405        check_install $? "libccid" >> $ACCV_LOG
406        zero-installer install pcscd >> $ACCV_LOG
407        check_install $? "pcscd" >> $ACCV_LOG
408        zero-installer install libpcsclite1 >> $ACCV_LOG
409        check_install $? "libpcsclite1" >> $ACCV_LOG
410        zero-installer install libwxbase2.8-0 >> $ACCV_LOG
411        check_install $? "libwxbase2.8-0" >> $ACCV_LOG
412        zero-installer install libwxgtk2.8-0 >> $ACCV_LOG
413        check_install $? "libwxgtk2.8-0" >> $ACCV_LOG
414        zero-installer install safesignidentityclient >> $ACCV_LOG
415        check_install $? "safesignidentityclient" >> $ACCV_LOG
416
417else 
418
419        #echo "Es 32 bits"
420        zero-installer install libccid >> $ACCV_LOG
421        check_install $? "libccid" >> $ACCV_LOG
422        zero-installer install pcscd >> $ACCV_LOG
423        check_install $? "pcscd" >> $ACCV_LOG
424        zero-installer install libpcsclite1 >> $ACCV_LOG
425        check_install $? "libpcsclite1" >> $ACCV_LOG
426        zero-installer install libtiff4_3.9.6 >> $ACCV_LOG
427        check_install $? "libtiff4_3.9.6" >> $ACCV_LOG
428        zero-installer install libwxbase2.8 >> $ACCV_LOG
429        check_install $? "libwxbase2.8" >> $ACCV_LOG
430        zero-installer install libwxgtk2.8 >> $ACCV_LOG
431        check_install $? "libwxgtk2.8-0" >> $ACCV_LOG
432        zero-installer install safesignidentityclient >> $ACCV_LOG
433        check_install $? "safesignidentityclient" >> $ACCV_LOG
434
435
436fi
437
438# Si falla la instalacion de algun paquete se habrá abortado la instalación
439(
440## Get user home folder
441#######################
442user_home
443#echo "$USER_HOME"
444#Configuració SafeSign
445[ -d $USER_HOME/.safesign ] || su - $USER -c "mkdir ~/.safesign" >> $ACCV_LOG
446su - $USER -c "cp $ACCV_FILES/registry ~/.safesign" >>  $ACCV_LOG
447
448# Make link
449make_link
450#
451echo "# $MSG_ZENITY_ACCV_FIREFOX_1" ; sleep 1
452echo "20"
453echo "# $MSG_ZENITY_ACCV_FIREFOX_2" ; FF_MODULE_NAME="ACCV_GYD_PKCS_11"
454echo "40"
455echo "# $MSG_ZENITY_ACCV_FIREFOX_2"; FF_PATH="$USER_HOME/.mozilla/firefox"
456do_firefox
457echo "60"
458if [ $(rgrep 1 $ACCV_ERROR) ] ; then 
459        zenity --error --text="$MSG_FINAL_ERROR" 
460        exit 1
461fi
462echo "# $MSG_ZENITY_ACCV_THUNDER_1";TH_MODULE_NAME="ACCV_GYD_PKCS_11"
463echo "80"
464echo "# $MSG_ZENITY_ACCV_THUNDER_1";TH_PATH="$USER_HOME/.thunderbird"
465do_thunderbird
466echo "100"
467) |
468zenity --progress \
469 --title="ZERO-LLIUREX-ACCV" \
470  --text="$MSG_INSTALLING_ACCV_PROGRESS" \
471  --percentage=0 \
472  --auto-close \
473   --width=500 \
474  --auto-kill
475 
476#capturo el error a ver si todo fue bien o fallo algo
477ERROR=$(cat $ACCV_ERROR)
478
479if [ $(rgrep 1 $ACCV_ERROR) ] ; then 
480        zenity --error --text="$MSG_FINAL_ERROR" 
481        echo "" >> $ACCV_LOG
482        echo "$MSG_FINAL_ERROR" >> $ACCV_LOG
483        exit 1
484  else
485        zenity --info --text="$MSG_FINAL_ACCV_OK"
486        echo "" >> $ACCV_LOG
487        echo "$MSG_FINAL_ACCV_OK" >> $ACCV_LOG
488fi
489
490exit 0
Note: See TracBrowser for help on using the repository browser.