#!/usr/bin/bash

# Copyright (c) 2019 Fedora CoreOS Authors. All rights reserved.
# Copyright (c) 2014 The CoreOS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Modified from the CoreOS repository: https://github.com/coreos/init/blob/master/scripts/motdgen

# Get updated system information and generate a motd
# to display this at login.

. /usr/lib/console-login-helper-messages/libutil.sh
. /usr/lib/console-login-helper-messages/motdgen.defs

set -e

# Generate a final motd from compiling the snippets.
# Pick 40 as a prefix as other files can order around it easily.
generated_file="/run/motd.d/40_${PKG_NAME}.motd"
source_dirs=("${ETC_SNIPPETS}" "${RUN_SNIPPETS}" "${USR_LIB_SNIPPETS}")

cat_via_tempfile "${generated_file}" ".motd" "${source_dirs[@]}"
