#! /bin/bash # - Take new tar file as argument DONE # - Verify argument is valid DONE # - Verify script is running as sudo DONE # - Move existing firefox to firefox.OLD DONE # - create directory for new installation DONE # - unpack tar file to new location DONE # - Optional, verify desktop file extsts helpFunction() { echo " " echo "Provides convenient means to install a new firefox file." echo "Pass new TAR or TAR.BZ file as argument and this script will unpack and update the symlinks and verify installation." echo "Must run with root privileges." echo " " echo "Usage: sudo $0 [filename]" echo " " } ## Take input and verify file and root user## projectname="Firefox Browser Update Script" projectdir="/home/mike/Software/firefox" imagepath="$projectdir/apps" executablelink="/usr/local/bin" desktoppath="/usr/local/share/applications" assetspath="$projectdir/assets" version="0.1" echo "$projectname v$version" # Check Arguments # if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then helpFunction exit 0 fi # Check if user is root # if [ "$USER" != "root" ]; then echo "Must be running as root to install new software. Use sudo or root user" helpFunction exit 1 fi # Check if any string was provided as in input # if [ -z "$1" ]; then echo " " echo "No filename given. Aborting." helpFunction exit 1 fi # Check if the string is a valid file # if ! [ -f "$1" ]; then echo "$1 not found." helpFunction exit 1 else # Set filename now that we have a good file # filename=$(basename $1) ##Take Basename in case file in case user is in unusual directory when calling script. fi # Move file if necessary # if ! [ -f "$imagepath/$filename" ]; then echo "Moving $1 to $imagepath/" mv $1 $imagepath/ echo "Done." fi # Argument and file checking complete...# # Start Script # echo "Updating $projectname ..." echo "Checking for old installations" if [ -d "/opt/firefox.OLD" ]; then read -p "firefox.OLD already exists? Should I delete it? ENTER to continue or CTRL+C to abort." input fi echo "Deleting existing firefox.OLD folder" rm -rf /opt/firefox.OLD echo "Moving Existing firefox to firefox.OLD" mv /opt/firefox /opt/firefox.OLD echo "Making new firefox directory" mkdir /opt/firefox echo "unpacking "$filename" to /opt/firefox" ## Check file type and unpack accordingly ## if [[ "$filename" == *.tar.xz ]]; then echo "Unpacking as tar.xz file" tar -xvf "$imagepath/$filename" -C "/opt/" elif [[ "$filename" == *.tar.bz2 ]]; then echo "Unpacking as tar.bz2 file" tar -xjvf "$imagepath/$filename" -C "/opt/" else echo "WARNING: Unknown Compression Type. Aborting." exit 1 fi # # # ## Ensure AppImage is Executable # #echo "Setting $filename as executable" #sudo chmod +x $imagepath/$filename #echo "Done." # # # Ensure symlink is set echo "Setting symlink /usr/local/bin/firefox" ln -fs /opt/firefox/firefox $executablelink/firefox chowm mike:mike /opt/firefox # Write permissions needed for firefox to check for updates echo "Done." # Ensure Desktop file is set if ! [ -f "$assetspath/firefox.desktop" ]; then echo "WARNING: firefox.desktop file not found!" echo "WARNING: Desktop file not set!" exit 1 fi echo "Setting firefox.desktop in /usr/local/share/applications and verifying permissions" ln -fs $assetspath/firefox.desktop $desktoppath/ chmod +x $assetspath/firefox.desktop echo "Done." echo "Update Complete. Done." exit 0