install.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #! /bin/bash
  2. # - Take new tar file as argument DONE
  3. # - Verify argument is valid DONE
  4. # - Verify script is running as sudo DONE
  5. # - Move existing firefox to firefox.OLD DONE
  6. # - create directory for new installation DONE
  7. # - unpack tar file to new location DONE
  8. # - Optional, verify desktop file extsts
  9. helpFunction()
  10. {
  11. echo " "
  12. echo "Provides convenient means to install a new Firefox tar file."
  13. echo "Pass new tar file as argument and this script will handle backing up the current installation and unpacking the new installation."
  14. echo "This script will prompt before deleting a previous archive."
  15. echo "Must run with root privileges."
  16. echo " "
  17. echo "Usage: $0 [filename]"
  18. echo " "
  19. }
  20. ## Take input and verify file and root user##
  21. filename=$1
  22. if [ "$filename" = "-h" ] || [ "$filename" = "--help" ]; then
  23. helpFunction
  24. exit 0
  25. fi
  26. if ! [ -f "$filename" ]; then
  27. echo "$1 not found."
  28. helpFunction
  29. exit 1
  30. fi
  31. if [ -z "$filename" ]
  32. then
  33. echo " "
  34. echo "No filename given. Aborting."
  35. helpFunction
  36. exit 1
  37. fi
  38. if [ "$USER" != "root" ]; then
  39. echo "Must be running as root to install new software. Use sudo or root user"
  40. helpFunction
  41. exit 1
  42. fi
  43. echo "$1 file found"
  44. ## Move existing folder to .OLD and delete existing .OLD if needed ##
  45. echo "Checking for old installations"
  46. if [ -d "/opt/firefox.OLD" ]; then
  47. read -p "firefox.OLD already exists? Should I delete it? ENTER to continue or CTRL+C to abort." input
  48. fi
  49. echo "Deleting existing firefox.OLD folder"
  50. rm -rf /opt/firefox.OLD
  51. echo "Moving Existing firefox to firefox.OLD"
  52. mv /opt/firefox /opt/firefox.OLD
  53. echo "Making new firefox directory"
  54. mkdir /opt/firefox
  55. echo "unpacking "$filename" to /opt/firefox"
  56. ## Check file type and unpack accordingly ##
  57. if [[ "$filename" == *.tar.xz ]]; then
  58. echo "Unpacking as tar.xf file"
  59. tar -xvf "$filename" -C "/opt/"
  60. elif [[ "$filename" == *.tar.bz2 ]]; then
  61. echo "Unpacking as tar.bz2 file"
  62. tar -xjvf "$filename" -C "/opt/"
  63. else
  64. echo "WARNING: Unknown Compression Type. Aborting."
  65. exit 1
  66. fi
  67. # ensure symlink is set
  68. ln -fs /opt/firefox/firefox /usr/local/bin/firefox
  69. echo "Symlink /usr/local/bin/firefox set."
  70. # ensure /opt permissions are set correctly
  71. chown mike:mike /opt/firefox
  72. echo "/opt/firefox permissions set"
  73. # ensure .desktop file is set
  74. if [ -f "firefox.desktop" ]; then
  75. echo "Setting .desktop file."
  76. ln -fs /home/mike/Software/firefox/firefox.desktop /usr/local/share/applications
  77. echo "Done."
  78. else
  79. echo ""
  80. echo "WARNING: firefox.desktop not found. Could not install desktop file."
  81. echo "Check for existence of firefox.desktop file in this folder."
  82. exit 1
  83. fi