martes, 15 de enero de 2013

Moving out Firefox's profile to ram filesystem

Firefox's profile dir

Hi, I need to optimize firefox execution getting somes files out of disk to ram and come back to disk to retaing data. In linux firefox use the folder $HOME/.mozilla/firefox to store all available profiles. I use this script to make it possible.

FF_BIN=/opt/32/firefox/firefox
PROFILE_NAME=$USER

# Launch firefox with profile in ramfs, wait and update modified files to backup

RAMFS=/ramfs
PROFILE_ROOT=$HOME/.mozilla/firefox   #firefox root directory
PROFILE_FILE=$PROFILE_ROOT/profiles.ini

#check preconditions
[ ! -e $PROFILE_FILE ] && echo "error: not file $PROFILE_FILE " >> /opt/bin.log && exit


#read all section when name is present hold. for next keys use name.key = value

while IFS="\=" read -r key val ; do
    [ -z $val ] && continue             # eval -zero string if true eval continue, the result is not use

    if [ $key == "Name" ] ; then
        PREFIX=$val
        continue
    fi

    [ -z $PREFIX ] && continue

    export "${PREFIX}_$key=$val"        #make visible out of while do not use dot because it is not valid for variable name 

done < $PROFILE_FILE 

# copy to ramfs only one time, remain until next reboot, get backup on every exit
eval PROFILE_DIR=\$\{${PROFILE_NAME}_Path\}
eval PROFILE_PATH=$PROFILE_ROOT/\$\{${PROFILE_NAME}_Path\}

[ -z $PROFILE_DIR ] && echo "error: profile $PROFILE_NAME not found in $PROFILE_FILE " >> /opt/bin.log && exit
[ ! -d ${PROFILE_PATH}.backup ] && echo "error: directory ${PROFILE_PATH}.backup not found " >> /opt/bin.log && exit

RAMFS_PROFILE_PATH=${RAMFS}$PROFILE_PATH

if [ ! -d $RAMFS_PROFILE_PATH ] ; then
    mkdir -p $RAMFS_PROFILE_PATH
    cp -axr ${PROFILE_PATH}.backup/. $RAMFS_PROFILE_PATH
    ln -sf $RAMFS_PROFILE_PATH  $PROFILE_ROOT
fi

$FF_BIN -p $PROFILE_NAME -no-remote  $@

#update modified files
if [ ! -z $RAMFS_PROFILE_PATH ] ; then
# -E to preserve exection flag.
rsync -avqE --delete-after $RAMFS_PROFILE_PATH/. ${PROFILE_PATH}.backup
fi

exit

   

No hay comentarios:

Publicar un comentario