#!/bin/bash #set -x ## Global Variables ################### USER_NAME=$USER # User name USER_HOME="" # Home user folder FF_PROFILE_PATH="" # Absolute path to user firefox profile TH_PROFILE_PATH="" # Absolute path to user firefox profile LIBRARY="/usr/lib/libaetpkss.so" OLD_LIBRARY="/usr/lib/libaetpkss.so" ERROR=0 export TEXTDOMAIN="zero-lliurex-dni" # MSGS MSG_LIBRARY_NOT_FOUND="$(gettext 'Library not found:')" MSG_SOME_PROBLEM_FIREFOX="$(gettext 'Some problem with firefox profile')" MSG_ONCE_FIREFOX="$(gettext 'Start firefox once at least')" MSG_SOME_PROBLEM_THUNDER="$(gettext 'Some problem with Thunderbird profile')" MSG_ONCE_THUNDER="$(gettext 'Start Thunderbird once at least')" MSG_RUNNING_FIREFOX="$(gettext 'Firefox is running. Stop it!')" MSG_RUNNING_THUNDER="$(gettext 'Thunderbird is running. Stop it!')" MSG_NOT_FIREFOX="$(gettext 'Firefox is not installed')" MSG_NOT_THUNDER="$(gettext 'Thunderbird is not installed')" MSG_INSTALLING_ACCV_PROGRESS="$(gettext 'Installing ACCV in your computer...')" MSG_ZENITY_ACCV_FIREFOX_1="$(gettext 'Installing ACCV modules in your system')" MSG_ZENITY_ACCV_FIREFOX_2="$(gettext 'ACCV modules in Firefox')" MSG_ZENITY_ACCV_THUNDER_1="$(gettext 'ACCV modules in Thunderbird')" MSG_FINAL_ACCV_ERROR="$(gettext 'Impossible to install ACCV module, correct the problems and execute this program again please.')" MSG_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.')" MSG_CREATING_THUNDER="$(gettext 'We have to create your Thundebird profile, now it will be launched, please close thunderbird and installation continues')" MSG_CREATING_FIREFOX="$(gettext 'We have to create your Firefox profile, now it will be launched, then please close Firefox and installation continues')" #instalo paquetes necesarios de los repositorios zero-installer install safesignidentityclient # Si falla la instalacion del paquete se aborat el resto y da error if [ $? != 0 ] ; then zenity --error --text="Impossible to install libpkcs11-dnie problems with repos. $MSG_FINAL_ACCV_ERROR" ERROR=1 echo "$ERROR" > /tmp/zero-lliurex-accv.tmp exit 1 fi user_home(){ USER_HOME=$(getent passwd "$USER_NAME" | cut -d: -f 6) } test_libaetpkss(){ if [ ! -e $LIBRARY ]; then zenity --info --text="$MSG_LIBRARY_NOT_FOUND $LIBRARY" ERROR=1 echo "$ERROR" > /tmp/zero-lliurex-accv.tmp exit 1 fi } test_running_firefox(){ is_running=$(ps -aux | grep /usr/lib/firefox/firefox | grep -v grep | wc -l) if [ $is_running -gt 0 ]; then while [ $is_running -gt 0 ] ; do zenity --info --text="$MSG_RUNNING_FIREFOX" is_running=$(ps -aux | grep /usr/lib/firefox/firefox | grep -v grep | wc -l) done fi return 0 } test_running_thunderbird(){ is_running=$(ps -fe | grep thunderbird | grep -v grep | wc -l) if [ $is_running -gt 0 ]; then while [ $is_running -gt 0 ] ; do zenity --info --text="$MSG_RUNNING_THUNDER" is_running=$(ps -fe | grep thunderbird | grep -v grep | wc -l) done fi return 0 } test_installed_package(){ dpkg -s $1 iRESULT=$? if [ $iRESULT -eq 1 ]; then return 0 else ERROR=1 echo "$ERROR" > /tmp/zero-lliurex-accv.tmp return 1 fi } ## Firefox functions #################### get_firefox_default_profile(){ # Getting Mozilla products default profile # http://kb.mozillazine.org/Profiles.ini_file # # Get default profile info # This script must be capable of dealing with multiple profiles # and relative or absolute paths, for now ... buff!! # # This script get Default path profile if Default=1 or # get first profile in other case TMP_FILE=$(mktemp) cat $FF_PATH/profiles.ini | awk -F ' *= *' '{ if ($1 ~ /^\[/) section=$1; else if ($1 !~ /^$/) print $1 section "=" "\"" $2 "\"" }' > $TMP_FILE DEFAULT_EXISTS=$(grep ^Default $TMP_FILE) if [ -n $DEFAULT_EXISTS ]; then PROFILE_ID=$(cat $TMP_FILE | grep -m 1 Profile[0-9] | cut -d"[" -f 2 | cut -d"]" -f 1 ) else PROFILE_ID=$(echo $DEFAULT_EXISTS | grep -m 1 Profile[0-9] | cut -d"[" -f 2 | cut -d"]" -f 1 ) fi IS_RELATIVE=$(cat $TMP_FILE | grep $PROFILE_ID | grep ^IsRelative | cut -d"=" -f 2 | sed -e 's/\"//g') TMP_PATH=$(cat $TMP_FILE | grep $PROFILE_ID | grep ^Path | cut -d"=" -f 2 | sed -e 's/\"//g') if [ $IS_RELATIVE = "0" ]; then FF_PROFILE_PATH=$TMP_PATH else FF_PROFILE_PATH=$FF_PATH/$TMP_PATH fi rm -f $TMP_FILE } ## Thunderbird functions #################### get_thunderbird_default_profile(){ # Getting Mozilla products default profile # http://kb.mozillazine.org/Profiles.ini_file # # Get default profile info # This script must be capable of dealing with multiple profiles # and relative or absolute paths, for now ... buff!! # # This script get Default path profile if Default=1 or # get first profile in other case TMP_FILE=$(mktemp) cat $TH_PATH/profiles.ini | awk -F ' *= *' '{ if ($1 ~ /^\[/) section=$1; else if ($1 !~ /^$/) print $1 section "=" "\"" $2 "\"" }' > $TMP_FILE DEFAULT_EXISTS=$(grep ^Default $TMP_FILE) if [ -n $DEFAULT_EXISTS ]; then PROFILE_ID=$(cat $TMP_FILE | grep -m 1 Profile[0-9] | cut -d"[" -f 2 | cut -d"]" -f 1 ) else PROFILE_ID=$(echo $DEFAULT_EXISTS | grep -m 1 Profile[0-9] | cut -d"[" -f 2 | cut -d"]" -f 1 ) fi IS_RELATIVE=$(cat $TMP_FILE | grep $PROFILE_ID | grep ^IsRelative | cut -d"=" -f 2 | sed -e 's/\"//g') TMP_PATH=$(cat $TMP_FILE | grep $PROFILE_ID | grep ^Path | cut -d"=" -f 2 | sed -e 's/\"//g') if [ $IS_RELATIVE = "0" ]; then TH_PROFILE_PATH=$TMP_PATH else TH_PROFILE_PATH=$TH_PATH/$TMP_PATH fi rm -f $TMP_FILE } test_firefox_user_profile() { if [ -d $FF_PATH ]; then get_firefox_default_profile if [ ! -d $FF_PROFILE_PATH ]; then zenity --info --text="$MSG_SOME_PROBLEM_FIREFOX" return 0 fi ERROR=1 echo "$ERROR" > /tmp/zero-lliurex-accv.tmp return 1 else zenity --info --text="$MSG_CREATING_FIREFOX" su $USER -c "firefox" test_running_firefox get_firefox_default_profile fi } test_thunderbird_user_profile() { if [ -d $TH_PATH ]; then get_thunderbird_default_profile if [ ! -d $TH_PROFILE_PATH ]; then zenity --info --text="$MSG_SOME_PROBLEM_THUNDER" return 0 fi ERROR=1 echo "$ERROR" > /tmp/zero-lliurex-accv.tmp return 1 else zenity --info --text="$MSG_CREATING_THUNDER" su $USER -c "thunderbird" test_running_thunderbird get_thunderbird_default_profile fi } test_firefox_accv_module(){ if [ -z $FF_MODULE_EXISTS ]; then return 1 fi return 0 } remove_accv_module_firefox(){ su $USER -c "modutil -disable $FF_MODULE_NAME -force -dbdir $FF_PROFILE_PATH 2>&1" su $USER -c "modutil -delete $FF_MODULE_NAME -force -dbdir $FF_PROFILE_PATH 2>&1" } remove_accv_module_thunderbird(){ su $USER -c "modutil -disable $TH_MODULE_NAME -force -dbdir $TH_PROFILE_PATH 2>&1" su $USER -c "modutil -delete $TH_MODULE_NAME -force -dbdir $TH_PROFILE_PATH 2>&1" } enable_accv_module_firefox(){ su $USER -c "modutil -add $FF_MODULE_NAME -force -libfile $LIBRARY -dbdir $FF_PROFILE_PATH 2>&1" su $USER -c "modutil -enable $FF_MODULE_NAME -force -dbdir $FF_PROFILE_PATH 2>&1" } enable_accv_module_thunderbird(){ su $USER -c "modutil -add $TH_MODULE_NAME -force -libfile $LIBRARY -dbdir $TH_PROFILE_PATH 2>&1" su $USER -c "modutil -enable $TH_MODULE_NAME -force -dbdir $TH_PROFILE_PATH 2>&1" } do_firefox(){ test_installed_package "firefox" if [ $? ]; then test_running_firefox if [ $? -gt 0 ]; then zenity --info --text="$MSG_RUNNING_FIREFOX" ERROR=1 echo "$ERROR" > /tmp/zero-lliurex-accv.tmp exit 2 else test_firefox_user_profile test_ff_up=$? echo "--->"$test_ff_up"<---" if [ $? ]; then remove_accv_module_firefox enable_accv_module_firefox fi fi else zenity --info --text="$MSG_NOT_FIREFOX" ERROR=1 echo "$ERROR" > /tmp/zero-lliurex-accv.tmp exit 1 fi } do_thunderbird(){ test_installed_package "thunderbird" if [ $? ]; then test_running_thunderbird if [ $? -gt 0 ]; then zenity --info --text="$MSG_RUNNING_THUNDER" ERROR=1 echo "$ERROR" > /tmp/zero-lliurex-accv.tmp exit 2 else test_thunderbird_user_profile test_th_up=$? echo "--->"$test_th_up"<---" if [ $? ]; then remove_accv_module_thunderbird enable_accv_module_thunderbird fi fi else zenity --info --text="$MSG_NOT_THUNDER" ERROR=1 echo "$ERROR" > /tmp/zero-lliurex-accv.tmp exit 1 fi } make_link(){ if [ ! -e $LIBRARY ]; then if [ -e $LIBRARY.3 ]; then ln -s $LIBRARY.3 $LIBRARY || echo " Link is not done: $LIBRARY " else echo " * Warning : $LIBRARY.3 not found" fi fi } ( ## Get user home folder ####################### user_home # # Make link make_link echo "# $MSG_ZENITY_ACCV_FIREFOX_1" ; sleep 1 echo "20" echo "# $MSG_ZENITY_ACCV_FIREFOX_2" ; FF_MODULE_NAME="ACCV_GYD_PKCS_11" echo "40" echo "# $MSG_ZENITY_ACCV_FIREFOX_2"; FF_PATH="$USER_HOME/.mozilla/firefox" do_firefox echo "60" echo "# $MSG_ZENITY_ACCV_THUNDER_1";TH_MODULE_NAME="ACCV_GYD_PKCS_11" echo "80" echo "# $MSG_ZENITY_ACCV_THUNDER_1";TH_PATH="$USER_HOME/.thunderbird" do_thunderbird echo "100" ) | zenity --progress \ --title="ZERO-LLIUREX-ACCV" \ --text="$MSG_INSTALLING_ACCV_PROGRESS" \ --percentage=0 \ --auto-close \ --width=500 \ --auto-kill #capturo el error a ver si todo fue bien o fallo algo ERROR=$(cat /tmp/zero-lliurex-dni.tmp) if [ $ERROR != 0 ] ; then zenity --error --text="$MSG_FINAL_ERROR" exit 1 else zenity --info --text="$MSG_FINAL_ACCV_OK" fi exit 0