Greg Hartman | c8d55bd | 2018-07-11 16:48:46 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | set -x |
| 4 | set -o errexit |
| 5 | |
| 6 | sudo apt-get update |
| 7 | |
| 8 | # Stuff we need to get build support |
| 9 | |
| 10 | sudo apt install -y debhelper ubuntu-dev-tools equivs "${extra_packages[@]}" |
| 11 | |
| 12 | # Install the cuttlefish build deps |
| 13 | |
| 14 | for dsc in *.dsc; do |
| 15 | yes | sudo mk-build-deps -i "${dsc}" -t apt-get |
| 16 | done |
| 17 | |
| 18 | # Installing the build dependencies left some .deb files around. Remove them |
| 19 | # to keep them from landing on the image. |
| 20 | yes | rm -f *.deb |
| 21 | |
| 22 | for 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 |
| 31 | done |
| 32 | |
| 33 | # Now gather all of the *.deb files to copy them into the image |
| 34 | debs=(*.deb) |
Greg Hartman | 20580ae | 2018-09-28 18:26:59 -0700 | [diff] [blame] | 35 | |
Greg Hartman | c8d55bd | 2018-07-11 16:48:46 -0700 | [diff] [blame] | 36 | tmp_debs=() |
| 37 | for i in "${debs[@]}"; do |
Greg Hartman | 20580ae | 2018-09-28 18:26:59 -0700 | [diff] [blame] | 38 | tmp_debs+=(/tmp/"$(basename "$i")") |
Greg Hartman | c8d55bd | 2018-07-11 16:48:46 -0700 | [diff] [blame] | 39 | done |
| 40 | |
| 41 | # Now install the packages on the disk |
| 42 | sudo mkdir /mnt/image |
| 43 | sudo mount /dev/sdb1 /mnt/image |
| 44 | cp "${debs[@]}" /mnt/image/tmp |
| 45 | sudo mount -t sysfs none /mnt/image/sys |
| 46 | sudo mount -t proc none /mnt/image/proc |
| 47 | sudo mount --bind /dev/ /mnt/image/dev |
| 48 | sudo mount --bind /dev/pts /mnt/image/dev/pts |
| 49 | sudo mount --bind /run /mnt/image/run |
| 50 | # resolv.conf is needed on Debian but not Ubuntu |
| 51 | sudo cp /etc/resolv.conf /mnt/image/etc/ |
| 52 | sudo chroot /mnt/image /usr/bin/apt update |
| 53 | sudo chroot /mnt/image /usr/bin/apt install -y "${tmp_debs[@]}" |
Julien Desprez | 300913d | 2018-10-16 15:51:22 -0700 | [diff] [blame] | 54 | # install tools dependencies |
Julien Desprez | 74bc983 | 2019-08-01 19:11:17 -0700 | [diff] [blame] | 55 | sudo chroot /mnt/image /usr/bin/apt install -y openjdk-11-jre |
Jason Macnak | 3cedcc5 | 2019-12-05 09:31:54 -0800 | [diff] [blame] | 56 | sudo chroot /mnt/image /usr/bin/apt install -y unzip bzip2 lzop |
Julien Desprez | c111012 | 2018-10-18 11:18:37 -0700 | [diff] [blame] | 57 | sudo chroot /mnt/image /usr/bin/apt install -y aapt |
Julien Desprez | 300913d | 2018-10-16 15:51:22 -0700 | [diff] [blame] | 58 | |
Greg Hartman | c8d55bd | 2018-07-11 16:48:46 -0700 | [diff] [blame] | 59 | sudo chroot /mnt/image /usr/bin/find /home -ls |
Jason Macnak | 3cedcc5 | 2019-12-05 09:31:54 -0800 | [diff] [blame] | 60 | |
| 61 | |
| 62 | # Install GPU driver dependencies |
| 63 | sudo chroot /mnt/image /usr/bin/apt install -y gcc |
| 64 | sudo chroot /mnt/image /usr/bin/apt install -y linux-source |
| 65 | sudo chroot /mnt/image /usr/bin/apt install -y linux-headers-`uname -r` |
| 66 | sudo chroot /mnt/image /usr/bin/apt install -y make |
| 67 | |
| 68 | # Download the latest GPU driver installer |
| 69 | gsutil 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 |
| 76 | chmod +x /mnt/image/tmp/nvidia-driver-installer.run |
| 77 | |
| 78 | # Install the latest GPU driver with default options and the dispatch libs |
| 79 | sudo chroot /mnt/image /tmp/nvidia-driver-installer.run \ |
| 80 | --silent \ |
| 81 | --install-libglvnd |
| 82 | |
| 83 | # Cleanup after install |
| 84 | rm /mnt/image/tmp/nvidia-driver-installer.run |
| 85 | |
| 86 | # Verify |
| 87 | query_nvidia() { |
| 88 | sudo chroot /mnt/image nvidia-smi --format=csv,noheader --query-gpu="$@" |
| 89 | } |
| 90 | |
| 91 | if [[ $(query_nvidia "count") != "1" ]]; then |
| 92 | echo "Failed to detect GPU." |
| 93 | exit 1 |
| 94 | fi |
| 95 | |
| 96 | if [[ $(query_nvidia "driver_version") == "" ]]; then |
| 97 | echo "Failed to detect GPU driver." |
| 98 | exit 1 |
| 99 | fi |
| 100 | |
| 101 | |
Greg Hartman | c8d55bd | 2018-07-11 16:48:46 -0700 | [diff] [blame] | 102 | # Clean up the builder's version of resolv.conf |
| 103 | sudo 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 Macnak | 3cedcc5 | 2019-12-05 09:31:54 -0800 | [diff] [blame] | 108 | |
Greg Hartman | c8d55bd | 2018-07-11 16:48:46 -0700 | [diff] [blame] | 109 | echo IMAGE_WAS_CREATED |