#!/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 LIBRARY="/usr/lib/libpkcs11-fnmtdnie.so" OLD_LIBRARY="/usr/lib/opensc-pkcs11.so /usr/lib/libpkcs11-dnie.so" user_home(){ USER_HOME=$(getent passwd "$USER_NAME" | cut -d: -f 6) } test_libpkcs11_dnie(){ if [ ! -f $LIBRARY ]; then zenity --info --text="Library not found: $LIBRARY" exit 1 fi } test_running(){ is_running=$(ps -fe | grep ^$USER_NAME | grep /usr/lib/firefox/firefox | grep -v grep | wc -l) if [ $is_running -gt 0 ]; then return 1 else return 0 fi } test_installed_package(){ dpkg -s $1 iRESULT=$? if [ $iRESULT -eq 1 ]; then return 0 else 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 } test_firefox_user_profile() { if [ -d $FF_PATH ]; then get_firefox_default_profile if [ ! -d $FF_PROFILE_PATH ]; then zenity --info --text="Some problem with firefox profile" return 0 fi return 1 else zenity --info --text="Start firefox once at least" exit 3 fi } test_firefox_dni_module(){ if [ -z $FF_MODULE_EXISTS ]; then return 1 fi return 0 } remove_dni_module_firefox(){ modutil -disable $FF_MODULE_NAME -force -dbdir $FF_PROFILE_PATH 2>&1 modutil -delete $FF_MODULE_NAME -force -dbdir $FF_PROFILE_PATH 2>&1 } enable_dni_module_firefox(){ modutil -add $FF_MODULE_NAME -force -libfile $LIBRARY -dbdir $FF_PROFILE_PATH 2>&1 modutil -enable $FF_MODULE_NAME -force -dbdir $FF_PROFILE_PATH 2>&1 } do_firefox(){ test_installed_package "firefox" if [ $? ]; then test_running if [ $? -gt 0 ]; then zenity --info --text="Firefox is running. Stop it!" exit 2 else test_firefox_user_profile test_ff_up=$? echo "--->"$test_ff_up"<---" if [ $? ]; then remove_dni_module_firefox enable_dni_module_firefox fi fi else zenity --info --text="Firefox is not installed" exit 1 fi } ## Get user home folder ####################### user_home ## Test if dni library exists ############################# test_libpkcs11_dnie # firefox FF_MODULE_NAME="DNI_E" FF_PATH="$USER_HOME/.mozilla/firefox" do_firefox zenity --info --text="Setup finished with exit" exit 0