-
-
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
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
#!/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]} "$@" |
To-do
rpm -qa
,dpkg -l
, andport echo installed
- list installed packagesrpm -ql
,dpkg -L
, andport list
- list specific package's contentsrpm -qf
,dpkg -S
, andport provides
- which package owns a specific file?port deps
port rdepends
,apt-cache rdepends
, and whatever therpm
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
Symlink as
yum
,apt
, andport
and relax. It'll do the thing.