#!/bin/bash#destdir="/usr/local/firefox32" for firefox32destdir="/usr/lib/firefox"FILE="$destdir/res/forms.css"BEGIN="/*** BEGIN EXTRA FIREFOX WIDGETS ***/"sed_BEGIN="$(echo "$BEGIN" | sed 's@\*@\\*@g')"END="/*** END EXTRA FIREFOX WIDGETS ***/"create_backup(){echo "Creating backup $FILE.bak"sudo cp "$FILE" "$FILE.bak}##################### INSTALL FUNCTION #####################install(){echo -e "\nWe are going to be installing the firefox widgets.\n\This consists of widget images contained in the folder \"form-widgets\"\n\and CSS to be appended to the forms.css file.\n\----------------------------------\n\Press enter to begin installation."read# Check if widgets have already been installedgrep "$sed_BEGIN" "$FILE" &> /dev/nullif [ "$?" = 0 ] ; then echo "The CSS appears to have already been installed." css=trueelse css=falsefiecho "Installing the widget images"sudo cp -r form-widgets "$destdir"/res# Install the cssif [ "$css" = false ] ; then # Create a backup if wanted loop=true while [ "$loop" = true ] ; do echo "We are about to overwrite $FILE." echo -n 'Would you like to create a backup? (y/n) ' loop=false read backup_choice case "$backup_choice" in y | Y | [Yy][Ee][Ss] ) if [ -e "$FILE.bak" ] ; then loop1=false while [ "$loop1" = true ] ; do echo '"$FILE.bak" exists. Do you want to overwrite the file? (y/n)' read overwrite_choice case "$overwrite_choice" in [yY] | [Yy][Ee][Ss] ) create_backup ;; [nN] | [Nn][Oo] ) echo "No backup will be created." ;; * ) echo "Incorrect option!" loop1=true ;; esac unset overwrite_choice done unset loop1 else create_backup fi ;; n | N | [Nn][Oo] ) : ;; * ) echo "Unknown option!" loop=true ;; esac unset backup_choice done unset loop echo "Appending forms-extra.css to forms.css" sudo bash -c "echo \"$BEGIN\" >> \"$FILE\" ; \ cat forms-extra.css >> \"$FILE\" ; \ echo \"$END\" >> \"$FILE\""fiif [ "$css" = true ] ; then echo "Firefox widgets installed successfully."} ####################### UNINSTALL FUNCTION ####################### uninstall(){grep "$sed_BEGIN" "$FILE" &> /dev/nullif [ "$?" = 0 ] ; then css=trueelse echo "Text \"$BEGIN\" not found in $FILE" echo "The CSS does not appear to be installed." css=falsefi if [ -d "$destdir/res/form-widgets" ] ; then widgets=trueelse echo "The directory $destdir/res/form-widgets does not exist." echo "The widget images do not appear to be installed." widgets=falsefidelete=falseif [ "$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 "Removing the CSS" sudo bash -c "echo \"$temp\" > \"$FILE\"" unset tempfiif [ "$widgets" = true ] ; then echo "Removing widget images." sudo rm -r "$destdir/res/form-widgets"fiif [ "$widgets" = false -a "$css" = false ] ; then echo "No actions taken. Firefox widgets are not installed."else echo "Firefox widgets successfully removed."fi}echo '1 ) Install Firefox Widgets'echo '2 ) Remove Firefox Widgets'echo -n 'Select an Option: 'loop=truewhile [ "$loop" = true ] ; do read option loop=false case "$option" in 1 ) install ;; 2 ) uninstall ;; * ) echo 'Unknown Option!' loop=true ;; esac unset optiondoneunset loop