mirror of
https://github.com/community-scripts/ProxmoxVE.git
synced 2026-04-27 21:00:40 +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:
+5
-6
@@ -116,14 +116,14 @@ setting_up_container() {
|
||||
(chown root:root / 2>/dev/null) || true
|
||||
fi
|
||||
|
||||
local _host_ip=""
|
||||
for ((i = RETRY_NUM; i > 0; i--)); do
|
||||
if [ "$(hostname -I)" != "" ]; then
|
||||
break
|
||||
fi
|
||||
_host_ip=$(hostname -I 2>/dev/null | awk '{print $1}')
|
||||
[[ -n "$_host_ip" ]] && break
|
||||
echo 1>&2 -en "${CROSS}${RD} No Network! "
|
||||
sleep $RETRY_EVERY
|
||||
done
|
||||
if [ "$(hostname -I)" = "" ]; then
|
||||
if [[ -z "$_host_ip" ]]; then
|
||||
echo 1>&2 -e "\n${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}"
|
||||
echo -e "${NETWORK}Check Network Settings"
|
||||
exit 121
|
||||
@@ -131,8 +131,7 @@ setting_up_container() {
|
||||
rm -rf /usr/lib/python3.*/EXTERNALLY-MANAGED
|
||||
systemctl disable -q --now systemd-networkd-wait-online.service
|
||||
msg_ok "Set up Container OS"
|
||||
#msg_custom "${CM}" "${GN}" "Network Connected: ${BL}$(hostname -I)"
|
||||
msg_ok "Network Connected: ${BL}$(hostname -I)"
|
||||
msg_ok "Network Connected: ${BL}${_host_ip}"
|
||||
post_progress_to_api
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user