Skip to content

Commit

Permalink
fix(livenet): split imgsize calculation to avoid misleading error m…
Browse files Browse the repository at this point in the history
…essage

If `curl` fails to reach the URL of the live image, or if the header received
does not provide `Content-Length`, the error message displayed is misleading.

```
[    8.118432] dracut-initqueue[800]: /usr/sbin/livenetroot: line 21: / (1024 * 1024): syntax error: operand expected (error token is "/ (1024 * 1024)")
```

Therefore, split the calculation and provide proper error messages.

Reported-by: Knut Anderssen <kanderssen@suse.com>
  • Loading branch information
aafeijoo-suse committed Jan 22, 2024
1 parent a572e23 commit 87c8f82
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions modules.d/90livenet/livenetroot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,21 @@ liveurl="${netroot#livenet:}"
info "fetching $liveurl"

if getargbool 0 'rd.writable.fsimg'; then
imgheader=$(curl -sIL "$liveurl")

imgsize=$(($(curl -sIL "$liveurl" | sed -n 's/[cC]ontent-[lL]ength: *\([[:digit:]]*\).*/\1/p') / (1024 * 1024)))

check_live_ram $imgsize
# shellcheck disable=SC2181
ret=$?
if [ $ret != 0 ]; then
warn "failed to get live image header: error $ret"
else
imgheaderlen=$(echo "$imgheader" | sed -n 's/[cC]ontent-[lL]ength: *\([[:digit:]]*\).*/\1/p')
if [ -z "$imgheaderlen" ]; then
warn "failed to get 'Content-Length' header from live image"
else
imgsize=$((imgheaderlen / (1024 * 1024)))
check_live_ram $imgsize
fi
fi
fi

imgfile=
Expand Down

0 comments on commit 87c8f82

Please sign in to comment.