| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- #!/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
- #
- ######
- ######
- #
- # INSTALLING THIS SCRIPT
- #
- # Link to this script in /usr/bin so it can be called by the sudo command
- # ex. sudo ln -fs /home/mike/Software/TG_Installer/TG_Installer.sh /usr/bin/tg_installer
- #
- ######
- 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
|