#!/bin/bash # # Run Firefox in Kiosk mode for lwat # Author: 2008 Jose Ricardo Pla Pons # Re-structure: 2009 Luis Garcia Gisbert # Minor fixes: 2009 Fco Javier Lopez Perez declare -a PROFILE_LIST chromefile='/usr/share/lliurex-lwat/profile/userChrome.css' profilefile='/usr/share/lliurex-lwat/profile/profilelwat' FIRE_PATH="$HOME/.mozilla/firefox" PROFILE_PATH="$FIRE_PATH/lwat-client" chromepath="$FIRE_PATH/lwat-client/chrome" mozillaprofileini="$FIRE_PATH/profiles.ini" mozillaprofilename='lwat-client' numberprofile=0 #PROFILE_REGEXP="^[[:blank:]]*\[Profile.*\][[:blank:]]*$" COPY_LIST="cert8.db secmod.db key3.db" export TEXTDOMAIN="lwat-client" MSG_ERROR="$(gettext "You must close firefox before running lwat")" profile_regexp(){ PNAME="$1" [ "$PNAME" ] || PNAME="Profile.*" echo "^[[:blank:]]*\[$PNAME\][[:blank:]]*$" return 0 } list_profile_names(){ sed -ne "/$(profile_regexp)/{s%^.*\[%%;s%\].*$%%;p}" "$mozillaprofileini" return 0 } get_profile_data(){ sed -ne "/$(profile_regexp "$1")/,/$(profile_regexp)/{/^$2=/s%^$2=%%p}" "$mozillaprofileini" return 0 } get_profile_name(){ get_profile_data "$1" Name return 0 } get_profile_path(){ get_profile_data "$1" Path return 0 } get_default_profile(){ NUM_PROF=$(sed -ne "/^Default=/s%^.*=%%p" "$mozillaprofileini") [ "$NUM_PROF" ] || NUM_PROF=1 NUM_PROF=$(($NUM_PROF - 1)) echo ${PROFILE_LIST[$NUM_PROF]} return 0 } lwat_profile_test(){ [ -d "$chromepath" ] || return 1 grep -q "$mozillaprofilename" "$mozillaprofileini" || return 1 return 0 } lwat_profile_make(){ numberprofile=$(grep -c "$(profile_regexp)" "$mozillaprofileini") || numberprofile=0 TMP_FILE="$(tempfile)" cp -a "$mozillaprofileini" "$TMP_FILE" for p in ${PROFILE_LIST[@]} ; do if [ "$(get_profile_name "$p")" = "$mozillaprofilename" ] ; then sed -i -e "/$(profile_regexp "$p")/,/$(profile_regexp)/d" "$TMP_FILE" fi done sed -i -e "/^Default=/d" "$TMP_FILE" sed -e "s/_@_PROFILE_NUMBER_@_/$numberprofile/" "$profilefile" >> "$TMP_FILE" mv -f "$TMP_FILE" "$mozillaprofileini" mkdir -p "$chromepath" cp "$chromefile" "$chromepath" DEF_PROF_NAME="$(get_default_profile)" DEF_PROF_PATH="$(get_profile_path "$DEF_PROF_NAME")" for f in $COPY_LIST ; do F="$FIRE_PATH/$DEF_PROF_PATH/$f" [ ! -e "$F" ] || cp "$F" "$PROFILE_PATH" done lliurex-user-certs return 0 } run_firefox(){ FIREFOX_IS_RUNNING="" pid=$(pidof firefox) for numpro in $pid; do piduser="$(ps -p $numpro -o user=)" if [ "$piduser" = "$LOGNAME" ]; then FIREFOX_IS_RUNNING="Y" fi done if [ "$FIREFOX_IS_RUNNING" ]; then zenity --error --text="$MSG_ERROR" --title="Lwat-Client" else firefox -P lwat-client http://admin fi } # main [ -e "$mozillaprofileini" ] || exit 0 [ "$HOME" ] || exit 0 [ "$LOGNAME" ] || exit 0 PROFILE_LIST=($(list_profile_names)) [ ${#PROFILE_LIST[@]} -gt 0 ] || exit 0 lwat_profile_test || lwat_profile_make run_firefox exit 0