Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save n3bulous/55ef7931c802e1e41c9b339f3db9ce2f to your computer and use it in GitHub Desktop.
Save n3bulous/55ef7931c802e1e41c9b339f3db9ce2f to your computer and use it in GitHub Desktop.
List installed software on Mac, Debian, and RedHat
#!/usr/bin/env bash
# Usage, if you use SDKMAN: ./list_all_software_bash.sh sdk
# Otherwise: ./list_all_software_bash.sh
if [ "$1" = "sdk" ]; then
# Your *_profile is a login shell and should reference your bashrc
# if [ -f ~/.bashrc ]; then
# source ~/.bashrc
# fi
# .zprofile for zsh
shell_name=$(basename $SHELL)
case "$shell_name" in
bash) source ~/.bashrc ;;
zsh) source ~/.zshrc ;;
fish) echo "Why is Fish's config so non-standard?"; exit 1; ;;
*) echo "$SHELL isn't supported"; exit 1 ;;
esac
if declare -f sdk >/dev/null; then
echo ""
echo "SDKMAN SDKs:"
echo "=========="
sdk current | cut -d':' -f1
fi
fi
if hash gradle 2>/dev/null; then
echo ""
echo "Gradle cache:"
echo "=========="
pushd ~/.gradle/caches >/dev/null && find . -name '*.jar' | grep -v 'sources' | rev | cut -d'/' -f1 | rev | sed 's/[-_][0-9].*//'
popd >/dev/null
fi
if [ -d ~/.m2 ]; then
echo ""
echo "Maven cache:"
echo "=========="
pushd ~/.m2 >/dev/null
find . -name '*.jar' | sed 's/\.\/repository\///' | sed 's/[-_][0-9].*//' | sed 's/\/[0-9].*\//\//' | sort | uniq
popd >/dev/null
fi
if hash python2 2>/dev/null; then
echo ""
echo "Python2 Pip:"
echo "=========="
python2 -m pip list | cut -d' ' -f1
#echo "Python2 builtins:"
#python2 -c "help('modules')"
fi
if hash python3 2>/dev/null; then
echo ""
echo "Python3 Pip:"
echo "=========="
python3 -m pip list | cut -d' ' -f1
#echo "Python3 builtins:"
#python3 -c "help('modules')"
fi
if hash dpkg 2>/dev/null; then
echo ""
echo "DPKG:"
echo "=========="
dpkg --get-selections | grep -v "deinstall" | cut -f1
fi
# Ignoring project specific packages for now
#if hash find 2>/dev/null; then
# pushd ~ >/dev/null
# echo "Finding python requirement files"
# find . -name 'requirements.txt' -exec cat {} \; |sort |uniq
# echo "Done with python requirements files"
# echo "Finding compile libraries from gradle"
# find . -name 'build.gradle' -exec cat {} \; | grep 'compile ' |sort |uniq
# echo "Finding ruby file requirements"
# find -name '*.rb' -exec cat {} \; |grep 'require' |sort |uniq
# echo "Any brewfiles: "
# find -name 'Brewfile' -exec cat{} \; | cut -d' ' -f2 | tr -d '"' | tr -d ',' | sort | uniq
# popd
#fi
if hash yum 2>/dev/null; then
echo ""
echo "YUM packages:"
echo "=========="
yum list installed
fi
# Ignoring Docker images for now
#if hash docker 2>/dev/null; then
# echo ""
# echo "Docker images:"
# echo "=========="
# docker images
#fi
if hash gem 2>/dev/null; then
echo ""
echo "Rubygems:"
echo "=========="
gem list | grep '(' | cut -d' ' -f1 | sort | uniq
fi
# Ignore ruby versions for now
#if hash rvm 2>/dev/null; then
# echo ""
# echo "RVM:"
# echo "=========="
# rvm list
#fi
if hash npm 2>/dev/null; then
echo ""
echo "NPM:"
echo "=========="
npm list -g | grep '@' | rev | cut -d' ' -f1 | cut -d'@' -f2 |rev | sed 's/[[:space:]]*$//' |sort| uniq
fi
if hash go 2>/dev/null; then
echo ""
echo "Go:"
echo "=========="
pushd $GOPATH >/dev/null
go list ...
popd >/dev/null
fi
if hash port 2>/dev/null; then
echo ""
echo "Port:"
echo "=========="
port installed
fi
if hash brew 2>/dev/null; then
echo ""
echo "Brew:"
echo "=========="
pushd /tmp >/dev/null && rm -f Brewfile
brew bundle dump --all
cat Brewfile | cut -d' ' -f2 | tr -d '"' | tr -d ',' | sort | uniq
popd >/dev/null
fi
if [ -d /Applications ]; then
echo ""
echo "Mac Apps - Global:"
echo "=========="
ls -d /Applications/*.app 2>/dev/null | cut -d'/' -f3 | sort
ls -d /Applications/* 2>/dev/null | grep -v app | cut -d'/' -f3 | sort
fi
if [ -d ~/Applications ]; then
echo ""
echo "Mac Apps - User:"
echo "=========="
ls -d ~/Applications/*.app 2>/dev/null | cut -d'/' -f3 | sort
ls -d ~/Applications/* 2>/dev/null | grep -v app | rev | cut -d'/' -f1 | rev | sort
fi
if hash cargo 2>/dev/null; then
echo ""
echo "Rust:"
echo "=========="
# unsure of output format
cargo install --list | rev | cut -d' ' -f2 | rev | sort | uniq
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment