• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2
3show_help() {
4  echo "Usage: sudo $0 [OPTION]..."
5  echo "Builds a debian image and save it to image.raw."
6  echo "Options:"
7  echo "-h         Print usage and this help message and exit."
8  echo "-a ARCH    Architecture of the image [default is host arch: $(uname -m)]"
9  echo "-g         Use Debian generic kernel [default is our custom kernel]"
10  echo "-r         Release mode build"
11  echo "-s         Leave a shell open [default: only if the build fails]"
12  echo "-u         Set VM boot mode to u-boot [default is to load kernel directly]"
13  echo "-w         Save temp work directory in the container [for debugging]"
14}
15
16arch="$(uname -m)"
17kernel_flag=
18release_flag=
19save_workdir_flag=
20shell_condition="||"
21uboot_flag=
22
23while getopts "a:ghrsuw" option; do
24  case ${option} in
25    a)
26      arch="$OPTARG"
27      ;;
28    g)
29      kernel_flag="-g"
30      ;;
31    h)
32      show_help ; exit
33      ;;
34    r)
35      release_flag="-r"
36      ;;
37    s)
38      shell_condition=";"
39      ;;
40    u)
41      uboot_flag="-u"
42      ;;
43    w)
44      save_workdir_flag="-w"
45      ;;
46    *)
47      echo "Invalid option: $OPTARG" ; exit 1
48      ;;
49  esac
50done
51
52if [[ "$arch" != "aarch64" && "$arch" != "x86_64" ]]; then
53  echo "Invalid architecture: $arch" ; exit 1
54fi
55
56if [ -z "$ANDROID_BUILD_TOP" ] ; then
57  echo '`ANDROID_BUILD_TOP` is undefined.'
58  echo 'Please `lunch` an Android target, or manually set the variable.'
59  exit 1
60fi
61
62docker run --privileged -it -v /dev:/dev \
63  -v "$ANDROID_BUILD_TOP/packages/modules/Virtualization:/root/Virtualization" \
64  --workdir /root/Virtualization/build/debian \
65  ubuntu:22.04 \
66  bash -c "./build.sh -a $arch $release_flag $kernel_flag $uboot_flag $save_workdir_flag $shell_condition bash"
67