blob: e7e44f2b2d529093cf68e08b6914628ebdb7f222 [file] [log] [blame]
Jiyong Parka128bad2024-09-20 16:53:57 +09001#!/bin/bash
2
3# This is a script to build a Debian image that can run in a VM created via AVF.
4# TODOs:
5# - Support x86_64 architecture
6# - Add Android-specific packages via a new class
7# - Use a stable release from debian-cloud-images
8
9show_help() {
10 echo Usage: $0 [OPTION]... [FILE]
11 echo Builds a debian image and save it to FILE.
12 echo Options:
13 echo -h Pring usage and this help message and exit.
14}
15
16check_sudo() {
17 if [ "$EUID" -ne 0 ]; then
18 echo "Please run as root."
19 exit
20 fi
21}
22
23parse_options() {
24 while getopts ":h" option; do
25 case ${option} in
26 h)
27 show_help
28 exit;;
29 esac
30 done
31 if [ -n "$1" ]; then
32 built_image=$1
33 fi
34}
35
36install_prerequisites() {
Jiyong Park0e565ed2024-09-24 12:39:53 +090037 apt update
Jiyong Park44dd28f2024-09-20 18:47:40 +090038 DEBIAN_FRONTEND=noninteractive \
Jiyong Parka128bad2024-09-20 16:53:57 +090039 apt install --no-install-recommends --assume-yes \
40 ca-certificates \
41 debsums \
42 dosfstools \
43 fai-server \
44 fai-setup-storage \
45 fdisk \
46 make \
47 python3 \
48 python3-libcloud \
49 python3-marshmallow \
50 python3-pytest \
51 python3-yaml \
52 qemu-utils \
Jeongik Cha652f73a2024-09-20 09:24:48 +000053 udev \
54 qemu-system-arm \
55 qemu-user-static
Jiyong Parka128bad2024-09-20 16:53:57 +090056}
57
58download_debian_cloud_image() {
59 local ver=master
60 local prj=debian-cloud-images
61 local url=https://salsa.debian.org/cloud-team/${prj}/-/archive/${ver}/${prj}-${ver}.tar.gz
62 local outdir=${debian_cloud_image}
63
64 mkdir -p ${outdir}
65 wget -O - ${url} | tar xz -C ${outdir} --strip-components=1
66}
67
Jiyong Park44dd28f2024-09-20 18:47:40 +090068copy_android_config() {
69 local src=$(dirname $0)/fai_config
70 local dst=${config_space}
71
72 cp -R ${src}/* ${dst}
Jeongik Cha37047c32024-09-20 23:09:16 +090073 cp $(dirname $0)/image.yaml ${resources_dir}
Jeongik Cha50952062024-09-23 18:13:38 +090074
75 local ttyd_version=1.7.7
76 local url=https://github.com/tsl0922/ttyd/releases/download/${ttyd_version}/ttyd.aarch64
77 mkdir -p ${dst}/files/usr/local/bin/ttyd
78 wget ${url} -O ${dst}/files/usr/local/bin/ttyd/AVF
79 chmod 777 ${dst}/files/usr/local/bin/ttyd/AVF
Jiyong Park44dd28f2024-09-20 18:47:40 +090080}
81
Jiyong Parka128bad2024-09-20 16:53:57 +090082run_fai() {
Jiyong Parka128bad2024-09-20 16:53:57 +090083 local out=${built_image}
Jeongik Cha37047c32024-09-20 23:09:16 +090084 make -C ${debian_cloud_image} image_bookworm_nocloud_arm64
85 mv ${debian_cloud_image}/image_bookworm_nocloud_arm64.raw ${out}
Jiyong Parka128bad2024-09-20 16:53:57 +090086}
87
88clean_up() {
89 rm -rf ${workdir}
90}
91
92set -e
93trap clean_up EXIT
94
95built_image=image.raw
96workdir=$(mktemp -d)
97debian_cloud_image=${workdir}/debian_cloud_image
Jiyong Park44dd28f2024-09-20 18:47:40 +090098debian_version=bookworm
99config_space=${debian_cloud_image}/config_space/${debian_version}
Jeongik Cha37047c32024-09-20 23:09:16 +0900100resources_dir=${debian_cloud_image}/src/debian_cloud_images/resources
Jiyong Parka128bad2024-09-20 16:53:57 +0900101check_sudo
102parse_options $@
103install_prerequisites
104download_debian_cloud_image
Jiyong Park44dd28f2024-09-20 18:47:40 +0900105copy_android_config
Jiyong Park0e565ed2024-09-24 12:39:53 +0900106run_fai