#!/usr/bin/env bash

# Microsoft Azure Linux Agent
#
# Copyright 2018 Microsoft Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

#
# Echos the value in waagent.conf for the specified setting if it exists.
#

set -euo pipefail

if [[ $# -lt 1 ]]; then
    echo "Usage: get-waagent-conf-value <setting>"
    exit 1
fi

PYTHON=$(get-agent-python)
waagent_conf=$($PYTHON -c 'from azurelinuxagent.common.osutil import get_osutil; print(get_osutil().agent_conf_file_path)')

cat $waagent_conf | while read line
do
  if [[ $line == $1* ]]; then
    IFS='=' read -a values <<< "$line"
    echo ${values[1]}
    exit 0
  fi
done
