Ostatnio aktywny 6 months ago

waja zrewidował ten Gist 7 years ago. Przejdź do rewizji

1 file changed, 50 insertions

cloudatcost-pxe.sh(stworzono plik)

@@ -0,0 +1,50 @@
1 + #!/usr/bin/env bash
2 +
3 + cdr2mask ()
4 + {
5 + # Number of args to shift, 255..255, first non-255 byte, zeroes
6 + set -- $(( 5 - ($1 / 8) )) 255 255 255 255 $(( (255 << (8 - ($1 % 8))) & 255 )) 0 0 0
7 + [[ $1 -gt 1 ]] && shift ${1} || shift
8 + echo "${1-0}.${2-0}.${3-0}.${4-0}"
9 + }
10 +
11 + cd /boot || exit 1
12 + wget --continue --output-document=/boot/netboot.xyz.lkrn https://boot.netboot.xyz/ipxe/netboot.xyz.lkrn
13 +
14 + _Dev="$(ip route list | awk '/^default/ {print $5}')"
15 + _Gateway="$(ip route list | awk '/^default/ {print $3}')"
16 + _IP="$(ip -o -4 addr show "${_Dev}" | awk '{print $4}')"
17 + _Netmask="$(cdr2mask "${_IP#*/}")"
18 + _IP=${_IP%/*}
19 +
20 + cat <<_EOF_ > /boot/netboot.xyz-initrd
21 + #!ipxe
22 + #/boot/netboot.xyz-initrd
23 + imgfree
24 + set net0/ip ${_IP%/*}
25 + set net0/netmask ${_Netmask}
26 + set net0/gateway ${_Gateway}
27 + set dns 208.67.222.222
28 + ifopen net0
29 + chain --autofree https://boot.netboot.xyz
30 + _EOF_
31 +
32 + cat <<_EOF_ > /etc/grub.d/09_custom
33 + echo "
34 + menuentry 'netboot.xyz' {
35 + set root='hd0,msdos1'
36 + linux16 /netboot.xyz.lkrn
37 + initrd16 /netboot.xyz-initrd
38 + }
39 + "
40 + _EOF_
41 + chmod +x /etc/grub.d/09_custom
42 +
43 + update-grub2 || { grub2-mkconfig -o /boot/grub2/grub.cfg; grub2-set-default 0; }
44 +
45 + echo "Network Interface: ${_Dev}"
46 + echo "IP: ${_IP%/*}"
47 + echo "Netmask: ${_Netmask}"
48 + echo "Gateway: ${_Gateway}"
49 +
50 + reboot
Nowsze Starsze