-
Notifications
You must be signed in to change notification settings - Fork 2
/
09_debian-netinst
executable file
·46 lines (37 loc) · 1.91 KB
/
09_debian-netinst
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
#!/bin/sh
debianrelease=jessie
debianarch=amd64
hostname=newmachine
domain=
nameserver=8.8.8.8
cidr2mask ()
{
# Number of args to shift, 255..255, first non-255 byte, zeroes
set -- $(( 5 - ($1 / 8) )) 255 255 255 255 $(( (255 << (8 - ($1 % 8))) & 255 )) 0 0 0
[ $1 -gt 1 ] && shift $1 || shift
echo ${1-0}.${2-0}.${3-0}.${4-0}
}
ip=$(ip route get 1 | awk '{print $NF;exit}')
gateway=$(ip route get 1 | awk '{print $3;exit}')
default_if=$(ip route list | awk '/^default/ {print $5}')
cidr=$(ip -o -f inet addr show $default_if | awk '{print $4}')
netmask=$(cidr2mask "${cidr##*/}")
echo "Detected network configuration:" 1>&2
echo "IP: $ip" 1>&2
echo "Gateway: $gateway" 1>&2
echo "Netmask: $netmask" 1>&2
if mountpoint /boot > /dev/null 2>&1
then
ipxepath="/ipxe.lkrn"
else
ipxepath="/boot/ipxe.lkrn"
fi
if ! test -f "/boot/ipxe.lkrn"
then
wget http://boot.ipxe.org/ipxe.lkrn -O /boot/ipxe.lkrn
fi
cat <<EOF
menuentry "Install from internet mirror: Debian ${debianrelease} amd64" {
linux16 ${ipxepath} set net0/ip $ip \&\& set net0/netmask $netmask \&\& set net0/gateway $gateway \&\& set dns $nameserver \&\& ifopen net0 \&\& initrd http://ftp2.de.debian.org/debian/dists/${debianrelease}/main/installer-${debianarch}/current/images/netboot/debian-installer/${debianarch}/initrd.gz \&\& chain http://ftp2.de.debian.org/debian/dists/${debianrelease}/main/installer-${debianarch}/current/images/netboot/debian-installer/${debianarch}/linux netcfg/choose_interface=\\\$\{net0/mac\} netcfg/disable_autoconfig=true netcfg/get_ipaddress=$ip netcfg/get_netmask=$netmask netcfg/get_gateway=$gateway netcfg/get_nameservers=$nameserver netcfg/confirm_static=true netcfg/get_hostname=$hostname netcfg/get_domain=$domain netcfg/hostname=$hostname debian-installer/language=en debian-installer/country=DE debian-installer/locale=en_US.UTF-8 keyboard-configuration/xkb-keymap=us url=http://wget.racing/debian-preseed.txt
}
EOF