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

Last change on this file since 507 was 507, checked in by jrpelegrina, 4 years ago

First release to xenial

File size: 9.6 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="/usr/lib/libaetpkss.so"
14OLD_LIBRARY="/usr/lib/libaetpkss.so"
15ERROR=0
16
17export TEXTDOMAIN="zero-lliurex-dni"
18
19# MSGS
20MSG_LIBRARY_NOT_FOUND="$(gettext 'Library not found:')"
21MSG_SOME_PROBLEM_FIREFOX="$(gettext 'Some problem with firefox profile')"
22MSG_ONCE_FIREFOX="$(gettext 'Start firefox once at least')"
23MSG_SOME_PROBLEM_THUNDER="$(gettext 'Some problem with Thunderbird profile')"
24MSG_ONCE_THUNDER="$(gettext 'Start Thunderbird once at least')"
25MSG_RUNNING_FIREFOX="$(gettext 'Firefox is running. Stop it!')"
26MSG_RUNNING_THUNDER="$(gettext 'Thunderbird is running. Stop it!')"
27MSG_NOT_FIREFOX="$(gettext 'Firefox is not installed')"
28MSG_NOT_THUNDER="$(gettext 'Thunderbird is not installed')"
29MSG_INSTALLING_ACCV_PROGRESS="$(gettext 'Installing ACCV in your computer...')"
30MSG_ZENITY_ACCV_FIREFOX_1="$(gettext 'Installing ACCV modules in your system')"
31MSG_ZENITY_ACCV_FIREFOX_2="$(gettext 'ACCV modules in Firefox')"
32MSG_ZENITY_ACCV_THUNDER_1="$(gettext 'ACCV modules in Thunderbird')"
33MSG_FINAL_ACCV_ERROR="$(gettext 'Impossible to install ACCV module, correct the problems and execute this program again please.')"
34MSG_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.')"
35MSG_CREATING_THUNDER="$(gettext 'We have to create your Thundebird profile, now it will be launched, please close thunderbird and installation continues')"
36MSG_CREATING_FIREFOX="$(gettext 'We have to create your Firefox profile, now it will be launched, then please close Firefox and installation continues')"
37
38
39#instalo paquetes necesarios de los repositorios
40
41zero-installer install safesignidentityclient
42# Si falla la instalacion del paquete se aborat el resto y da error
43if [ $? != 0 ] ; then
44        zenity --error --text="Impossible to install libpkcs11-dnie problems with repos. $MSG_FINAL_ACCV_ERROR" 
45        ERROR=1
46        echo "$ERROR" > /tmp/zero-lliurex-accv.tmp
47        exit 1
48fi
49
50
51user_home(){
52   
53   USER_HOME=$(getent passwd "$USER_NAME" | cut -d: -f 6)
54}
55
56test_libaetpkss(){
57
58   if [ ! -e $LIBRARY ]; then
59      zenity --info --text="$MSG_LIBRARY_NOT_FOUND $LIBRARY"
60      ERROR=1
61        echo "$ERROR" > /tmp/zero-lliurex-accv.tmp
62      exit 1
63   fi
64}
65
66test_running_firefox(){
67
68   is_running=$(ps -aux | grep /usr/lib/firefox/firefox | grep -v grep | wc -l)
69        if [ $is_running -gt 0 ]; then
70                while [ $is_running -gt 0 ] ; do
71                        zenity --info --text="$MSG_RUNNING_FIREFOX"
72                        is_running=$(ps -aux | grep /usr/lib/firefox/firefox | grep -v grep | wc -l)
73                done
74        fi
75        return 0
76}
77
78test_running_thunderbird(){
79
80   is_running=$(ps -fe | grep thunderbird | grep -v grep | wc -l)
81        if [ $is_running -gt 0 ]; then
82                while [ $is_running -gt 0 ] ; do
83                        zenity --info --text="$MSG_RUNNING_THUNDER"
84                        is_running=$(ps -fe | grep thunderbird | grep -v grep | wc -l)
85                done
86        fi
87        return 0
88}
89
90test_installed_package(){
91
92   dpkg -s $1
93   iRESULT=$?
94   if [ $iRESULT -eq 1 ]; then
95        return 0
96   else
97        ERROR=1
98        echo "$ERROR" > /tmp/zero-lliurex-accv.tmp
99        return 1
100   fi
101}
102
103## Firefox functions
104####################
105
106get_firefox_default_profile(){
107   
108   # Getting Mozilla products default profile
109   # http://kb.mozillazine.org/Profiles.ini_file
110   #
111   # Get default profile info
112   # This script must be capable of dealing with multiple profiles
113   # and relative or absolute paths, for now ... buff!!
114   #
115   # This script get Default path profile if Default=1 or
116   # get first profile in other case
117 
118   TMP_FILE=$(mktemp)
119   cat $FF_PATH/profiles.ini | awk -F ' *= *' '{ if ($1 ~ /^\[/) section=$1; else if ($1 !~ /^$/) print $1 section "=" "\"" $2 "\"" }' > $TMP_FILE
120   DEFAULT_EXISTS=$(grep ^Default $TMP_FILE)
121   if [ -n $DEFAULT_EXISTS ]; then
122        PROFILE_ID=$(cat $TMP_FILE | grep -m 1 Profile[0-9] | cut -d"[" -f 2 | cut -d"]" -f 1 )
123   else
124        PROFILE_ID=$(echo $DEFAULT_EXISTS | grep -m 1 Profile[0-9] | cut -d"[" -f 2 | cut -d"]" -f 1 )
125   fi
126   IS_RELATIVE=$(cat $TMP_FILE | grep $PROFILE_ID | grep ^IsRelative | cut -d"=" -f 2 | sed -e 's/\"//g')
127   TMP_PATH=$(cat $TMP_FILE | grep $PROFILE_ID | grep ^Path | cut -d"=" -f 2 | sed -e 's/\"//g')
128   if [ $IS_RELATIVE = "0" ]; then
129      FF_PROFILE_PATH=$TMP_PATH
130   else
131      FF_PROFILE_PATH=$FF_PATH/$TMP_PATH
132   fi
133   rm -f $TMP_FILE
134}
135
136## Thunderbird functions
137####################
138
139get_thunderbird_default_profile(){
140   
141   # Getting Mozilla products default profile
142   # http://kb.mozillazine.org/Profiles.ini_file
143   #
144   # Get default profile info
145   # This script must be capable of dealing with multiple profiles
146   # and relative or absolute paths, for now ... buff!!
147   #
148   # This script get Default path profile if Default=1 or
149   # get first profile in other case
150 
151   TMP_FILE=$(mktemp)
152   cat $TH_PATH/profiles.ini | awk -F ' *= *' '{ if ($1 ~ /^\[/) section=$1; else if ($1 !~ /^$/) print $1 section "=" "\"" $2 "\"" }' > $TMP_FILE
153   DEFAULT_EXISTS=$(grep ^Default $TMP_FILE)
154   if [ -n $DEFAULT_EXISTS ]; then
155        PROFILE_ID=$(cat $TMP_FILE | grep -m 1 Profile[0-9] | cut -d"[" -f 2 | cut -d"]" -f 1 )
156   else
157        PROFILE_ID=$(echo $DEFAULT_EXISTS | grep -m 1 Profile[0-9] | cut -d"[" -f 2 | cut -d"]" -f 1 )
158   fi
159   IS_RELATIVE=$(cat $TMP_FILE | grep $PROFILE_ID | grep ^IsRelative | cut -d"=" -f 2 | sed -e 's/\"//g')
160   TMP_PATH=$(cat $TMP_FILE | grep $PROFILE_ID | grep ^Path | cut -d"=" -f 2 | sed -e 's/\"//g')
161   if [ $IS_RELATIVE = "0" ]; then
162      TH_PROFILE_PATH=$TMP_PATH
163   else
164      TH_PROFILE_PATH=$TH_PATH/$TMP_PATH
165   fi
166   rm -f $TMP_FILE
167}
168
169test_firefox_user_profile() {
170
171   if [ -d $FF_PATH ]; then
172        get_firefox_default_profile
173        if [ ! -d $FF_PROFILE_PATH ]; then
174                zenity --info --text="$MSG_SOME_PROBLEM_FIREFOX"
175                return 0
176        fi
177        ERROR=1
178        echo "$ERROR" > /tmp/zero-lliurex-accv.tmp
179        return 1
180   else
181      zenity --info --text="$MSG_CREATING_FIREFOX"
182        su $USER -c "firefox"
183        test_running_firefox
184        get_firefox_default_profile
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 0
196        fi
197        ERROR=1
198        echo "$ERROR" > /tmp/zero-lliurex-accv.tmp
199        return 1
200   else
201        zenity --info --text="$MSG_CREATING_THUNDER"
202        su $USER -c "thunderbird"
203        test_running_thunderbird
204        get_thunderbird_default_profile
205   fi
206       
207}
208
209test_firefox_accv_module(){
210
211   if [ -z $FF_MODULE_EXISTS ]; then
212        return 1
213   fi
214   return 0
215}
216
217remove_accv_module_firefox(){
218
219   su $USER -c "modutil -disable $FF_MODULE_NAME -force -dbdir $FF_PROFILE_PATH 2>&1"
220   su $USER -c "modutil -delete $FF_MODULE_NAME -force -dbdir $FF_PROFILE_PATH 2>&1"
221}
222
223remove_accv_module_thunderbird(){
224
225   su $USER -c "modutil -disable $TH_MODULE_NAME -force -dbdir $TH_PROFILE_PATH 2>&1"
226   su $USER -c "modutil -delete $TH_MODULE_NAME -force -dbdir $TH_PROFILE_PATH 2>&1"
227}
228
229enable_accv_module_firefox(){
230
231   su $USER -c "modutil -add $FF_MODULE_NAME -force -libfile $LIBRARY -dbdir $FF_PROFILE_PATH 2>&1"
232   su $USER -c "modutil -enable $FF_MODULE_NAME -force -dbdir $FF_PROFILE_PATH 2>&1"
233}
234
235enable_accv_module_thunderbird(){
236
237   su $USER -c "modutil -add $TH_MODULE_NAME -force -libfile $LIBRARY -dbdir $TH_PROFILE_PATH 2>&1"
238   su $USER -c "modutil -enable $TH_MODULE_NAME -force -dbdir $TH_PROFILE_PATH 2>&1"
239}
240
241do_firefox(){
242
243   test_installed_package "firefox"
244   if [ $? ]; then
245        test_running_firefox
246        if [ $? -gt 0 ]; then
247                zenity --info --text="$MSG_RUNNING_FIREFOX"
248                ERROR=1
249                echo "$ERROR" > /tmp/zero-lliurex-accv.tmp
250                exit 2
251        else
252                test_firefox_user_profile
253                test_ff_up=$?
254                echo "--->"$test_ff_up"<---"
255                if [ $? ]; then
256                        remove_accv_module_firefox
257                        enable_accv_module_firefox
258                fi
259        fi
260   else
261      zenity --info --text="$MSG_NOT_FIREFOX"
262      ERROR=1
263        echo "$ERROR" > /tmp/zero-lliurex-accv.tmp
264      exit 1
265   fi
266}
267
268do_thunderbird(){
269
270   test_installed_package "thunderbird"
271   if [ $? ]; then
272        test_running_thunderbird
273        if [ $? -gt 0 ]; then
274                zenity --info --text="$MSG_RUNNING_THUNDER"
275                 ERROR=1
276                echo "$ERROR" > /tmp/zero-lliurex-accv.tmp
277                exit 2
278        else
279                test_thunderbird_user_profile
280                test_th_up=$?
281                echo "--->"$test_th_up"<---"
282                if [ $? ]; then
283                        remove_accv_module_thunderbird
284                        enable_accv_module_thunderbird
285                fi
286        fi
287   else
288      zenity --info --text="$MSG_NOT_THUNDER"
289      ERROR=1
290      echo "$ERROR" > /tmp/zero-lliurex-accv.tmp
291      exit 1
292   fi
293}
294
295
296make_link(){
297
298        if [ ! -e $LIBRARY ]; then
299                if [ -e $LIBRARY.3 ]; then
300                        ln -s $LIBRARY.3 $LIBRARY || echo " Link is not done: $LIBRARY "
301       
302                else
303                        echo " * Warning :  $LIBRARY.3  not found"
304                fi
305        fi
306
307}
308
309(
310## Get user home folder
311#######################
312user_home
313
314#
315# Make link
316make_link
317echo "# $MSG_ZENITY_ACCV_FIREFOX_1" ; sleep 1
318echo "20"
319echo "# $MSG_ZENITY_ACCV_FIREFOX_2" ; FF_MODULE_NAME="ACCV_GYD_PKCS_11"
320echo "40"
321echo "# $MSG_ZENITY_ACCV_FIREFOX_2"; FF_PATH="$USER_HOME/.mozilla/firefox"
322do_firefox
323echo "60"
324echo "# $MSG_ZENITY_ACCV_THUNDER_1";TH_MODULE_NAME="ACCV_GYD_PKCS_11"
325echo "80"
326echo "# $MSG_ZENITY_ACCV_THUNDER_1";TH_PATH="$USER_HOME/.thunderbird"
327do_thunderbird
328echo "100"
329) |
330zenity --progress \
331  --title="ZERO-LLIUREX-ACCV" \
332  --text="$MSG_INSTALLING_ACCV_PROGRESS" \
333  --percentage=0 \
334  --auto-close \
335   --width=500 \
336  --auto-kill
337 
338#capturo el error a ver si todo fue bien o fallo algo
339ERROR=$(cat /tmp/zero-lliurex-dni.tmp)
340
341if [ $ERROR != 0 ] ; then 
342        zenity --error --text="$MSG_FINAL_ERROR" 
343        exit 1
344  else
345        zenity --info --text="$MSG_FINAL_ACCV_OK"
346fi
347
348exit 0
Note: See TracBrowser for help on using the repository browser.