flatcar-scripts/build_library/set_lsb_release
Mathieu Tortuyaux dc0f93015b
build_library/set_release: add CPE_NAME - v2.3
Flatcar is in the NIST CPE dictionary. Let's programmatically build the
`CPE_NAME` in the build process in order to be scanned.

`CPE_NAME` is part of `/etc/os-release` with the following manual entry:

```
CPE_NAME=
  A CPE name for the operating system, in URI binding syntax, following the Common Platform Enumeration Specification[2] as proposed by the NIST.
  This field is optional. Example: "CPE_NAME="cpe:/o:fedoraproject:fedora:17""
...
[^2]: Common Platform Enumeration Specification
           http://scap.nist.gov/specifications/cpe/
```

Which indicates that the current version of CPE is 2.3.

Closes: https://github.com/flatcar-linux/Flatcar/issues/536

Signed-off-by: Mathieu Tortuyaux <mtortuyaux@microsoft.com>
2021-11-23 18:22:16 +01:00

80 lines
2.6 KiB
Bash
Executable File

#!/bin/bash
# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Script to set /etc/lsb-release on the root file system. This script is run by
# build_image inside chroot.
SCRIPT_ROOT=$(readlink -f $(dirname "$0")/..)
. "${SCRIPT_ROOT}/common.sh" || exit 1
# Flags
DEFINE_string board "" "The board to build an image for."
DEFINE_string root "" "The root file system to write /etc/lsb-release to."
DEFINE_string group "" "The default update group for update_engine."
# Parse command line
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
switch_to_strict_mode
ROOT_FS_DIR="$FLAGS_root"
[ -n "$ROOT_FS_DIR" ] || die "--root is required."
[ -d "$ROOT_FS_DIR" ] || die "Root FS does not exist? ($ROOT_FS_DIR)"
OS_NAME="Flatcar Container Linux by Kinvolk"
OS_CODENAME="Oklo"
OS_ID="flatcar"
OS_ID_LIKE="coreos"
OS_PRETTY_NAME="$OS_NAME $FLATCAR_VERSION (${OS_CODENAME})"
FLATCAR_APPID="{e96281a6-d1af-4bde-9a0a-97b76e56dc57}"
# DISTRIB_* are the standard lsb-release names
sudo mkdir -p "${ROOT_FS_DIR}/usr/share/flatcar" "${ROOT_FS_DIR}/etc/flatcar"
sudo_clobber "${ROOT_FS_DIR}/usr/share/flatcar/lsb-release" <<EOF
DISTRIB_ID="$OS_NAME"
DISTRIB_RELEASE=$FLATCAR_VERSION
DISTRIB_CODENAME="$OS_CODENAME"
DISTRIB_DESCRIPTION="$OS_PRETTY_NAME"
EOF
sudo ln -sf "../usr/share/flatcar/lsb-release" "${ROOT_FS_DIR}/etc/lsb-release"
# And the new standard, os-release
# https://www.freedesktop.org/software/systemd/man/os-release.html
sudo_clobber "${ROOT_FS_DIR}/usr/lib/os-release" <<EOF
NAME="$OS_NAME"
ID=$OS_ID
ID_LIKE=$OS_ID_LIKE
VERSION=$FLATCAR_VERSION
VERSION_ID=$FLATCAR_VERSION_ID
BUILD_ID=$FLATCAR_BUILD_ID
PRETTY_NAME="$OS_PRETTY_NAME"
ANSI_COLOR="38;5;75"
HOME_URL="https://flatcar-linux.org/"
BUG_REPORT_URL="https://issues.flatcar-linux.org"
FLATCAR_BOARD="$FLAGS_board"
CPE_NAME="cpe:2.3:o:${OS_ID}-linux:${OS_ID}_linux:${FLATCAR_VERSION}:*:*:*:*:*:*:*"
EOF
sudo ln -sf "../usr/lib/os-release" "${ROOT_FS_DIR}/etc/os-release"
sudo ln -sf "../../lib/os-release" "${ROOT_FS_DIR}/usr/share/flatcar/os-release"
# Create the defaults for the coreos configuration files in the usr directory
sudo_clobber "${ROOT_FS_DIR}/usr/share/flatcar/release" <<EOF
FLATCAR_RELEASE_VERSION=$FLATCAR_VERSION
FLATCAR_RELEASE_BOARD=$FLAGS_board
FLATCAR_RELEASE_APPID=$FLATCAR_APPID
EOF
sudo_clobber "${ROOT_FS_DIR}/usr/share/flatcar/update.conf" <<EOF
SERVER=https://public.update.flatcar-linux.net/v1/update/
GROUP=$FLAGS_group
EOF
sudo_clobber "${ROOT_FS_DIR}/etc/flatcar/update.conf" <<EOF
GROUP=$FLAGS_group
EOF