install.sh 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. #!/bin/bash
  2. #####
  3. #
  4. # This script will:
  5. # - Identify the type type of file being passed as an argument
  6. # - Install that file
  7. #
  8. # USAGE -
  9. #
  10. # sudo ./install <opt> <filename>
  11. #
  12. # opts:
  13. # -n Nextcloud
  14. # -k KeePass
  15. # -f Firefox
  16. # -h Help File
  17. # -v Version
  18. #
  19. ######
  20. ######
  21. #
  22. # INSTALLING THIS SCRIPT
  23. #
  24. # Link to this script in /usr/bin so it can be called by the sudo command
  25. # ex. sudo ln -fs /home/mike/Software/TG_Installer/TG_Installer.sh /usr/bin/tg_installer
  26. #
  27. ######
  28. helpFunction()
  29. {
  30. echo " "
  31. echo "Installs Nextcloud and KeePass AppImages, as well as Firefox Tarballs, in a consistent manner."
  32. echo "Requires a manually created .desktop file placed in an assets/ folder in the application installation directory at /home/USER/Software/APPLICATION"
  33. echo "Requires a folder apps in the application installation folder for receiving application AppImages or Tarballs."
  34. echo "Must run with root privileges."
  35. echo " "
  36. echo "Usage: sudo $0 [opts] [filename]"
  37. echo " -n Nextcloud"
  38. echo " -k KeePass"
  39. echo " -f Firefox"
  40. echo " -h Help File"
  41. echo " -v Version"
  42. echo " "
  43. }
  44. ## VARIABLES ##
  45. projectdir="/home/mike/Software"
  46. #imagepath="$projectdir/apps"
  47. executablelink="/usr/local/bin"
  48. desktoppath="/usr/local/share/applications"
  49. #assetspath="$projectdir/assets"
  50. version="0.1"
  51. ## Applications Permitted ##
  52. applications_array=("Nextcloud" "KeePass" "Firefox")
  53. echo "TG Generic Installer Script v$version"
  54. # Check Arguments #
  55. if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
  56. helpFunction
  57. exit 0
  58. fi
  59. # Check if user is root #
  60. if [ "$USER" != "root" ]; then
  61. echo "Must be running as root to install new software. Use sudo or root user"
  62. helpFunction
  63. exit 1
  64. fi
  65. # Check if user-provided file is valid #
  66. if [ -z "$1" ]; then
  67. echo " "
  68. echo "No filename given. Aborting."
  69. helpFunction
  70. exit 1
  71. fi
  72. # Check if the string is a valid file #
  73. if ! [ -f "$1" ]; then
  74. echo "$1 not found."
  75. helpFunction
  76. exit 1
  77. else
  78. # Set filename now that we have a good file #
  79. filename=$(basename $1) ##Take Basename in case file in case user is in unusual directory when cal>
  80. echo "$filename appears valid."
  81. fi
  82. # Check what application this is #
  83. for app in "${applications_array[@]}"; do
  84. if [[ "${filename,,}" == *"${app,,}"* ]]; then
  85. application_formal=$app
  86. application=${app,,}
  87. echo "Configuring to install: $app"
  88. projectdir=$projectdir/$application
  89. imagepath=$projectdir/apps
  90. assetspath=$projectdir/assets
  91. fi
  92. done
  93. # Check if projectdir exists
  94. echo "Checking Project Directory"
  95. if ! [ -d $projectdir ]; then
  96. echo "Folder $projectdir not found. Creating folder structure..."
  97. mkdir $projectdir
  98. mkdir $projectdir/apps
  99. mkdir $projectdir/assets
  100. chown -R mike:mike $projectdir
  101. echo "Project directory is created."
  102. echo "WARNING! You must create a .desktop file and icon in assets/ folder!"
  103. else
  104. echo "Done"
  105. fi
  106. # Move file, if required
  107. echo "Checking App Location"
  108. if ! [ -f "$projectdir/apps/$filename" ]; then
  109. echo "Moving $1 to $imagepath/"
  110. mv $1 $projectdir/apps/$filename
  111. echo "Done."
  112. else
  113. echo "Done"
  114. fi
  115. ####
  116. #
  117. # INSTALL
  118. #
  119. ###
  120. echo "Installing $application_formal"
  121. if [ $application == 'firefox' ]; then
  122. echo "Checking for old installations"
  123. if [ -d "/opt/$application.OLD" ]; then
  124. read -p "$application.OLD already exists? Should I delete it? ENTER to continue or CTRL+C to abort." input
  125. fi
  126. echo "Deleting existing $application.OLD folder"
  127. rm -rf /opt/$application.OLD
  128. echo "Moving Existing $application to $application.OLD"
  129. mv /opt/$application /opt/$application.OLD
  130. echo "Making new $application directory"
  131. mkdir /opt/$application
  132. echo "unpacking "$filename" to /opt/$application"
  133. ## Check file type and unpack accordingly ##
  134. if [[ "$filename" == *.tar.xz ]]; then
  135. echo "Unpacking as tar.xz file"
  136. tar -xvf "$projectdir/apps/$filename" -C "/opt/"
  137. elif [[ "$filename" == *.tar.bz2 ]]; then
  138. echo "Unpacking as tar.bz2 file"
  139. tar -xjvf "$projectdir/apps/$filename" -C "/opt/"
  140. else
  141. echo "WARNING: Unknown Compression Type. Aborting."
  142. exit 1
  143. fi
  144. applink=/opt/$application/$application
  145. chowm mike:mike /opt/firefox # Write permissions needed for firefox to check for updates
  146. elif [[ $application == 'nextcloud' || $application == 'keepass' ]]; then
  147. echo "Setting $filename as executable"
  148. sudo chmod +x $projectdir/apps/$filename
  149. echo "Done."
  150. applink=$projectdir/apps/$filename
  151. else
  152. echo "Unknown Application. Unable to Install. Aborting."
  153. exit 1
  154. fi
  155. # Install as Required
  156. # AppImage - ensure executable
  157. #
  158. # Ensure symlink is set and executable
  159. echo "Setting symlink /usr/local/bin/$application"
  160. ln -fs $applink $executablelink/$application
  161. echo "Done."
  162. # Ensure desktop file is set and executable
  163. if ! [ -f "$projectdir/assets/$application.desktop" ]; then
  164. echo "WARNING: $application.desktop file not found!"
  165. echo "WARNING: Desktop file not set!"
  166. exit 1
  167. fi
  168. echo "Setting $application.desktop in /usr/local/share/applications and verifying permissions"
  169. ln -fs $assetspath/$application.desktop $desktoppath/
  170. chmod +x $assetspath/$application.desktop
  171. echo "Done."
  172. # FINISHED SUCCESSFULLY #
  173. echo "Update Complete. Done."
  174. exit 0