1*2f2c4c7aSAndroid Build Coastguard Worker#!/bin/bash 2*2f2c4c7aSAndroid Build Coastguard Worker# 3*2f2c4c7aSAndroid Build Coastguard Worker# Copyright (C) 2022 The Android Open Source Project 4*2f2c4c7aSAndroid Build Coastguard Worker# 5*2f2c4c7aSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License"); 6*2f2c4c7aSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License. 7*2f2c4c7aSAndroid Build Coastguard Worker# You may obtain a copy of the License at 8*2f2c4c7aSAndroid Build Coastguard Worker# 9*2f2c4c7aSAndroid Build Coastguard Worker# http://www.apache.org/licenses/LICENSE-2.0 10*2f2c4c7aSAndroid Build Coastguard Worker# 11*2f2c4c7aSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software 12*2f2c4c7aSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS, 13*2f2c4c7aSAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14*2f2c4c7aSAndroid Build Coastguard Worker# See the License for the specific language governing permissions and 15*2f2c4c7aSAndroid Build Coastguard Worker# limitations under the License. 16*2f2c4c7aSAndroid Build Coastguard Worker# 17*2f2c4c7aSAndroid Build Coastguard Worker 18*2f2c4c7aSAndroid Build Coastguard Workerset -e 19*2f2c4c7aSAndroid Build Coastguard Workerset -u 20*2f2c4c7aSAndroid Build Coastguard Worker 21*2f2c4c7aSAndroid Build Coastguard WorkerSCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P) 22*2f2c4c7aSAndroid Build Coastguard Worker 23*2f2c4c7aSAndroid Build Coastguard Worker. $SCRIPT_DIR/bullseye-common.sh 24*2f2c4c7aSAndroid Build Coastguard Worker 25*2f2c4c7aSAndroid Build Coastguard Workerarch=$(uname -m) 26*2f2c4c7aSAndroid Build Coastguard Workernvidia_arch=${arch} 27*2f2c4c7aSAndroid Build Coastguard Worker[ "${arch}" = "x86_64" ] && arch=amd64 28*2f2c4c7aSAndroid Build Coastguard Worker[ "${arch}" = "aarch64" ] && arch=arm64 29*2f2c4c7aSAndroid Build Coastguard Worker 30*2f2c4c7aSAndroid Build Coastguard Worker# Workaround for unnecessary firmware warning on ampere/gigabyte 31*2f2c4c7aSAndroid Build Coastguard Workermkdir -p /lib/firmware 32*2f2c4c7aSAndroid Build Coastguard Workertouch /lib/firmware/ast_dp501_fw.bin 33*2f2c4c7aSAndroid Build Coastguard Worker 34*2f2c4c7aSAndroid Build Coastguard Workersetup_dynamic_networking "eth0" "" 35*2f2c4c7aSAndroid Build Coastguard Worker 36*2f2c4c7aSAndroid Build Coastguard Worker# NVIDIA driver needs dkms which requires /dev/fd 37*2f2c4c7aSAndroid Build Coastguard Workerif [ ! -d /dev/fd ]; then 38*2f2c4c7aSAndroid Build Coastguard Worker ln -s /proc/self/fd /dev/fd 39*2f2c4c7aSAndroid Build Coastguard Workerfi 40*2f2c4c7aSAndroid Build Coastguard Worker 41*2f2c4c7aSAndroid Build Coastguard Workerupdate_apt_sources "bullseye bullseye-backports" "non-free" 42*2f2c4c7aSAndroid Build Coastguard Worker 43*2f2c4c7aSAndroid Build Coastguard Workersetup_cuttlefish_user 44*2f2c4c7aSAndroid Build Coastguard Worker 45*2f2c4c7aSAndroid Build Coastguard Worker# Install JRE 46*2f2c4c7aSAndroid Build Coastguard Workerapt-get install -y openjdk-17-jre 47*2f2c4c7aSAndroid Build Coastguard Worker 48*2f2c4c7aSAndroid Build Coastguard Worker# Ubuntu compatibility 49*2f2c4c7aSAndroid Build Coastguard Workercat >>/etc/skel/.profile << EOF 50*2f2c4c7aSAndroid Build Coastguard WorkerPATH="/usr/sbin:\$PATH" 51*2f2c4c7aSAndroid Build Coastguard WorkerEOF 52*2f2c4c7aSAndroid Build Coastguard Worker 53*2f2c4c7aSAndroid Build Coastguard Worker# Get kernel and QEMU from backports 54*2f2c4c7aSAndroid Build Coastguard Workerfor package in linux-image-${arch} qemu-system-arm qemu-system-x86; do 55*2f2c4c7aSAndroid Build Coastguard Worker apt-get install -y -t bullseye-backports ${package} 56*2f2c4c7aSAndroid Build Coastguard Workerdone 57*2f2c4c7aSAndroid Build Coastguard Worker 58*2f2c4c7aSAndroid Build Coastguard Worker# Install AOSP customized kernel package and extra Debian packages 59*2f2c4c7aSAndroid Build Coastguard Workerif [ -e /root/extradeb.tar.gz ]; then 60*2f2c4c7aSAndroid Build Coastguard Worker tar --one-top-level=/root/extra_deb -zxvf /root/extradeb.tar.gz 61*2f2c4c7aSAndroid Build Coastguard Worker apt -o APT::Color=0 -o DPkgPM::Progress-Fancy=0 install /root/extra_deb/*.deb 62*2f2c4c7aSAndroid Build Coastguard Worker rm -rf /root/extra_deb 63*2f2c4c7aSAndroid Build Coastguard Worker rm -f /root/extradeb.tar.gz 64*2f2c4c7aSAndroid Build Coastguard Workerfi 65*2f2c4c7aSAndroid Build Coastguard Worker 66*2f2c4c7aSAndroid Build Coastguard Worker# Install firmware package for AMD graphics 67*2f2c4c7aSAndroid Build Coastguard Workerapt-get install -y firmware-amd-graphics 68*2f2c4c7aSAndroid Build Coastguard Worker 69*2f2c4c7aSAndroid Build Coastguard Workerget_installed_packages >/root/originally-installed 70*2f2c4c7aSAndroid Build Coastguard Worker 71*2f2c4c7aSAndroid Build Coastguard Worker# Using "Depends:" is more reliable than "Version:", because it works for 72*2f2c4c7aSAndroid Build Coastguard Worker# backported ("bpo") kernels as well. NOTE: "Package" can be used instead 73*2f2c4c7aSAndroid Build Coastguard Worker# if we don't install the metapackage ("linux-image-${arch}") but a 74*2f2c4c7aSAndroid Build Coastguard Worker# specific version in the future 75*2f2c4c7aSAndroid Build Coastguard Workerkmodver=$(dpkg -s linux-image-${arch} | grep ^Depends: | \ 76*2f2c4c7aSAndroid Build Coastguard Worker cut -d: -f2 | cut -d" " -f2 | sed 's/linux-image-//') 77*2f2c4c7aSAndroid Build Coastguard Worker 78*2f2c4c7aSAndroid Build Coastguard Worker# Install headers from backports, to match the linux-image (removed below) 79*2f2c4c7aSAndroid Build Coastguard Workerapt-get install -y -t bullseye-backports $(echo linux-headers-${kmodver}) 80*2f2c4c7aSAndroid Build Coastguard Worker 81*2f2c4c7aSAndroid Build Coastguard Worker# Dependencies for nvidia-installer (removed below) 82*2f2c4c7aSAndroid Build Coastguard Workerapt-get install -y dkms libglvnd-dev libc6-dev pkg-config 83*2f2c4c7aSAndroid Build Coastguard Worker 84*2f2c4c7aSAndroid Build Coastguard Workernvidia_version=525.60.13 85*2f2c4c7aSAndroid Build Coastguard Workerwget -q https://us.download.nvidia.com/tesla/${nvidia_version}/NVIDIA-Linux-${nvidia_arch}-${nvidia_version}.run 86*2f2c4c7aSAndroid Build Coastguard Workerchmod a+x NVIDIA-Linux-${nvidia_arch}-${nvidia_version}.run 87*2f2c4c7aSAndroid Build Coastguard Worker./NVIDIA-Linux-${nvidia_arch}-${nvidia_version}.run -x 88*2f2c4c7aSAndroid Build Coastguard Workercd NVIDIA-Linux-${nvidia_arch}-${nvidia_version} 89*2f2c4c7aSAndroid Build Coastguard Workerif [[ "${nvidia_arch}" = "x86_64" ]]; then 90*2f2c4c7aSAndroid Build Coastguard Worker installer_flags="--no-install-compat32-libs" 91*2f2c4c7aSAndroid Build Coastguard Workerelse 92*2f2c4c7aSAndroid Build Coastguard Worker installer_flags="" 93*2f2c4c7aSAndroid Build Coastguard Workerfi 94*2f2c4c7aSAndroid Build Coastguard Worker./nvidia-installer ${installer_flags} --silent --no-backup --no-wine-files \ 95*2f2c4c7aSAndroid Build Coastguard Worker --install-libglvnd --dkms -k "${kmodver}" 96*2f2c4c7aSAndroid Build Coastguard Workercd - 97*2f2c4c7aSAndroid Build Coastguard Workerrm -rf NVIDIA-Linux-${nvidia_arch}-${nvidia_version}* 98*2f2c4c7aSAndroid Build Coastguard Worker 99*2f2c4c7aSAndroid Build Coastguard Workerget_installed_packages >/root/installed 100*2f2c4c7aSAndroid Build Coastguard Worker 101*2f2c4c7aSAndroid Build Coastguard Workerremove_installed_packages /root/originally-installed /root/installed 102*2f2c4c7aSAndroid Build Coastguard Worker 103*2f2c4c7aSAndroid Build Coastguard Workersetup_and_build_cuttlefish 104*2f2c4c7aSAndroid Build Coastguard Worker 105*2f2c4c7aSAndroid Build Coastguard Workerinstall_and_cleanup_cuttlefish 106*2f2c4c7aSAndroid Build Coastguard Worker 107*2f2c4c7aSAndroid Build Coastguard Worker# ttyAMA0 for ampere/gigabyte 108*2f2c4c7aSAndroid Build Coastguard Worker# ttyS0 for GCE t2a 109*2f2c4c7aSAndroid Build Coastguard Workercreate_systemd_getty_symlinks ttyAMA0 ttyS0 110*2f2c4c7aSAndroid Build Coastguard Worker 111*2f2c4c7aSAndroid Build Coastguard Workersetup_grub "net.ifnames=0 console=ttyAMA0 8250.nr_uarts=1 console=ttyS0 loglevel=4 amdgpu.runpm=0 amdgpu.dc=0" 112*2f2c4c7aSAndroid Build Coastguard Worker 113*2f2c4c7aSAndroid Build Coastguard Worker# Set up NTP using Google time servers and switch to UTC for uniformity 114*2f2c4c7aSAndroid Build Coastguard Worker# NOTE: Installing ntp removes systemd-timesyncd 115*2f2c4c7aSAndroid Build Coastguard Workerapt-get install -y ntp 116*2f2c4c7aSAndroid Build Coastguard Workersed -i -e 's,^\(pool .*debian.*\)$,# \1,' /etc/ntp.conf 117*2f2c4c7aSAndroid Build Coastguard Workercat >>/etc/ntp.conf <<EOF 118*2f2c4c7aSAndroid Build Coastguard Workerpool time1.google.com iburst 119*2f2c4c7aSAndroid Build Coastguard Workerpool time2.google.com iburst 120*2f2c4c7aSAndroid Build Coastguard Workerpool time3.google.com iburst 121*2f2c4c7aSAndroid Build Coastguard Workerpool time4.google.com iburst 122*2f2c4c7aSAndroid Build Coastguard Worker# time.google.com as backup 123*2f2c4c7aSAndroid Build Coastguard Workerpool time.google.com iburst 124*2f2c4c7aSAndroid Build Coastguard WorkerEOF 125*2f2c4c7aSAndroid Build Coastguard Workertimedatectl set-timezone UTC 126*2f2c4c7aSAndroid Build Coastguard Worker 127*2f2c4c7aSAndroid Build Coastguard Worker# Switch to NetworkManager. To disrupt the bootstrapping the least, do this 128*2f2c4c7aSAndroid Build Coastguard Worker# right at the end.. 129*2f2c4c7aSAndroid Build Coastguard Workerrm -f /etc/network/interfaces.d/eth0.conf 130*2f2c4c7aSAndroid Build Coastguard Workerapt-get install -y network-manager 131*2f2c4c7aSAndroid Build Coastguard Workerapt-get purge -y vim-tiny 132*2f2c4c7aSAndroid Build Coastguard Workerbullseye_cleanup 133