Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / scripts / lldb-test-qemu / rootfs.sh
blob33ff278c1702a232b1dbc139aa8b6ea7d83fa788
1 #!/bin/bash
3 set -e
5 print_usage() {
6 echo "Usage: $(basename $0) [options]"
7 echo -e "Creates a Ubuntu root file system image.\n"
8 echo -e " --help\t\t\tDisplay this information."
9 echo -e " --arch {armhf|arm64}\t\tSelects architecture of rootfs image."
10 echo -e " --distro {bionic|focal}\tSelects Ubuntu distribution of rootfs image."
11 echo -e " --size n{K|M|G}\t\tSets size of rootfs image to n Kilo, Mega or Giga bytes."
12 exit "$1"
15 invalid_arg() {
16 echo "ERROR: Unrecognized argument: $1" >&2
17 print_usage 1
20 update_repositories() {
21 echo -e "\nUpdating apt repositories. "
22 echo -e "\nPress 'y' to continue or any other key to exit..."
23 read -s -n 1 user_input
24 if [[ $user_input == 'Y' ]] || [[ $user_input == 'y' ]]; then
25 sudo apt update
26 else
27 exit
31 # Parse options
32 while [[ $# -gt 0 ]]; do
33 case "${END_OF_OPT}${1}" in
34 --help) print_usage 0 ;;
35 --arch) rfs_arch=$2; shift;;
36 --distro) rfs_distro=$2; shift;;
37 --size) rfs_size=$2; shift;;
38 *) invalid_arg "$1" ;;
39 esac
40 shift
41 done
43 if [ -z "$rfs_arch" ]; then
44 echo "Missing architecture"
45 print_usage 1
47 if [ -z "$rfs_distro" ]; then
48 echo "Missing distribution"
49 print_usage 1
51 if [ -z "$rfs_size" ]; then
52 echo "Missing size"
53 print_usage 1
56 if [[ "$rfs_arch" != "arm64" && "$rfs_arch" != "armhf" ]]; then
57 echo "Invalid architecture: $rfs_arch"
58 print_usage 1
61 pat='^[0-9]+[K|M|G]$'
62 if [[ ! $rfs_size =~ $pat ]]; then
63 echo "Invalid size: $rfs_size"
64 print_usage 1
67 update_repositories
69 echo "Installing build dependencies ..."
70 sudo apt-get install debootstrap qemu-user-static schroot qemu-utils
72 image_name=$rfs_distro-$rfs_arch-"rootfs"
73 echo "Creating $rfs_distro ($rfs_arch) root file system ..."
74 echo "Image name: $image_name.img"
75 echo "Image size: $rfs_size"
77 qemu-img create $image_name.img $rfs_size
79 mkfs.ext4 $image_name.img
80 mkdir $image_name.dir
81 sudo mount -o loop $image_name.img $image_name.dir
83 sudo qemu-debootstrap --arch $rfs_arch $rfs_distro $image_name.dir
85 sudo chroot $image_name.dir locale-gen en_US.UTF-8
87 sudo chroot $image_name.dir sed -i \
88 's/main/main restricted multiverse universe/g' /etc/apt/sources.list
90 sudo chroot $image_name.dir sed -i '$ a\nameserver 8.8.8.8' /etc/resolv.conf
92 sudo chroot $image_name.dir apt update
93 sudo chroot $image_name.dir apt -y install ssh bash-completion
94 sudo chroot $image_name.dir adduser --gecos "" $USER
95 sudo chroot $image_name.dir adduser $USER sudo
96 sudo umount $image_name.dir
97 rmdir $image_name.dir