| 1 | #!/bin/sh |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | set -eux |
| 7 | |
| 8 | INSTALL_IPTABLES=0 |
| 9 | if [ "${LIMA_CIDATA_CONTAINERD_SYSTEM}" = 1 ] || [ "${LIMA_CIDATA_CONTAINERD_USER}" = 1 ]; then |
| 10 | INSTALL_IPTABLES=1 |
| 11 | fi |
| 12 | if [ "${LIMA_CIDATA_UDP_DNS_LOCAL_PORT}" -ne 0 ] || [ "${LIMA_CIDATA_TCP_DNS_LOCAL_PORT}" -ne 0 ]; then |
| 13 | INSTALL_IPTABLES=1 |
| 14 | fi |
| 15 | |
| 16 | |
| 17 | |
| 18 | if [ -d "${LIMA_CIDATA_MNT}"/provision.dependency ]; then |
| 19 | echo "Detected dependency provisioning scripts, running before default dependency installation" |
| 20 | CODE=0 |
| 21 | for f in "${LIMA_CIDATA_MNT}"/provision.dependency/*; do |
| 22 | if ! "$f"; then |
| 23 | CODE=1 |
| 24 | fi |
| 25 | done |
| 26 | if [ $CODE != 0 ]; then |
| 27 | exit "$CODE" |
| 28 | fi |
| 29 | fi |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | if [ "${LIMA_CIDATA_SKIP_DEFAULT_DEPENDENCY_RESOLUTION}" = 1 ]; then |
| 37 | echo "LIMA_CIDATA_SKIP_DEFAULT_DEPENDENCY_RESOLUTION is set, skipping regular dependency installation" |
| 38 | exit 0 |
| 39 | fi |
| 40 | |
| 41 | REMOUNT_VIRTIOFS=0 |
| 42 | |
| 43 | if head -c 4 "$(command -v apt-get)" | grep -qP '\x7fELF' >/dev/null 2>&1; then |
| 44 | pkgs="" |
| 45 | if [ "${LIMA_CIDATA_MOUNTTYPE}" = "reverse-sshfs" ]; then |
| 46 | if [ "${LIMA_CIDATA_MOUNTS}" -gt 0 ] && ! command -v sshfs >/dev/null 2>&1; then |
| 47 | pkgs="${pkgs} sshfs" |
| 48 | fi |
| 49 | fi |
| 50 | if [ "${INSTALL_IPTABLES}" = 1 ] && [ ! -e /usr/sbin/iptables ]; then |
| 51 | pkgs="${pkgs} iptables" |
| 52 | fi |
| 53 | if [ "${LIMA_CIDATA_CONTAINERD_USER}" = 1 ] && ! command -v newuidmap >/dev/null 2>&1; then |
| 54 | pkgs="${pkgs} uidmap fuse3 dbus-user-session" |
| 55 | fi |
| 56 | if ! command -v rsync >/dev/null 2>&1; then |
| 57 | pkgs="${pkgs} rsync" |
| 58 | fi |
| 59 | if [ -n "${pkgs}" ]; then |
| 60 | DEBIAN_FRONTEND=noninteractive |
| 61 | export DEBIAN_FRONTEND |
| 62 | apt-get update |
| 63 | |
| 64 | apt-get install -y --no-upgrade --no-install-recommends -q ${pkgs} |
| 65 | fi |
| 66 | elif command -v dnf >/dev/null 2>&1; then |
| 67 | pkgs="" |
| 68 | extrapkgs="" |
| 69 | if ! command -v tar >/dev/null 2>&1; then |
| 70 | pkgs="${pkgs} tar" |
| 71 | fi |
| 72 | if [ "${LIMA_CIDATA_MOUNTTYPE}" = "reverse-sshfs" ]; then |
| 73 | if [ "${LIMA_CIDATA_MOUNTS}" -gt 0 ] && ! command -v sshfs >/dev/null 2>&1; then |
| 74 | |
| 75 | extrapkgs="${extrapkgs} fuse-sshfs" |
| 76 | fi |
| 77 | fi |
| 78 | if [ "${INSTALL_IPTABLES}" = 1 ] && [ ! -e /usr/sbin/iptables ]; then |
| 79 | pkgs="${pkgs} iptables" |
| 80 | fi |
| 81 | if [ "${LIMA_CIDATA_CONTAINERD_USER}" = 1 ]; then |
| 82 | if ! command -v newuidmap >/dev/null 2>&1; then |
| 83 | pkgs="${pkgs} shadow-utils" |
| 84 | fi |
| 85 | if ! command -v mount.fuse3 >/dev/null 2>&1; then |
| 86 | pkgs="${pkgs} fuse3" |
| 87 | fi |
| 88 | fi |
| 89 | if ! command -v rsync >/dev/null 2>&1; then |
| 90 | pkgs="${pkgs} rsync" |
| 91 | fi |
| 92 | if [ -n "${pkgs}" ] || [ -n "${extrapkgs}" ]; then |
| 93 | dnf_install_flags="-y --setopt=install_weak_deps=False" |
| 94 | epel_install_flags="" |
| 95 | if grep -q "Oracle Linux Server release 8" /etc/system-release; then |
| 96 | |
| 97 | dnf_install_flags="${dnf_install_flags} --repo ol8_baseos_latest --repo ol8_codeready_builder" |
| 98 | elif grep -q "release 8" /etc/system-release; then |
| 99 | dnf_install_flags="${dnf_install_flags} --enablerepo powertools" |
| 100 | elif grep -q "Oracle Linux Server release 9" /etc/system-release; then |
| 101 | |
| 102 | dnf install ${dnf_install_flags} oracle-epel-release-el9 |
| 103 | dnf config-manager --disable ol9_developer_EPEL >/dev/null 2>&1 |
| 104 | epel_install_flags="${epel_install_flags} --enablerepo ol9_developer_EPEL" |
| 105 | elif grep -q "Oracle Linux Server release 10" /etc/system-release; then |
| 106 | oraclelinux_version="$(awk '{print $5}' /etc/system-release)" |
| 107 | oraclelinux_version_major=$(echo "$oraclelinux_version" | cut -d. -f1) |
| 108 | oraclelinux_version_minor=$(echo "$oraclelinux_version" | cut -d. -f2) |
| 109 | oraclelinux_epel_repo="ol${oraclelinux_version_major}_u${oraclelinux_version_minor}_developer_EPEL" |
| 110 | |
| 111 | dnf install ${dnf_install_flags} oracle-epel-release-el${oraclelinux_version_major} |
| 112 | dnf config-manager --disable "$oraclelinux_epel_repo" >/dev/null 2>&1 || true |
| 113 | epel_install_flags="${epel_install_flags} --enablerepo $oraclelinux_epel_repo" |
| 114 | elif grep -q -E "release (9|10)" /etc/system-release; then |
| 115 | |
| 116 | dnf install ${dnf_install_flags} epel-release |
| 117 | |
| 118 | dnf config-manager --disable epel\* >/dev/null 2>&1 |
| 119 | epel_install_flags="${epel_install_flags} --enablerepo epel" |
| 120 | fi |
| 121 | if grep -q "Oracle Linux Server" /etc/system-release && [ "${LIMA_CIDATA_MOUNTTYPE}" = "virtiofs" ]; then |
| 122 | |
| 123 | for repo in $(dnf -q repolist | awk '/UEK/NR>1{print $1}'); do |
| 124 | epel_install_flags="${epel_install_flags} --enablerepo ${repo}" |
| 125 | done |
| 126 | extrapkgs="${extrapkgs} kernel-uek-modules-$(uname -r)" |
| 127 | REMOUNT_VIRTIOFS=1 |
| 128 | fi |
| 129 | if [ -n "${pkgs}" ]; then |
| 130 | |
| 131 | dnf install ${dnf_install_flags} ${pkgs} |
| 132 | fi |
| 133 | if [ -n "${extrapkgs}" ]; then |
| 134 | |
| 135 | dnf install ${dnf_install_flags} ${epel_install_flags} ${extrapkgs} |
| 136 | fi |
| 137 | fi |
| 138 | if [ "${LIMA_CIDATA_CONTAINERD_USER}" = 1 ] && [ ! -e /usr/bin/fusermount ]; then |
| 139 | |
| 140 | ln -s fusermount3 /usr/bin/fusermount |
| 141 | fi |
| 142 | elif command -v yum >/dev/null 2>&1; then |
| 143 | echo "DEPRECATED: CentOS7 and others RHEL-like version 7 are unsupported and might be removed or stop to work in future lima releases" |
| 144 | pkgs="" |
| 145 | yum_install_flags="-y" |
| 146 | if ! rpm -ql epel-release >/dev/null 2>&1; then |
| 147 | yum install ${yum_install_flags} epel-release |
| 148 | fi |
| 149 | if ! command -v tar >/dev/null 2>&1; then |
| 150 | pkgs="${pkgs} tar" |
| 151 | fi |
| 152 | if [ "${LIMA_CIDATA_MOUNTS}" -gt 0 ] && ! command -v sshfs >/dev/null 2>&1; then |
| 153 | pkgs="${pkgs} fuse-sshfs" |
| 154 | fi |
| 155 | if [ "${INSTALL_IPTABLES}" = 1 ] && [ ! -e /usr/sbin/iptables ]; then |
| 156 | pkgs="${pkgs} iptables" |
| 157 | fi |
| 158 | if [ "${LIMA_CIDATA_CONTAINERD_USER}" = 1 ]; then |
| 159 | if ! command -v newuidmap >/dev/null 2>&1; then |
| 160 | pkgs="${pkgs} shadow-utils" |
| 161 | fi |
| 162 | if ! command -v mount.fuse3 >/dev/null 2>&1; then |
| 163 | pkgs="${pkgs} fuse3" |
| 164 | fi |
| 165 | fi |
| 166 | if ! command -v rsync >/dev/null 2>&1; then |
| 167 | pkgs="${pkgs} rsync" |
| 168 | fi |
| 169 | if [ -n "${pkgs}" ]; then |
| 170 | |
| 171 | yum install ${yum_install_flags} ${pkgs} |
| 172 | yum-config-manager --disable epel >/dev/null 2>&1 |
| 173 | fi |
| 174 | elif command -v pacman >/dev/null 2>&1; then |
| 175 | pkgs="" |
| 176 | if [ "${LIMA_CIDATA_MOUNTTYPE}" = "reverse-sshfs" ]; then |
| 177 | if [ "${LIMA_CIDATA_MOUNTS}" -gt 0 ] && ! command -v sshfs >/dev/null 2>&1; then |
| 178 | pkgs="${pkgs} sshfs" |
| 179 | fi |
| 180 | fi |
| 181 | if ! command -v rsync >/dev/null 2>&1; then |
| 182 | pkgs="${pkgs} rsync" |
| 183 | fi |
| 184 | |
| 185 | if [ -n "${pkgs}" ]; then |
| 186 | |
| 187 | pacman -Sy --noconfirm ${pkgs} |
| 188 | fi |
| 189 | elif command -v zypper >/dev/null 2>&1; then |
| 190 | pkgs="" |
| 191 | if [ "${LIMA_CIDATA_MOUNTTYPE}" = "reverse-sshfs" ]; then |
| 192 | if [ "${LIMA_CIDATA_MOUNTS}" -gt 0 ] && ! command -v sshfs >/dev/null 2>&1; then |
| 193 | pkgs="${pkgs} sshfs" |
| 194 | fi |
| 195 | fi |
| 196 | if [ "${INSTALL_IPTABLES}" = 1 ] && [ ! -e /usr/sbin/iptables ]; then |
| 197 | pkgs="${pkgs} iptables" |
| 198 | fi |
| 199 | if [ "${LIMA_CIDATA_CONTAINERD_USER}" = 1 ] && ! command -v mount.fuse3 >/dev/null 2>&1; then |
| 200 | pkgs="${pkgs} fuse3" |
| 201 | fi |
| 202 | if ! command -v rsync >/dev/null 2>&1; then |
| 203 | pkgs="${pkgs} rsync" |
| 204 | fi |
| 205 | if [ -n "${pkgs}" ]; then |
| 206 | |
| 207 | zypper --non-interactive install -y --no-recommends ${pkgs} |
| 208 | fi |
| 209 | elif command -v apk >/dev/null 2>&1; then |
| 210 | pkgs="" |
| 211 | if [ "${LIMA_CIDATA_MOUNTTYPE}" = "reverse-sshfs" ]; then |
| 212 | if [ "${LIMA_CIDATA_MOUNTS}" -gt 0 ] && ! command -v sshfs >/dev/null 2>&1; then |
| 213 | pkgs="${pkgs} sshfs" |
| 214 | fi |
| 215 | fi |
| 216 | if [ "${INSTALL_IPTABLES}" = 1 ] && ! command -v iptables >/dev/null 2>&1; then |
| 217 | pkgs="${pkgs} iptables" |
| 218 | fi |
| 219 | if ! command -v rsync >/dev/null 2>&1; then |
| 220 | pkgs="${pkgs} rsync" |
| 221 | fi |
| 222 | if [ -n "${pkgs}" ]; then |
| 223 | apk update |
| 224 | |
| 225 | apk add ${pkgs} |
| 226 | fi |
| 227 | fi |
| 228 | |
| 229 | if [ "${REMOUNT_VIRTIOFS}" = 1 ]; then |
| 230 | mount -t virtiofs -a |
| 231 | fi |