Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion package/suc/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ cleanup() {
rm -rf "/host${TMPDIR}"
}

no_proxy_usage() {
echo "WARNING: Malformed NO_PROXY environment variable value format, detected whitespace in value. Value must be a comma-delimited string with no spaces containing one or more IP address prefixes (1.2.3.4, 1.2.3.4:80), IP address prefixes in CIDR notation (1.2.3.4/8), domain names, or special DNS labels (*)"
echo "WARNING: Will automatically remove detected whitespace. This may lead to unexpected behavior."
}

trap cleanup EXIT
trap exit INT HUP TERM

Expand Down Expand Up @@ -43,14 +48,37 @@ export CATTLE_AGENT_BINARY_LOCAL=true
export CATTLE_AGENT_UNINSTALL_LOCAL=true
export CATTLE_AGENT_BINARY_LOCAL_LOCATION=${TMPDIR}/rancher-system-agent
export CATTLE_AGENT_UNINSTALL_LOCAL_LOCATION=${TMPDIR}/rancher-system-agent-uninstall.sh

if [ -s /host/etc/systemd/system/rancher-system-agent.env ]; then
for line in $(grep -v '^#' /host/etc/systemd/system/rancher-system-agent.env); do
# Read line by line, skipping any variables that are commented out (#)
grep -v '^#' /host/etc/systemd/system/rancher-system-agent.env | while IFS= read -r line; do

# Determine the name and previously set
# value of the environment variable
var=${line%%=*}
val=${line##*=}

# Check if the variable is already exported.
eval v=\"\$$var\"
# If a previously seen environment variable isn't currently exported,
# reuse the last known value stored in the environment variables file
if [ -z "$v" ]; then
export "$var=$val"
v="$val"
fi

# If NO_PROXY is set, ensure it meets the minimum format requirements (no spaces).
if [ "$var" = "NO_PROXY" ] || [ "$var" = "no_proxy" ]; then
if [ -n "$v" ]; then
if echo "$v" | grep -q " "; then
no_proxy_usage
v="$(echo "$v" | tr -d '[:space:]')"
export "$var=$v"
fi
fi
fi

done
fi

chroot /host ${TMPDIR}/install.sh "$@"
Loading