install.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 file."
  13. echo "Pass new TAR or TAR.BZ file as argument and this script will unpack and update the symlinks and verify installation."
  14. echo "Must run with root privileges."
  15. echo " "
  16. echo "Usage: sudo $0 [filename]"
  17. echo " "
  18. }
  19. ## Take input and verify file and root user##
  20. projectname="Firefox Browser Update Script"
  21. projectdir="/home/mike/Software/firefox"
  22. imagepath="$projectdir/apps"
  23. executablelink="/usr/local/bin"
  24. desktoppath="/usr/local/share/applications"
  25. assetspath="$projectdir/assets"
  26. version="0.1"
  27. echo "$projectname v$version"
  28. # Check Arguments #
  29. if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
  30. helpFunction
  31. exit 0
  32. fi
  33. # Check if user is root #
  34. if [ "$USER" != "root" ]; then
  35. echo "Must be running as root to install new software. Use sudo or root user"
  36. helpFunction
  37. exit 1
  38. fi
  39. # Check if any string was provided as in input #
  40. if [ -z "$1" ]; then
  41. echo " "
  42. echo "No filename given. Aborting."
  43. helpFunction
  44. exit 1
  45. fi
  46. # Check if the string is a valid file #
  47. if ! [ -f "$1" ]; then
  48. echo "$1 not found."
  49. helpFunction
  50. exit 1
  51. else
  52. # Set filename now that we have a good file #
  53. filename=$(basename $1) ##Take Basename in case file in case user is in unusual directory when calling script.
  54. fi
  55. # Move file if necessary #
  56. if ! [ -f "$imagepath/$filename" ]; then
  57. echo "Moving $1 to $imagepath/"
  58. mv $1 $imagepath/
  59. echo "Done."
  60. fi
  61. # Argument and file checking complete...#
  62. # Start Script #
  63. echo "Updating $projectname ..."
  64. echo "Checking for old installations"
  65. if [ -d "/opt/firefox.OLD" ]; then
  66. read -p "firefox.OLD already exists? Should I delete it? ENTER to continue or CTRL+C to abort." input
  67. fi
  68. echo "Deleting existing firefox.OLD folder"
  69. rm -rf /opt/firefox.OLD
  70. echo "Moving Existing firefox to firefox.OLD"
  71. mv /opt/firefox /opt/firefox.OLD
  72. echo "Making new firefox directory"
  73. mkdir /opt/firefox
  74. echo "unpacking "$filename" to /opt/firefox"
  75. ## Check file type and unpack accordingly ##
  76. if [[ "$filename" == *.tar.xz ]]; then
  77. echo "Unpacking as tar.xz file"
  78. tar -xvf "$imagepath/$filename" -C "/opt/"
  79. elif [[ "$filename" == *.tar.bz2 ]]; then
  80. echo "Unpacking as tar.bz2 file"
  81. tar -xjvf "$imagepath/$filename" -C "/opt/"
  82. else
  83. echo "WARNING: Unknown Compression Type. Aborting."
  84. exit 1
  85. fi
  86. #
  87. #
  88. #
  89. ## Ensure AppImage is Executable
  90. #
  91. #echo "Setting $filename as executable"
  92. #sudo chmod +x $imagepath/$filename
  93. #echo "Done."
  94. #
  95. #
  96. # Ensure symlink is set
  97. echo "Setting symlink /usr/local/bin/firefox"
  98. ln -fs /opt/firefox/firefox $executablelink/firefox
  99. chowm mike:mike /opt/firefox # Write permissions needed for firefox to check for updates
  100. echo "Done."
  101. # Ensure Desktop file is set
  102. if ! [ -f "$assetspath/firefox.desktop" ]; then
  103. echo "WARNING: firefox.desktop file not found!"
  104. echo "WARNING: Desktop file not set!"
  105. exit 1
  106. fi
  107. echo "Setting firefox.desktop in /usr/local/share/applications and verifying permissions"
  108. ln -fs $assetspath/firefox.desktop $desktoppath/
  109. chmod +x $assetspath/firefox.desktop
  110. echo "Done."
  111. echo "Update Complete. Done."
  112. exit 0