blob: 7c693c574a6347b6815cc1d139ca41ea18ae5752 [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
Jason Macnak0b52bd32020-01-29 10:31:46 -080058sudo chroot /mnt/image /usr/bin/apt install -y screen # needed by tradefed
Julien Desprez300913d2018-10-16 15:51:22 -070059
Greg Hartmanc8d55bd2018-07-11 16:48:46 -070060sudo chroot /mnt/image /usr/bin/find /home -ls
Jason Macnak3cedcc52019-12-05 09:31:54 -080061
62
63# Install GPU driver dependencies
64sudo chroot /mnt/image /usr/bin/apt install -y gcc
65sudo chroot /mnt/image /usr/bin/apt install -y linux-source
66sudo chroot /mnt/image /usr/bin/apt install -y linux-headers-`uname -r`
67sudo chroot /mnt/image /usr/bin/apt install -y make
68
69# Download the latest GPU driver installer
70gsutil cp \
71 $(gsutil ls gs://nvidia-drivers-us-public/GRID/GRID*/*-Linux-x86_64-*.run \
72 | sort \
73 | tail -n 1) \
74 /mnt/image/tmp/nvidia-driver-installer.run
75
76# Make GPU driver installer executable
77chmod +x /mnt/image/tmp/nvidia-driver-installer.run
78
79# Install the latest GPU driver with default options and the dispatch libs
80sudo chroot /mnt/image /tmp/nvidia-driver-installer.run \
81 --silent \
82 --install-libglvnd
83
84# Cleanup after install
85rm /mnt/image/tmp/nvidia-driver-installer.run
86
87# Verify
88query_nvidia() {
89 sudo chroot /mnt/image nvidia-smi --format=csv,noheader --query-gpu="$@"
90}
91
92if [[ $(query_nvidia "count") != "1" ]]; then
93 echo "Failed to detect GPU."
94 exit 1
95fi
96
97if [[ $(query_nvidia "driver_version") == "" ]]; then
98 echo "Failed to detect GPU driver."
99 exit 1
100fi
101
102
Greg Hartmanc8d55bd2018-07-11 16:48:46 -0700103# Clean up the builder's version of resolv.conf
104sudo rm /mnt/image/etc/resolv.conf
105
106# Skip unmounting:
107# Sometimes systemd starts, making it hard to unmount
108# In any case we'll unmount cleanly when the instance shuts down
Jason Macnak3cedcc52019-12-05 09:31:54 -0800109
Greg Hartmanc8d55bd2018-07-11 16:48:46 -0700110echo IMAGE_WAS_CREATED