-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TRITON-2159 Port
/lib/sdc/config.sh
to linux
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/bash | ||
# | ||
# functions for getting USB headnode config values (intended to be sourced | ||
# from other scripts) | ||
# | ||
# It is also possible to use this to get a JSON hash of the config options using: | ||
# | ||
# bash config.sh -json | ||
# | ||
# Copyright 2020 Joyent Inc. | ||
# | ||
|
||
# Sets SDC_CONFIG_FILENAME with the location of the config file. | ||
# On linux this is always the same, this function is here for | ||
# compatibility purposes | ||
function load_sdc_config_filename { | ||
# the default | ||
COMPUTE_NODE_CONFIG_FILENAME="/usr/triton/config/node.config" | ||
SDC_CONFIG_FILENAME=${COMPUTE_NODE_CONFIG_FILENAME} | ||
SDC_CONFIG_INC_DIR="$(dirname ${COMPUTE_NODE_CONFIG_FILENAME})" | ||
|
||
} | ||
|
||
|
||
# Loads config variables with prefix (default: CONFIG_) | ||
function load_sdc_config { | ||
|
||
prefix=$1 | ||
[[ -z ${prefix} ]] && prefix="CONFIG_" | ||
|
||
load_sdc_config_filename | ||
if [[ -f ${SDC_CONFIG_INC_DIR}/generic ]]; then | ||
GEN_FILE=${SDC_CONFIG_INC_DIR}/generic | ||
else | ||
GEN_FILE=/dev/null | ||
fi | ||
|
||
# Ignore comments, spaces at the beginning of lines and lines that don't | ||
# start with a letter. | ||
eval $((cat ${GEN_FILE} ${SDC_CONFIG_FILENAME}; echo "config_inc_dir=${SDC_CONFIG_INC_DIR}") | \ | ||
sed -e "s/^ *//" | grep -v "^#" | grep "^[a-zA-Z]" | \ | ||
sed -e "s/^/${prefix}/") | ||
} |