Last active
August 29, 2015 14:15
-
-
Save kurobeats/a7a8f22513f82a93903b to your computer and use it in GitHub Desktop.
pacapt package manager checker
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
# Detect package type from /etc/issue | |
_found_arch() { | |
local _ostype="$1" | |
shift | |
grep -qis "$*" /etc/issue && _OSTYPE="$_ostype" | |
} | |
# Detect package type | |
_OSTYPE_detect() { | |
_found_arch PACMAN "Arch Linux" && return | |
_found_arch DPKG "Debian GNU/Linux" && return | |
_found_arch DPKG "Ubuntu" && return | |
_found_arch YUM "CentOS" && return | |
_found_arch YUM "Red Hat" && return | |
_found_arch YUM "Fedora" && return | |
_found_arch ZYPPER "SUSE" && return | |
[[ -z "$_OSTYPE" ]] || return | |
# See also https://github.com/icy/pacapt/pull/22 | |
# Please not that $OSTYPE (which is `linux-gnu` on Linux system) | |
# is not our $_OSTYPE. The choice is not very good because | |
# a typo can just break the logic of the program. | |
if [[ "$OSTYPE" != "darwin"* ]]; then | |
_error "Can't detect OS type from /etc/issue. Running fallback method." | |
fi | |
[[ -x "/usr/bin/pacman" ]] && _OSTYPE="PACMAN" && return | |
[[ -x "/usr/bin/apt-get" ]] && _OSTYPE="DPKG" && return | |
[[ -x "/usr/bin/yum" ]] && _OSTYPE="YUM" && return | |
[[ -x "/opt/local/bin/port" ]] && _OSTYPE="MACPORTS" && return | |
command -v brew >/dev/null && _OSTYPE="HOMEBREW" && return | |
[[ -x "/usr/bin/emerge" ]] && _OSTYPE="PORTAGE" && return | |
[[ -x "/usr/bin/zypper" ]] && _OSTYPE="ZYPPER" && return | |
if [[ -z "$_OSTYPE" ]]; then | |
_error "No supported package manager installed on system" | |
_error "(supported: apt, homebrew, pacman, portage, yum)" | |
exit 1 | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment