1#!/bin/bash -xe
2#
3# Build the required docker image to run rootfs_size.py
4#
5# Script Variables:
6#   DOCKER_IMG_NAME:  <optional, the name of the docker image to generate>
7#                     default is openbmc/ubuntu-rootfs-size
8#   DISTRO:           <optional, the distro to build a docker image against>
9
10set -uo pipefail
11
12DOCKER_IMG_NAME=${DOCKER_IMG_NAME:-"openbmc/ubuntu-rootfs-size"}
13DISTRO=${DISTRO:-"ubuntu:bionic"}
14
15# Determine the architecture
16ARCH=$(uname -m)
17case ${ARCH} in
18    "ppc64le")
19        DOCKER_BASE="ppc64le/"
20        ;;
21    "x86_64")
22        DOCKER_BASE=""
23        ;;
24    "aarch64")
25        DOCKER_BASE="arm64v8/"
26        ;;
27    *)
28        echo "Unsupported system architecture(${ARCH}) found for docker image"
29        exit 1
30esac
31
32################################# docker img # #################################
33
34if [[ "${DISTRO}" == "ubuntu"* ]]; then
35Dockerfile=$(cat << EOF
36FROM ${DOCKER_BASE}${DISTRO}
37
38ENV DEBIAN_FRONTEND noninteractive
39
40RUN apt-get update && apt-get install -yy \
41    python3 \
42    python3-dev\
43    python3-yaml \
44    python3-mako \
45    python3-pip \
46    python3-setuptools \
47    curl \
48    git \
49    wget \
50    sudo \
51    squashfs-tools
52
53# Final configuration for the workspace
54RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER}
55RUN mkdir -p $(dirname "${HOME}")
56RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER}
57RUN sed -i '1iDefaults umask=000' /etc/sudoers
58RUN echo "${USER} ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers
59
60RUN /bin/bash
61EOF
62)
63fi
64################################# docker img # #################################
65
66# Build above image
67docker build --network=host -t "${DOCKER_IMG_NAME}" - <<< "${Dockerfile}"
68