]>
Commit | Line | Data |
---|---|---|
e1619ee1 | 1 | #!/bin/sh |
6d2a7943 | 2 | # livenetroot - fetch a live image from the network and run it |
6d2a7943 | 3 | |
9a52c3fd | 4 | type getarg > /dev/null 2>&1 || . /lib/dracut-lib.sh |
6d2a7943 | 5 | |
5978983b WW |
6 | . /lib/url-lib.sh |
7 | ||
6d2a7943 | 8 | PATH=/usr/sbin:/usr/bin:/sbin:/bin |
0bac59ee NR |
9 | RETRIES=${RETRIES:-100} |
10 | SLEEP=${SLEEP:-5} | |
6d2a7943 | 11 | |
3913d061 HH |
12 | [ -e /tmp/livenet.downloaded ] && exit 0 |
13 | ||
6d2a7943 | 14 | # args get passed from 40network/netroot |
5978983b WW |
15 | netroot="$2" |
16 | liveurl="${netroot#livenet:}" | |
17 | info "fetching $liveurl" | |
3913d061 | 18 | |
52351cfa TB |
19 | if getargbool 0 'rd.writable.fsimg'; then |
20 | ||
21 | imgsize=$(($(curl -sIL "$liveurl" | sed -n 's/Content-Length: *\([[:digit:]]*\).*/\1/p') / (1024 * 1024))) | |
22 | ||
23 | check_live_ram $imgsize | |
24 | fi | |
25 | ||
678627f3 | 26 | imgfile= |
66bfa66a | 27 | #retry until the imgfile is populated with data or the max retries |
916ac45c | 28 | i=1 |
0315e169 | 29 | while [ "$i" -le "$RETRIES" ]; do |
678627f3 | 30 | imgfile=$(fetch_url "$liveurl") |
3913d061 | 31 | |
0315e169 | 32 | # shellcheck disable=SC2181 |
678627f3 | 33 | if [ $? != 0 ]; then |
9a52c3fd HH |
34 | warn "failed to download live image: error $?" |
35 | imgfile= | |
678627f3 | 36 | fi |
66bfa66a | 37 | |
0315e169 | 38 | if [ -n "$imgfile" -a -s "$imgfile" ]; then |
66bfa66a NR |
39 | break |
40 | else | |
0315e169 | 41 | if [ $i -ge "$RETRIES" ]; then |
1b38fa41 NR |
42 | warn "failed to download live image after $i attempts." |
43 | exit 1 | |
44 | fi | |
45 | ||
0315e169 | 46 | sleep "$SLEEP" |
66bfa66a | 47 | fi |
916ac45c NR |
48 | |
49 | i=$((i + 1)) | |
678627f3 | 50 | done > /tmp/livenet.downloaded |
5978983b WW |
51 | |
52 | # TODO: couldn't dmsquash-live-root handle this? | |
0315e169 | 53 | if [ "${imgfile##*.}" = "iso" ]; then |
6d2a7943 | 54 | root=$(losetup -f) |
0315e169 | 55 | losetup "$root" "$imgfile" |
6d2a7943 WW |
56 | else |
57 | root=$imgfile | |
58 | fi | |
5978983b | 59 | |
0315e169 | 60 | exec /sbin/dmsquash-live-root "$root" |