Skip to content

Instantly share code, notes, and snippets.

@cjemorton
Created February 5, 2024 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cjemorton/20a5af1576635d065becfa039836e0ec to your computer and use it in GitHub Desktop.
Save cjemorton/20a5af1576635d065becfa039836e0ec to your computer and use it in GitHub Desktop.
#!/bin/sh
# Detect the shell
if [ -n "$BASH_VERSION" ]; then
SHELL_NAME="bash"
elif [ -n "$ZSH_VERSION" ]; then
SHELL_NAME="zsh"
else
SHELL_NAME="unknown"
fi
# Detect the package manager
case "$SHELL_NAME" in
"bash" | "zsh")
if command -v pkg &> /dev/null; then
echo "FreeBSD system using pkg"
elif command -v apt-get &> /dev/null; then
echo "Debian-based system using apt-get"
elif command -v yum &> /dev/null; then
echo "Red Hat-based system using yum"
elif command -v dnf &> /dev/null; then
echo "Red Hat-based system using dnf"
else
echo "Unsupported or unknown package manager"
fi
;;
*)
echo "Unsupported shell: $SHELL_NAME"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment