install.sh 4.9 KB

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