Bladeren bron

Initial Commit.

Mike 1 maand geleden
commit
08099803cc
1 gewijzigde bestanden met toevoegingen van 214 en 0 verwijderingen
  1. 214 0
      install.sh

+ 214 - 0
install.sh

@@ -0,0 +1,214 @@
+#!/bin/bash
+
+#####
+#
+# This script will:
+# - Identify the type type of file being passed as an argument
+# - Install that file
+#
+# USAGE -
+#
+# sudo ./install <opt> <filename>
+#
+# opts:
+# -n Nextcloud
+# -k KeePass
+# -f Firefox
+# -h Help File
+# -v Version
+#
+######
+
+helpFunction()
+{
+  echo " "
+  echo "Installs Nextcloud and KeePass AppImages, as well as Firefox Tarballs, in a consistent manner."
+  echo "Requires a manually created .desktop file placed in an assets/ folder in the application installation directory at /home/USER/Software/APPLICATION"
+  echo "Requires a folder apps in the application installation folder for receiving application AppImages or Tarballs."
+  echo "Must run with root privileges."
+  echo " "
+  echo "Usage: sudo $0 [opts] [filename]"
+  echo " -n Nextcloud"
+  echo " -k KeePass"
+  echo " -f Firefox"
+  echo " -h Help File"
+  echo " -v Version"
+  echo " "
+}
+
+## VARIABLES ##
+
+projectdir="/home/mike/Software"
+#imagepath="$projectdir/apps"
+executablelink="/usr/local/bin"
+desktoppath="/usr/local/share/applications"
+#assetspath="$projectdir/assets"
+version="0.1"
+
+## Applications Permitted ##
+
+applications_array=("Nextcloud" "KeePass" "Firefox")
+
+echo "TG Generic Installer Script 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 user-provided file is valid #
+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 cal>
+  echo "$filename appears valid."
+fi
+
+# Check what application this is #
+
+for app in "${applications_array[@]}"; do
+  if [[ "${filename,,}" == *"${app,,}"* ]]; then
+    application_formal=$app
+    application=${app,,}
+    echo "Configuring to install: $app"
+    projectdir=$projectdir/$application
+    imagepath=$projectdir/apps
+    assetspath=$projectdir/assets
+  fi
+done
+
+# Check if projectdir exists
+
+echo "Checking Project Directory"
+
+if ! [ -d $projectdir ]; then
+  echo "Folder $projectdir not found.  Creating folder structure..."
+  mkdir $projectdir
+  mkdir $projectdir/apps
+  mkdir $projectdir/assets
+  chown -R mike:mike $projectdir
+  echo "Project directory is created."
+  echo "WARNING!  You must create a .desktop file and icon in assets/ folder!"
+else
+  echo "Done"
+fi
+
+# Move file, if required
+
+echo "Checking App Location"
+
+if ! [ -f "$projectdir/apps/$filename" ]; then
+  echo "Moving $1 to $imagepath/"
+  mv $1 $projectdir/apps/$filename
+  echo "Done."
+else
+  echo "Done"
+fi
+
+####
+#
+# INSTALL
+#
+###
+
+echo "Installing $application_formal"
+
+if [ $application == 'firefox' ]; then
+
+  echo "Checking for old installations"
+
+  if [ -d "/opt/$application.OLD" ]; then
+    read -p  "$application.OLD already exists?  Should I delete it? ENTER to continue or CTRL+C to abort." input
+  fi
+
+  echo "Deleting existing $application.OLD folder"
+
+  rm -rf /opt/$application.OLD
+
+  echo "Moving Existing $application to $application.OLD"
+
+  mv /opt/$application /opt/$application.OLD
+
+  echo "Making new $application directory"
+
+  mkdir /opt/$application
+
+  echo "unpacking "$filename" to /opt/$application"
+
+  ## Check file type and unpack accordingly ##
+
+  if [[ "$filename" == *.tar.xz ]]; then
+    echo "Unpacking as tar.xz file" 
+    tar -xvf "$projectdir/apps/$filename" -C "/opt/"
+  elif [[ "$filename" == *.tar.bz2 ]]; then
+    echo "Unpacking as tar.bz2 file"
+    tar -xjvf "$projectdir/apps/$filename" -C "/opt/"
+  else
+    echo "WARNING: Unknown Compression Type.  Aborting."
+    exit 1
+  fi
+
+  applink='/opt/$application/$application'
+
+  chowm mike:mike /opt/firefox # Write permissions needed for firefox to check for updates
+
+elif [[ $application == 'nextcloud' || $application == 'keepass' ]]; then
+
+  echo "Setting $filename as executable"
+  sudo chmod +x $projectdir/apps/$filename
+  echo "Done."
+
+  applink=$projectdir/apps/$filename
+else
+  echo "Unknown Application.  Unable to Install.  Aborting."
+  exit 1
+fi
+
+# Install as Required
+# AppImage - ensure executable
+#
+# Ensure symlink is set and executable
+
+echo "Setting symlink /usr/local/bin/$application"
+ln -fs $applink $executablelink/$application
+echo "Done."
+
+# Ensure desktop file is set and executable
+if ! [ -f "$projectdir/assets/$application.desktop" ]; then
+  echo "WARNING: $application.desktop file not found!"
+  echo "WARNING: Desktop file not set!"
+  exit 1
+fi
+
+echo "Setting $application.desktop in /usr/local/share/applications and verifying permissions"
+ln -fs $assetspath/$application.desktop $desktoppath/
+chmod +x $assetspath/$application.desktop
+echo "Done."
+
+# FINISHED SUCCESSFULLY #
+
+echo "Update Complete.  Done."
+exit 0
+
+
+