Skip to content

Commit

Permalink
feat: use package manager, not distro for installing podman
Browse files Browse the repository at this point in the history
  • Loading branch information
jgresham committed May 6, 2024
1 parent 6b6b84f commit ee22856
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 28 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/podman-install-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ jobs:
"ubuntu:22.04",
"debian:12",
"fedora:40",
"fedora:39"
"fedora:39",
"manjarolinux/base",
"archlinux:latest",
"opensuse/leap:latest"
]

container:
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/main/nn-auto-updater/findPackageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { promisify } from 'node:util';

const exec = promisify(execCallback);

export type PackageType = 'deb' | 'rpm';
export type PackageManager = 'dpkg' | 'dnf' | 'yum' | 'zypper';
export type PackageType = 'deb' | 'pacman' | 'rpm';
export type PackageManager = 'dpkg' | 'dnf' | 'pacman' | 'yum' | 'zypper';

interface PackageManagerMap {
[key: string]: PackageManager;
Expand All @@ -17,16 +17,16 @@ interface PackageManagerToTypeMap {
const packageManagers: PackageManagerMap = {
'apt-get': 'dpkg', // "deb (apt)",
dnf: 'dnf', // "rpm (dnf)",
pacman: 'pacman',
yum: 'yum', // "rpm (yum)",
// pacman: "pacman",
zypper: 'zypper', // "rpm (zypper)"
};

const packageTypes: PackageManagerToTypeMap = {
'apt-get': 'deb', // "deb (apt)",
dnf: 'rpm', // "rpm (dnf)",
pacman: 'pacman',
yum: 'rpm', // "rpm (yum)",
// pacman: "pacman",
zypper: 'rpm', // "rpm (zypper)"
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Reference https://podman.io/docs/installation
// first line is to remove a depracted apt source that will conflict with the official one
export const script = `rm -rf /etc/apt/sources.list.d/devel:kubic:libcontainers:unstable.list
apt -y update -qq
apt install -y podman`;
File renamed without changes.
37 changes: 22 additions & 15 deletions src/main/podman/install/installOnLinux.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { reportEvent } from '../../events';
import { execAwait } from '../../execHelper';
import logger from '../../logger';
import {
type PackageManager,
findPackageManager,
} from '../../nn-auto-updater/findPackageManager.js';
import { getOperatingSystemInfo } from '../../systemInfo';
import { sendMessageOnGrantPermissionToInstallPodman } from '../messageFrontEnd';
import { script as debianInstallScript } from './debianInstallScript';
import { script as fedoraInstallScript } from './fedoraInstallScript';
import { script as linuxMintInstallScript } from './linuxMintInstallScript';
import { script as manjaroInstallScript } from './manjaroInstallScript';
import { script as ubuntuInstallScript } from './ubuntuInstallScript';
import { script as aptInstallScript } from './aptInstallScript';
import { script as dnfInstallScript } from './dnfInstallScript';
import { script as pacmanInstallScript } from './pacmanInstallScript';
import { script as yumInstallScript } from './yumInstallScript';
import { script as zypperInstallScript } from './zypperInstallScript';

// const UBUNTU_INSTALL_SCRIPT = 'installOnUbuntuScript';
/**
Expand All @@ -17,6 +21,7 @@ import { script as ubuntuInstallScript } from './ubuntuInstallScript';
const installOnLinux = async (): Promise<any> => {
logger.info('Starting podman install on Linux...');
const { distro, release } = await getOperatingSystemInfo();
// ex: Ubuntu & 22.04.4 LTS
logger.info(
`Attempting to install Podman on distro and release: ${distro} & ${release} ...`,
);
Expand All @@ -25,21 +30,23 @@ const installOnLinux = async (): Promise<any> => {
let installScript = '';
// Run "cat /etc/*-release; cat /usr/lib/os-release; cat /etc/openwrt_release" on a Linux Distro
// or see https://github.com/sebhildebrandt/systeminformation/blob/master/lib/osinfo.js to determine.
if (lcDistro.includes('ubuntu')) {
installScript = ubuntuInstallScript;
} else if (lcDistro.includes('debian')) {
installScript = debianInstallScript;
} else if (lcDistro.includes('fedora')) {
installScript = fedoraInstallScript;
} else if (lcDistro.includes('manjaro') || lcDistro.includes('arch')) {
installScript = manjaroInstallScript;
} else if (lcDistro.includes('linuxmint')) {
installScript = linuxMintInstallScript;
const pkgManager: PackageManager = await findPackageManager();
if (pkgManager === 'dpkg') {
installScript = aptInstallScript;
} else if (pkgManager === 'dnf') {
installScript = dnfInstallScript;
} else if (pkgManager === 'yum') {
installScript = yumInstallScript;
} else if (pkgManager === 'pacman') {
installScript = pacmanInstallScript;
} else if (pkgManager === 'zypper') {
installScript = zypperInstallScript;
} else {
const errorMessage = `Installing Podman is not suported on this distro and release: ${distro} & ${release}`;
logger.error(errorMessage);
return { error: errorMessage };
}

try {
try {
const { stdout, stderr } = await execAwait(installScript, {
Expand Down
4 changes: 0 additions & 4 deletions src/main/podman/install/ubuntuInstallScript.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Same script as on https://podman.io/docs/installation, except the 'sudo' is removed as
// sudo-prompt will not execute a command with sudo
export const script = `apt -y update -qq
apt -qq -y install podman`;
export const script = 'dnf -y update && dnf -y install podman';
3 changes: 3 additions & 0 deletions src/main/podman/install/zypperInstallScript.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Reference https://podman.io/docs/installation
// biome-ignore lint/style/noUnusedTemplateLiteral: less diff for future changes
export const script = `zypper install -y podman`;

0 comments on commit ee22856

Please sign in to comment.