90 lines
3.1 KiB
Bash
Executable File
90 lines
3.1 KiB
Bash
Executable File
#!/bin/sh
|
|
# One Package Manager ... to Rule Them All
|
|
# idea by Case Duckworth <acdw@acdw.net> 2022
|
|
|
|
# Linux distros are pretty similar, except they all have different package
|
|
# managers and it's hard to remember what's what, when all you want to do is
|
|
# install `sl` or the latest meme editor. PET aims to help with this by mapping
|
|
# common package-management transactions to one easy-to-remember command list.
|
|
|
|
# There are two ways that this improves over other one-size-fits-all package
|
|
# managers: (A) you can use whichever your favorite package manager's syntax is
|
|
# by setting `$PET_ARGUMENT_STYLE`; and (B) you don't have to call PET with the
|
|
# name PET.
|
|
|
|
# PET can be symlinked to another filename on disk, or renamed; if it's called
|
|
# by that name (and it maps to one of PET's known package managers), it will use
|
|
# that manager's syntax for the transaction. It will also warn the user
|
|
# (depending on the value of `$PET_WARN_ALTERNATE`, which defaults to true) that
|
|
# they're currently in another distro, and if they want to do more complex
|
|
# package management, they need to use that distro's manager.
|
|
|
|
# Indeed, the philosophy of PET stipulates that most of the time, only a certain
|
|
# subset of package management transactions are necessary, and those most common
|
|
# transactions are supported by the vast majority of package managers. Anything
|
|
# more complicated will likely be distro- or package-manager-specific, and is
|
|
# better served by using that particular manager.
|
|
|
|
: "${PET_ARGUMENT_STYLE:=pet}"
|
|
: "${PET_WARN_ALTERNATE:=true}"
|
|
|
|
## PET_PACKAGE_MANAGERS is a space-separated list of supported package managers.
|
|
PET_PACKAGE_MANAGERS="pet"
|
|
|
|
### Dispatching
|
|
|
|
pet_executable_p() { # pet_executable_p NAME
|
|
## Return success if NAME exists in $PATH and is executable, else fail.
|
|
command -v "$1" >/dev/null 2>&1
|
|
}
|
|
|
|
pet_package_manager() {
|
|
## Figure out what package manager to perform transactions as.
|
|
# If $0 is something other than pet or pet.sh, use that. Else, if
|
|
# $PET_ARGUMENT_STYLE exists on the system, use that. Else, try all the
|
|
# package managers PET knows about, and use the first found.
|
|
case "$0" in
|
|
*pet|*pet.sh) echo pet ;;
|
|
*)
|
|
if ! [ "$PET_ARGUMENT_STYLE" = pet ] &&
|
|
pet_executable_p "$PET_ARGUMENT_STYLE"; then
|
|
echo "$PET_ARGUMENT_STYLE"
|
|
else
|
|
set -- $PET_PACKAGE_MANAGERS # no quotes intentional
|
|
for pm; do
|
|
if pet_executable_p "$pm"; then
|
|
echo "$PET_ARGUMENT_STYLE"
|
|
return 0
|
|
fi
|
|
return 1 # not found
|
|
done
|
|
fi
|
|
}
|
|
|
|
pet_dispatch() { # pet_dispatch PACKAGE_MANAGER TRANSACTION PACKAGE
|
|
## Perform TRANSACTION on PACKAGE, using PACKAGE_MANAGER.
|
|
}
|
|
|
|
### Package transactions
|
|
|
|
package_install() {
|
|
## Install a package.
|
|
}
|
|
|
|
package_uninstall() {
|
|
## Uninstall a package.
|
|
}
|
|
|
|
package_search() {
|
|
## Search for a package.
|
|
}
|
|
|
|
package_update() {
|
|
## Update package repositories.
|
|
}
|
|
|
|
package_upgrade() {
|
|
## Upgrade a package.
|
|
# Without arguments, upgrade all packages.
|
|
}
|