1- # ' Determine the operating system from a base image
1+ # ' Determine the Linux Distribution from a base image
2+ # '
3+ # ' Analyzes a Docker base image name to determine the underlying distribution
24# '
35# ' @param base_image Base image name
4- # ' @return Character string of OS type (e.g., "ubuntu", "centos", "debian")
6+ # '
7+ # ' @return
8+ # ' Character string of OS type (e.g., "ubuntu", "centos", "debian", "alpine")
9+ # '
10+ # ' @examples
11+ # ' determine_linux_distribution("rocker/r-ver:4.4.0") # Returns "ubuntu"
12+ # ' determine_linux_distribution("alpine:3.16") # Returns "alpine"
13+ # ' determine_linux_distribution("centos:7") # Returns "centos"
14+ # '
15+ # ' @details
16+ # ' This function parses the base image name to extract the underlying
17+ # ' distribution. For Rocker Project images (which are based on Ubuntu/Debian),
18+ # ' it returns "ubuntu". For other distributions, it attempts to identify
19+ # ' common ones like Debian, CentOS, Fedora, Alpine, etc.
20+ # '
21+ # ' @seealso
22+ # ' [determine_package_manager()] for determining the package manager &
23+ # ' [map_to_sysreqs_platform()] for mapping to sysreqs platform
24+ # '
25+ # ' @family utility functions
526# ' @export
6- determine_os <- function (base_image ) {
27+ determine_linux_distribution <- function (base_image ) {
728 if (is.null(base_image )) {
829 return (NULL )
930 }
@@ -47,18 +68,44 @@ determine_os <- function(base_image) {
4768
4869# ' Determine the package manager from a base image
4970# '
71+ # ' Analyzes a Docker base image name to determine the appropriate package manager.
72+ # '
5073# ' @param base_image Base image name
51- # ' @return Character string of package manager type ("apt", "yum", "apk", etc.)
74+ # '
75+ # ' @return
76+ # ' Character string of package manager type ("apt", "yum", "apk", "zypper", "pacman")
77+ # '
78+ # ' @examples
79+ # ' determine_package_manager("rocker/r-ver:4.4.0") # Returns "apt"
80+ # ' determine_package_manager("alpine:3.16") # Returns "apk"
81+ # ' determine_package_manager("centos:7") # Returns "yum"
82+ # '
83+ # ' @details
84+ # ' This function first identifies the linux distribution using
85+ # ' [determine_linux_distribution()], then maps that to the appropriate
86+ # ' package manager:
87+ # '
88+ # ' * Ubuntu/Debian → apt
89+ # ' * CentOS/Fedora/RHEL → yum
90+ # ' * Alpine → apk
91+ # ' * OpenSUSE → zypper
92+ # ' * Arch → pacman
93+ # '
94+ # ' @seealso
95+ # ' [determine_linux_distribution()] for determining the operating system &
96+ # ' [generate_pkg_install_cmd()] for generating package installation commands
97+ # '
98+ # ' @family utility functions
5299# ' @export
53100determine_package_manager <- function (base_image ) {
54101 if (is.null(base_image )) {
55102 return (NULL )
56103 }
57104
58- # Get the OS first
59- os <- determine_os (base_image )
105+ # Get the distribution first
106+ os <- determine_linux_distribution (base_image )
60107
61- # Map OS to package manager
108+ # Map distribution to package manager
62109 if (os %in% c(" ubuntu" , " debian" )) {
63110 return (" apt" )
64111 } else if (os %in% c(" centos" , " fedora" , " redhat" , " rockylinux" )) {
@@ -77,9 +124,34 @@ determine_package_manager <- function(base_image) {
77124
78125# ' Map package manager to sysreqs platform
79126# '
80- # ' @param package_manager Package manager type
127+ # ' Maps a package manager to the corresponding platform identifier used by
128+ # ' the pak package's system requirements feature.
129+ # '
130+ # ' @param package_manager Package manager type (e.g., "apt", "yum")
81131# ' @param os Operating system (if known)
82- # ' @return Character string of platform for sysreqs
132+ # '
133+ # ' @return
134+ # ' Character string of platform for sysreqs
135+ # '
136+ # ' @details
137+ # ' This internal function maps package managers to platform identifiers
138+ # ' understood by the pak package's system requirements feature. It uses
139+ # ' the following mappings:
140+ # '
141+ # ' - apt → ubuntu (or debian if specified)
142+ # ' - yum → centos (or fedora, redhat, rockylinux if specified)
143+ # ' - zypper → opensuse (or sle if specified)
144+ # ' - apk → ubuntu (Alpine not directly supported)
145+ # ' - pacman → ubuntu (Arch not directly supported)
146+ # '
147+ # ' If the OS is explicitly provided and supported by pak, that platform
148+ # ' is used directly.
149+ # '
150+ # ' @seealso
151+ # ' [determine_package_manager()] for determining the package manager &
152+ # ' [dk_add_sysreqs()] for adding system requirements to a dockerfile
153+ # '
154+ # ' @family utility functions
83155# ' @keywords internal
84156map_to_sysreqs_platform <- function (package_manager , os = NULL ) {
85157 if (! is.null(os )) {
0 commit comments