#!/bin/bash # Release file globals G_PLAT_RELEASE_FILE="" G_PLAT_NAME_TOKEN="" G_PLAT_PRETTY_NAME_TOKEN="" G_PLAT_OTA_PRETTY_NAME_TOKEN="" G_PLAT_STRING_TOKEN="" G_PLAT_SERIAL_NUMBER_TOKEN="" G_PLAT_OTA_VERSION_TOKEN="" G_PLAT_OTA_DATE_TOKEN="" G_PLAT_ABRIDGED_WRITE="false" G_PLAT_DEFER_CONFIG="false" G_EL_SUPPORT_TOKEN="" # Other globals MY_PATH=$(dirname $0) SELF="${MY_PATH}/write_release.bash" G_OTA_SKIP_WRITE_FILE="/tmp/ota_skip_write" G_OTA_VERSION="1.0.0" G_EL_SUPPORT_VERSION="" parse_args() { # No arguments provided if [ $# -eq 0 ]; then usage exit 1 fi # Loop through arguments for arg in ${@}; do case "$arg" in relfile=*) G_PLAT_RELEASE_FILE="${arg#*=}" shift ;; ver=*) G_OTA_VERSION="${arg#*=}" shift ;; elsupport=*) G_EL_SUPPORT_VERSION="${arg#*=}" shift ;; abridged) G_PLAT_ABRIDGED_WRITE="true" ;; defer_config) G_PLAT_DEFER_CONFIG="true" ;; h|help) usage exit 0 ;; esac done if [ -z "${G_PLAT_RELEASE_FILE}" ]; then usage exit 1 fi } usage() { echo "${SELF} " echo " valid options are:" echo " relfile=" echo " File to write to. Mandatory option." echo " Example: relfile=/etc/dgx-release" echo " ver=" echo " Version string to write." echo " Example: ver=1.0.0" echo " elsupport=" echo " Version string to write." echo " Example: elsupport=8" echo " abridged: Skips writing platform-dependent information" echo " help: Shows this help menu" } init_global_vars() { if [ $(basename "${G_PLAT_RELEASE_FILE}") = "dgx-release" ]; then G_PLAT_NAME_TOKEN="DGX_NAME" G_PLAT_PRETTY_NAME_TOKEN="DGX_PRETTY_NAME" G_PLAT_OTA_PRETTY_NAME_TOKEN="DGX_OTA_PRETTY_NAME=\"DGX OS\"" G_PLAT_STRING_TOKEN="DGX_PLATFORM" G_PLAT_SERIAL_NUMBER_TOKEN="DGX_SERIAL_NUMBER" G_PLAT_OTA_VERSION_TOKEN="DGX_OTA_VERSION" G_PLAT_OTA_DATE_TOKEN="DGX_OTA_DATE" G_EL_SUPPORT_TOKEN="DGX_EL_SUPPORTED" elif [ $(basename "${G_PLAT_RELEASE_FILE}") = "dcs-release" ]; then G_PLAT_NAME_TOKEN="DCS_NAME" G_PLAT_PRETTY_NAME_TOKEN="DCS_PRETTY_NAME" G_PLAT_OTA_PRETTY_NAME_TOKEN="DCS_OTA_PRETTY_NAME=\"DCS OS\"" G_PLAT_STRING_TOKEN="DCS_PLATFORM" G_PLAT_SERIAL_NUMBER_TOKEN="DCS_SERIAL_NUMBER" G_PLAT_OTA_VERSION_TOKEN="DCS_OTA_VERSION" G_PLAT_OTA_DATE_TOKEN="DCS_OTA_DATE" G_EL_SUPPORT_TOKEN="DCS_EL_SUPPORTED" elif [ $(basename "${G_PLAT_RELEASE_FILE}") = "egx-release" ]; then G_PLAT_NAME_TOKEN="EGX_NAME" G_PLAT_PRETTY_NAME_TOKEN="EGX_PRETTY_NAME" G_PLAT_OTA_PRETTY_NAME_TOKEN="EGX_OTA_PRETTY_NAME=\"EGX OS\"" G_PLAT_STRING_TOKEN="EGX_PLATFORM" G_PLAT_SERIAL_NUMBER_TOKEN="EGX_SERIAL_NUMBER" G_PLAT_OTA_VERSION_TOKEN="EGX_OTA_VERSION" G_PLAT_OTA_DATE_TOKEN="EGX_OTA_DATE" G_EL_SUPPORT_TOKEN="EGX_EL_SUPPORTED" else G_PLAT_NAME_TOKEN="NAME" G_PLAT_PRETTY_NAME_TOKEN="PRETTY_NAME" G_PLAT_OTA_PRETTY_NAME_TOKEN="OTA_PRETTY_NAME=\"Unknown OS\"" G_PLAT_STRING_TOKEN="PLATFORM" G_PLAT_SERIAL_NUMBER_TOKEN="SERIAL_NUMBER" G_PLAT_OTA_VERSION_TOKEN="OTA_VERSION" G_PLAT_OTA_DATE_TOKEN="OTA_DATE" G_EL_SUPPORT_TOKEN="EL_SUPPORTED" fi } write_release_file() { DATE=$(date) plat_info_script="${MY_PATH}/get_platform_info.bash" plat_info_out=$(${plat_info_script}) # Expected output: #platform:All Series #name:All Series #pretty_name:All Series #platform_string:All Series #serial_number:System Serial Number # #echo "DBG: ${plat_info_out}" platstring=$(echo "${plat_info_out}" | grep -m 1 'platform_string:' | sed 's/platform_string://') serial=$(echo "${plat_info_out}" | grep -m 1 'serial_number:' | sed 's/serial_number://') # Initialize release file if it is not already present if [[ ! -f ${G_PLAT_RELEASE_FILE} ]]; then if ${G_PLAT_ABRIDGED_WRITE}; then # Skip writing platform-specific information if abridged echo """${G_PLAT_NAME_TOKEN}=\"NVIDIA Server\" ${G_PLAT_PRETTY_NAME_TOKEN}=\"NVIDIA Server\" ${G_PLAT_OTA_PRETTY_NAME_TOKEN} ${G_PLAT_OTA_VERSION_TOKEN}=\"${G_OTA_VERSION}\" ${G_PLAT_OTA_DATE_TOKEN}=\"${DATE}\"""" | tee ${G_PLAT_RELEASE_FILE} else name=$(echo "${plat_info_out}" | grep -m 1 'name:' | sed 's/name://') prettyname=$(echo "${plat_info_out}" | grep -m 1 'pretty_name:' | sed 's/pretty_name://') echo """${G_PLAT_NAME_TOKEN}=\"${name}\" ${G_PLAT_PRETTY_NAME_TOKEN}=\"${prettyname}\" ${G_PLAT_OTA_PRETTY_NAME_TOKEN} ${G_PLAT_OTA_VERSION_TOKEN}=\"${G_OTA_VERSION}\" ${G_PLAT_OTA_DATE_TOKEN}=\"${DATE}\" ${G_PLAT_STRING_TOKEN}=\"${platstring}\" ${G_PLAT_SERIAL_NUMBER_TOKEN}=\"${serial}\"""" | tee ${G_PLAT_RELEASE_FILE} fi if [ ! -z "${G_EL_SUPPORT_VERSION}" ]; then echo "${G_EL_SUPPORT_TOKEN}=\"${G_EL_SUPPORT_VERSION}\"" >> ${G_PLAT_RELEASE_FILE} fi else # /etc/dgx-release file exists # called with defer_config plat_grep=$(grep -vFq PLATFORM ${G_PLAT_RELEASE_FILE} 2>/dev/null) if ( ${G_PLAT_DEFER_CONFIG} ) && ( [ ! ${G_PLAT_ABRIDGED_WRITE} ] || ${plat_grep} ); then # /etc/dgx-release exists but WITHOUT PLATFORM in /etc/dgx-release # we should only be here in the runtime with deferred_config so make the change # to only add the platform and serial number echo "${G_PLAT_STRING_TOKEN}=\"${platstring}\"" >> ${G_PLAT_RELEASE_FILE} echo "${G_PLAT_SERIAL_NUMBER_TOKEN}=\"${serial}\"" >> ${G_PLAT_RELEASE_FILE} else # /etc/dgx-release exists and contains PLATFORM, # and in runtime with defer_config or with OTA upgrade. # We need to only add version and date info echo "" >> ${G_PLAT_RELEASE_FILE} echo "${G_PLAT_OTA_VERSION_TOKEN}=\"${G_OTA_VERSION}\"" >> ${G_PLAT_RELEASE_FILE} if [ ! -z "${G_EL_SUPPORT_VERSION}" ]; then echo "${G_EL_SUPPORT_TOKEN}=\"${G_EL_SUPPORT_VERSION}\"" >> ${G_PLAT_RELEASE_FILE} fi echo "${G_PLAT_OTA_DATE_TOKEN}=\"${DATE}\"" >> ${G_PLAT_RELEASE_FILE} fi # Also fix up the serial number sed -i "s/${G_PLAT_SERIAL_NUMBER_TOKEN}=.*$/${G_PLAT_SERIAL_NUMBER_TOKEN}=\"${serial//\//\\/}\"/" ${G_PLAT_RELEASE_FILE} fi } ### MAIN ### source ${MY_PATH}/general_funcs.bash source ${MY_PATH}/plat_funcs.bash must_run_as_root parse_args "${@}" init_global_vars # Skip write based on tmp-file, environment variable, etc. ENV_VAR=${SKIP_OTA_WRITE:-} if [[ -f "${G_OTA_SKIP_WRITE_FILE}" ]] || \ [[ "${ENV_VAR}" = "true" ]] || \ [[ "${ENV_VAR}" = "yes" ]] || \ grep -q skip_ota_write /proc/cmdline; then echo "Skip writing to release file" else write_release_file fi exit 0