-
Notifications
You must be signed in to change notification settings - Fork 359
/
Copy pathfetch-kickstart-net.sh
executable file
·96 lines (82 loc) · 2.94 KB
/
fetch-kickstart-net.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/bash
# fetch-kickstart-net - fetch kickstart file from the network.
# runs from the "initqueue/online" hook whenever a net interface comes online
# initqueue/online hook passes interface name as $1
netif="$1"
# we already processed the kickstart - exit
[ -e /tmp/ks.cfg.done ] && return 0
# no kickstart requested - exit
[ -n "$kickstart" ] || return 0
# user requested a specific device, but this isn't it - exit
[ -n "$ksdevice" ] && [ "$ksdevice" != "$netif" ] && return 0
command -v getarg >/dev/null || . /lib/dracut-lib.sh
. /lib/url-lib.sh
. /lib/anaconda-lib.sh
# Find locations to the kickstart files.
locations=""
case $kickstart in
nfs*)
# Construct URL for nfs:auto.
if [ "$kickstart" = "nfs:auto" ]; then
# Construct kickstart URL from dhcp info.
# Server is next_server, or the dhcp server itself if missing.
. /tmp/net.$netif.dhcpopts
server="${new_next_server:-$new_dhcp_server_identifier}"
# Filename is dhcp 'filename' option, or '/kickstart/' if missing.
filename="/kickstart/"
# Read the dhcp lease file and see if we can find 'filename'.
{ while read line; do
val="${line#filename }"
if [ "$val" != "$line" ]; then
eval "filename=$val" # Drop quoting and semicolon.
fi
done
} < /tmp/net.$netif.lease
kickstart="nfs:$server:$filename"
fi
# URLs that end in '/' get '$IP_ADDR-kickstart' appended.
if [[ $kickstart == nfs*/ ]]; then
kickstart="${kickstart}${new_ip_address:=$(ip -4 addr show ${netif} | sed -n -e '/^ *inet / s|^ *inet \([^/]\+\)/.*$|\1|p')}-kickstart"
fi
# Use the prepared url.
locations="$kickstart"
;;
http*|ftp*)
# Use the location from the variable.
locations="$kickstart"
;;
urls)
# Use the locations from the file.
# We will try them one by one until we succeed.
locations="$(</tmp/ks_urls)"
;;
*)
warn "unknown network kickstart URL: $kickstart"
return 1
;;
esac
# If we're doing sendmac, we need to run after anaconda-ks-sendheaders.sh
if getargbool 0 inst.ks.sendmac kssendmac; then
newjob=$hookdir/initqueue/settled/fetch-ks-${netif}.sh
else
newjob=$hookdir/initqueue/fetch-ks-${netif}.sh
fi
# Create a new job.
cat > $newjob <<__EOT__
. /lib/url-lib.sh
. /lib/anaconda-lib.sh
locations="$locations"
info "anaconda: kickstart locations are: \$locations"
for kickstart in \$locations; do
info "anaconda: fetching kickstart from \$kickstart"
if fetch_url "\$kickstart" /tmp/ks.cfg; then
info "anaconda: successfully fetched kickstart from \$kickstart"
parse_kickstart /tmp/ks.cfg
run_kickstart
break
else
warn "anaconda: failed to fetch kickstart from \$kickstart"
fi
done
rm \$job # remove self from initqueue
__EOT__