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

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

Adding extra files

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