Merge pull request #229 from dylanaraps/pkg_fix

Fix issues with users having more than one package manager installed.
This commit is contained in:
Dylan Araps 2016-04-26 17:38:37 +10:00
commit dc579d3fb3

View file

@ -646,69 +646,58 @@ getuptime () {
getpackages () {
case "$os" in
"Linux")
if type -p pacman >/dev/null 2>&1; then
type -p pacman >/dev/null 2>&1 && \
packages="$(pacman -Qq --color never | wc -l)"
elif type -p dpkg >/dev/null 2>&1; then
packages="$(dpkg --get-selections | grep -cv deinstall$)"
type -p dpkg >/dev/null 2>&1 && \
packages=$((packages+=$(dpkg --get-selections | grep -cv deinstall$)))
elif type -p /sbin/pkgtool >/dev/null 2>&1; then
packages="$(ls -1 /var/log/packages | wc -l)"
type -p /sbin/pkgtool >/dev/null 2>&1 && \
packages=$((packages+=$(ls -1 /var/log/packages | wc -l)))
elif type -p rpm >/dev/null 2>&1; then
packages="$(rpm -qa | wc -l)"
type -p rpm >/dev/null 2>&1 && \
packages=$((packages+=$(rpm -qa | wc -l)))
elif type -p xbps-query >/dev/null 2>&1; then
packages="$(xbps-query -l | wc -l)"
type -p xbps-query >/dev/null 2>&1 && \
packages=$((packages+=$(xbps-query -l | wc -l)))
elif type -p pkginfo >/dev/null 2>&1; then
packages="$(pkginfo -i | wc -l)"
type -p pkginfo >/dev/null 2>&1 && \
packages=$((packages+=$(pkginfo -i | wc -l)))
elif type -p pisi >/dev/null 2>&1; then
packages="$(pisi list-installed | wc -l)"
type -p pisi >/dev/null 2>&1 && \
packages=$((packages+=$(pisi list-installed | wc -l)))
elif type -p pkg >/dev/null 2>&1; then
packages="$(ls -1 /var/db/pkg | wc -l)"
type -p pkg >/dev/null 2>&1 && \
packages=$((packages+=$(ls -1 /var/db/pkg | wc -l)))
elif type -p emerge >/dev/null 2>&1; then
packages="$(ls -d /var/db/pkg/*/* | wc -l)"
type -p emerge >/dev/null 2>&1 && \
packages=$((packages+=$(ls -d /var/db/pkg/*/* | wc -l)))
elif type -p nix-env >/dev/null 2>&1; then
packages="$(ls -d -1 /nix/store/*/ | wc -l)"
type -p nix-env >/dev/null 2>&1 && \
packages=$((packages+=$(ls -d -1 /nix/store/*/ | wc -l)))
elif type -p apk >/dev/null 2>&1; then
packages="$(apk info | wc -l)"
type -p apk >/dev/null 2>&1 && \
packages=$((packages+=$(apk info | wc -l)))
elif type -p pacman-g2 >/dev/null 2>&1; then
packages="$(pacman-g2 -Q | wc -l)"
type -p pacman-g2 >/dev/null 2>&1 && \
packages=$((packages+=$(pacman-g2 -Q | wc -l)))
elif type -p cave >/dev/null 2>&1; then
cross_packages=$(ls -d -1 /var/db/paludis/repositories/cross-installed/*/data/* | wc -l)
packages=$(ls -d -1 /var/db/paludis/repositories/installed/data/* | wc -l)
packages=$((packages + cross_packages))
fi
type -p cave >/dev/null 2>&1 && \
packages=$((packages+=$(ls -d -1 /var/db/paludis/repositories/cross-installed/*/data/* /var/db/paludis/repositories/installed/data/* | wc -l)))
;;
"Mac OS X")
if [ -d "/usr/local/bin" ]; then
local_packages=$(ls -l /usr/local/bin/ | grep -v "\(../Cellar/\|brew\)" | wc -l)
packages=$((local_packages - 1))
fi
[ -d "/usr/local/bin" ] && \
packages=$(($(ls -l /usr/local/bin/ | grep -v "\(../Cellar/\|brew\)" | wc -l) - 1))
if type -p port >/dev/null 2>&1; then
port_packages=$(port installed 2>/dev/null | wc -l)
packages=$((packages + port_packages - 1))
fi
type -p port >/dev/null 2>&1 && \
packages=$((packages + $(port installed 2>/dev/null | wc -l) - 1))
if type -p brew >/dev/null 2>&1; then
brew_packages=$(find /usr/local/Cellar -maxdepth 1 2>/dev/null | wc -l)
packages=$((packages + brew_packages - 1))
fi
type -p brew >/dev/null 2>&1 && \
packages=$((packages + $(find /usr/local/Cellar -maxdepth 1 2>/dev/null | wc -l) - 1))
if type -p pkgin >/dev/null 2>&1; then
pkgsrc_packages=$(pkgin list 2>/dev/null | wc -l)
packages=$((packages + pkgsrc_packages))
fi
type -p pkgin >/dev/null 2>&1 && \
packages=$((packages + $(pkgin list 2>/dev/null | wc -l)))
;;
*"BSD")
@ -724,10 +713,8 @@ getpackages () {
packages=$(cygcheck -cd | wc -l)
# Count chocolatey packages
if [ -d "/cygdrive/c/ProgramData/chocolatey/lib" ]; then
choco_packages=$(ls -1 /cygdrive/c/ProgramData/chocolatey/lib | wc -l)
packages=$((packages + choco_packages))
fi
[ -d "/cygdrive/c/ProgramData/chocolatey/lib" ] && \
packages=$((packages+=$(ls -1 /cygdrive/c/ProgramData/chocolatey/lib | wc -l)))
;;
esac
packages=${packages// }