archiso_pxe_http 2.46 KB
Newer Older
1
#!/bin/ash
2
3
#
# SPDX-License-Identifier: GPL-3.0-or-later
4
5

run_hook() {
6
7
    # shellcheck disable=SC2154
    # defined via initcpio's parse_cmdline()
8
    if [ -n "${ip}" ] && [ -n "${archiso_http_srv}" ]; then
9

10
11
        # booting with http is always copy-to-ram, so set here to make sure
        # addresses are flushed and interface is set down
12
        export copytoram="y"
13

14
15
        archiso_http_srv=$(eval echo "${archiso_http_srv}")
        [ -z "${archiso_http_spc}" ] && archiso_http_spc="75%"
16

17
        export mount_handler="archiso_pxe_http_mount_handler"
18
19
20
21
22
23
    fi
}

# Fetch a file with CURL
#
# $1 URL
24
# $2 Destination directory inside httpspace/${archisobasedir}
25
26
27
28
29
_curl_get() {
    local _url="${1}"
    local _dst="${2}"

    msg ":: Downloading '${_url}'"
30
31
    # shellcheck disable=SC2154
    # defined via initcpio's parse_cmdline()
32
    if ! curl -L -f -o "/run/archiso/httpspace/${archisobasedir}${_dst}/${_url##*/}" --create-dirs "${_url}"; then
33
34
35
36
37
38
39
        echo "ERROR: Downloading '${_url}'"
        echo "   Falling back to interactive prompt"
        echo "   You can try to fix the problem manually, log out when you are finished"
        launch_interactive_shell
    fi
}

40
archiso_pxe_http_mount_handler () {
41
    newroot="${1}"
nl6720's avatar
nl6720 committed
42
    local img_type="sfs"
43

44
45
46
    msg ":: Mounting /run/archiso/httpspace (tmpfs) filesystem, size='${archiso_http_spc}'"
    mkdir -p "/run/archiso/httpspace"
    mount -t tmpfs -o size="${archiso_http_spc}",mode=0755 httpspace "/run/archiso/httpspace"
47

48
49
    # shellcheck disable=SC2154
    # defined via initcpio's parse_cmdline()
nl6720's avatar
nl6720 committed
50
51
52
53
54
55
    if ! curl -L -f -o /dev/null -s -r 0-0 "${archiso_http_srv}${archisobasedir}/${arch}/airootfs.sfs"; then
        if curl -L -f -o /dev/null -s -r 0-0 "${archiso_http_srv}${archisobasedir}/${arch}/airootfs.erofs"; then
            img_type="erofs"
        fi
    fi
    _curl_get "${archiso_http_srv}${archisobasedir}/${arch}/airootfs.${img_type}" "/${arch}"
56

57
58
    # shellcheck disable=SC2154
    # defined via initcpio's parse_cmdline()
59
    if [ "${checksum}" = "y" ]; then
60
        _curl_get "${archiso_http_srv}${archisobasedir}/${arch}/airootfs.sha512" "/${arch}"
61
    fi
62
63
    # shellcheck disable=SC2154
    # defined via initcpio's parse_cmdline()
64
    if [ "${verify}" = "y" ]; then
nl6720's avatar
nl6720 committed
65
        _curl_get "${archiso_http_srv}${archisobasedir}/${arch}/airootfs.${img_type}.sig" "/${arch}"
66
    fi
67

68
    mkdir -p "/run/archiso/bootmnt"
69
    mount -o bind /run/archiso/httpspace /run/archiso/bootmnt
70

71
    archiso_mount_handler "${newroot}"
72
}
73
74

# vim: set ft=sh: