Renaming boot scripts for refactoring them into numbered plugins.
[debian-live-boot/hramrach.git] / scripts / boot / 9990-mount-http.sh
blob1b718c0a841c4fa8ab1dc0c0a00321659bc11724
1 #!/bin/sh
3 #set -e
5 do_httpmount ()
7 rc=1
9 for webfile in HTTPFS FTPFS FETCH
11 local url="$(eval echo \"\$\{${webfile}\}\")"
12 local extension="$(echo "${url}" | sed 's/\(.*\)\.\(.*\)/\2/')"
14 if [ -n "$url" ]
15 then
16 case "${extension}" in
17 iso|squashfs|tgz|tar)
18 if [ "${extension}" = "iso" ]
19 then
20 mkdir -p "${alt_mountpoint}"
21 dest="${alt_mountpoint}"
22 else
23 local dest="${mountpoint}/${LIVE_MEDIA_PATH}"
24 mount -t ramfs ram "${mountpoint}"
25 mkdir -p "${dest}"
27 if [ "${webfile}" = "FETCH" ]
28 then
29 case "$url" in
30 tftp*)
31 ip="$(dirname $url | sed -e 's|tftp://||g' -e 's|/.*$||g')"
32 rfile="$(echo $url | sed -e "s|tftp://$ip||g")"
33 lfile="$(basename $url)"
34 log_begin_msg "Trying tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip"
35 tftp -g -b 10240 -r $rfile -l ${dest}/$lfile $ip
39 log_begin_msg "Trying wget ${url} -O ${dest}/$(basename ${url})"
40 wget "${url}" -O "${dest}/$(basename ${url})"
42 esac
43 else
44 log_begin_msg "Trying to mount ${url} on ${dest}/$(basename ${url})"
45 if [ "${webfile}" = "FTPFS" ]
46 then
47 FUSE_MOUNT="curlftpfs"
48 url="$(dirname ${url})"
49 else
50 FUSE_MOUNT="httpfs"
52 modprobe fuse
53 $FUSE_MOUNT "${url}" "${dest}"
54 ROOT_PID="$(minips h -C "$FUSE_MOUNT" | { read x y ; echo "$x" ; } )"
56 [ ${?} -eq 0 ] && rc=0
57 [ "${extension}" = "tgz" ] && live_dest="ram"
58 if [ "${extension}" = "iso" ]
59 then
60 isoloop=$(setup_loop "${dest}/$(basename "${url}")" "loop" "/sys/block/loop*" "" '')
61 mount -t iso9660 "${isoloop}" "${mountpoint}"
62 rc=${?}
64 break
68 log_begin_msg "Unrecognized archive extension for ${url}"
70 esac
72 done
74 if [ ${rc} != 0 ]
75 then
76 if [ -d "${alt_mountpoint}" ]
77 then
78 umount "${alt_mountpoint}"
79 rmdir "${alt_mountpoint}"
81 umount "${mountpoint}"
82 elif [ "${webfile}" != "FETCH" ] ; then
83 NETBOOT="${webfile}"
84 export NETBOOT
87 return ${rc}