2023-04-03 09:51:58 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# Store the first command line argument in the variable "command" and shift the rest
|
2023-05-06 01:18:02 +00:00
|
|
|
command_args="$1"
|
2023-04-03 09:51:58 +00:00
|
|
|
shift
|
2023-05-06 01:34:31 +00:00
|
|
|
command=""
|
|
|
|
more_arguments=false
|
|
|
|
su_needed=false
|
|
|
|
|
2024-06-10 04:52:28 +00:00
|
|
|
# If sudo is needed and necessary (and installed), prepend it, if not installed throw error
|
|
|
|
check_sudo() {
|
|
|
|
if [ "$su_needed" = "true" ] && [ "$UID" != 0 ]; then
|
|
|
|
if command -v "sudo" &>/dev/null; then
|
|
|
|
command="sudo $command"
|
|
|
|
else
|
|
|
|
echo "sudo command needed but not found" > /dev/stderr
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Execute the command
|
|
|
|
execute_command() {
|
|
|
|
check_sudo
|
|
|
|
$command $command_args "${@}"
|
|
|
|
}
|
|
|
|
|
2023-05-06 01:34:31 +00:00
|
|
|
# Check if yay (aur)
|
2023-05-06 01:37:59 +00:00
|
|
|
if [ "$command_args" = "yay" ] || [ "$command_args" = "aur" ]; then
|
2023-05-06 01:34:31 +00:00
|
|
|
command="yay"
|
|
|
|
command_args="$1"
|
|
|
|
shift
|
|
|
|
more_arguments=true
|
|
|
|
# Check if config
|
|
|
|
elif [ "$command_args" = "config" ]; then
|
|
|
|
command="nano"
|
|
|
|
command_args="/etc/pacman.conf"
|
|
|
|
su_needed=true
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If command is empty, command is pacman
|
|
|
|
if [ "$command" = "" ]; then
|
|
|
|
command="pacman"
|
|
|
|
more_arguments=true
|
|
|
|
fi
|
2023-04-03 09:51:58 +00:00
|
|
|
|
2023-05-06 01:18:02 +00:00
|
|
|
# Evaluate the command arguments
|
2024-06-10 04:57:55 +00:00
|
|
|
case "$command_args" in
|
|
|
|
"search")
|
|
|
|
command_args="-Ss"
|
|
|
|
;;
|
2024-06-10 05:01:46 +00:00
|
|
|
"info")
|
|
|
|
command_args="-Si"
|
|
|
|
;;
|
|
|
|
"localinfo")
|
|
|
|
command_args="-Qi"
|
|
|
|
;;
|
2024-06-10 04:57:55 +00:00
|
|
|
"provides")
|
|
|
|
# Update the cache
|
2023-05-15 06:11:05 +00:00
|
|
|
su_needed=true
|
2024-06-10 04:57:55 +00:00
|
|
|
command_args="-Fy"
|
|
|
|
execute_command "${@}"
|
|
|
|
|
|
|
|
su_needed=false
|
|
|
|
command_args="-F"
|
|
|
|
;;
|
2024-08-01 00:02:52 +00:00
|
|
|
"providefiles")
|
|
|
|
# Update the cache
|
|
|
|
su_needed=true
|
|
|
|
command_args="-Fy"
|
|
|
|
execute_command "${@}"
|
|
|
|
|
|
|
|
su_needed=false
|
|
|
|
command_args="-Fl"
|
|
|
|
;;
|
2024-06-10 04:57:55 +00:00
|
|
|
"installed")
|
|
|
|
command_args="-Q"
|
|
|
|
;;
|
|
|
|
"install")
|
|
|
|
command_args="-S"
|
|
|
|
if [ "$command" = "pacman" ]; then
|
|
|
|
su_needed=true
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
"update")
|
|
|
|
command_args="-Sy"
|
|
|
|
if [ "$command" = "pacman" ]; then
|
|
|
|
su_needed=true
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
"upgradable")
|
|
|
|
command_args="-Qu"
|
|
|
|
;;
|
|
|
|
"upgrade")
|
|
|
|
command_args="-Syu"
|
|
|
|
if [ "$command" = "pacman" ]; then
|
|
|
|
su_needed=true
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
"remove")
|
|
|
|
command_args="-Rs"
|
|
|
|
if [ "$command" = "pacman" ]; then
|
|
|
|
su_needed=true
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
"purge")
|
|
|
|
command_args="-Rns"
|
|
|
|
if [ "$command" = "pacman" ]; then
|
|
|
|
su_needed=true
|
|
|
|
fi
|
|
|
|
;;
|
2024-06-10 04:59:23 +00:00
|
|
|
"clean")
|
|
|
|
command_args="-Scc"
|
|
|
|
if [ "$command" = "pacman" ]; then
|
|
|
|
su_needed=true
|
|
|
|
fi
|
|
|
|
;;
|
2024-06-10 04:57:55 +00:00
|
|
|
*)
|
|
|
|
if [ "$more_arguments" = "true" ]; then
|
2024-09-16 09:13:57 +00:00
|
|
|
echo "Invalid command: \"$command_args\""
|
2024-06-10 04:57:55 +00:00
|
|
|
echo
|
|
|
|
echo "Usage: pman <command> [args...]"
|
|
|
|
echo "Available commands:"
|
2024-08-01 00:02:52 +00:00
|
|
|
echo " yay (aur) - yay | invoke yay "
|
2024-06-10 04:57:55 +00:00
|
|
|
echo " (aur packages - all the normal operations except config are available)"
|
2024-08-01 00:02:52 +00:00
|
|
|
echo " aur (yay) - yay | same as \"yay\""
|
|
|
|
echo " search - pacman -Ss | search packages"
|
|
|
|
echo " info - pacman -Si | show package information"
|
|
|
|
echo " localinfo - pacman -Qi | show local package information"
|
|
|
|
echo " provides - pacman -F | list packages that provide file"
|
|
|
|
echo " providefiles - pacman -Fl | list files provided by package"
|
|
|
|
echo " installed - pacman -Q | list installed packages"
|
|
|
|
echo " install - pacman -S | install packages"
|
|
|
|
echo " update - pacman -Sy | updates the repositories"
|
|
|
|
echo " upgradable - pacman -Qu | list available upgrades"
|
|
|
|
echo " upgrade - pacman -Syu | upgrades your system"
|
|
|
|
echo " remove - pacman -Rs | remove packages & dependencies"
|
|
|
|
echo " purge - pacman -Rns | remove packages, dependencies & conf"
|
|
|
|
echo " clean - pacman -Scc | remove all package files & trash"
|
|
|
|
echo " config - /etc/pacman.conf | edits pacman configuration"
|
2024-06-10 04:57:55 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
2023-04-03 09:51:58 +00:00
|
|
|
|
2024-06-10 04:52:28 +00:00
|
|
|
execute_command "${@}"
|