Skip to content

Commit

Permalink
pmm: add yay support
Browse files Browse the repository at this point in the history
  • Loading branch information
paradigm committed Apr 8, 2020
1 parent 5f97ea2 commit c67573e
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 14 deletions.
4 changes: 4 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.7.14beta12

- Add pmm yay support

# 0.7.14beta11

- Fix Path handling in crossfs ini filter
Expand Down
11 changes: 11 additions & 0 deletions src/slash-bedrock/etc/bedrock.conf
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,17 @@ ignore-non-system-package-managers = true
# stratum. See `brl hide --help` and `brl show --help`.
#

#
# Some package managers such as yay recommend against running as root. If pmm
# is called as root, pmm will call such package managers with this user via
# `sudo`.
#
# sudo sets $SUDO_USER accordingly and is thus a good general default if pmm is
# called via sudo. If you do not use this, consider setting it either your
# primary user or a dedicated unprivileged user.
#
unprivileged-user = $SUDO_USER

#
# Most package managers support only a subset of available operations. If a
# given package manager is unable to fulfill an operation, it is skipped.
Expand Down
34 changes: 25 additions & 9 deletions src/slash-bedrock/libexec/pmm
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ color[\"strat\"] = \"${color_strat}\"
color[\"sub\"] = \"${color_sub}\"
color[\"warn\"] = \"${color_warn}\""

# Check if running as root user
if [ "$(id -u)" -eq 0 ]; then
initialize_awk_variables="${initialize_awk_variables}
am_root=1"
fi

#
# Gather unprivileged user
#
initialize_awk_variables="${initialize_awk_variables}
unprivileged_user=\"$(cfg_value "pmm" "unprivileged-user" | sed -e "s/['\"\\]/\\\&/" -e "s/^x//")\""

#
# Check if warnings are desired when skipping package managers.
#
Expand Down Expand Up @@ -130,10 +142,6 @@ cfg_ignore_non_system_package_managers=1"
if [ "${cfg_cache_package_manager_list}" = "true" ]; then
initialize_awk_variables="${initialize_awk_variables}
cfg_cache_package_manager_list=1"
if [ "$(id -u)" -eq 0 ]; then
initialize_awk_variables="${initialize_awk_variables}
am_root=1"
fi
fi
fi

Expand Down Expand Up @@ -675,7 +683,7 @@ function generate_pairs(_return, unfiltered_pairs,
notice("Run as root to generate package manager cache")
}

# Get ordered list of everything to consider
# Get ordered list of everything to consider. Duplicates will be filtered out later.
for (i = 1; i in cfg_pmm_priority; i++) {
partial_considerations[++partial_consideration_count] = cfg_pmm_priority[i]
}
Expand Down Expand Up @@ -707,17 +715,20 @@ function generate_pairs(_return, unfiltered_pairs,
considerations[++consideration_count] = pair "" i
}
}
for (i in package_manager_canary_executables) {
if (!(i in system_package_managers)) {
considerations[++consideration_count] = pair "" i
if (!cfg_ignore_non_system_package_managers) {
for (i in package_manager_canary_executables) {
if (!(i in system_package_managers)) {
considerations[++consideration_count] = pair "" i
}
}
}
} else {
abort("Unrecognized [pmm]/priority entry: "partial_considerations[i])
}
}

# Build final (unfiltered) pair list. Remove disallowed and repeated items.
# Build final (unfiltered) pair list. Remove repeated items and items
# which do not exist on disk.
for (c = 1; c in considerations; c++) {
pair = considerations[c]
split(pair, a, ":")
Expand Down Expand Up @@ -767,6 +778,11 @@ function prep_shell_environment(stratum, package_manager, items,
_local, output, f, i, a, count) {
output = "export stratum=\""shell_escape(stratum)"\";"
output = output " export package_manager=\""shell_escape(package_manager)"\";"
if (am_root && unprivileged_user) {
output = output " export unprivileged_user=\"sudo -u " unprivileged_user "\";"
} else {
output = output " export unprivileged_user=\"\";"
}
output = output " export flags=\""
count = 0
for (f in global_flags) {
Expand Down
10 changes: 5 additions & 5 deletions src/slash-bedrock/share/pmm/package_managers/pacman
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ user_interfaces["pacman", "mark-packages-implicit"] = "pmm -D/--database --asd
user_interfaces["pacman", "show-package-information"] = "pmm -S/--sync -i/--info <pkgs>"
user_interfaces["pacman", "clear-cache"] = "pmm -S/--sync -c/--clean"
user_interfaces["pacman", "remove-orphans"] = "" # no user facing command
user_interfaces["pacman", "update-package-database"] = "" # no separate file database concept, uses combine
user_interfaces["pacman", "update-package-database"] = "pmm -S/--sync -y/--refresh"
user_interfaces["pacman", "update-file-database"] = "pmm -F/--files -y/--refresh"
user_interfaces["pacman", "upgrade-packages-limited"] = "" # no partial upgrade concept
user_interfaces["pacman", "upgrade-packages-full"] = "pmm -S/--sync -u/--sysupgrade"
Expand Down Expand Up @@ -83,7 +83,7 @@ user_interfaces["pacman", "upgrade-packages-full,install-packages"]
user_interfaces["pacman", "update-package-database,upgrade-packages-partial,install-packages"] = ""
user_interfaces["pacman", "update-package-database,upgrade-packages-full,install-packages"] = ""
user_interfaces["pacman", "update-package-database,update-file-database,upgrade-packages-partial,install-packages"] = ""
user_interfaces["pacman", "update-package-database,update-file-database,upgrade-packages-full,install-packages"] = "pmm -S/--sync -y/--refresh -u/--sysupgrade <pkgs>"
user_interfaces["pacman", "update-package-database,update-file-database,upgrade-packages-full,install-packages"] = ""

implementations["pacman", "clear-cache,remove-orphans"] = ""
implementations["pacman", "mark-packages-implicit,remove-orphans"] = ""
Expand All @@ -100,8 +100,8 @@ implementations["pacman", "upgrade-packages-limited,install-packages"]
implementations["pacman", "upgrade-packages-full,install-packages"] = "strat -r ${stratum} pacman ${flags} -Su --asexplicit ${items}"
implementations["pacman", "update-package-database,upgrade-packages-partial,install-packages"] = "strat -r ${stratum} pacman ${flags} -Syu --asexplicit ${items}"
implementations["pacman", "update-package-database,upgrade-packages-full,install-packages"] = "strat -r ${stratum} pacman ${flags} -Syu --asexplicit ${items}"
implementations["pacman", "update-package-database,update-file-database,upgrade-packages-partial,install-packages"] = "strat -r ${stratum} pacman ${flags} -Syu --asexplicit ${items}"
implementations["pacman", "update-package-database,update-file-database,upgrade-packages-full,install-packages"] = "strat -r ${stratum} pacman ${flags} -Syu --asexplicit ${items}"
implementations["pacman", "update-package-database,update-file-database,upgrade-packages-partial,install-packages"] = ""
implementations["pacman", "update-package-database,update-file-database,upgrade-packages-full,install-packages"] = ""

#
# Operations which have a standardized output format.
Expand All @@ -121,7 +121,7 @@ implementations["pacman", "list-installed-explicit"] = "strat -r ${stratum}
implementations["pacman", "list-installed-implicit"] = "strat -r ${stratum} pacman -Qd | cut -d' ' -f1"
implementations["pacman", "list-installed-packages"] = "strat -r ${stratum} pacman -Q | cut -d' ' -f1"
implementations["pacman", "list-available-packages"] = "strat -r ${stratum} pacman -Sl | cut -d' ' -f2"
implementations["pacman", "search-for-package-by-name"] = "strat -r ${stratum} pacman -Sl | cut -d' ' -f2 | grep ${items}"
implementations["pacman", "search-for-package-by-name"] = "strat -r ${stratum} pacman -Sl ${items} | cut -d' ' -f2 | grep ${items}"
implementations["pacman", "search-for-package-by-all"] = "strat -r ${stratum} pacman -Ss ${items} | awk -F'[ /]' '/^[^ ]/{print$2}'"
implementations["pacman", "which-package-owns-file"] = "strat -r ${stratum} pacman -Qo ${items} | awk '{print$(NF-1)}'"
implementations["pacman", "which-packages-provide-file"] = "strat -r ${stratum} pacman -F ${items} |\
Expand Down
Loading

0 comments on commit c67573e

Please sign in to comment.