Skip to content

Instantly share code, notes, and snippets.

@ravihara
Last active September 6, 2022 12:41
Show Gist options
  • Save ravihara/1a612a6f054e2878de8a9905824891da to your computer and use it in GitHub Desktop.
Save ravihara/1a612a6f054e2878de8a9905824891da to your computer and use it in GitHub Desktop.
Script to setup podman repo on Debian based systems
#!/bin/bash
podman_bin=$(which podman)
if [ -n "${podman_bin}" ]; then
echo -e "Podman installation found at $podman_bin. Skipping the setup."
exit 1
fi
## Do all the job in tmp folder
cd /tmp
echo -e "Installing script dependencies..."
sudo apt update -qq
sudo apt install -qq -y lsb-release wget
keyring_file="/etc/apt/keyrings/kubic-libcontainers.asc"
repo_key_base="https://download.opensuse.org/repositories/devel:kubic:libcontainers:stable"
repo_base_path="https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable"
distro_name=$(lsb_release -d | awk {'print $2'})
if [ $distro_name == "Debian" ]; then
distro_version=$(lsb_release -d | awk {'print $4'} | awk -F '.' {'print $1'})
else
distro_version=$(lsb_release -d | awk {'print $3'} | sed -e 's/\.[0-9]\+$//g')
fi
if [ $distro_name == "Ubuntu" ]; then
repo_path="${repo_base_path}/xUbuntu_${distro_version}"
repo_key_path="${repo_key_base}/xUbuntu_${distro_version}/Release.key"
elif [ $distro_name == "LMDE" ]; then
if [ $distro_version -eq 5 ]; then
distro_version=11
elif [ $distro_version -eq 4 ]; then
distro_version=10
fi
repo_path="${repo_base_path}/Debian_${distro_version}"
repo_key_path="${repo_key_base}/Debian_${distro_version}/Release.key"
elif [ $distro_name == "Debian" ]; then
repo_path="${repo_base_path}/Debian_${distro_version}"
repo_key_path="${repo_key_base}/Debian_${distro_version}/Release.key"
else
echo -e "\nUnhandled distribution ${distro_name}"
exit 1
fi
echo -e "\nThe computed repo path is: ${repo_path}"
echo -e "The computed repo-key path is: ${repo_key_path}"
wget -qO- ${repo_key_path} | sudo tee $keyring_file
sudo sh -c "echo 'deb [arch=amd64 signed-by=${keyring_file}] ${repo_path}/ /' > /etc/apt/sources.list.d/kubic-libcontainers.list"
sudo apt update -qq
sudo apt -qq -y install podman buildah
sudo mkdir -p /etc/containers
echo -e "[registries.search]\nregistries = ['docker.io', 'quay.io']" | sudo tee /etc/containers/registries.conf
## For non-root user, setup the rootless podman configuration
if [ $UID -ne 0 ]; then
sync && mkdir -p $HOME/.config/containers
podman info >/dev/null ## On first run, it tends to print some warning. Hence, skipping it.
podman info >$HOME/.config/containers/libpod.conf
fi
echo -e "All done."
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment