Created
July 31, 2021 15:00
-
-
Save marshki/0ef73bee15ccda8b058fc6ab047baa9b to your computer and use it in GitHub Desktop.
A boilerplate script for retrieving and installing .deb files, using TeamViewer as an example. Easy to modify!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# boilerplate | |
# | |
# A boilerplate script for retrieving and installing .deb files, using TeamViewer as an example. Easy to modify! | |
# | |
# Author: M. Krinitz | |
# Date: 2021.07.31 | |
# License: MIT | |
PACKAGE_NAME="teamviewer" | |
URL="https://download.teamviewer.com/download/linux/teamviewer_amd64.deb" | |
DEB="teamviewer_amd64.deb" | |
DOWNLOAD_DESTINATION="$HOME/Downloads" | |
# If not Debian-based OS, exit. | |
check_OS () { | |
printf "%s\\n" "Checking OS version..." | |
if [[ ! -f "/etc/debian_version" ]]; then | |
printf "%s\\n" "NOT a Debian-based OS. Exiting." | |
exit 1 | |
else | |
printf "%s\\n" "Debian-based OS detected. Continuing..." | |
fi | |
} | |
# If package detected, exit. | |
check_package () { | |
printf "%s\\n" "Checking for installed version of: $PACKAGE_NAME..." | |
if dpkg-query --show --showformat='${Status}' "$PACKAGE_NAME" | grep "ok installed" &>/dev/null ; then | |
printf "%s\\n" "Installed version of: $PACKAGE_NAME DETECTED. Exiting." | |
exit 1 | |
else | |
printf "%s\\n" "Installed version of: $PACKAGE_NAME NOT DETECTED. Continuing..." | |
fi | |
} | |
# Retrieve package, and place in logged in user's Downloads directory. | |
get_package () { | |
printf "%s\\n" "Retrieving: $PACKAGE_NAME..." | |
wget --progress=bar --tries=3 --wait=5 --continue "$URL" --output-document="$DOWNLOAD_DESTINATION"/"$DEB" | |
} | |
# Use apt to install the .deb file. | |
install_package () { | |
printf "%s\\n" "Installing: $PACKAGE_NAME..." | |
sudo apt --yes install ./"$DOWNLOAD_DESTINATION"/"$DEB" | |
} | |
# Get exit status. | |
exit_status () { | |
if [[ $retVal -ne 0 ]]; then | |
printf "%s\\n" "Something went wrong, homie..." | |
else | |
printf "%s\\n" "Done." | |
fi | |
} | |
main () { | |
printf "%s\\n" "Running $PACKAGE_NAME installer." | |
check_OS | |
check_package | |
get_package | |
install_package | |
} | |
main "$@" | |
retVal=$? | |
exit_status |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment