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    *)
25        echo "Unsupported system architecture(${ARCH}) found for docker image"
26        exit 1
27esac
28
29################################# docker img # #################################
30
31if [[ "${DISTRO}" == "ubuntu"* ]]; then
32Dockerfile=$(cat << EOF
33FROM ${DOCKER_BASE}${DISTRO}
34
35ENV DEBIAN_FRONTEND noninteractive
36
37RUN apt-get update && apt-get install -yy \
38    python3 \
39    python3-dev\
40    python3-yaml \
41    python3-mako \
42    python3-pip \
43    python3-setuptools \
44    curl \
45    git \
46    wget \
47    sudo \
48    squashfs-tools
49
50# Final configuration for the workspace
51RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER}
52RUN mkdir -p $(dirname "${HOME}")
53RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER}
54RUN sed -i '1iDefaults umask=000' /etc/sudoers
55RUN echo "${USER} ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers
56
57RUN /bin/bash
58EOF
59)
60fi
61################################# docker img # #################################
62
63# Build above image
64docker build --network=host -t "${DOCKER_IMG_NAME}" - <<< "${Dockerfile}"
65