Skip to content

Instantly share code, notes, and snippets.

@EdinUser
Last active March 11, 2025 08:54
Show Gist options
  • Select an option

  • Save EdinUser/63096b6fec8f5ef8e4d78614050171aa to your computer and use it in GitHub Desktop.

Select an option

Save EdinUser/63096b6fec8f5ef8e4d78614050171aa to your computer and use it in GitHub Desktop.

Check App Installation Source Script

A simple and helpful Bash script for Ubuntu (and other Debian-based distros) that quickly checks:

  • How an application is installed (Snap, Flatpak, or APT).
  • Installed application version compared to the versions available from Snap, Flatpak, and APT.
  • Provides an option to install the application if it's currently not installed.

Usage

Check installed app version and source:

./check-install-source.sh <app_name>

Example:

./check-install-source.sh zoom

If the app is not installed, the script will present you with installation options from:

  • Snap
  • Flatpak
  • APT

You can easily select the desired source by entering the corresponding number (1-3), or cancel the operation.


How to Install the Script:

  1. Clone or download the script:
git clone <repo_url>
cd <repo_folder>
chmod +x check-install-source.sh
  1. Run the script:
./check-install-source.sh <app_name>

Make the script globally accessible:

If you want to call the script directly from anywhere, follow these steps:

System-wide (requires sudo privileges):

sudo cp check-install-source.sh /usr/local/bin/check-install-source
sudo chmod +x /usr/bin/check-install-source.sh

Now, you can run the script directly:

check-install-source.sh zoom

User-specific (no sudo privileges required):

mkdir -p ~/bin
cp check-install-source.sh ~/bin/check-install-source
chmod +x ~/bin/check-install-source

Add your ~/bin to your PATH if it's not already:

echo 'export PATH=$PATH:~/bin' >> ~/.bashrc
source ~/.bashrc

Now you can use it anywhere with:

check-install-source zoom

Requirements:

  • Ubuntu or Debian-based Linux distribution.
  • Optional (for maximum compatibility):
    • snap
    • flatpak
  • Required:
    • apt

Features:

  • Clearly identifies installation method (Snap, Flatpak, or APT).
  • Shows installed and available versions from Snap, Flatpak, and APT.
  • Colored output indicating newer, older, or up-to-date versions.
  • Offers user-friendly installation options when the app isn't installed.
  • Safely handles cases when snap, flatpak, or apt are missing.

Color Legend:

  • 🟢 Green: Up-to-date
  • Magenta: Newer version available
  • Yellow: Older version
  • Red: Not available

Requirements:

  • Ubuntu or Debian-based Linux distribution.
  • Optional but recommended:
    • snap
    • flatpak
  • Required:
    • apt

Compatibility:

  • Tested on Ubuntu 22.04 and 24.04
  • Compatible with most Debian-based Linux distributions

Contribution:

Feel free to contribute, improve or report issues!

#!/bin/bash
APP_NAME="$1"
if [ -z "$APP_NAME" ]; then
echo "Usage: $0 <app_name>"
exit 1
fi
# Colors
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[0;33m'
CYAN='\033[0;36m'
MAGENTA='\033[0;35m'
NC='\033[0m'
# Check availability of tools
command -v snap >/dev/null 2>&1 && HAS_SNAP=true || HAS_SNAP=false
command -v flatpak >/dev/null 2>&1 && HAS_FLATPAK=true || HAS_FLATPAK=false
command -v apt >/dev/null 2>&1 && HAS_APT=true || HAS_APT=false
# Snap Version
if $HAS_SNAP; then
SNAP_VERSION=$(snap info "$APP_NAME" 2>/dev/null | grep -m1 stable | awk '{print $2}')
fi
# Flatpak Version
if $HAS_FLATPAK; then
FLATPAK_VERSION=$(flatpak search "$APP_NAME" --columns=name,version 2>/dev/null | grep -i "$APP_NAME" | awk '{print $NF}' | head -n1)
fi
# APT Version
if $HAS_APT; then
APT_VERSION=$(apt-cache policy "$APP_NAME" | grep Candidate | awk '{print $2}')
fi
# Check Installation Source and Version
if $HAS_SNAP && snap list | grep -iq "^${APP_NAME}"; then
INSTALL_SOURCE="Snap"
APP_VERSION=$(snap list | grep -i "^${APP_NAME}" | awk '{print $2}')
elif $HAS_FLATPAK && flatpak list --app | grep -iq "$APP_NAME"; then
INSTALL_SOURCE="Flatpak"
APP_VERSION=$(flatpak list --app | grep -i "$APP_NAME" | awk '{print $2}')
elif $HAS_APT && apt list --installed 2>/dev/null | grep -iq "^${APP_NAME}/"; then
INSTALL_SOURCE="APT"
APP_VERSION=$(dpkg -s "$APP_NAME" | grep '^Version:' | awk '{print $2}')
else
echo -e "${YELLOW}The app \"$APP_NAME\" is not installed.${NC}"
echo -e "\nAvailable versions to install:"
[ "$HAS_SNAP" = true ] && echo -e "1) Snap: ${SNAP_VERSION:-${RED}Not available${NC}}"
[ "$HAS_FLATPAK" = true ] && echo -e "2) Flatpak: ${FLATPAK_VERSION:-${RED}Not available${NC}}"
[ "$HAS_APT" = true ] && echo -e "3) APT: ${APT_VERSION:-${RED}Not available${NC}}"
echo -e "4) Do not install"
read -p "Select an installation method [number]: " INSTALL_CHOICE
case $INSTALL_CHOICE in
1)
[ "$HAS_SNAP" = true ] && sudo snap install "$APP_NAME" || echo -e "${RED}Snap is not installed.${NC}" ;;
2)
[ "$HAS_FLATPAK" = true ] && flatpak install flathub "$APP_NAME" -y || echo -e "${RED}Flatpak is not installed.${NC}" ;;
3)
[ "$HAS_APT" = true ] && sudo apt update && sudo apt install "$APP_NAME" -y || echo -e "${RED}APT is not available.${NC}" ;;
*)
echo -e "${CYAN}Installation canceled.${NC}" ;;
esac
exit 0
fi
echo -e "The app \"$APP_NAME\" was installed via ${CYAN}$INSTALL_SOURCE${NC}."
echo -e "Your installed version is ${GREEN}$APP_VERSION${NC}."
echo -e "\nVersions from all sources:"
version_compare() {
dpkg --compare-versions "$1" gt "$2" && return 1
dpkg --compare-versions "$1" lt "$2" && return 2
return 0
}
compare_version() {
if [ -z "$1" ]; then
echo -e "${RED}Not available${NC}"
else
version_compare "$1" "$APP_VERSION"
case $? in
0) echo -e "${GREEN}$1 (up-to-date)${NC}" ;;
1) echo -e "${MAGENTA}$1 (newer)${NC}" ;;
2) echo -e "${YELLOW}$1 (older)${NC}" ;;
esac
fi
}
[ "$HAS_SNAP" = true ] && echo -e "Snap: $(compare_version "$SNAP_VERSION")"
[ "$HAS_FLATPAK" = true ] && echo -e "Flatpak: $(compare_version "$FLATPAK_VERSION")"
[ "$HAS_APT" = true ] && echo -e "APT: $(compare_version "$APT_VERSION")"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment