diff --git a/misc/alpine-install.func b/misc/alpine-install.func index 23af25128..6169c64a3 100644 --- a/misc/alpine-install.func +++ b/misc/alpine-install.func @@ -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 } diff --git a/misc/api.func b/misc/api.func index e29975e2c..a268c919c 100644 --- a/misc/api.func +++ b/misc/api.func @@ -401,7 +401,7 @@ get_error_text() { fi if [[ -n "$logfile" && -s "$logfile" ]]; then - tail -n 20 "$logfile" 2>/dev/null | sed 's/\r$//' | sed 's/\x1b\[[0-9;]*[a-zA-Z]//g' + tail -n 20 "$logfile" 2>/dev/null | sed -E 's/\r$//; s/\x1b\[[0-9;]*[a-zA-Z]//g' fi } @@ -508,7 +508,8 @@ detect_gpu() { if [[ -n "$gpu_line" ]]; then # Extract model: everything after the colon, clean up - GPU_MODEL=$(echo "$gpu_line" | sed 's/.*: //' | sed 's/ (rev .*)$//' | cut -c1-64) + GPU_MODEL=$(echo "$gpu_line" | sed -E 's/.*: //; s/ \(rev .*\)$//') + GPU_MODEL="${GPU_MODEL:0:64}" # Detect vendor and passthrough type if echo "$gpu_line" | grep -qi "Intel"; then @@ -557,7 +558,8 @@ detect_cpu() { esac # Extract model name and clean it up - CPU_MODEL=$(grep -m1 "model name" /proc/cpuinfo 2>/dev/null | cut -d: -f2 | sed 's/^ *//' | sed 's/(R)//g' | sed 's/(TM)//g' | sed 's/ */ /g' | cut -c1-64) + CPU_MODEL=$(grep -m1 "model name" /proc/cpuinfo 2>/dev/null | cut -d: -f2 | sed -E 's/^ *//; s/\(R\)//g; s/\(TM\)//g; s/ +/ /g') + CPU_MODEL="${CPU_MODEL:0:64}" fi export CPU_VENDOR CPU_MODEL @@ -1325,11 +1327,16 @@ post_addon_to_api() { error_category=$(categorize_error "$exit_code") fi - # Detect OS info + # Detect OS info (single read) local os_type="" os_version="" if [[ -f /etc/os-release ]]; then - os_type=$(grep "^ID=" /etc/os-release | cut -d= -f2 | tr -d '"') - os_version=$(grep "^VERSION_ID=" /etc/os-release | cut -d= -f2 | tr -d '"') + while IFS='=' read -r _k _v; do + _v="${_v//\"/}" + case "$_k" in + ID) os_type="$_v" ;; + VERSION_ID) os_version="$_v" ;; + esac + done < /etc/os-release fi local JSON_PAYLOAD diff --git a/misc/core.func b/misc/core.func index e3b9d2cff..20af1f65b 100644 --- a/misc/core.func +++ b/misc/core.func @@ -1644,7 +1644,7 @@ function get_lxc_ip() { local ip # Try direct interface lookup for eth0 FIRST (most reliable for LXC) - IPv4 - ip=$(ip -4 addr show eth0 2>/dev/null | awk '/inet / {print $2}' | cut -d/ -f1 | head -n1) + ip=$(ip -4 addr show eth0 2>/dev/null | awk '/inet / {sub(/\/.*/, "", $2); print $2; exit}') if [[ -n "$ip" && "$ip" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then echo "$ip" return 0 @@ -1652,11 +1652,14 @@ function get_lxc_ip() { # Fallback: Try hostname -I (returns IPv4 first if available) if command -v hostname >/dev/null 2>&1; then - ip=$(hostname -I 2>/dev/null | awk '{print $1}') - if [[ -n "$ip" && "$ip" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - echo "$ip" - return 0 - fi + local -a _ips + read -ra _ips <<<"$(hostname -I 2>/dev/null)" + for ip in "${_ips[@]}"; do + if [[ "$ip" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "$ip" + return 0 + fi + done fi # Try routing table with IPv4 targets @@ -1674,7 +1677,7 @@ function get_lxc_ip() { done # IPv6 fallback: Try direct interface lookup for eth0 - ip=$(ip -6 addr show eth0 scope global 2>/dev/null | awk '/inet6 / {print $2}' | cut -d/ -f1 | head -n1) + ip=$(ip -6 addr show eth0 scope global 2>/dev/null | awk '/inet6 / {sub(/\/.*/, "", $2); print $2; exit}') if [[ -n "$ip" && "$ip" =~ : ]]; then echo "$ip" return 0 @@ -1682,11 +1685,11 @@ function get_lxc_ip() { # IPv6 fallback: Try hostname -I for IPv6 if command -v hostname >/dev/null 2>&1; then - ip=$(hostname -I 2>/dev/null | tr ' ' '\n' | grep -E ':' | head -n1) - if [[ -n "$ip" && "$ip" =~ : ]]; then - echo "$ip" - return 0 - fi + local -a _ips6 + read -ra _ips6 <<<"$(hostname -I 2>/dev/null)" + for ip in "${_ips6[@]}"; do + [[ "$ip" == *:* ]] && { echo "$ip"; return 0; } + done fi # IPv6 fallback: Use routing table with IPv6 targets diff --git a/misc/install.func b/misc/install.func index 94f005b26..2c34264d5 100644 --- a/misc/install.func +++ b/misc/install.func @@ -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 }