mirror of
https://github.com/community-scripts/ProxmoxVE.git
synced 2026-04-28 21:30:41 +00:00
perf(misc): optimize network checks, IP detection, and subprocess chains
Files: install.func, alpine-install.func, core.func, api.func Changes: - install.func: Cache hostname -I result in setting_up_container() — eliminates 3 redundant calls (retry loop + post-check + display). Single awk extracts first IP from cached call. - alpine-install.func: Cache ip addr result in setting_up_container() — replaces 3 identical 4-process pipelines (ip|grep|grep|awk|cut) with one call using single awk (sub+print in one pass). - core.func get_lxc_ip(): Merge awk+cut into single awk (sub+print) for eth0 IPv4/IPv6 lookups. Replace tr|grep pipeline for IPv6 hostname fallback with bash array iteration (read -ra + for loop). - api.func detect_gpu(): Merge 2x sed + cut into single sed -E + bash substring. detect_cpu(): Merge 4x sed + cut into single sed -E + bash substring. get_error_text(): Merge 2x sed into single sed -E. post_addon_to_api(): Replace 2x grep|cut|tr on /etc/os-release with single while-read loop (1 file read instead of 6 subprocess forks).
This commit is contained in:
@@ -67,22 +67,22 @@ EOF
|
||||
# This function sets up the Container OS by generating the locale, setting the timezone, and checking the network connection
|
||||
setting_up_container() {
|
||||
msg_info "Setting up Container OS"
|
||||
local _ip=""
|
||||
while [ $i -gt 0 ]; do
|
||||
if [ "$(ip addr show | grep 'inet ' | grep -v '127.0.0.1' | awk '{print $2}' | cut -d'/' -f1)" != "" ]; then
|
||||
break
|
||||
fi
|
||||
_ip=$(ip -4 addr show 2>/dev/null | awk '/inet [0-9]/ && !/127\.0\.0\.1/ {sub(/\/.*/, "", $2); print $2; exit}')
|
||||
[[ -n "$_ip" ]] && break
|
||||
echo 1>&2 -en "${CROSS}${RD} No Network! "
|
||||
sleep $RETRY_EVERY
|
||||
i=$((i - 1))
|
||||
done
|
||||
|
||||
if [ "$(ip addr show | grep 'inet ' | grep -v '127.0.0.1' | awk '{print $2}' | cut -d'/' -f1)" = "" ]; then
|
||||
if [[ -z "$_ip" ]]; then
|
||||
echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}"
|
||||
echo -e "${NETWORK}Check Network Settings"
|
||||
exit 121
|
||||
fi
|
||||
msg_ok "Set up Container OS"
|
||||
msg_ok "Network Connected: ${BL}$(ip addr show | grep 'inet ' | awk '{print $2}' | cut -d'/' -f1 | tail -n1)${CL}"
|
||||
msg_ok "Network Connected: ${BL}${_ip}${CL}"
|
||||
post_progress_to_api
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user