Path: blob/master/pkg/cidata/cidata.TEMPLATE.d/boot/30-install-packages.sh
2661 views
#!/bin/sh12# SPDX-FileCopyrightText: Copyright The Lima Authors3# SPDX-License-Identifier: Apache-2.045set -eux67INSTALL_IPTABLES=08if [ "${LIMA_CIDATA_CONTAINERD_SYSTEM}" = 1 ] || [ "${LIMA_CIDATA_CONTAINERD_USER}" = 1 ]; then9INSTALL_IPTABLES=110fi11if [ "${LIMA_CIDATA_UDP_DNS_LOCAL_PORT}" -ne 0 ] || [ "${LIMA_CIDATA_TCP_DNS_LOCAL_PORT}" -ne 0 ]; then12INSTALL_IPTABLES=113fi1415# Install minimum dependencies16# Run any user provided dependency scripts first17if [ -d "${LIMA_CIDATA_MNT}"/provision.dependency ]; then18echo "Detected dependency provisioning scripts, running before default dependency installation"19CODE=020for f in "${LIMA_CIDATA_MNT}"/provision.dependency/*; do21if ! "$f"; then22CODE=123fi24done25if [ $CODE != 0 ]; then26exit "$CODE"27fi28fi2930# apt-get detected through the first bytes of apt-get binary to ensure we're31# matching to an actual binary and not a wrapper script. This case is an issue32# on OpenSuse which wraps its own package manager in to a script named apt-get33# to mimic certain options but doesn't offer full parameters compatibility34# See : https://github.com/lima-vm/lima/pull/101435if [ "${LIMA_CIDATA_SKIP_DEFAULT_DEPENDENCY_RESOLUTION}" = 1 ]; then36echo "LIMA_CIDATA_SKIP_DEFAULT_DEPENDENCY_RESOLUTION is set, skipping regular dependency installation"37exit 038fi3940REMOUNT_VIRTIOFS=04142if head -c 4 "$(command -v apt-get)" | grep -qP '\x7fELF' >/dev/null 2>&1; then43pkgs=""44if [ "${LIMA_CIDATA_MOUNTTYPE}" = "reverse-sshfs" ]; then45if [ "${LIMA_CIDATA_MOUNTS}" -gt 0 ] && ! command -v sshfs >/dev/null 2>&1; then46pkgs="${pkgs} sshfs"47fi48fi49if [ "${INSTALL_IPTABLES}" = 1 ] && [ ! -e /usr/sbin/iptables ]; then50pkgs="${pkgs} iptables"51fi52if [ "${LIMA_CIDATA_CONTAINERD_USER}" = 1 ] && ! command -v newuidmap >/dev/null 2>&1; then53pkgs="${pkgs} uidmap fuse3 dbus-user-session"54fi55if ! command -v rsync >/dev/null 2>&1; then56pkgs="${pkgs} rsync"57fi58if [ -n "${pkgs}" ]; then59DEBIAN_FRONTEND=noninteractive60export DEBIAN_FRONTEND61apt-get update62# shellcheck disable=SC208663apt-get install -y --no-upgrade --no-install-recommends -q ${pkgs}64fi65elif command -v dnf >/dev/null 2>&1; then66pkgs=""67extrapkgs=""68if ! command -v tar >/dev/null 2>&1; then69pkgs="${pkgs} tar"70fi71if [ "${LIMA_CIDATA_MOUNTTYPE}" = "reverse-sshfs" ]; then72if [ "${LIMA_CIDATA_MOUNTS}" -gt 0 ] && ! command -v sshfs >/dev/null 2>&1; then73# fuse-sshfs is not included in EL74extrapkgs="${extrapkgs} fuse-sshfs"75fi76fi77if [ "${INSTALL_IPTABLES}" = 1 ] && [ ! -e /usr/sbin/iptables ]; then78pkgs="${pkgs} iptables"79fi80if [ "${LIMA_CIDATA_CONTAINERD_USER}" = 1 ]; then81if ! command -v newuidmap >/dev/null 2>&1; then82pkgs="${pkgs} shadow-utils"83fi84if ! command -v mount.fuse3 >/dev/null 2>&1; then85pkgs="${pkgs} fuse3"86fi87fi88if ! command -v rsync >/dev/null 2>&1; then89pkgs="${pkgs} rsync"90fi91if [ -n "${pkgs}" ] || [ -n "${extrapkgs}" ]; then92dnf_install_flags="-y --setopt=install_weak_deps=False"93epel_install_flags=""94if grep -q "Oracle Linux Server release 8" /etc/system-release; then95# repo flag instead of enable repo to reduce metadata syncing on slow Oracle repos96dnf_install_flags="${dnf_install_flags} --repo ol8_baseos_latest --repo ol8_codeready_builder"97elif grep -q "release 8" /etc/system-release; then98dnf_install_flags="${dnf_install_flags} --enablerepo powertools"99elif grep -q "Oracle Linux Server release 9" /etc/system-release; then100# shellcheck disable=SC2086101dnf install ${dnf_install_flags} oracle-epel-release-el9102dnf config-manager --disable ol9_developer_EPEL >/dev/null 2>&1103epel_install_flags="${epel_install_flags} --enablerepo ol9_developer_EPEL"104elif grep -q "Oracle Linux Server release 10" /etc/system-release; then105oraclelinux_version="$(awk '{print $5}' /etc/system-release)"106oraclelinux_version_major=$(echo "$oraclelinux_version" | cut -d. -f1)107oraclelinux_version_minor=$(echo "$oraclelinux_version" | cut -d. -f2)108oraclelinux_epel_repo="ol${oraclelinux_version_major}_u${oraclelinux_version_minor}_developer_EPEL"109# shellcheck disable=SC2086110dnf install ${dnf_install_flags} oracle-epel-release-el${oraclelinux_version_major}111dnf config-manager --disable "$oraclelinux_epel_repo" >/dev/null 2>&1 || true112epel_install_flags="${epel_install_flags} --enablerepo $oraclelinux_epel_repo"113elif grep -q -E "release (9|10)" /etc/system-release; then114# shellcheck disable=SC2086115dnf install ${dnf_install_flags} epel-release116# Disable the OpenH264 repository as well, by default117dnf config-manager --disable epel\* >/dev/null 2>&1118epel_install_flags="${epel_install_flags} --enablerepo epel"119fi120if grep -q "Oracle Linux Server" /etc/system-release && [ "${LIMA_CIDATA_MOUNTTYPE}" = "virtiofs" ]; then121# Enable repositories like "ol9_UEKR7"122for repo in $(dnf -q repolist | awk '/UEK/NR>1{print $1}'); do123epel_install_flags="${epel_install_flags} --enablerepo ${repo}"124done125extrapkgs="${extrapkgs} kernel-uek-modules-$(uname -r)"126REMOUNT_VIRTIOFS=1127fi128if [ -n "${pkgs}" ]; then129# shellcheck disable=SC2086130dnf install ${dnf_install_flags} ${pkgs}131fi132if [ -n "${extrapkgs}" ]; then133# shellcheck disable=SC2086134dnf install ${dnf_install_flags} ${epel_install_flags} ${extrapkgs}135fi136fi137if [ "${LIMA_CIDATA_CONTAINERD_USER}" = 1 ] && [ ! -e /usr/bin/fusermount ]; then138# Workaround for https://github.com/containerd/stargz-snapshotter/issues/340139ln -s fusermount3 /usr/bin/fusermount140fi141elif command -v yum >/dev/null 2>&1; then142echo "DEPRECATED: CentOS7 and others RHEL-like version 7 are unsupported and might be removed or stop to work in future lima releases"143pkgs=""144yum_install_flags="-y"145if ! rpm -ql epel-release >/dev/null 2>&1; then146yum install ${yum_install_flags} epel-release147fi148if ! command -v tar >/dev/null 2>&1; then149pkgs="${pkgs} tar"150fi151if [ "${LIMA_CIDATA_MOUNTS}" -gt 0 ] && ! command -v sshfs >/dev/null 2>&1; then152pkgs="${pkgs} fuse-sshfs"153fi154if [ "${INSTALL_IPTABLES}" = 1 ] && [ ! -e /usr/sbin/iptables ]; then155pkgs="${pkgs} iptables"156fi157if [ "${LIMA_CIDATA_CONTAINERD_USER}" = 1 ]; then158if ! command -v newuidmap >/dev/null 2>&1; then159pkgs="${pkgs} shadow-utils"160fi161if ! command -v mount.fuse3 >/dev/null 2>&1; then162pkgs="${pkgs} fuse3"163fi164fi165if ! command -v rsync >/dev/null 2>&1; then166pkgs="${pkgs} rsync"167fi168if [ -n "${pkgs}" ]; then169# shellcheck disable=SC2086170yum install ${yum_install_flags} ${pkgs}171yum-config-manager --disable epel >/dev/null 2>&1172fi173elif command -v pacman >/dev/null 2>&1; then174pkgs=""175if [ "${LIMA_CIDATA_MOUNTTYPE}" = "reverse-sshfs" ]; then176if [ "${LIMA_CIDATA_MOUNTS}" -gt 0 ] && ! command -v sshfs >/dev/null 2>&1; then177pkgs="${pkgs} sshfs"178fi179fi180if ! command -v rsync >/dev/null 2>&1; then181pkgs="${pkgs} rsync"182fi183# other dependencies are preinstalled on Arch Linux184if [ -n "${pkgs}" ]; then185# shellcheck disable=SC2086186pacman -Sy --noconfirm ${pkgs}187fi188elif command -v zypper >/dev/null 2>&1; then189pkgs=""190if [ "${LIMA_CIDATA_MOUNTTYPE}" = "reverse-sshfs" ]; then191if [ "${LIMA_CIDATA_MOUNTS}" -gt 0 ] && ! command -v sshfs >/dev/null 2>&1; then192pkgs="${pkgs} sshfs"193fi194fi195if [ "${INSTALL_IPTABLES}" = 1 ] && [ ! -e /usr/sbin/iptables ]; then196pkgs="${pkgs} iptables"197fi198if [ "${LIMA_CIDATA_CONTAINERD_USER}" = 1 ] && ! command -v mount.fuse3 >/dev/null 2>&1; then199pkgs="${pkgs} fuse3"200fi201if ! command -v rsync >/dev/null 2>&1; then202pkgs="${pkgs} rsync"203fi204if [ -n "${pkgs}" ]; then205# shellcheck disable=SC2086206zypper --non-interactive install -y --no-recommends ${pkgs}207fi208elif command -v apk >/dev/null 2>&1; then209pkgs=""210if [ "${LIMA_CIDATA_MOUNTTYPE}" = "reverse-sshfs" ]; then211if [ "${LIMA_CIDATA_MOUNTS}" -gt 0 ] && ! command -v sshfs >/dev/null 2>&1; then212pkgs="${pkgs} sshfs"213fi214fi215if [ "${INSTALL_IPTABLES}" = 1 ] && ! command -v iptables >/dev/null 2>&1; then216pkgs="${pkgs} iptables"217fi218if ! command -v rsync >/dev/null 2>&1; then219pkgs="${pkgs} rsync"220fi221if [ -n "${pkgs}" ]; then222apk update223# shellcheck disable=SC2086224apk add ${pkgs}225fi226fi227228if [ "${REMOUNT_VIRTIOFS}" = 1 ]; then229mount -t virtiofs -a230fi231232233