blob: 09443e37f78b1c0def17e21cbb4a3c3cbfb20c4d [file] [log] [blame]
Greg Hartmanc8d55bd2018-07-11 16:48:46 -07001#!/bin/bash
2
3set -x
4set -o errexit
5
6sudo apt-get update
7
8# Stuff we need to get build support
9
10sudo apt install -y debhelper ubuntu-dev-tools equivs "${extra_packages[@]}"
11
12# Install the cuttlefish build deps
13
14for dsc in *.dsc; do
15 yes | sudo mk-build-deps -i "${dsc}" -t apt-get
16done
17
18# Installing the build dependencies left some .deb files around. Remove them
19# to keep them from landing on the image.
20yes | rm -f *.deb
21
22for dsc in *.dsc; do
23 # Unpack the source and build it
24
25 dpkg-source -x "${dsc}"
26 dir="$(basename "${dsc}" .dsc)"
27 dir="${dir/_/-}"
28 pushd "${dir}/"
29 debuild -uc -us
30 popd
31done
32
33# Now gather all of the *.deb files to copy them into the image
34debs=(*.deb)
Greg Hartman20580ae2018-09-28 18:26:59 -070035
Greg Hartmanc8d55bd2018-07-11 16:48:46 -070036tmp_debs=()
37for i in "${debs[@]}"; do
Greg Hartman20580ae2018-09-28 18:26:59 -070038 tmp_debs+=(/tmp/"$(basename "$i")")
Greg Hartmanc8d55bd2018-07-11 16:48:46 -070039done
40
41# Now install the packages on the disk
42sudo mkdir /mnt/image
43sudo mount /dev/sdb1 /mnt/image
44cp "${debs[@]}" /mnt/image/tmp
45sudo mount -t sysfs none /mnt/image/sys
46sudo mount -t proc none /mnt/image/proc
47sudo mount --bind /dev/ /mnt/image/dev
48sudo mount --bind /dev/pts /mnt/image/dev/pts
49sudo mount --bind /run /mnt/image/run
50# resolv.conf is needed on Debian but not Ubuntu
51sudo cp /etc/resolv.conf /mnt/image/etc/
52sudo chroot /mnt/image /usr/bin/apt update
53sudo chroot /mnt/image /usr/bin/apt install -y "${tmp_debs[@]}"
Julien Desprez300913d2018-10-16 15:51:22 -070054# install tools dependencies
Julien Desprez74bc9832019-08-01 19:11:17 -070055sudo chroot /mnt/image /usr/bin/apt install -y openjdk-11-jre
Jason Macnak3cedcc52019-12-05 09:31:54 -080056sudo chroot /mnt/image /usr/bin/apt install -y unzip bzip2 lzop
Julien Desprezc1110122018-10-18 11:18:37 -070057sudo chroot /mnt/image /usr/bin/apt install -y aapt
Julien Desprez300913d2018-10-16 15:51:22 -070058
Greg Hartmanc8d55bd2018-07-11 16:48:46 -070059sudo chroot /mnt/image /usr/bin/find /home -ls
Jason Macnak3cedcc52019-12-05 09:31:54 -080060
61
62# Install GPU driver dependencies
63sudo chroot /mnt/image /usr/bin/apt install -y gcc
64sudo chroot /mnt/image /usr/bin/apt install -y linux-source
65sudo chroot /mnt/image /usr/bin/apt install -y linux-headers-`uname -r`
66sudo chroot /mnt/image /usr/bin/apt install -y make
67
68# Download the latest GPU driver installer
69gsutil cp \
70 $(gsutil ls gs://nvidia-drivers-us-public/GRID/GRID*/*-Linux-x86_64-*.run \
71 | sort \
72 | tail -n 1) \
73 /mnt/image/tmp/nvidia-driver-installer.run
74
75# Make GPU driver installer executable
76chmod +x /mnt/image/tmp/nvidia-driver-installer.run
77
78# Install the latest GPU driver with default options and the dispatch libs
79sudo chroot /mnt/image /tmp/nvidia-driver-installer.run \
80 --silent \
81 --install-libglvnd
82
83# Cleanup after install
84rm /mnt/image/tmp/nvidia-driver-installer.run
85
86# Verify
87query_nvidia() {
88 sudo chroot /mnt/image nvidia-smi --format=csv,noheader --query-gpu="$@"
89}
90
91if [[ $(query_nvidia "count") != "1" ]]; then
92 echo "Failed to detect GPU."
93 exit 1
94fi
95
96if [[ $(query_nvidia "driver_version") == "" ]]; then
97 echo "Failed to detect GPU driver."
98 exit 1
99fi
100
101
Greg Hartmanc8d55bd2018-07-11 16:48:46 -0700102# Clean up the builder's version of resolv.conf
103sudo rm /mnt/image/etc/resolv.conf
104
105# Skip unmounting:
106# Sometimes systemd starts, making it hard to unmount
107# In any case we'll unmount cleanly when the instance shuts down
Jason Macnak3cedcc52019-12-05 09:31:54 -0800108
Greg Hartmanc8d55bd2018-07-11 16:48:46 -0700109echo IMAGE_WAS_CREATED