Checking for ${overlay}, not ${device} when trying to close ${overlay}.
[debian-live-boot.git] / scripts / boot / 9990-mount-http.sh
blobb5574049463ebe1bbae2df12ff8d227b6816c07f
1 #!/bin/sh
3 #set -e
5 do_httpmount ()
7 rc=1
9 for webfile in HTTPFS FTPFS FETCH
11 local url extension dest
12 url="$(eval echo \"\$\{${webfile}\}\")"
13 extension="$(echo "${url}" | sed 's/\(.*\)\.\(.*\)/\2/')"
15 if [ -n "$url" ]
16 then
17 case "${extension}" in
18 iso|squashfs|tgz|tar)
19 if [ "${extension}" = "iso" ]
20 then
21 mkdir -p "${alt_mountpoint}"
22 dest="${alt_mountpoint}"
23 else
24 dest="${mountpoint}/${LIVE_MEDIA_PATH}"
25 mount -t ramfs ram "${mountpoint}"
26 mkdir -p "${dest}"
28 if [ "${webfile}" = "FETCH" ]
29 then
30 case "$url" in
31 tftp*)
32 ip="$(dirname $url | sed -e 's|tftp://||g' -e 's|/.*$||g')"
33 rfile="$(echo $url | sed -e "s|tftp://$ip||g")"
34 lfile="$(basename $url)"
35 log_begin_msg "Trying tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip"
36 tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip
40 log_begin_msg "Trying wget ${url} -O ${dest}/$(basename ${url})"
41 wget "${url}" -O "${dest}/$(basename ${url})"
43 esac
44 else
45 log_begin_msg "Trying to mount ${url} on ${dest}/$(basename ${url})"
46 if [ "${webfile}" = "FTPFS" ]
47 then
48 FUSE_MOUNT="curlftpfs"
49 url="$(dirname ${url})"
50 else
51 FUSE_MOUNT="httpfs"
53 modprobe fuse
54 $FUSE_MOUNT "${url}" "${dest}"
55 ROOT_PID="$(minips h -C "$FUSE_MOUNT" | { read x y ; echo "$x" ; } )"
57 [ ${?} -eq 0 ] && rc=0
58 [ "${extension}" = "tgz" ] && live_dest="ram"
59 if [ "${extension}" = "iso" ]
60 then
61 isoloop=$(setup_loop "${dest}/$(basename "${url}")" "loop" "/sys/block/loop*" "" '')
62 mount -t iso9660 "${isoloop}" "${mountpoint}"
63 rc=${?}
65 break
69 log_begin_msg "Unrecognized archive extension for ${url}"
71 esac
73 done
75 if [ ${rc} != 0 ]
76 then
77 if [ -d "${alt_mountpoint}" ]
78 then
79 umount "${alt_mountpoint}"
80 rmdir "${alt_mountpoint}"
82 umount "${mountpoint}"
83 elif [ "${webfile}" != "FETCH" ] ; then
84 NETBOOT="${webfile}"
85 export NETBOOT
88 return ${rc}