Skip to content

Instantly share code, notes, and snippets.

@ernstki
Last active January 17, 2024 01:34
Show Gist options
  • Save ernstki/6a62445896f77848dc852b03f4a423b3 to your computer and use it in GitHub Desktop.
Save ernstki/6a62445896f77848dc852b03f4a423b3 to your computer and use it in GitHub Desktop.
jdtt - accept command line arguments for 'yum', 'apt', or 'port' and just do the thing based on the platform
#!/usr/bin/env bash
##
## Accept arguments from popular package management tools (except Homebrew)
## and just do the right thing, based on the platform.
##
## Created out of frustration at typing `yum` on Macs and `port` on Linux
## boxes, and `apt` on RHEL/CentOS boxes all too often.
##
## Author: Kevin Ernst <ernstki -at- mail.uc.edu>
## Date: 16 Januar 2024
## License: WTFPL
## Source: https://gist.github.com/ernstki/6a62445896f77848dc852b03f4a423b3
##
set -u
system=$(uname -s)
case $system in
Darwin)
if which port &>/dev/null; then
if which brew &>/dev/null; then
echo "Detected Homebrew, ignoring in favor of MacPorts" >&2
fi
platform=MacPorts
else
echo "ERROR: MacPorts 'port' command not found." >&2
exit 1
fi
;;
Linux)
if [[ $(lsb-release) =~ (Debian|Ubuntu) ]]; then
platform=DebianOrUbuntu
elif [[ $(lsb-release) =~ (CentOS|Red Hat) ]]; then
platform=CentOSorRHEL
else
echo "ERROR: Unsupported Linux platform. :-(" >&2
exit 1
fi
;;
*)
echo "ERROR: Sorry, unsupported platform. :-(" >&2
exit 1
;;
esac
declare -A package_managers
package_managers=(
[MacPorts]=port
[DebianOrUbuntu]=apt
[CentOSorRHEL]=yum
)
# 'install' will work for a version 0.1
exec ${package_managers[$platform]} "$@"
@ernstki
Copy link
Author

ernstki commented Jan 17, 2024

Symlink as yum, apt, and port and relax. It'll do the thing.

GIST=6a62445896f77848dc852b03f4a423b3
cd ~/bin
wget https://gist.githubusercontent.com/ernstki/$GIST/raw/jdtt
chmod a+x jdtt
ln -s jdtt yum
ln -s jdtt apt
ln -s jdtt port

@ernstki
Copy link
Author

ernstki commented Jan 17, 2024

To-do

  • rpm -qa, dpkg -l, and port echo installed - list installed packages
  • rpm -ql, dpkg -L, and port list - list specific package's contents
  • rpm -qf, dpkg -S, and port provides - which package owns a specific file?
  • port deps port rdepends, apt-cache rdepends, and whatever the rpm version is - all those ones I can never remember that answer the questions "which packages does this package require?" and "which packages require this package as a dependency?"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment