#!/bin/bash destdir="/usr/lib/mozilla-firefox" FILE="$destdir/res/forms.css" BEGIN="/*** BEGIN EXTRA FIREFOX WIDGETS ***/" sed_BEGIN="$(echo "$BEGIN" | sed 's@\*@\\*@g')" END="/*** END EXTRA FIREFOX WIDGETS ***/" sed_END="$(echo "$END" | sed 's@\*@\\*@g')" function install() { # Check if widgets have already been installed grep "$sed_BEGIN" "$FILE" &> /dev/null if [ "$?" = 0 ] ; then echo "The text \"$BEGIN\" was found in $FILE." echo "The CSS appears to have already been installed." css=true else css=false fi if [ -d "$destdir/res/form-widgets" ] ; then echo "The directory "$destdir/res/form-widgets" already exists." echo "The widget images appear to be installed." css=true else css=false fi if [ "$css" = false ] ; then # Create a backup if wanted echo "We are about to overwrite $FILE." echo "Would you like to create a backup? (y/n)" read backup_choice case "$backup_choice" in y | Y | yes | Yes | YES ) echo "Creating backup $FILE.bak" #sudo cp "$FILE" "$FILE".bak ;; n | N | no | No | NO ) : ;; esac # append forms-extra.css to forms.css temp="$(cat forms-extra.css)" #sudo echo "$temp" >> "$destdir"/res/forms.css #sudo cp -r form-widgets "$destdir"/res } function uninstall() { grep "$sed_BEGIN" "$FILE" &> /dev/null if [ "$?" = 0 ] ; then css=true else echo "Text \"$BEGIN\" not found in $FILE" echo "The CSS does not appear to be installed." css=false fi if [ -d "$destdir/res/form-widgets" ] ; then widgets=true else echo "The directory "$destdir/res/form-widgets" does not exist." echo "The widget images do not appear to be installed." widgets=false fi delete=false if [ "$css" = true ] ; then temp="$(cat "$FILE" | while read line; do if [ "$line" = "$BEGIN" ]; then delete=true fi if [ "$delete" = false ]; then echo "$line" fi if [ "$delete" = true ] ; then if [ "$line" = "$END" ] ; then delete=false fi fi done)" echo "Restoring "$FILE"" echo "$temp" > "$FILE" fi if [ "$widgets" = true ] ; then echo "Removing widget images." sudo rm -r "$destdir/res/form-widgets" fi echo "Firefox widgets successfully removed." } echo "1 ) Install Firefox Widgets" echo "2 ) Remove Firefox Widgets" echo "Select an Option: " read option case "$option" in 1 ) install ;; 2 ) uninstall ;; * ) echo "Unknown Option!" ;; esac