flatcar-scripts/build_library/set_lsb_release

71 lines
2.4 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)"
COREOS_VERSION_NAME="CoreOS"
# DISTRIB_* are the standard lsb-release names
sudo mkdir -p "${ROOT_FS_DIR}/usr/share/coreos" "${ROOT_FS_DIR}/etc/coreos"
sudo_clobber "${ROOT_FS_DIR}/usr/share/coreos/lsb-release" <<EOF
DISTRIB_ID=$COREOS_VERSION_NAME
DISTRIB_RELEASE=$COREOS_VERSION_STRING
DISTRIB_CODENAME="Red Dog"
DISTRIB_DESCRIPTION="$COREOS_VERSION_NAME $COREOS_VERSION_STRING"
EOF
sudo ln -sf "../usr/share/coreos/lsb-release" "${ROOT_FS_DIR}/etc/lsb-release"
# Aaaannd for the new systemd world order
# os-release provides a separate build-id field, so split it from version
OS_ID=$(tr '[:upper:]' '[:lower:]' <<<"$COREOS_VERSION_NAME")
sudo_clobber "${ROOT_FS_DIR}/usr/lib/os-release" <<EOF
NAME=$COREOS_VERSION_NAME
ID=$OS_ID
VERSION=$COREOS_VERSION_STRING
VERSION_ID=$COREOS_VERSION_ID
BUILD_ID=$COREOS_BUILD_ID
PRETTY_NAME="$COREOS_VERSION_NAME $COREOS_VERSION_STRING"
ANSI_COLOR="1;32"
HOME_URL="https://coreos.com/"
BUG_REPORT_URL="https://github.com/coreos/bugs/issues"
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/coreos/os-release"
# Create the defaults for the coreos configuration files in the usr directory
sudo_clobber "${ROOT_FS_DIR}/usr/share/coreos/release" <<EOF
COREOS_RELEASE_VERSION=$COREOS_VERSION_STRING
COREOS_RELEASE_BOARD=$FLAGS_board
EOF
sudo_clobber "${ROOT_FS_DIR}/usr/share/coreos/update.conf" <<EOF
SERVER=https://public.update.core-os.net/v1/update/
GROUP=$FLAGS_group
EOF
sudo_clobber "${ROOT_FS_DIR}/etc/coreos/update.conf" <<EOF
GROUP=$FLAGS_group
EOF