|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Copyright (C) 2024 Intel Corporation |
| 4 | +# SPDX-License-Identifier: Apache-2.0 |
| 5 | + |
| 6 | +set -e |
| 7 | + |
| 8 | +# BKC |
| 9 | +OS_ID="ubuntu" |
| 10 | +OS_VERSION="24.04" |
| 11 | +KERNEL_VERSION="6.6-intel" |
| 12 | + |
| 13 | +# symbol |
| 14 | +S_VALID="✓" |
| 15 | +#S_INVALID="✗" |
| 16 | + |
| 17 | +# verify current user |
| 18 | +if [ "$EUID" -eq 0 ]; then |
| 19 | + echo "Must not run with sudo or root user" |
| 20 | + exit 1 |
| 21 | +fi |
| 22 | + |
| 23 | +# resolve scripts directory |
| 24 | +SOURCE="${BASH_SOURCE[0]}" |
| 25 | +while [ -h "$SOURCE" ]; do |
| 26 | + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" |
| 27 | + SOURCE="$(readlink "$SOURCE")" |
| 28 | + [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" |
| 29 | +done |
| 30 | +DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" |
| 31 | + |
| 32 | +install_packages(){ |
| 33 | + local PACKAGES=("$@") |
| 34 | + local INSTALL_REQUIRED=0 |
| 35 | + for PACKAGE in "${PACKAGES[@]}"; do |
| 36 | + INSTALLED_VERSION=$(dpkg-query -W -f='${Version}' "$PACKAGE" 2>/dev/null || true) |
| 37 | + LATEST_VERSION=$(apt-cache policy "$PACKAGE" | grep Candidate | awk '{print $2}') |
| 38 | + |
| 39 | + if [ -z "$INSTALLED_VERSION" ] || [ "$INSTALLED_VERSION" != "$LATEST_VERSION" ]; then |
| 40 | + echo "$PACKAGE is not installed or not the latest version." |
| 41 | + INSTALL_REQUIRED=1 |
| 42 | + fi |
| 43 | + done |
| 44 | + if [ $INSTALL_REQUIRED -eq 1 ]; then |
| 45 | + sudo -E apt update |
| 46 | + sudo -E apt install -y "${PACKAGES[@]}" |
| 47 | + fi |
| 48 | +} |
| 49 | + |
| 50 | +verify_dependencies(){ |
| 51 | + echo -e "# Verifying dependencies" |
| 52 | + DEPENDENCIES_PACKAGES=( |
| 53 | + git |
| 54 | + curl |
| 55 | + wget |
| 56 | + clinfo |
| 57 | + ) |
| 58 | + install_packages "${DEPENDENCIES_PACKAGES[@]}" |
| 59 | + echo "$S_VALID Dependencies installed" |
| 60 | +} |
| 61 | + |
| 62 | +verify_intel_gpu_package_repo(){ |
| 63 | + if [ ! -e /etc/apt/sources.list.d/intel-gpu-jammy.list ]; then |
| 64 | + echo "Adding Intel GPU repository" |
| 65 | + wget -qO - https://repositories.intel.com/gpu/intel-graphics.key | \ |
| 66 | + sudo gpg --yes --dearmor --output /usr/share/keyrings/intel-graphics.gpg |
| 67 | + echo "deb [arch=amd64,i386 signed-by=/usr/share/keyrings/intel-graphics.gpg] https://repositories.intel.com/gpu/ubuntu noble client" | \ |
| 68 | + sudo tee /etc/apt/sources.list.d/intel-gpu-noble.list |
| 69 | + sudo -E apt update |
| 70 | + fi |
| 71 | +} |
| 72 | + |
| 73 | +verify_igpu_driver(){ |
| 74 | + # TODO: verify if same iGPU driver setup can use for dGPU |
| 75 | + echo -e "Verifying iGPU driver" |
| 76 | + |
| 77 | + # verify compute and media runtimes |
| 78 | + if [ -z "$(clinfo | grep 'Driver Version' | awk '{print $NF}')" ]; then |
| 79 | + verify_intel_gpu_package_repo |
| 80 | + IGPU_PACKAGES=( |
| 81 | + libze-intel-gpu1 |
| 82 | + intel-gsc |
| 83 | + intel-opencl-icd |
| 84 | + libze-dev |
| 85 | + intel-ocloc |
| 86 | + libze1 |
| 87 | + clinfo |
| 88 | + vainfo |
| 89 | + hwinfo |
| 90 | + ) |
| 91 | + install_packages "${IGPU_PACKAGES[@]}" |
| 92 | + if ! id -nG "$USER" | grep -q -w '\<video\>'; then |
| 93 | + echo "Adding current user to 'video' group" |
| 94 | + sudo usermod -aG video "$USER" |
| 95 | + fi |
| 96 | + if ! id -nG "$USER" | grep -q '\<render\>'; then |
| 97 | + echo "Adding current user to 'render' group" |
| 98 | + sudo usermod -aG render "$USER" |
| 99 | + fi |
| 100 | + fi |
| 101 | +} |
| 102 | + |
| 103 | +install_kernel_overlay() { |
| 104 | + echo -e "## Install User Space Components" |
| 105 | + sudo apt -y update |
| 106 | + sudo apt -y upgrade |
| 107 | + |
| 108 | + echo -e "### Add download link into /etc/apt/sources.list.d/intel-asladln.list" |
| 109 | + sudo touch /etc/apt/sources.list.d/intel-asladln.list |
| 110 | + echo -e "deb https://download.01.org/intel-linux-overlay/ubuntu noble main non-free multimedia kernels\n\ |
| 111 | + deb-src https://download.01.org/intel-linux-overlay/ubuntu noble main non-free multimedia kernels" | sudo tee /etc/apt/sources.list.d/intel-asladln.list |
| 112 | + |
| 113 | + echo -e "### Download the GPG key to /etc/apt/trusted.gpg.d and rename it to asladln.gpg" |
| 114 | + sudo wget https://download.01.org/intel-linux-overlay/ubuntu/E6FA98203588250569758E97D176E3162086EE4C.gpg -O /etc/apt/trusted.gpg.d/asladln.gpg |
| 115 | + |
| 116 | + echo -e "### Set the preferred list in /etc/apt/preferences.d/intel-asladln" |
| 117 | + sudo touch /etc/apt/preferences.d/intel-asladln |
| 118 | + echo -e "Package: *\n\ |
| 119 | + Pin: release o=intel-iot-linux-overlay-noble\n\ |
| 120 | + Pin-Priority: 2000" | sudo tee /etc/apt/preferences.d/intel-asladln |
| 121 | + |
| 122 | + echo -e "## Install Kernel Overlay" |
| 123 | + sudo apt -y update |
| 124 | + sudo apt -y install linux-image-6.6-intel |
| 125 | + sudo apt -y install linux-headers-6.6-intel |
| 126 | + sudo apt -y install linux-libc-dev |
| 127 | + |
| 128 | + echo -e "## Update grub" |
| 129 | + sudo sed -i 's/^GRUB_DEFAULT=.*$/GRUB_DEFAULT="Advanced options for Ubuntu>Ubuntu, with Linux 6.6-intel"/' /etc/default/grub |
| 130 | + sudo update-grub |
| 131 | + |
| 132 | + echo "System reboot is required. Re-run the script after reboot" |
| 133 | + exit 0 |
| 134 | +} |
| 135 | + |
| 136 | +verify_platform() { |
| 137 | + echo -e "\n# Verifying platform" |
| 138 | + CPU_MODEL=$(< /proc/cpuinfo grep -m1 "model name" | cut -d: -f2 | sed 's/^[ \t]*//') |
| 139 | + echo "- CPU model: $CPU_MODEL" |
| 140 | +} |
| 141 | + |
| 142 | +verify_gpu() { |
| 143 | + echo -e "\n# Verifying GPU" |
| 144 | + DGPU="$(lspci | grep VGA | grep Intel -c)" |
| 145 | + |
| 146 | + if [ "$DGPU" -ge 1 ]; then |
| 147 | + if [ ! -e "/dev/dri" ]; then |
| 148 | + IGPU=1 |
| 149 | + else |
| 150 | + IGPU="$(find /dev/dri -maxdepth 1 -type c -name 'renderD128*' | wc -l)" |
| 151 | + fi |
| 152 | + fi |
| 153 | + if [ -e "/dev/dri" ]; then |
| 154 | + IGPU="$(find /dev/dri -maxdepth 1 -type c -name 'renderD128*' | wc -l)" |
| 155 | + fi |
| 156 | + |
| 157 | + if [ "$DGPU" -ge 2 ]; then |
| 158 | + GPU_STAT_LABEL="- iGPU\n-dGPU (default)" |
| 159 | + echo kern_upgrade_dgpu |
| 160 | + else |
| 161 | + if [ "$IGPU" -lt 1 ]; then |
| 162 | + GPU_STAT_LABEL="- n/a" |
| 163 | + else |
| 164 | + GPU_STAT_LABEL="- iGPU (default)" |
| 165 | + fi |
| 166 | + fi |
| 167 | + echo -e "$GPU_STAT_LABEL" |
| 168 | +} |
| 169 | + |
| 170 | +verify_os() { |
| 171 | + echo -e "\n# Verifying operating system" |
| 172 | + if [ ! -e /etc/os-release ]; then |
| 173 | + echo "Error: /etc/os-release file not found" |
| 174 | + exit 1 |
| 175 | + fi |
| 176 | + CURRENT_OS_ID=$(grep -E '^ID=' /etc/os-release | cut -d'=' -f2- | tr -d '"') |
| 177 | + CURRENT_OS_VERSION=$(grep -E '^VERSION_ID=' /etc/os-release | cut -d'=' -f2- | tr -d '"') |
| 178 | + if [ "$OS_ID" != "$CURRENT_OS_ID" ] || [ "$OS_VERSION" != "$CURRENT_OS_VERSION" ]; then |
| 179 | + echo "Error: OS is not supported. Please make sure $OS_ID $OS_VERSION is installed" |
| 180 | + exit 1 |
| 181 | + fi |
| 182 | + echo "$S_VALID OS version: $CURRENT_OS_ID $CURRENT_OS_VERSION" |
| 183 | +} |
| 184 | + |
| 185 | +verify_kernel() { |
| 186 | + echo -e "\n# Verifying kernel version" |
| 187 | + CURRENT_KERNEL_VERSION=$(uname -r | cut -d'-' -f1) |
| 188 | + CURRENT_KERNEL_REVISION=$(uname -r | cut -d'-' -f2) |
| 189 | + CURRENT_KERNEL_VERSION_REVISION="$CURRENT_KERNEL_VERSION-$CURRENT_KERNEL_REVISION" |
| 190 | + |
| 191 | + if [ "$CURRENT_KERNEL_VERSION_REVISION" != "$KERNEL_VERSION" ]; then |
| 192 | + echo -e "Current Kernel: $CURRENT_KERNEL_VERSION_REVISION" |
| 193 | + echo -e "To be install: $KERNEL_VERSION" |
| 194 | + install_kernel_overlay |
| 195 | + elif [ "$CURRENT_KERNEL_VERSION_REVISION" == "$KERNEL_VERSION" ]; then |
| 196 | + echo -e "Current Kernel: $CURRENT_KERNEL_VERSION_REVISION" |
| 197 | + echo -e "Kernel Updated" |
| 198 | + else |
| 199 | + # TODO: option to install kernel via verify_custom_build_kernel |
| 200 | + echo "Error: Custom build kernel not yet supported." |
| 201 | + exit 1 |
| 202 | + fi |
| 203 | + echo "$S_VALID Kernel version: $(uname -r)" |
| 204 | +} |
| 205 | + |
| 206 | +verify_drivers() { |
| 207 | + echo -e "\n# Verifying drivers" |
| 208 | + if [ "$DGPU" -ge 2 ]; then |
| 209 | + # TODO: verify_dgpu_driver for supported platform |
| 210 | + echo "Error: dGPU driver is not supported" |
| 211 | + exit 1 |
| 212 | + else |
| 213 | + verify_igpu_driver |
| 214 | + fi |
| 215 | + if [ -z "$(clinfo | grep 'Driver Version' | awk '{print $NF}')" ]; then |
| 216 | + echo "Error: Failed to configure GPU driver" |
| 217 | + exit 1 |
| 218 | + fi |
| 219 | + GPU_DRIVER_VERSION="$(clinfo | grep 'Driver Version' | awk '{print $NF}')" |
| 220 | + echo "$S_VALID Intel GPU Drivers: $GPU_DRIVER_VERSION" |
| 221 | +} |
| 222 | + |
| 223 | +setup() { |
| 224 | + verify_dependencies |
| 225 | + verify_platform |
| 226 | + verify_gpu |
| 227 | + verify_os |
| 228 | + verify_kernel |
| 229 | + verify_drivers |
| 230 | + |
| 231 | + echo -e "\n# Status" |
| 232 | + echo "$S_VALID Platform configured" |
| 233 | +} |
| 234 | + |
| 235 | +setup |
0 commit comments