Skip to content

Commit

Permalink
fix #2967 (#2978)
Browse files Browse the repository at this point in the history
* fix: #issues/2967 get_lan_ip error echo

* update sops 模板
  • Loading branch information
bingoct authored Feb 28, 2024
1 parent 5cf70c2 commit 72404a5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion bcs-ops/sops/bcs_bk_sops_common.dat
100755 → 100644

Large diffs are not rendered by default.

15 changes: 10 additions & 5 deletions bcs-ops/system/get_lan_ip
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ version() {
echo "$PROGRAM version $VERSION"
}

error() {
local color_code="\033[031;1m"
echo -e "${color_code}$*\033[0m" >&2
}

#######################################
# get ip by cloud_api
# Return:
Expand Down Expand Up @@ -68,22 +73,22 @@ _on_cloud() {
}

_on_baremetal() {
if ! ip route show | grep "default via"; then
echo "fail to obtain LAN_IP, default route missing"
if ! ip route show | grep -q "default via"; then
error "fail to obtain LAN_IP, default route missing"
exit 2
fi
LAN_IP=$(ip -4 -o route get 10/8 | sed -n 's/.*src \([0-9.]\+\).*/\1/p')
if [[ -n $LAN_IP ]]; then
echo "$LAN_IP"
return 0
fi
echo "fail to obtain LAN_IP"
error "fail to obtain LAN_IP"
exit 1
}

_on_baremetal_v6() {
if ! ip -6 route show | grep "default via"; then
echo "fail to obtain LAN_IPv6, default route missing"
if ! ip -6 route show | grep -q "default via"; then
error "fail to obtain LAN_IPv6, default route missing"
exit 2
fi
LAN_IPv6=$(ip -6 -o route get fd00::/8 | grep -Po '(?<=src) \K[^ ]+')
Expand Down

0 comments on commit 72404a5

Please sign in to comment.