Use PERSISTENCE_PATH with a trailing "/".
[debian-live-boot.git] / components / 9990-mount-http.sh
blob16e69b692e04ac178e016591a5f7fe6c8cfbffc9
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 65464 -r $rfile -l ${dest}/$lfile $ip"
36 tftp -g -b 65464 -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"
54 if [ -n "${FUSE_MOUNT}" ] && [ -x /bin/mount.util-linux ]
55 then
56 # fuse does not work with klibc mount
57 ln -f /bin/mount.util-linux /bin/mount
60 modprobe fuse
61 $FUSE_MOUNT "${url}" "${dest}"
62 ROOT_PID="$(minips h -C "$FUSE_MOUNT" | { read x y ; echo "$x" ; } )"
64 [ ${?} -eq 0 ] && rc=0
65 [ "${extension}" = "tgz" ] && live_dest="ram"
66 if [ "${extension}" = "iso" ]
67 then
68 isoloop=$(setup_loop "${dest}/$(basename "${url}")" "loop" "/sys/block/loop*" "" '')
69 mount -t iso9660 "${isoloop}" "${mountpoint}"
70 rc=${?}
72 break
76 log_begin_msg "Unrecognized archive extension for ${url}"
78 esac
80 done
82 if [ ${rc} != 0 ]
83 then
84 if [ -d "${alt_mountpoint}" ]
85 then
86 umount "${alt_mountpoint}"
87 rmdir "${alt_mountpoint}"
89 umount "${mountpoint}"
90 elif [ "${webfile}" != "FETCH" ] ; then
91 NETBOOT="${webfile}"
92 export NETBOOT
95 return ${rc}