Debian Codegraph @

dracut/modules.d/59kiwi-lib/kiwi-net-lib.sh

raw
1 #!/bin/bash
2
3 type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
4
5 # URI pattern Based on https://tools.ietf.org/html/rfc3986#appendix-B
6 # with additional sub-expressions to split authority into
7 # userinfo, host and port
8 readonly URI_REGEX='^(([^:/?#]+):)?(//((([^:/?#]+)@)?([^:/?#]+)(:([0-9]+))?))?(/([^?#]*))(\?([^#]*))?(#(.*))?'
9
10 function fetch_file {
11 local source_url=$1
12 local source_uncompressed_bytes=$2
13 local fetch_info=/tmp/fetch.info
14 local fetch
15 local curl_options
16 local dolly_options
17 curl_options=$(getarg rd.kiwi.install.pxe.curl_options=)
18 dolly_options=$(getarg rd.kiwi.install.pxe.dolly_options=)
19 if [ -n "${curl_options}" ]; then
20 curl_options=$(str_replace "${curl_options}" "," " ")
21 fetch="curl ${curl_options} -f ${source_url}"
22 else
23 fetch="curl -f ${source_url}"
24 fi
25 if [ -n "${dolly_options}" ]; then
26 dolly_options=$(str_replace "${dolly_options}" "," " ")
27 fetch="dolly ${dolly_options} -f ${source_url}"
28 fi
29 if _is_dolly "${source_url}";then
30 fetch="dolly"
31 fi
32 if _is_xz_compressed "${source_url}";then
33 fetch="${fetch} | xz -d"
34 fi
35 if [ -z "${source_uncompressed_bytes}" ];then
36 eval "${fetch}" 2>${fetch_info}
37 else
38 eval "${fetch}" 2>${fetch_info} |\
39 pv --size "${source_uncompressed_bytes}" --stop-at-size -n
40 fi
41 return "${PIPESTATUS[0]}"
42 }
43
44 function uri_scheme {
45 [[ "$*" =~ ${URI_REGEX} ]] && echo "${BASH_REMATCH[2]}"
46 }
47
48 function uri_authority {
49 [[ "$*" =~ ${URI_REGEX} ]] && echo "${BASH_REMATCH[4]}"
50 }
51
52 function uri_user {
53 [[ "$*" =~ ${URI_REGEX} ]] && echo "${BASH_REMATCH[6]}"
54 }
55
56 function uri_host {
57 [[ "$*" =~ ${URI_REGEX} ]] && echo "${BASH_REMATCH[7]}"
58 }
59
60 function uri_port {
61 [[ "$*" =~ ${URI_REGEX} ]] && echo "${BASH_REMATCH[9]}"
62 }
63
64 function uri_path {
65 [[ "$*" =~ ${URI_REGEX} ]] && echo "${BASH_REMATCH[10]}"
66 }
67
68 function uri_relative_path {
69 [[ "$*" =~ ${URI_REGEX} ]] && echo "${BASH_REMATCH[11]}"
70 }
71
72 function uri_query {
73 [[ "$*" =~ ${URI_REGEX} ]] && echo "${BASH_REMATCH[13]}"
74 }
75
76 function uri_fragment {
77 [[ "$*" =~ ${URI_REGEX} ]] && echo "${BASH_REMATCH[15]}"
78 }
79
80 #======================================
81 # Methods considered private
82 #--------------------------------------
83 function _is_xz_compressed {
84 local source_url=$1
85 [[ ${source_url} =~ .xz$ ]]
86 }
87
88 function _is_dolly {
89 local source_url=$1
90 [[ ${source_url} =~ ^dolly ]]
91 }