* Gets the package manager for a specific distribution type
(distroType: LinuxDistroType)
| 174 | * Gets the package manager for a specific distribution type |
| 175 | */ |
| 176 | function getPackageManager(distroType: LinuxDistroType): PackageManager { |
| 177 | switch (distroType) { |
| 178 | case LinuxDistroType.DEBIAN: { |
| 179 | return { |
| 180 | name: 'apt', |
| 181 | installCommand: 'apt-get install', |
| 182 | requiresSudo: true, |
| 183 | updateCommand: 'apt-get update', |
| 184 | }; |
| 185 | } |
| 186 | case LinuxDistroType.REDHAT: { |
| 187 | // Prefer dnf over yum |
| 188 | if (checkCommandExists('dnf')) { |
| 189 | return { |
| 190 | name: 'dnf', |
| 191 | installCommand: 'dnf install', |
| 192 | requiresSudo: true, |
| 193 | }; |
| 194 | } else { |
| 195 | return { |
| 196 | name: 'yum', |
| 197 | installCommand: 'yum install', |
| 198 | requiresSudo: true, |
| 199 | }; |
| 200 | } |
| 201 | } |
| 202 | case LinuxDistroType.ARCH: { |
| 203 | return { |
| 204 | name: 'pacman', |
| 205 | installCommand: 'pacman -S', |
| 206 | requiresSudo: true, |
| 207 | updateCommand: 'pacman -Sy', |
| 208 | }; |
| 209 | } |
| 210 | case LinuxDistroType.SUSE: { |
| 211 | return { |
| 212 | name: 'zypper', |
| 213 | installCommand: 'zypper install', |
| 214 | requiresSudo: true, |
| 215 | }; |
| 216 | } |
| 217 | default: { |
| 218 | return { |
| 219 | name: 'unknown', |
| 220 | installCommand: '', |
| 221 | requiresSudo: true, |
| 222 | }; |
| 223 | } |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * Gets the appropriate package name for the current distribution |
no test coverage detected