]> git.ipfire.org Git - thirdparty/dracut.git/blob - modules.d/90livenet/livenetroot.sh
747a0706ac17b8646770f22f376f86155397fc83
[thirdparty/dracut.git] / modules.d / 90livenet / livenetroot.sh
1 #!/bin/sh
2 # livenetroot - fetch a live image from the network and run it
3
4 type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
5
6 . /lib/url-lib.sh
7
8 PATH=/usr/sbin:/usr/bin:/sbin:/bin
9 RETRIES={$RETRIES:-100}
10 SLEEP={$SLEEP:-5}
11
12 [ -e /tmp/livenet.downloaded ] && exit 0
13
14 # args get passed from 40network/netroot
15 netroot="$2"
16 liveurl="${netroot#livenet:}"
17 info "fetching $liveurl"
18
19 imgfile=
20 #retry until the imgfile is populated with data or the max retries
21 for (( i=1; i<=$RETRIES; i++))
22 do
23 imgfile=$(fetch_url "$liveurl")
24
25 if [ $? != 0 ]; then
26 warn "failed to download live image: error $?"
27 imgfile=
28 fi
29
30 if [ ! -z "$imgfile" -a -s "$imgfile" ]; then
31 break
32 else
33 if [ $i -ge $RETRIES ]; then
34 warn "failed to download live image after $i attempts."
35 exit 1
36 fi
37
38 sleep $SLEEP
39 fi
40 done > /tmp/livenet.downloaded
41
42 # TODO: couldn't dmsquash-live-root handle this?
43 if [ ${imgfile##*.} = "iso" ]; then
44 root=$(losetup -f)
45 losetup $root $imgfile
46 else
47 root=$imgfile
48 fi
49
50 exec /sbin/dmsquash-live-root $root